< prev index next >

src/share/vm/prims/jni.cpp

Print this page




  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/jfieldIDWorkaround.hpp"
  67 #include "runtime/orderAccess.inline.hpp"
  68 #include "runtime/reflection.hpp"
  69 #include "runtime/sharedRuntime.hpp"
  70 #include "runtime/signature.hpp"
  71 #include "runtime/thread.inline.hpp"
  72 #include "runtime/vm_operations.hpp"
  73 #include "services/memTracker.hpp"
  74 #include "services/runtimeService.hpp"
  75 #include "trace/tracing.hpp"
  76 #include "utilities/defaultStream.hpp"
  77 #include "utilities/dtrace.hpp"
  78 #include "utilities/events.hpp"
  79 #include "utilities/histogram.hpp"
  80 #include "utilities/macros.hpp"
  81 #if INCLUDE_ALL_GCS
  82 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  83 #endif // INCLUDE_ALL_GCS




  84 
  85 static jint CurrentVersion = JNI_VERSION_1_8;
  86 
  87 #ifdef _WIN32
  88 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
  89 #endif
  90 
  91 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
  92 // '-return' probe regardless of the return path is taken out of the function.
  93 // Methods that have multiple return paths use this to avoid having to
  94 // instrument each return path.  Methods that use CHECK or THROW must use this
  95 // since those macros can cause an immedate uninstrumented return.
  96 //
  97 // In order to get the return value, a reference to the variable containing
  98 // the return value must be passed to the contructor of the object, and
  99 // the return value must be set before return (since the mark object has
 100 // a reference to it).
 101 //
 102 // Example:
 103 // DT_RETURN_MARK_DECL(SomeFunc, int);


3969   /**
3970    * Certain errors during initialization are recoverable and do not
3971    * prevent this method from being called again at a later time
3972    * (perhaps with different arguments).  However, at a certain
3973    * point during initialization if an error occurs we cannot allow
3974    * this function to be called again (or it will crash).  In those
3975    * situations, the 'canTryAgain' flag is set to false, which atomically
3976    * sets safe_to_recreate_vm to 1, such that any new call to
3977    * JNI_CreateJavaVM will immediately fail using the above logic.
3978    */
3979   bool can_try_again = true;
3980 
3981   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
3982   if (result == JNI_OK) {
3983     JavaThread *thread = JavaThread::current();
3984     assert(!thread->has_pending_exception(), "should have returned not OK");
3985     /* thread is thread_in_vm here */
3986     *vm = (JavaVM *)(&main_vm);
3987     *(JNIEnv**)penv = thread->jni_environment();
3988 













3989     // Tracks the time application was running before GC
3990     RuntimeService::record_application_start();
3991 
3992     // Notify JVMTI
3993     if (JvmtiExport::should_post_thread_life()) {
3994        JvmtiExport::post_thread_start(thread);
3995     }
3996 
3997     EventThreadStart event;
3998     if (event.should_commit()) {
3999       event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj()));
4000       event.commit();
4001     }
4002 
4003 #ifndef PRODUCT
4004     // Check if we should compile all classes on bootclasspath
4005     if (CompileTheWorld) ClassLoader::compile_the_world();
4006     if (ReplayCompiles) ciReplay::replay(thread);
4007 
4008     // Some platforms (like Win*) need a wrapper around these test




  64 #include "runtime/java.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/jfieldIDWorkaround.hpp"
  67 #include "runtime/orderAccess.inline.hpp"
  68 #include "runtime/reflection.hpp"
  69 #include "runtime/sharedRuntime.hpp"
  70 #include "runtime/signature.hpp"
  71 #include "runtime/thread.inline.hpp"
  72 #include "runtime/vm_operations.hpp"
  73 #include "services/memTracker.hpp"
  74 #include "services/runtimeService.hpp"
  75 #include "trace/tracing.hpp"
  76 #include "utilities/defaultStream.hpp"
  77 #include "utilities/dtrace.hpp"
  78 #include "utilities/events.hpp"
  79 #include "utilities/histogram.hpp"
  80 #include "utilities/macros.hpp"
  81 #if INCLUDE_ALL_GCS
  82 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  83 #endif // INCLUDE_ALL_GCS
  84 #if INCLUDE_JVMCI
  85 #include "jvmci/jvmciCompiler.hpp"
  86 #include "jvmci/jvmciRuntime.hpp"
  87 #endif
  88 
  89 static jint CurrentVersion = JNI_VERSION_1_8;
  90 
  91 #ifdef _WIN32
  92 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
  93 #endif
  94 
  95 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
  96 // '-return' probe regardless of the return path is taken out of the function.
  97 // Methods that have multiple return paths use this to avoid having to
  98 // instrument each return path.  Methods that use CHECK or THROW must use this
  99 // since those macros can cause an immedate uninstrumented return.
 100 //
 101 // In order to get the return value, a reference to the variable containing
 102 // the return value must be passed to the contructor of the object, and
 103 // the return value must be set before return (since the mark object has
 104 // a reference to it).
 105 //
 106 // Example:
 107 // DT_RETURN_MARK_DECL(SomeFunc, int);


3973   /**
3974    * Certain errors during initialization are recoverable and do not
3975    * prevent this method from being called again at a later time
3976    * (perhaps with different arguments).  However, at a certain
3977    * point during initialization if an error occurs we cannot allow
3978    * this function to be called again (or it will crash).  In those
3979    * situations, the 'canTryAgain' flag is set to false, which atomically
3980    * sets safe_to_recreate_vm to 1, such that any new call to
3981    * JNI_CreateJavaVM will immediately fail using the above logic.
3982    */
3983   bool can_try_again = true;
3984 
3985   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
3986   if (result == JNI_OK) {
3987     JavaThread *thread = JavaThread::current();
3988     assert(!thread->has_pending_exception(), "should have returned not OK");
3989     /* thread is thread_in_vm here */
3990     *vm = (JavaVM *)(&main_vm);
3991     *(JNIEnv**)penv = thread->jni_environment();
3992 
3993 #if INCLUDE_JVMCI
3994     if (EnableJVMCI) {
3995       if (UseJVMCICompiler) {
3996         // JVMCI is initialized on a CompilerThread
3997         if (BootstrapJVMCI) {
3998           JavaThread* THREAD = thread;
3999           JVMCICompiler* compiler = JVMCICompiler::instance(CATCH);
4000           compiler->bootstrap();
4001         }
4002       }
4003     }
4004 #endif
4005 
4006     // Tracks the time application was running before GC
4007     RuntimeService::record_application_start();
4008 
4009     // Notify JVMTI
4010     if (JvmtiExport::should_post_thread_life()) {
4011        JvmtiExport::post_thread_start(thread);
4012     }
4013 
4014     EventThreadStart event;
4015     if (event.should_commit()) {
4016       event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj()));
4017       event.commit();
4018     }
4019 
4020 #ifndef PRODUCT
4021     // Check if we should compile all classes on bootclasspath
4022     if (CompileTheWorld) ClassLoader::compile_the_world();
4023     if (ReplayCompiles) ciReplay::replay(thread);
4024 
4025     // Some platforms (like Win*) need a wrapper around these test


< prev index next >