< prev index next >

src/share/vm/prims/jni.cpp

Print this page
rev 8910 : full patch for jfr
   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012 Red Hat, Inc.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


5222    */
5223   bool can_try_again = true;
5224 
5225   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
5226   if (result == JNI_OK) {
5227     JavaThread *thread = JavaThread::current();
5228     /* thread is thread_in_vm here */
5229     *vm = (JavaVM *)(&main_vm);
5230     *(JNIEnv**)penv = thread->jni_environment();
5231 
5232     // Tracks the time application was running before GC
5233     RuntimeService::record_application_start();
5234 
5235     // Notify JVMTI
5236     if (JvmtiExport::should_post_thread_life()) {
5237        JvmtiExport::post_thread_start(thread);
5238     }
5239 
5240     EventThreadStart event;
5241     if (event.should_commit()) {
5242       event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj()));
5243       event.commit();
5244     }
5245 
5246 #ifndef PRODUCT
5247   #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
5248     #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
5249   #endif
5250 
5251     // Check if we should compile all classes on bootclasspath
5252     if (CompileTheWorld) ClassLoader::compile_the_world();
5253     if (ReplayCompiles) ciReplay::replay(thread);
5254 
5255     // Some platforms (like Win*) need a wrapper around these test
5256     // functions in order to properly handle error conditions.
5257     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler);
5258     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests);
5259 #endif
5260 
5261     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
5262     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);


5437     thread->cleanup_failed_attach_current_thread();
5438     return JNI_ERR;
5439   }
5440 
5441   // mark the thread as no longer attaching
5442   // this uses a fence to push the change through so we don't have
5443   // to regrab the threads_lock
5444   thread->set_done_attaching_via_jni();
5445 
5446   // Set java thread status.
5447   java_lang_Thread::set_thread_status(thread->threadObj(),
5448               java_lang_Thread::RUNNABLE);
5449 
5450   // Notify the debugger
5451   if (JvmtiExport::should_post_thread_life()) {
5452     JvmtiExport::post_thread_start(thread);
5453   }
5454 
5455   EventThreadStart event;
5456   if (event.should_commit()) {
5457     event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj()));
5458     event.commit();
5459   }
5460 
5461   *(JNIEnv**)penv = thread->jni_environment();
5462 
5463   // Now leaving the VM, so change thread_state. This is normally automatically taken care
5464   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
5465   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
5466   // needed.
5467 
5468   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5469 
5470   // Perform any platform dependent FPU setup
5471   os::setup_fpu();
5472 
5473   return JNI_OK;
5474 }
5475 
5476 
5477 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012 Red Hat, Inc.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


5222    */
5223   bool can_try_again = true;
5224 
5225   result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again);
5226   if (result == JNI_OK) {
5227     JavaThread *thread = JavaThread::current();
5228     /* thread is thread_in_vm here */
5229     *vm = (JavaVM *)(&main_vm);
5230     *(JNIEnv**)penv = thread->jni_environment();
5231 
5232     // Tracks the time application was running before GC
5233     RuntimeService::record_application_start();
5234 
5235     // Notify JVMTI
5236     if (JvmtiExport::should_post_thread_life()) {
5237        JvmtiExport::post_thread_start(thread);
5238     }
5239 
5240     EventThreadStart event;
5241     if (event.should_commit()) {
5242       event.set_thread(THREAD_TRACE_ID(thread));
5243       event.commit();
5244     }
5245 
5246 #ifndef PRODUCT
5247   #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
5248     #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
5249   #endif
5250 
5251     // Check if we should compile all classes on bootclasspath
5252     if (CompileTheWorld) ClassLoader::compile_the_world();
5253     if (ReplayCompiles) ciReplay::replay(thread);
5254 
5255     // Some platforms (like Win*) need a wrapper around these test
5256     // functions in order to properly handle error conditions.
5257     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler);
5258     CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests);
5259 #endif
5260 
5261     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
5262     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);


5437     thread->cleanup_failed_attach_current_thread();
5438     return JNI_ERR;
5439   }
5440 
5441   // mark the thread as no longer attaching
5442   // this uses a fence to push the change through so we don't have
5443   // to regrab the threads_lock
5444   thread->set_done_attaching_via_jni();
5445 
5446   // Set java thread status.
5447   java_lang_Thread::set_thread_status(thread->threadObj(),
5448               java_lang_Thread::RUNNABLE);
5449 
5450   // Notify the debugger
5451   if (JvmtiExport::should_post_thread_life()) {
5452     JvmtiExport::post_thread_start(thread);
5453   }
5454 
5455   EventThreadStart event;
5456   if (event.should_commit()) {
5457     event.set_thread(THREAD_TRACE_ID(thread));
5458     event.commit();
5459   }
5460 
5461   *(JNIEnv**)penv = thread->jni_environment();
5462 
5463   // Now leaving the VM, so change thread_state. This is normally automatically taken care
5464   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
5465   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
5466   // needed.
5467 
5468   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
5469 
5470   // Perform any platform dependent FPU setup
5471   os::setup_fpu();
5472 
5473   return JNI_OK;
5474 }
5475 
5476 
5477 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {


< prev index next >