Skip to content

Commit fddefea

Browse files
committed
mpi/java: Remove dlopen() workaround
* See discussion on Issue #3705 regarding why this is no longer needed. Signed-off-by: Joshua Hursey <[email protected]> (cherry picked from commit 49c40f0) Signed-off-by: Joshua Hursey <[email protected]>
1 parent 913bc8f commit fddefea

File tree

1 file changed

+1
-57
lines changed

1 file changed

+1
-57
lines changed

ompi/mpi/java/c/mpi_MPI.c

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Copyright (c) 2015 Intel, Inc. All rights reserved.
1717
* Copyright (c) 2015 Research Organization for Information Science
1818
* and Technology (RIST). All rights reserved.
19-
* Copyright (c) 2016 IBM Corporation. All rights reserved.
19+
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
2020
* $COPYRIGHT$
2121
*
2222
* Additional copyrights may follow
@@ -87,7 +87,6 @@
8787
ompi_java_globals_t ompi_java = {0};
8888
int ompi_mpi_java_eager = 65536;
8989
opal_free_list_t ompi_java_buffers = {{{0}}};
90-
static void *libmpi = NULL;
9190

9291
static void bufferConstructor(ompi_java_buffer_t *item)
9392
{
@@ -108,71 +107,16 @@ OBJ_CLASS_INSTANCE(ompi_java_buffer_t,
108107
* Class: mpi_MPI
109108
* Method: loadGlobalLibraries
110109
*
111-
* Java implementations typically default to loading dynamic
112-
* libraries strictly to a local namespace. This breaks the
113-
* Open MPI model where components reference back up to the
114-
* base libraries (e.g., libmpi) as it requires that the
115-
* symbols in those base libraries be globally available.
116-
*
117-
* One option, of course, is to build with --disable-dlopen.
118-
* However, this would preclude the ability to pickup 3rd-party
119-
* binary plug-ins at time of execution. This is a valuable
120-
* capability that would be a negative factor towards use of
121-
* the Java bindings.
122-
*
123-
* The other option is to explicitly dlopen libmpi ourselves
124-
* and instruct dlopen to add all those symbols to the global
125-
* namespace. This must be done prior to calling any MPI
126-
* function (e.g., MPI_Init) or else Java will have already
127-
* loaded the library to the local namespace. So create a
128-
* special JNI entry point that just loads the required libmpi
129-
* to the global namespace and call it first (see MPI.java),
130-
* thus making all symbols available to subsequent dlopen calls
131-
* when opening OMPI components.
132110
*/
133111
jint JNI_OnLoad(JavaVM *vm, void *reserved)
134112
{
135113
// Ensure that PSM signal hijacking is disabled *before* loading
136114
// the library (see comment in the function for more detail).
137115
opal_init_psm();
138116

139-
libmpi = dlopen("lib" OMPI_LIBMPI_NAME "." OPAL_DYN_LIB_SUFFIX, RTLD_NOW | RTLD_GLOBAL);
140-
141-
#if defined(HAVE_DL_INFO) && defined(HAVE_LIBGEN_H)
142-
/*
143-
* OS X El Capitan does not propagate DYLD_LIBRARY_PATH to children any more
144-
* so if previous dlopen failed, try to open libmpi in the same directory
145-
* than the current libmpi_java
146-
*/
147-
if(NULL == libmpi) {
148-
Dl_info info;
149-
if(0 != dladdr((void *)JNI_OnLoad, &info)) {
150-
char libmpipath[OPAL_PATH_MAX];
151-
char *libmpijavapath = strdup(info.dli_fname);
152-
if (NULL != libmpijavapath) {
153-
snprintf(libmpipath, OPAL_PATH_MAX-1, "%s/lib" OMPI_LIBMPI_NAME "." OPAL_DYN_LIB_SUFFIX, dirname(libmpijavapath));
154-
free(libmpijavapath);
155-
libmpi = dlopen(libmpipath, RTLD_NOW | RTLD_GLOBAL);
156-
}
157-
}
158-
}
159-
#endif
160-
161-
if(NULL == libmpi)
162-
{
163-
fprintf(stderr, "Java bindings failed to load lib" OMPI_LIBMPI_NAME ": %s\n",dlerror());
164-
exit(1);
165-
}
166-
167117
return JNI_VERSION_1_6;
168118
}
169119

170-
void JNI_OnUnload(JavaVM *vm, void *reserved)
171-
{
172-
if(libmpi != NULL)
173-
dlclose(libmpi);
174-
}
175-
176120
static void initFreeList(void)
177121
{
178122
OBJ_CONSTRUCT(&ompi_java_buffers, opal_free_list_t);

0 commit comments

Comments
 (0)