Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix appendToClassLoaderSearch0 in multi-thread #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jdk/make/lib/ServiceabilityLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ LIBINSTRUMENT_CFLAGS := $(CFLAGS_JDKLIB) \
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/instrument \
-I$(JDK_TOPDIR)/src/share/bin

LIBINSTRUMENT_LDFLAGS :=
LIBINSTRUMENT_LDFLAGS := -pthread
LIBINSTRUMENT_LDFLAGS_SUFFIX :=

ifeq ($(OPENJDK_TARGET_OS), windows)
Expand Down
66 changes: 40 additions & 26 deletions jdk/src/solaris/instrument/EncodingSupport_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <locale.h>
#include <langinfo.h>
#include <iconv.h>
#include <pthread.h>

/* Routines to convert back and forth between Platform Encoding and UTF-8 */

Expand All @@ -43,9 +44,33 @@
#define UTF_ASSERT(x) ( (x)==0 ? UTF_ERROR("ASSERT ERROR " #x) : (void)0 )
#define UTF_DEBUG(x)

/* Global variables */
static iconv_t iconvToPlatform = (iconv_t)-1;
static iconv_t iconvFromPlatform = (iconv_t)-1;
static pthread_key_t iconvToPlatformKey;
static pthread_key_t iconvFromPlatformKey;
static pthread_once_t key_once = PTHREAD_ONCE_INIT;

/*
* Terminate all utf processing
*/
static void
utfTerminate(void *arg)
{
iconv_t iconvCd;
if ((iconvCd = pthread_getspecific(iconvToPlatformKey)) != NULL) {
(void)iconv_close(iconvCd);
pthread_setspecific(iconvToPlatformKey, NULL);
}
if ((iconvCd = pthread_getspecific(iconvFromPlatformKey)) != NULL) {
(void)iconv_close(iconvCd);
pthread_setspecific(iconvFromPlatformKey, NULL);
}
}

static void
make_key()
{
(void) pthread_key_create(&iconvToPlatformKey, utfTerminate);
(void) pthread_key_create(&iconvFromPlatformKey, utfTerminate);
}

/*
* Error handler
Expand Down Expand Up @@ -84,30 +109,16 @@ utfInitialize(void)
}

/* Open conversion descriptors */
iconvToPlatform = iconv_open(codeset, "UTF-8");
iconv_t iconvToPlatform = iconv_open(codeset, "UTF-8");
if ( iconvToPlatform == (iconv_t)-1 ) {
UTF_ERROR("Failed to complete iconv_open() setup");
}
iconvFromPlatform = iconv_open("UTF-8", codeset);
pthread_setspecific(iconvToPlatformKey, iconvToPlatform);
iconv_t iconvFromPlatform = iconv_open("UTF-8", codeset);
if ( iconvFromPlatform == (iconv_t)-1 ) {
UTF_ERROR("Failed to complete iconv_open() setup");
}
}

/*
* Terminate all utf processing
*/
static void
utfTerminate(void)
{
if ( iconvFromPlatform!=(iconv_t)-1 ) {
(void)iconv_close(iconvFromPlatform);
}
if ( iconvToPlatform!=(iconv_t)-1 ) {
(void)iconv_close(iconvToPlatform);
}
iconvToPlatform = (iconv_t)-1;
iconvFromPlatform = (iconv_t)-1;
pthread_setspecific(iconvToPlatformKey, iconvFromPlatform);
}

/*
Expand All @@ -127,7 +138,7 @@ iconvConvert(iconv_t ic, char *bytes, int len, char *output, int outputMaxLen)
output[0] = 0;
outputLen = 0;

if ( ic != (iconv_t)-1 ) {
if ( ic != (iconv_t)-1 && ic != NULL ) {
int returnValue;
size_t inLeft;
size_t outLeft;
Expand Down Expand Up @@ -161,7 +172,7 @@ iconvConvert(iconv_t ic, char *bytes, int len, char *output, int outputMaxLen)
* Returns length or -1 if output overflows.
*/
static int
utf8ToPlatform(char *utf8, int len, char *output, int outputMaxLen)
utf8ToPlatform(iconv_t iconvToPlatform, char *utf8, int len, char *output, int outputMaxLen)
{
return iconvConvert(iconvToPlatform, utf8, len, output, outputMaxLen);
}
Expand All @@ -171,15 +182,18 @@ utf8ToPlatform(char *utf8, int len, char *output, int outputMaxLen)
* Returns length or -1 if output overflows.
*/
static int
platformToUtf8(char *str, int len, char *output, int outputMaxLen)
platformToUtf8(iconv_t iconvFromPlatform, char *str, int len, char *output, int outputMaxLen)
{
return iconvConvert(iconvFromPlatform, str, len, output, outputMaxLen);
}

int
convertUft8ToPlatformString(char* utf8_str, int utf8_len, char* platform_str, int platform_len) {
if (iconvToPlatform == (iconv_t)-1) {
(void) pthread_once(&key_once, make_key);
iconv_t iconvToPlatform;
if ((iconvToPlatform = pthread_getspecific(iconvToPlatformKey)) == NULL) {
utfInitialize();
}
return utf8ToPlatform(utf8_str, utf8_len, platform_str, platform_len);
iconvToPlatform = pthread_getspecific(iconvToPlatformKey);
return utf8ToPlatform(iconvToPlatform, utf8_str, utf8_len, platform_str, platform_len);
}