< prev index next >

src/hotspot/share/prims/jni.cpp

Print this page




2938     if (method == NULL) {
2939       continue; // signature doesn't match, try the next prefix
2940     }
2941     if (method->is_native()) {
2942       method->set_is_prefixed_native();
2943       return method; // wahoo, we found a prefixed version of the method, return it
2944     }
2945     // found as non-native, so prefix is good, add it, probably just need more prefixes
2946     name_len = trial_len;
2947     name_str = trial_name_str;
2948   }
2949 #endif // INCLUDE_JVMTI
2950   return NULL; // not found
2951 }
2952 
2953 static bool register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
2954   Method* method = k->lookup_method(name, signature);
2955   if (method == NULL) {
2956     ResourceMark rm;
2957     stringStream st;
2958     st.print("Method '");
2959     Method::print_external_name(&st, k, name, signature);
2960     st.print("' name or signature does not match");
2961     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2962   }
2963   if (!method->is_native()) {
2964     // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
2965     method = find_prefixed_native(k, name, signature, THREAD);
2966     if (method == NULL) {
2967       ResourceMark rm;
2968       stringStream st;
2969       st.print("Method '");
2970       Method::print_external_name(&st, k, name, signature);
2971       st.print("' is not declared as native");
2972       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2973     }
2974   }
2975 
2976   if (entry != NULL) {
2977     method->set_native_function(entry,
2978       Method::native_bind_event_is_interesting);
2979   } else {
2980     method->clear_native_function();
2981   }
2982   if (PrintJNIResolving) {
2983     ResourceMark rm(THREAD);
2984     tty->print_cr("[Registering JNI native method %s.%s]",
2985       method->method_holder()->external_name(),
2986       method->name()->as_C_string());
2987   }
2988   return true;
2989 }
2990 
2991 DT_RETURN_MARK_DECL(RegisterNatives, jint


3954       }
3955     }
3956 #endif
3957 
3958     // Notify JVMTI
3959     if (JvmtiExport::should_post_thread_life()) {
3960        JvmtiExport::post_thread_start(thread);
3961     }
3962 
3963     post_thread_start_event(thread);
3964 
3965 #ifndef PRODUCT
3966     if (ReplayCompiles) ciReplay::replay(thread);
3967 
3968     // Some platforms (like Win*) need a wrapper around these test
3969     // functions in order to properly handle error conditions.
3970     VMError::test_error_handler();
3971 #endif
3972 
3973     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
3974     ThreadStateTransition::transition(thread, _thread_in_vm, _thread_in_native);
3975   } else {
3976     // If create_vm exits because of a pending exception, exit with that
3977     // exception.  In the future when we figure out how to reclaim memory,
3978     // we may be able to exit with JNI_ERR and allow the calling application
3979     // to continue.
3980     if (Universe::is_fully_initialized()) {
3981       // otherwise no pending exception possible - VM will already have aborted
3982       JavaThread* THREAD = JavaThread::current();
3983       if (HAS_PENDING_EXCEPTION) {
3984         HandleMark hm;
3985         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3986       }
3987     }
3988 
3989     if (can_try_again) {
3990       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3991       safe_to_recreate_vm = 1;
3992     }
3993 
3994     // Creation failed. We must reset vm_created


4056   JNIWrapper("DestroyJavaVM");
4057   JNIEnv *env;
4058   JavaVMAttachArgs destroyargs;
4059   destroyargs.version = CurrentVersion;
4060   destroyargs.name = (char *)"DestroyJavaVM";
4061   destroyargs.group = NULL;
4062   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
4063   if (res != JNI_OK) {
4064     return res;
4065   }
4066 
4067   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
4068   JavaThread* thread = JavaThread::current();
4069   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4070   if (Threads::destroy_vm()) {
4071     // Should not change thread state, VM is gone
4072     vm_created = 0;
4073     res = JNI_OK;
4074     return res;
4075   } else {
4076     ThreadStateTransition::transition(thread, _thread_in_vm, _thread_in_native);
4077     res = JNI_ERR;
4078     return res;
4079   }
4080 }
4081 
4082 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
4083   jint result = JNI_ERR;
4084   // On Windows, we need SEH protection
4085 #ifdef _WIN32
4086   __try {
4087 #endif
4088     result = jni_DestroyJavaVM_inner(vm);
4089 #ifdef _WIN32
4090   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
4091     // Nothing to do.
4092   }
4093 #endif
4094   return result;
4095 }
4096 


4178   thread->set_done_attaching_via_jni();
4179 
4180   // Set java thread status.
4181   java_lang_Thread::set_thread_status(thread->threadObj(),
4182               java_lang_Thread::RUNNABLE);
4183 
4184   // Notify the debugger
4185   if (JvmtiExport::should_post_thread_life()) {
4186     JvmtiExport::post_thread_start(thread);
4187   }
4188 
4189   post_thread_start_event(thread);
4190 
4191   *(JNIEnv**)penv = thread->jni_environment();
4192 
4193   // Now leaving the VM, so change thread_state. This is normally automatically taken care
4194   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
4195   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
4196   // needed.
4197 
4198   ThreadStateTransition::transition(thread, _thread_in_vm, _thread_in_native);
4199 
4200   // Perform any platform dependent FPU setup
4201   os::setup_fpu();
4202 
4203   return JNI_OK;
4204 }
4205 
4206 
4207 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
4208   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(vm, penv, _args);
4209   if (vm_created == 0) {
4210   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4211     return JNI_ERR;
4212   }
4213 
4214   JNIWrapper("AttachCurrentThread");
4215   jint ret = attach_current_thread(vm, penv, _args, false);
4216   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(ret);
4217   return ret;
4218 }




