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

JNI_CreateJavaVM crashing when debugging in VS2017

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 64 bit - Build 16299.rs3_release.170928-1534
      JDK 10.0.1
      Visual Studio 2017 15.6.6


      A DESCRIPTION OF THE PROBLEM :
      Having just migrated an application from VM2013 to VS2017 which uses JNI we experienced not previously seen errors when debugging the JNI code. Migration of application has been discounted as a factor as have reproduced this using standalone C++ program.

      Simply call JNI_CreateJavVM and you will get a "Frame not in module" when you step over the call to JNI.

      Issue appears to replicate with JDKs 8,9,10


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and link source below. Run in VS2017 debugger with additional command line java/util/Map

      Put a break point on the line with JNI_CreateJavaVM, stop at BP and then step over line;

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Step action works correctly no errors reported by VS2017
      ACTUAL -
       VS2017 reports "Frame not in module" ; execute may continue if you press Continue button more often it fails to continue

      ---------- BEGIN SOURCE ----------
      #include <windows.h>
      #include <jni.h>

      int main(int argc, char **argv)
      {
      JavaVMOption options[1];
      JNIEnv *env;
      JavaVM *jvm;
      JavaVMInitArgs vm_args;
      jint status;
      jclass cls;

      options[0].optionString = (char *) "-Djava.class.path=.";
      memset(&vm_args, 0, sizeof(vm_args));
      vm_args.version = JNI_VERSION_1_6;
      vm_args.nOptions = 1;
      vm_args.options = options;

      status = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
      printf("JNI_CreateJavaVM returned %x\n", status);

      if (status != JNI_ERR)
      {
      if (argc > 1) {
      for (int arg = 1; arg < argc; arg++) {
      char *className = argv[arg];
      cls = env->FindClass(className);
      if (cls != 0)
      {
      printf("Found [%s]\n",className);
      }
      else {
      printf("Failed to find [%s]\n", className);
      }

      }
      }

      jvm->DestroyJavaVM();
      return 0;
      }
      else
      return -1;
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None available. Makes it pretty difficult to debug code utilising JNI.

      FREQUENCY : always


            fmatte Fairoz Matte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: