Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#11568 from JasonFengJ9/jdk17winv24
Browse files Browse the repository at this point in the history
(v0.24.0-release) JDK15+ JVM_LoadLibrary convert libName for Windows platform
  • Loading branch information
pshipton authored Jan 5, 2021
2 parents 5a8928f + d4c34cb commit d7c0c54
Showing 1 changed file with 54 additions and 28 deletions.
82 changes: 54 additions & 28 deletions runtime/j9vm/jvm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2020 IBM Corp. and others
* Copyright (c) 2002, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -3639,14 +3639,16 @@ JVM_LoadSystemLibrary(const char *libName)
* successful, returns the file handle, otherwise returns NULL.
*
* @param libName a null terminated string containing the libName.
* For Windows platform, this incoming libName is encoded as J9STR_CODE_WINDEFAULTACP,
* and is required to be converted to J9STR_CODE_MUTF8 for internal usages.
*
* @return the shared library's handle if successful, throws java/lang/UnsatisfiedLinkError on failure
*
* DLL: jvm
*/

/* NOTE this is required by JDK15+ jdk.internal.loader.NativeLibraries.load().
* it is only invoked by jdk.internal.loader.BootLoader.loadLibrary(),
* it is only invoked by jdk.internal.loader.BootLoader.loadLibrary().
*/

void* JNICALL
Expand All @@ -3655,35 +3657,59 @@ JVM_LoadLibrary(const char *libName)
void *result = NULL;
J9JavaVM *javaVM = (J9JavaVM*)BFUjavaVM;

Trc_SC_LoadLibrary_Entry(libName);
if (NULL == javaVM->applicationClassLoader) {
J9NativeLibrary *nativeLibrary = NULL;
J9InternalVMFunctions *vmFuncs = javaVM->internalVMFunctions;
J9VMThread *currentThread = vmFuncs->currentVMThread(javaVM);
Assert_SC_notNull(currentThread);
vmFuncs->internalEnterVMFromJNI(currentThread);
vmFuncs->internalReleaseVMAccess(currentThread);
if (vmFuncs->registerBootstrapLibrary(currentThread, libName, &nativeLibrary, FALSE) == J9NATIVELIB_LOAD_OK) {
result = (void*)nativeLibrary->handle;
}
vmFuncs->internalAcquireVMAccess(currentThread);
vmFuncs->internalExitVMToJNI(currentThread);
Trc_SC_LoadLibrary_BootStrap(libName);
} else {
PORT_ACCESS_FROM_JAVAVM(javaVM);
UDATA handle = 0;
UDATA flags = 0;
UDATA slOpenResult = j9sl_open_shared_library((char *)libName, &handle, flags);

Trc_SC_LoadLibrary_OpenShared(libName);
if (0 != slOpenResult) {
slOpenResult = j9sl_open_shared_library((char *)libName, &handle, flags | J9PORT_SLOPEN_DECORATE);
Trc_SC_LoadLibrary_OpenShared_Decorate(libName);
#if defined(WIN32)
char *libNameConverted = NULL;
UDATA libNameLen = strlen(libName);
PORT_ACCESS_FROM_JAVAVM(javaVM);
UDATA libNameLenConverted = j9str_convert(J9STR_CODE_WINDEFAULTACP, J9STR_CODE_MUTF8, libName, libNameLen, NULL, 0);
if (libNameLenConverted > 0) {
libNameLenConverted += 1; /* adding an extra byte for null */
libNameConverted = j9mem_allocate_memory(libNameLenConverted, OMRMEM_CATEGORY_VM);
if (NULL != libNameConverted) {
libNameLenConverted = j9str_convert(J9STR_CODE_WINDEFAULTACP, J9STR_CODE_MUTF8, libName, libNameLen, libNameConverted, libNameLenConverted);
if (libNameLenConverted > 0) {
/* j9str_convert null-terminated the string */
libName = libNameConverted;
}
}
if (0 == slOpenResult) {
result = (void*)handle;
}
if (libName == libNameConverted) {
#endif /* defined(WIN32) */
Trc_SC_LoadLibrary_Entry(libName);
if (NULL == javaVM->applicationClassLoader) {
J9NativeLibrary *nativeLibrary = NULL;
J9InternalVMFunctions *vmFuncs = javaVM->internalVMFunctions;
J9VMThread *currentThread = vmFuncs->currentVMThread(javaVM);
Assert_SC_notNull(currentThread);
vmFuncs->internalEnterVMFromJNI(currentThread);
vmFuncs->internalReleaseVMAccess(currentThread);
if (vmFuncs->registerBootstrapLibrary(currentThread, libName, &nativeLibrary, FALSE) == J9NATIVELIB_LOAD_OK) {
result = (void*)nativeLibrary->handle;
}
vmFuncs->internalAcquireVMAccess(currentThread);
vmFuncs->internalExitVMToJNI(currentThread);
Trc_SC_LoadLibrary_BootStrap(libName);
} else {
PORT_ACCESS_FROM_JAVAVM(javaVM);
UDATA handle = 0;
UDATA flags = 0;
UDATA slOpenResult = j9sl_open_shared_library((char *)libName, &handle, flags);

Trc_SC_LoadLibrary_OpenShared(libName);
if (0 != slOpenResult) {
slOpenResult = j9sl_open_shared_library((char *)libName, &handle, flags | J9PORT_SLOPEN_DECORATE);
Trc_SC_LoadLibrary_OpenShared_Decorate(libName);
}
if (0 == slOpenResult) {
result = (void*)handle;
}
}
#if defined(WIN32)
}
if (NULL != libNameConverted) {
j9mem_free_memory(libNameConverted);
}
#endif /* defined(WIN32) */
Trc_SC_LoadLibrary_Exit(result);

return result;
Expand Down

0 comments on commit d7c0c54

Please sign in to comment.