Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8064542

JNI_CreateJavaVM can't be used in JRE on mac os x

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 8u25
    • hotspot
    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

      FULL OS VERSION :
      Mac OS X 10.10
      Darwin 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      JNI_CreateJavaVM can't be used in JRE on mac os x to create a JVM.
      (JRE 1.8.0_25 is installed to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/, no Legacy Java 6 is installed)

      I tried 2 approaches.

      With snippet 1,
      The symbol JNI_CreateJavaVM can't be find in libjvm.dll.

      With snippet 2.
      A dialog "To open “this Java application” you need to install the legacy Java SE 6 runtime." is prompted when this line is executed:
      lib_func(&jvm,(void**)&env,&vm_args);





      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Snippet 1:

      #import <Foundation/Foundation.h>
      #include "jni.h"


      static CFBundleRef javaVMBundle = NULL;

      void* findSymbol( void * handle, char * symbol ){
          
          CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, symbol, kCFStringEncodingASCII);
          void *ptr = CFBundleGetFunctionPointerForName(javaVMBundle, string);
          CFRelease(string);
          return ptr;
      }

      static void loadVMBundle( char * bundle ) {
          CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)bundle, strlen(bundle), true);
          javaVMBundle = CFBundleCreate(kCFAllocatorDefault, url);
          CFRelease(url);

      }


      int main(int argc, const char * argv[])
      {
          
          char* library = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/";
          loadVMBundle(library);
          char* symbol = "JNI_CreateJavaVM";
          void* lib_handle = findSymbol(&javaVMBundle, symbol);
          
          if(lib_handle == NULL){
              fprintf(stderr, "Can't find JNI_CreateJavaVM\n");
          }else{
              fprintf(stderr, "Get JNI_CreateJavaVM successfully\n");
          }
          
          return 0;
      }

      Snippet 2:


      #include <iostream>
      #include <dlfcn.h>
      #include "jni.h"


      int main(int argc, const char * argv[])
      {

          JNIEnv *env;
          JavaVM *jvm;
       
          void* lib_handle = 0;
          void* (*lib_func)(JavaVM **, void **, void *) = 0;
          jobjectArray args;
          
          lib_handle = dlopen("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/server/libjvm.dylib", RTLD_NOW);
          
          if (!lib_handle)
          {
              fprintf(stderr, "dlopen failed\n");
              
          }
          

          JavaVMOption options [1];
          memset(options, 0, sizeof(JavaVMOption) * 1);
          options[0].optionString = "-Xdebug";
          
          JavaVMInitArgs vm_args;
          vm_args.version = JNI_VERSION_1_4;
          vm_args.nOptions = 1;
          vm_args.ignoreUnrecognized = JNI_FALSE;
          vm_args.options = options;
          

          
          lib_func = (void*(*)(JavaVM **, void **, void *))dlsym(lib_handle, "JNI_CreateJavaVM");
          lib_func(&jvm,(void**)&env,&vm_args);
          
          jvm = NULL;
          
          

          return 0;
      }

      ---------- END SOURCE ----------

            gziemski Gerard Ziemski
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: