Search code examples
javac++jvmjava-native-interface

Using jvm.h from JNI


At the moment I am using the libraries within JAVA_HOME/include in my JNI application. This consists of

  • classfile_constants.h
  • jawt.h
  • jdwpTransport.h
  • jni.h
  • jvmti.h
  • jvmticmlr.h
  • windows/jawt_md.h
  • windows/jni_md.h
  • windows/bridge/AccessBridgeCallbacks.h
  • windows/bridge/AccessBridgeCalls.c
  • windows/bridge/AccessBridgeCalls.h
  • windows/bridge/AccessBridgePackages.h

While these offer me a lot of control, I really want to be able to call the actual C++ functions defined in hotspot source code. I looked at the JDK 8 source code and found that src/share/javavm/export contained lots more header files, such as jvm.h with much more powerful functions.

I tried including these in my project but I get a unresolved external symbol error, likely because these header files dont contain the actual function definitions.

How can I use these kind of functions in my JNI code base? Is it even possible?

Thank you in advance!


Solution

  • Functions declared in jvm.h are for internal JDK use only. They are not supposed to be called from user code. They are not a part of any public API, and they can change in any (even minor) JDK update.

    It is possible to call these functions, either by linking your binary against libjvm, or by using dynamic lookup, i.e. dlopen / dlsym, but the use of undocumented API is highly discouraged and makes you JNI code not portable between different JDK versions and/or builds.