4123
4124 Thread* t = Thread::current_or_null();
4125 if (t != NULL) {
4126 // If the thread has been attached this operation is a no-op
4127 *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
4128 return JNI_OK;
4129 }
4130
4131 // Create a thread and mark it as attaching so it will be skipped by the
4132 // ThreadsListEnumerator - see CR 6404306
4133 JavaThread* thread = new JavaThread(true);
4134
4135 // Set correct safepoint info. The thread is going to call into Java when
4136 // initializing the Java level thread object. Hence, the correct state must
4137 // be set in order for the Safepoint code to deal with it correctly.
4138 thread->set_thread_state(_thread_in_vm);
4139 thread->record_stack_base_and_size();
4140 thread->initialize_thread_current();
4141
4142 if (!os::create_attached_thread(thread)) {
4143 delete thread;
4144 return JNI_ERR;
4145 }
4146 // Enable stack overflow checks
4147 thread->create_stack_guard_pages();
4148
4149 thread->initialize_tlab();
4150
4151 thread->cache_global_variables();
4152
4153 // Crucial that we do not have a safepoint check for this thread, since it has
4154 // not been added to the Thread list yet.
4155 { Threads_lock->lock_without_safepoint_check();
4156 // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
4157 // avoid this thread trying to do a GC before it is added to the thread-list
4158 thread->set_active_handles(JNIHandleBlock::allocate_block());
4159 Threads::add(thread, daemon);
4160 Threads_lock->unlock();
4161 }
4162 // Create thread group and name info from attach arguments
4163 oop group = NULL;
4254 if (thread->has_last_Java_frame()) {
4255 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4256 // Can't detach a thread that's running java, that can't work.
4257 return JNI_ERR;
4258 }
4259
4260 // Safepoint support. Have to do call-back to safepoint code, if in the
4261 // middel of a safepoint operation
4262 ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4263
4264 // XXX: Note that JavaThread::exit() call below removes the guards on the
4265 // stack pages set up via enable_stack_{red,yellow}_zone() calls
4266 // above in jni_AttachCurrentThread. Unfortunately, while the setting
4267 // of the guards is visible in jni_AttachCurrentThread above,
4268 // the removal of the guards is buried below in JavaThread::exit()
4269 // here. The abstraction should be more symmetrically either exposed
4270 // or hidden (e.g. it could probably be hidden in the same
4271 // (platform-dependent) methods where we do alternate stack
4272 // maintenance work?)
4273 thread->exit(false, JavaThread::jni_detach);
4274 delete thread;
4275
4276 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4277 return JNI_OK;
4278 }
4279
4280 DT_RETURN_MARK_DECL(GetEnv, jint
4281 , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
4282
4283 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
4284 HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
4285 jint ret = JNI_ERR;
4286 DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
4287
4288 if (vm_created == 0) {
4289 *penv = NULL;
4290 ret = JNI_EDETACHED;
4291 return ret;
4292 }
4293
4294 if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
|
4123
4124 Thread* t = Thread::current_or_null();
4125 if (t != NULL) {
4126 // If the thread has been attached this operation is a no-op
4127 *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment();
4128 return JNI_OK;
4129 }
4130
4131 // Create a thread and mark it as attaching so it will be skipped by the
4132 // ThreadsListEnumerator - see CR 6404306
4133 JavaThread* thread = new JavaThread(true);
4134
4135 // Set correct safepoint info. The thread is going to call into Java when
4136 // initializing the Java level thread object. Hence, the correct state must
4137 // be set in order for the Safepoint code to deal with it correctly.
4138 thread->set_thread_state(_thread_in_vm);
4139 thread->record_stack_base_and_size();
4140 thread->initialize_thread_current();
4141
4142 if (!os::create_attached_thread(thread)) {
4143 thread->smr_delete();
4144 return JNI_ERR;
4145 }
4146 // Enable stack overflow checks
4147 thread->create_stack_guard_pages();
4148
4149 thread->initialize_tlab();
4150
4151 thread->cache_global_variables();
4152
4153 // Crucial that we do not have a safepoint check for this thread, since it has
4154 // not been added to the Thread list yet.
4155 { Threads_lock->lock_without_safepoint_check();
4156 // This must be inside this lock in order to get FullGCALot to work properly, i.e., to
4157 // avoid this thread trying to do a GC before it is added to the thread-list
4158 thread->set_active_handles(JNIHandleBlock::allocate_block());
4159 Threads::add(thread, daemon);
4160 Threads_lock->unlock();
4161 }
4162 // Create thread group and name info from attach arguments
4163 oop group = NULL;
4254 if (thread->has_last_Java_frame()) {
4255 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4256 // Can't detach a thread that's running java, that can't work.
4257 return JNI_ERR;
4258 }
4259
4260 // Safepoint support. Have to do call-back to safepoint code, if in the
4261 // middel of a safepoint operation
4262 ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4263
4264 // XXX: Note that JavaThread::exit() call below removes the guards on the
4265 // stack pages set up via enable_stack_{red,yellow}_zone() calls
4266 // above in jni_AttachCurrentThread. Unfortunately, while the setting
4267 // of the guards is visible in jni_AttachCurrentThread above,
4268 // the removal of the guards is buried below in JavaThread::exit()
4269 // here. The abstraction should be more symmetrically either exposed
4270 // or hidden (e.g. it could probably be hidden in the same
4271 // (platform-dependent) methods where we do alternate stack
4272 // maintenance work?)
4273 thread->exit(false, JavaThread::jni_detach);
4274 thread->smr_delete();
4275
4276 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
4277 return JNI_OK;
4278 }
4279
4280 DT_RETURN_MARK_DECL(GetEnv, jint
4281 , HOTSPOT_JNI_GETENV_RETURN(_ret_ref));
4282
4283 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) {
4284 HOTSPOT_JNI_GETENV_ENTRY(vm, penv, version);
4285 jint ret = JNI_ERR;
4286 DT_RETURN_MARK(GetEnv, jint, (const jint&)ret);
4287
4288 if (vm_created == 0) {
4289 *penv = NULL;
4290 ret = JNI_EDETACHED;
4291 return ret;
4292 }
4293
4294 if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) {
|