109 110 111 char* NativeLookup::long_jni_name(methodHandle method) { 112 // Signature ignore the wrapping parenteses and the trailing return type 113 stringStream st; 114 Symbol* signature = method->signature(); 115 st.print("__"); 116 // find ')' 117 int end; 118 for (end = 0; end < signature->utf8_length() && signature->byte_at(end) != ')'; end++); 119 // skip first '(' 120 mangle_name_on(&st, signature, 1, end); 121 return st.as_string(); 122 } 123 124 extern "C" { 125 void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls); 126 void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls); 127 void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass); 128 void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass); 129 } 130 131 #define CC (char*) /* cast a literal from (const char*) */ 132 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) 133 134 static JNINativeMethod lookup_special_native_methods[] = { 135 { CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) }, 136 { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, 137 { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) }, 138 { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) }, 139 }; 140 141 static address lookup_special_native(char* jni_name) { 142 int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod); 143 for (int i = 0; i < count; i++) { 144 // NB: To ignore the jni prefix and jni postfix strstr is used matching. 145 if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) { 146 return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr); 147 } 148 } 149 return NULL; 150 } 151 152 address NativeLookup::lookup_style(methodHandle method, char* pure_name, const char* long_name, int args_size, bool os_style, bool& in_base_library, TRAPS) { 153 address entry; 154 // Compute complete JNI name for style 155 stringStream st; 156 if (os_style) os::print_jni_name_prefix_on(&st, args_size); 157 st.print_raw(pure_name); 158 st.print_raw(long_name); | 109 110 111 char* NativeLookup::long_jni_name(methodHandle method) { 112 // Signature ignore the wrapping parenteses and the trailing return type 113 stringStream st; 114 Symbol* signature = method->signature(); 115 st.print("__"); 116 // find ')' 117 int end; 118 for (end = 0; end < signature->utf8_length() && signature->byte_at(end) != ')'; end++); 119 // skip first '(' 120 mangle_name_on(&st, signature, 1, end); 121 return st.as_string(); 122 } 123 124 extern "C" { 125 void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls); 126 void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls); 127 void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass); 128 void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass); 129 void JNICALL JVM_RegisterEventTracingMethods(JNIEnv *env, jclass evtclass); 130 } 131 132 #define CC (char*) /* cast a literal from (const char*) */ 133 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) 134 135 static JNINativeMethod lookup_special_native_methods[] = { 136 { CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) }, 137 { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, 138 { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) }, 139 { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) }, 140 { CC"Java_sun_evtracing_EventTracing_registerNatives", NULL, FN_PTR(JVM_RegisterEventTracingMethods) }, 141 }; 142 143 static address lookup_special_native(char* jni_name) { 144 int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod); 145 for (int i = 0; i < count; i++) { 146 // NB: To ignore the jni prefix and jni postfix strstr is used matching. 147 if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) { 148 return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr); 149 } 150 } 151 return NULL; 152 } 153 154 address NativeLookup::lookup_style(methodHandle method, char* pure_name, const char* long_name, int args_size, bool os_style, bool& in_base_library, TRAPS) { 155 address entry; 156 // Compute complete JNI name for style 157 stringStream st; 158 if (os_style) os::print_jni_name_prefix_on(&st, args_size); 159 st.print_raw(pure_name); 160 st.print_raw(long_name); |