< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10


4125 
4126   Thread* t = Thread::current_or_null();
4127   if (t != NULL) {
4128     // If the thread has been attached this operation is a no-op
4129     *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
4130     return JNI_OK;
4131   }
4132 
4133   // Create a thread and mark it as attaching so it will be skipped by the
4134   // ThreadsListEnumerator - see CR 6404306
4135   JavaThread* thread = new JavaThread(true);
4136 
4137   // Set correct safepoint info. The thread is going to call into Java when
4138   // initializing the Java level thread object. Hence, the correct state must
4139   // be set in order for the Safepoint code to deal with it correctly.
4140   thread->set_thread_state(_thread_in_vm);
4141   thread->record_stack_base_and_size();
4142   thread->initialize_thread_current();
4143 
4144   if (!os::create_attached_thread(thread)) {
4145     delete thread;
4146     return JNI_ERR;
4147   }
4148   // Enable stack overflow checks
4149   thread->create_stack_guard_pages();
4150 
4151   thread->initialize_tlab();
4152 
4153   thread->cache_global_variables();
4154 
4155   // Crucial that we do not have a safepoint check for this thread, since it has
4156   // not been added to the Thread list yet.
4157   { Threads_lock->lock_without_safepoint_check();
4158     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
4159     // avoid this thread trying to do a GC before it is added to the thread-list
4160     thread->set_active_handles(JNIHandleBlock::allocate_block());
4161     Threads::add(thread, daemon);
4162     Threads_lock->unlock();
4163   }
4164   // Create thread group and name info from attach arguments
4165   oop group = NULL;


4256   if (thread->has_last_Java_frame()) {
4257   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4258     // Can't detach a thread that's running java, that can't work.
4259     return JNI_ERR;
4260   }
4261 
4262   // Safepoint support. Have to do call-back to safepoint code, if in the
4263   // middel of a safepoint operation
4264   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4265 
4266   // XXX: Note that JavaThread::exit() call below removes the guards on the
4267   // stack pages set up via enable_stack_{red,yellow}_zone() calls
4268   // above in jni_AttachCurrentThread. Unfortunately, while the setting
4269   // of the guards is visible in jni_AttachCurrentThread above,
4270   // the removal of the guards is buried below in JavaThread::exit()
4271   // here. The abstraction should be more symmetrically either exposed
4272   // or hidden (e.g. it could probably be hidden in the same
4273   // (platform-dependent) methods where we do alternate stack
4274   // maintenance work?)
4275   thread->exit(false, JavaThread::jni_detach);
4276   delete thread;
4277 
4278   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4279   return JNI_OK;
4280 }
4281 
4282 DT_RETURN_MARK_DECL(GetEnv, jint
4283                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
4284 
4285 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
4286   HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
4287   jint ret = JNI_ERR;
4288   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
4289 
4290   if (!vm_created) {
4291     *penv = NULL;
4292     ret = JNI_EDETACHED;
4293     return ret;
4294   }
4295 
4296   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {




4125 
4126   Thread* t = Thread::current_or_null();
4127   if (t != NULL) {
4128     // If the thread has been attached this operation is a no-op
4129     *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
4130     return JNI_OK;
4131   }
4132 
4133   // Create a thread and mark it as attaching so it will be skipped by the
4134   // ThreadsListEnumerator - see CR 6404306
4135   JavaThread* thread = new JavaThread(true);
4136 
4137   // Set correct safepoint info. The thread is going to call into Java when
4138   // initializing the Java level thread object. Hence, the correct state must
4139   // be set in order for the Safepoint code to deal with it correctly.
4140   thread->set_thread_state(_thread_in_vm);
4141   thread->record_stack_base_and_size();
4142   thread->initialize_thread_current();
4143 
4144   if (!os::create_attached_thread(thread)) {
4145     thread->smr_delete();
4146     return JNI_ERR;
4147   }
4148   // Enable stack overflow checks
4149   thread->create_stack_guard_pages();
4150 
4151   thread->initialize_tlab();
4152 
4153   thread->cache_global_variables();
4154 
4155   // Crucial that we do not have a safepoint check for this thread, since it has
4156   // not been added to the Thread list yet.
4157   { Threads_lock->lock_without_safepoint_check();
4158     // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
4159     // avoid this thread trying to do a GC before it is added to the thread-list
4160     thread->set_active_handles(JNIHandleBlock::allocate_block());
4161     Threads::add(thread, daemon);
4162     Threads_lock->unlock();
4163   }
4164   // Create thread group and name info from attach arguments
4165   oop group = NULL;


4256   if (thread->has_last_Java_frame()) {
4257   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4258     // Can't detach a thread that's running java, that can't work.
4259     return JNI_ERR;
4260   }
4261 
4262   // Safepoint support. Have to do call-back to safepoint code, if in the
4263   // middel of a safepoint operation
4264   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4265 
4266   // XXX: Note that JavaThread::exit() call below removes the guards on the
4267   // stack pages set up via enable_stack_{red,yellow}_zone() calls
4268   // above in jni_AttachCurrentThread. Unfortunately, while the setting
4269   // of the guards is visible in jni_AttachCurrentThread above,
4270   // the removal of the guards is buried below in JavaThread::exit()
4271   // here. The abstraction should be more symmetrically either exposed
4272   // or hidden (e.g. it could probably be hidden in the same
4273   // (platform-dependent) methods where we do alternate stack
4274   // maintenance work?)
4275   thread->exit(false, JavaThread::jni_detach);
4276   thread->smr_delete();
4277 
4278   HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4279   return JNI_OK;
4280 }
4281 
4282 DT_RETURN_MARK_DECL(GetEnv, jint
4283                     , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
4284 
4285 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
4286   HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
4287   jint ret = JNI_ERR;
4288   DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
4289 
4290   if (!vm_created) {
4291     *penv = NULL;
4292     ret = JNI_EDETACHED;
4293     return ret;
4294   }
4295 
4296   if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {


< prev index next >