src/app/jdk/lib/jvm/os_genode.cpp
// Find the full path to the current module, libjvm
Find the full path to the current module, libjvm
Find the full path to the current module libjvm
void os::jvm_path(char *buf, jint buflen) {
  if (buflen < MAXPATHLEN) {
    assert(false, "must use a large-enough buffer");
    buf[0] = '\0';
    return;
  }
  if (saved_jvm_path[0] != 0) {
    strcpy(buf, saved_jvm_path);
    return;
  }
  char dli_fname[MAXPATHLEN];
  bool ret = dll_address_to_library_name(
                                         CAST_FROM_FN_PTR(address, os::jvm_path),
                                         dli_fname, sizeof(dli_fname), NULL);
  assert(ret, "cannot locate libjvm");
  char *rp = NULL;
  if (ret && dli_fname[0] != '\0') {
    rp = realpath(dli_fname, buf);
  }
  if (rp == NULL) {
    return;
  }
  if (Arguments::sun_java_launcher_is_altjvm()) {
    const char *p = buf + strlen(buf) - 1;
    for (int count = 0; p > buf && count < 5; ++count) {
      for (--p; p > buf && *p != '/'; --p)
         ;
    }
    if (strncmp(p, "/jre/lib/", 9) != 0) {
      char* java_home_var = ::getenv("JAVA_HOME");
      if (java_home_var != NULL && java_home_var[0] != 0) {
        char* jrelib_p;
        int len;
        p = strrchr(buf, '/');
        assert(strstr(p, "/libjvm") == p, "invalid library name");
        rp = realpath(java_home_var, buf);
        if (rp == NULL) {
          return;
        }
        len = strlen(buf);
        assert(len < buflen, "Ran out of buffer space");
        jrelib_p = buf + len;
        snprintf(jrelib_p, buflen-len, "/jre/lib");
        if (0 != access(buf, F_OK)) {
          snprintf(jrelib_p, buflen-len, "/lib");
        }
        len = strlen(buf);
        jrelib_p = buf + len;
        snprintf(jrelib_p, buflen-len, "/%s", COMPILER_VARIANT);
        if (0 != access(buf, F_OK)) {
          snprintf(jrelib_p, buflen-len, "%s", "");
        }
        if (0 == access(buf, F_OK)) {
          len = strlen(buf);
          snprintf(buf + len, buflen-len, "/libjvm%s", JNI_LIB_SUFFIX);
        } else {
          rp = realpath(dli_fname, buf);
          if (rp == NULL) {
            return;
          }
        }
      }
    }
  }
  strncpy(saved_jvm_path, buf, MAXPATHLEN);
  saved_jvm_path[MAXPATHLEN - 1] = '\0';
}
void os :: jvm_path ( char * buf , jint buflen ) { if ( buflen < MAXPATHLEN ) { assert ( false , " " ) ; buf [ 0 ] = ' \0 ' ; return ; } if ( saved_jvm_path [ 0 ] != 0 ) { strcpy ( buf , saved_jvm_path ) ; return ; } char dli_fname [ MAXPATHLEN ] ; bool ret = dll_address_to_library_name ( CAST_FROM_FN_PTR ( address , os :: jvm_path ) , dli_fname , sizeof ( dli_fname ) , NULL ) ; assert ( ret , " " ) ; char * rp = NULL ; if ( ret && dli_fname [ 0 ] != ' \0 ' ) { rp = realpath ( dli_fname , buf ) ; } if ( rp == NULL ) { return ; } if ( Arguments :: sun_java_launcher_is_altjvm ( ) ) { const char * p = buf + strlen ( buf ) - 1 ; for ( int count = 0 ; p > buf && count < 5 ; ++ count ) { for ( -- p ; p > buf && * p != ' ' ; -- p ) ; } if ( strncmp ( p , " " , 9 ) != 0 ) { char * java_home_var = :: getenv ( " " ) ; if ( java_home_var != NULL && java_home_var [ 0 ] != 0 ) { char * jrelib_p ; int len ; p = strrchr ( buf , ' ' ) ; assert ( strstr ( p , " " ) == p , " " ) ; rp = realpath ( java_home_var , buf ) ; if ( rp == NULL ) { return ; } len = strlen ( buf ) ; assert ( len < buflen , " " ) ; jrelib_p = buf + len ; snprintf ( jrelib_p , buflen - len , " " ) ; if ( 0 != access ( buf , F_OK ) ) { snprintf ( jrelib_p , buflen - len , " " ) ; } len = strlen ( buf ) ; jrelib_p = buf + len ; snprintf ( jrelib_p , buflen - len , " " , COMPILER_VARIANT ) ; if ( 0 != access ( buf , F_OK ) ) { snprintf ( jrelib_p , buflen - len , " " , " " ) ; } if ( 0 == access ( buf , F_OK ) ) { len = strlen ( buf ) ; snprintf ( buf + len , buflen - len , " " , JNI_LIB_SUFFIX ) ; } else { rp = realpath ( dli_fname , buf ) ; if ( rp == NULL ) { return ; } } } } } strncpy ( saved_jvm_path , buf , MAXPATHLEN ) ; saved_jvm_path [ MAXPATHLEN - 1 ] = ' \0 ' ; }
Find the full path to the current module, libjvm
Find the full path to the current module libjvm
// Error checking. // Lazy resolve the path to current module. // Support for the java launcher's '-XXaltjvm=<path>' option. Typical // value for buf is "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so" // or "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.dylib". If "/jre/lib/" // appears at the right place in the string, then assume we are // installed in a JDK and we're done. Otherwise, check for a // JAVA_HOME environment variable and construct a path to the JVM // being overridden. /* empty */ // Look for JAVA_HOME in the environment. // Check the current module name "libjvm" // determine if this is a legacy image or modules image // modules image doesn't have "jre" subdirectory // Add the appropriate library subdir // Add the appropriate client or server subdir // If the path exists within JAVA_HOME, add the JVM library name // to complete the path to JVM being overridden.  Otherwise fallback // to the path to the current library. // Use current module name "libjvm" // Fall back to path of current library