Skip to content

Commit

Permalink
Enable DEBUG and prepend default libjvm directory to DYLD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Feb 23, 2022
1 parent a245e34 commit 34c6612
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions runtime/redirector/redirector.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ static void chooseJVM(JavaVMInitArgs *args, char *retBuffer, size_t bufferLength
static void addToLibpath(const char *dir);
static J9StringBuffer *findDir(const char *libraryDir);

#if defined(OSX)
static void addToDyldLibraryPath(const char *dir, BOOLEAN isPrepend);
#endif /* defined(OSX) */

static J9StringBuffer* jvmBufferCat(J9StringBuffer* buffer, const char* string);
static J9StringBuffer* jvmBufferEnsure(J9StringBuffer* buffer, UDATA len);
static char* jvmBufferData(J9StringBuffer* buffer);
Expand All @@ -156,6 +160,8 @@ static BOOLEAN parseGCPolicy(char *buffer, int *value);

#define XMX "-Xmx"

#define DEBUG

/* We use forward slashes here because J9VM_LIB_ARCH_DIR is not used on Windows. */
#if (JAVA_SPEC_VERSION >= 9) || defined(OSX)
/* On OSX, <arch> doesn't exist, so OPENJ9_ARCH_DIR shouldn't be included in J9VM_LIB_ARCH_DIR. */
Expand Down Expand Up @@ -208,6 +214,50 @@ removeSuffix(char *string, const char *suffix)
}
#endif /* (JAVA_SPEC_VERSION == 8) || defined(AIXPPC) */

#if defined(OSX)
static void
addToDyldLibraryPath(const char *dir, BOOLEAN isPrepend)
{
char *oldPath = NULL;
char *newPath = NULL;
int rc = 0;
int newSize = 0;

oldPath = getenv("DYLD_LIBRARY_PATH");
#if defined(DEBUG)
printf("\nDYLD_LIBRARY_PATH before = %s\n", oldPath ? oldPath : "<empty>");
#endif /* defined(DEBUG) */
newSize = (oldPath ? strlen(oldPath) : 0) + strlen(dir) + 2; /* 1 for :, 1 for \0 terminator */
newPath = malloc(newSize);

if(NULL == newPath) {
fprintf(stderr, "addToDyldLibraryPath malloc(%d) 1 failed, aborting\n", newSize);
abort();
}

if (NULL != oldPath) {
if (isPrepend) {
strcpy(newPath, dir);
strcat(newPath, ":");
strcat(newPath, oldPath);
} else {
strcpy(newPath, oldPath);
strcat(newPath, ":");
strcat(newPath, dir);
}
} else {
strcpy(newPath, dir);
}

rc = setenv("DYLD_LIBRARY_PATH", newPath, 1);

#if defined(DEBUG)
printf("\nDYLD_LIBRARY_PATH after = %s\n", getenv("DYLD_LIBRARY_PATH"));
#endif /* defined(DEBUG) */
free(newPath);
}
#endif /* defined(OSX) */

static void
addToLibpath(const char *dir)
{
Expand Down Expand Up @@ -1142,7 +1192,11 @@ openLibraries(const char *libraryDir)
return JNI_ERR;
}
#else /* WIN32 */
#if defined(OSX)
addToDyldLibraryPath(jvmBufferData(buffer), TRUE);
#endif /* defined(OSX) */
buffer = jvmBufferCat(buffer, "/libjvm" J9PORT_LIBRARY_SUFFIX);
DBG_MSG(("trying %s\n", jvmBufferData(buffer)));
/* open the DLL and look up the symbols */
#if defined(AIXPPC)
/* CMVC 137341:
Expand Down

0 comments on commit 34c6612

Please sign in to comment.