18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "memory/oopFactory.hpp"
30 #include "memory/resourceArea.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "oops/instanceKlass.hpp"
33 #include "oops/method.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/symbol.hpp"
36 #include "prims/jvm_misc.hpp"
37 #include "prims/nativeLookup.hpp"
38 #include "runtime/arguments.hpp"
39 #include "runtime/handles.inline.hpp"
40 #include "runtime/javaCalls.hpp"
41 #include "runtime/sharedRuntime.hpp"
42 #include "runtime/signature.hpp"
43 #include "utilities/macros.hpp"
44
45
46 static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
47 char* bytes = (char*)name->bytes() + begin;
48 char* end_bytes = (char*)name->bytes() + end;
49 while (bytes < end_bytes) {
50 jchar c;
51 bytes = UTF8::next(bytes, &c);
52 if (c <= 0x7f && isalnum(c)) {
53 st->put((char) c);
54 } else {
55 if (c == '_') st->print("_1");
56 else if (c == '/') st->print("_");
57 else if (c == ';') st->print("_2");
90 // Method name
91 mangle_name_on(&st, method->name());
92 return st.as_string();
93 }
94
95
96 char* NativeLookup::long_jni_name(const methodHandle& method) {
97 // Signature ignore the wrapping parenteses and the trailing return type
98 stringStream st;
99 Symbol* signature = method->signature();
100 st.print("__");
101 // find ')'
102 int end;
103 for (end = 0; end < signature->utf8_length() && signature->byte_at(end) != ')'; end++);
104 // skip first '('
105 mangle_name_on(&st, signature, 1, end);
106 return st.as_string();
107 }
108
109 extern "C" {
110 void JNICALL JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
111 void JNICALL JVM_RegisterSunMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
112 void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
113 void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
114 void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass);
115 #if INCLUDE_JVMCI
116 jobject JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
117 void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
118 #endif
119 }
120
121 #define CC (char*) /* cast a literal from (const char*) */
122 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
123
124 static JNINativeMethod lookup_special_native_methods[] = {
125 { CC"Java_jdk_internal_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
126 { CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterSunMiscUnsafeMethods) },
127 { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
128 { CC"Java_jdk_internal_perf_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) },
129 { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
130 #if INCLUDE_JVMCI
131 { CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime", NULL, FN_PTR(JVM_GetJVMCIRuntime) },
132 { CC"Java_jdk_vm_ci_hotspot_CompilerToVM_registerNatives", NULL, FN_PTR(JVM_RegisterJVMCINatives) },
133 #endif
134 };
135
136 static address lookup_special_native(char* jni_name) {
137 int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
138 for (int i = 0; i < count; i++) {
139 // NB: To ignore the jni prefix and jni postfix strstr is used matching.
140 if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
141 return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
142 }
143 }
144 return NULL;
145 }
146
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "memory/oopFactory.hpp"
30 #include "memory/resourceArea.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "oops/instanceKlass.hpp"
33 #include "oops/method.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/symbol.hpp"
36 #include "prims/jvm_misc.hpp"
37 #include "prims/nativeLookup.hpp"
38 #include "prims/unsafe.hpp"
39 #include "runtime/arguments.hpp"
40 #include "runtime/handles.inline.hpp"
41 #include "runtime/javaCalls.hpp"
42 #include "runtime/sharedRuntime.hpp"
43 #include "runtime/signature.hpp"
44 #include "utilities/macros.hpp"
45
46
47 static void mangle_name_on(outputStream* st, Symbol* name, int begin, int end) {
48 char* bytes = (char*)name->bytes() + begin;
49 char* end_bytes = (char*)name->bytes() + end;
50 while (bytes < end_bytes) {
51 jchar c;
52 bytes = UTF8::next(bytes, &c);
53 if (c <= 0x7f && isalnum(c)) {
54 st->put((char) c);
55 } else {
56 if (c == '_') st->print("_1");
57 else if (c == '/') st->print("_");
58 else if (c == ';') st->print("_2");
91 // Method name
92 mangle_name_on(&st, method->name());
93 return st.as_string();
94 }
95
96
97 char* NativeLookup::long_jni_name(const methodHandle& method) {
98 // Signature ignore the wrapping parenteses and the trailing return type
99 stringStream st;
100 Symbol* signature = method->signature();
101 st.print("__");
102 // find ')'
103 int end;
104 for (end = 0; end < signature->utf8_length() && signature->byte_at(end) != ')'; end++);
105 // skip first '('
106 mangle_name_on(&st, signature, 1, end);
107 return st.as_string();
108 }
109
110 extern "C" {
111 void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
112 void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
113 void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass);
114 #if INCLUDE_JVMCI
115 jobject JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
116 void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
117 #endif
118 }
119
120 #define CC (char*) /* cast a literal from (const char*) */
121 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
122
123 static JNINativeMethod lookup_special_native_methods[] = {
124 { CC"Java_jdk_internal_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
125 { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
126 { CC"Java_jdk_internal_perf_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) },
127 { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
128 #if INCLUDE_JVMCI
129 { CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime", NULL, FN_PTR(JVM_GetJVMCIRuntime) },
130 { CC"Java_jdk_vm_ci_hotspot_CompilerToVM_registerNatives", NULL, FN_PTR(JVM_RegisterJVMCINatives) },
131 #endif
132 };
133
134 static address lookup_special_native(char* jni_name) {
135 int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
136 for (int i = 0; i < count; i++) {
137 // NB: To ignore the jni prefix and jni postfix strstr is used matching.
138 if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
139 return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
140 }
141 }
142 return NULL;
143 }
144
|