2892 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short
2893 , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2894 HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2895 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char
2896 , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2897 HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2898 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int
2899 , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2900 HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2901 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long
2902 , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2903 HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
2904 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float
2905 , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2906 HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
2907 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double
2908 , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2909 HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
2910
2911
2912 //
2913 // Interception of natives
2914 //
2915
2916 // The RegisterNatives call being attempted tried to register with a method that
2917 // is not native. Ask JVM TI what prefixes have been specified. Then check
2918 // to see if the native method is now wrapped with the prefixes. See the
2919 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.
2920 static Method* find_prefixed_native(Klass* k, Symbol* name, Symbol* signature, TRAPS) {
2921 #if INCLUDE_JVMTI
2922 ResourceMark rm(THREAD);
2923 Method* method;
2924 int name_len = name->utf8_length();
2925 char* name_str = name->as_utf8();
2926 int prefix_count;
2927 char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
2928 for (int i = 0; i < prefix_count; i++) {
2929 char* prefix = prefixes[i];
2930 int prefix_len = (int)strlen(prefix);
2931
2932 // try adding this prefix to the method name and see if it matches another method name
2933 int trial_len = name_len + prefix_len;
2934 char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
2935 strcpy(trial_name_str, prefix);
2936 strcat(trial_name_str, name_str);
2937 TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
2938 if (trial_name == NULL) {
2939 continue; // no such symbol, so this prefix wasn't used, try the next prefix
2940 }
2941 method = k->lookup_method(trial_name, signature);
2942 if (method == NULL) {
2943 continue; // signature doesn't match, try the next prefix
2944 }
2945 if (method->is_native()) {
2946 method->set_is_prefixed_native();
2947 return method; // wahoo, we found a prefixed version of the method, return it
2948 }
2949 // found as non-native, so prefix is good, add it, probably just need more prefixes
2950 name_len = trial_len;
2951 name_str = trial_name_str;
2952 }
2953 #endif // INCLUDE_JVMTI
2954 return NULL; // not found
2955 }
2956
2957 static bool register_native(Klass* k, Symbol* name, Symbol* signature, address entry, TRAPS) {
2958 Method* method = k->lookup_method(name, signature);
2959 if (method == NULL) {
2960 ResourceMark rm;
2961 stringStream st;
2962 st.print("Method '");
2963 Method::print_external_name(&st, k, name, signature);
2964 st.print("' name or signature does not match");
2965 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2966 }
2967 if (!method->is_native()) {
2968 // trying to register to a non-native method, see if a JVM TI agent has added prefix(es)
2969 method = find_prefixed_native(k, name, signature, THREAD);
2970 if (method == NULL) {
2971 ResourceMark rm;
2972 stringStream st;
2973 st.print("Method '");
2974 Method::print_external_name(&st, k, name, signature);
2975 st.print("' is not declared as native");
2976 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false);
2977 }
2978 }
2979
2980 if (entry != NULL) {
2981 method->set_native_function(entry,
2982 Method::native_bind_event_is_interesting);
2983 } else {
2984 method->clear_native_function();
2985 }
2986 if (PrintJNIResolving) {
2987 ResourceMark rm(THREAD);
2988 tty->print_cr("[Registering JNI native method %s.%s]",
2989 method->method_holder()->external_name(),
2990 method->name()->as_C_string());
2991 }
2992 return true;
2993 }
2994
2995 DT_RETURN_MARK_DECL(RegisterNatives, jint
2996 , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
2997
2998 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
2999 const JNINativeMethod *methods,
3000 jint nMethods))
3001 JNIWrapper("RegisterNatives");
3002 HOTSPOT_JNI_REGISTERNATIVES_ENTRY(env, clazz, (void *) methods, nMethods);
3003 jint ret = 0;
3004 DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
3005
3006 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
3007
3008 for (int index = 0; index < nMethods; index++) {
3009 const char* meth_name = methods[index].name;
3010 const char* meth_sig = methods[index].signature;
3011 int meth_name_len = (int)strlen(meth_name);
3012
3013 // The class should have been loaded (we have an instance of the class
3014 // passed in) so the method and signature should already be in the symbol
3015 // table. If they're not there, the method doesn't exist.
3016 TempNewSymbol name = SymbolTable::probe(meth_name, meth_name_len);
3017 TempNewSymbol signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig));
3018
3019 if (name == NULL || signature == NULL) {
3020 ResourceMark rm;
3021 stringStream st;
3022 st.print("Method %s.%s%s not found", k->external_name(), meth_name, meth_sig);
3023 // Must return negative value on failure
3024 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
3025 }
3026
3027 bool res = register_native(k, name, signature,
3028 (address) methods[index].fnPtr, THREAD);
3029 if (!res) {
3030 ret = -1;
3031 break;
3032 }
3033 }
3034 return ret;
3035 JNI_END
3036
3037
3038 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
3039 JNIWrapper("UnregisterNatives");
3040 HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(env, clazz);
3041 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
3042 //%note jni_2
3043 if (k->is_instance_klass()) {
3044 for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) {
3045 Method* m = InstanceKlass::cast(k)->methods()->at(index);
3046 if (m->is_native()) {
3047 m->clear_native_function();
|
2892 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short
2893 , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2894 HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN())
2895 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char
2896 , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf),
2897 HOTSPOT_JNI_SETCHARARRAYREGION_RETURN())
2898 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int
2899 , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf),
2900 HOTSPOT_JNI_SETINTARRAYREGION_RETURN())
2901 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long
2902 , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf),
2903 HOTSPOT_JNI_SETLONGARRAYREGION_RETURN())
2904 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float
2905 , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf),
2906 HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN())
2907 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double
2908 , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf),
2909 HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN())
2910
2911
2912 DT_RETURN_MARK_DECL(RegisterNatives, jint
2913 , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref));
2914
2915 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz,
2916 const JNINativeMethod *methods,
2917 jint nMethods))
2918 JNIWrapper("RegisterNatives");
2919 HOTSPOT_JNI_REGISTERNATIVES_ENTRY(env, clazz, (void *) methods, nMethods);
2920 jint ret = 0;
2921 DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret);
2922
2923 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2924
2925 for (int index = 0; index < nMethods; index++) {
2926 const char* meth_name = methods[index].name;
2927 const char* meth_sig = methods[index].signature;
2928 int meth_name_len = (int)strlen(meth_name);
2929
2930 // The class should have been loaded (we have an instance of the class
2931 // passed in) so the method and signature should already be in the symbol
2932 // table. If they're not there, the method doesn't exist.
2933 TempNewSymbol name = SymbolTable::probe(meth_name, meth_name_len);
2934 TempNewSymbol signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig));
2935
2936 if (name == NULL || signature == NULL) {
2937 ResourceMark rm;
2938 stringStream st;
2939 st.print("Method %s.%s%s not found", k->external_name(), meth_name, meth_sig);
2940 // Must return negative value on failure
2941 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1);
2942 }
2943
2944 bool res = SystemDictionary::register_native(k, name, signature,
2945 (address) methods[index].fnPtr, THREAD);
2946 if (!res) {
2947 ret = -1;
2948 break;
2949 }
2950 }
2951 return ret;
2952 JNI_END
2953
2954
2955 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz))
2956 JNIWrapper("UnregisterNatives");
2957 HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY(env, clazz);
2958 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
2959 //%note jni_2
2960 if (k->is_instance_klass()) {
2961 for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) {
2962 Method* m = InstanceKlass::cast(k)->methods()->at(index);
2963 if (m->is_native()) {
2964 m->clear_native_function();
|