2938     if (method == NULL) {
2939       continue; // signature doesn't match, try the next prefix
2940     }
2941     if (method->is_native()) {
2942       method->set_is_prefixed_native();
2943       return method; // wahoo, we found a prefixed version of the method, return it
2944     }
2945     // found as non-native, so prefix is good, add it, probably just need more prefixes
2946     name_len = trial_len;
2947     name_str = trial_name_str;
2948   }
2949 #endif // INCLUDE_JVMTI
2950   return NULL; // not found
2951 }
2952 
2953 static bool register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
2954   Method* method = k->lookup_method(name, signature);
2955   if (method == NULL) {
2956     ResourceMark rm;
2957     stringStream st;
2958     st.print("Method %s name or signature does not match",
2959              Method::name_and_sig_as_C_string(k, name, signature));

2960     THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2961   }
2962   if (!method->is_native()) {
2963     // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
2964     method = find_prefixed_native(k, name, signature, THREAD);
2965     if (method == NULL) {
2966       ResourceMark rm;
2967       stringStream st;
2968       st.print("Method %s is not declared as native",
2969                Method::name_and_sig_as_C_string(k, name, signature));

2970       THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2971     }
2972   }
2973 
2974   if (entry != NULL) {
2975     method->set_native_function(entry,
2976       Method::native_bind_event_is_interesting);
2977   } else {
2978     method->clear_native_function();
2979   }
2980   if (PrintJNIResolving) {
2981     ResourceMark rm(THREAD);
2982     tty->print_cr("[Registering JNI native method %s.%s]",
2983       method->method_holder()->external_name(),
2984       method->name()->as_C_string());
2985   }
2986   return true;
2987 }
2988 
2989 DT_RETURN_MARK_DECL(RegisterNatives, jint


3952       }
3953     }
3954 #endif
3955 
3956     // Notify JVMTI
3957     if (JvmtiExport::should_post_thread_life()) {
3958        JvmtiExport::post_thread_start(thread);
3959     }
3960 
3961     post_thread_start_event(thread);
3962 
3963 #ifndef PRODUCT
3964     if (ReplayCompiles) ciReplay::replay(thread);
3965 
3966     // Some platforms (like Win*) need a wrapper around these test
3967     // functions in order to properly handle error conditions.
3968     VMError::test_error_handler();
3969 #endif
3970 
3971     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
3972     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
3973   } else {
3974     // If create_vm exits because of a pending exception, exit with that
3975     // exception.  In the future when we figure out how to reclaim memory,
3976     // we may be able to exit with JNI_ERR and allow the calling application
3977     // to continue.
3978     if (Universe::is_fully_initialized()) {
3979       // otherwise no pending exception possible - VM will already have aborted
3980       JavaThread* THREAD = JavaThread::current();
3981       if (HAS_PENDING_EXCEPTION) {
3982         HandleMark hm;
3983         vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION));
3984       }
3985     }
3986 
3987     if (can_try_again) {
3988       // reset safe_to_recreate_vm to 1 so that retrial would be possible
3989       safe_to_recreate_vm = 1;
3990     }
3991 
3992     // Creation failed. We must reset vm_created


4054   JNIWrapper("DestroyJavaVM");
4055   JNIEnv *env;
4056   JavaVMAttachArgs destroyargs;
4057   destroyargs.version = CurrentVersion;
4058   destroyargs.name = (char *)"DestroyJavaVM";
4059   destroyargs.group = NULL;
4060   res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs);
4061   if (res != JNI_OK) {
4062     return res;
4063   }
4064 
4065   // Since this is not a JVM_ENTRY we have to set the thread state manually before entering.
4066   JavaThread* thread = JavaThread::current();
4067   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
4068   if (Threads::destroy_vm()) {
4069     // Should not change thread state, VM is gone
4070     vm_created = 0;
4071     res = JNI_OK;
4072     return res;
4073   } else {
4074     ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
4075     res = JNI_ERR;
4076     return res;
4077   }
4078 }
4079 
4080 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) {
4081   jint result = JNI_ERR;
4082   // On Windows, we need SEH protection
4083 #ifdef _WIN32
4084   __try {
4085 #endif
4086     result = jni_DestroyJavaVM_inner(vm);
4087 #ifdef _WIN32
4088   } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
4089     // Nothing to do.
4090   }
4091 #endif
4092   return result;
4093 }
4094 


4176   thread->set_done_attaching_via_jni();
4177 
4178   // Set java thread status.
4179   java_lang_Thread::set_thread_status(thread->threadObj(),
4180               java_lang_Thread::RUNNABLE);
4181 
4182   // Notify the debugger
4183   if (JvmtiExport::should_post_thread_life()) {
4184     JvmtiExport::post_thread_start(thread);
4185   }
4186 
4187   post_thread_start_event(thread);
4188 
4189   *(JNIEnv**)penv = thread->jni_environment();
4190 
4191   // Now leaving the VM, so change thread_state. This is normally automatically taken care
4192   // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by
4193   // using ThreadStateTransition::transition, we do a callback to the safepoint code if
4194   // needed.
4195 
4196   ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native);
4197 
4198   // Perform any platform dependent FPU setup
4199   os::setup_fpu();
4200 
4201   return JNI_OK;
4202 }
4203 
4204 
4205 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) {
4206   HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY(vm, penv, _args);
4207   if (vm_created == 0) {
4208   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
4209     return JNI_ERR;
4210   }
4211 
4212   JNIWrapper("AttachCurrentThread");
4213   jint ret = attach_current_thread(vm, penv, _args, false);
4214   HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN(ret);
4215   return ret;
4216 }


< prev index next >