< prev index next >

src/hotspot/share/prims/nativeLookup.cpp

Print this page

 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/systemDictionary.hpp"
 29 #include "classfile/vmClasses.hpp"
 30 #include "classfile/vmSymbols.hpp"
 31 #include "logging/log.hpp"
 32 #include "logging/logTag.hpp"
 33 #include "memory/oopFactory.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/klass.inline.hpp"
 37 #include "oops/method.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "oops/symbol.hpp"
 40 #include "prims/jvm_misc.hpp"
 41 #include "prims/jvmtiExport.hpp"
 42 #include "prims/nativeLookup.hpp"
 43 #include "prims/unsafe.hpp"
 44 #include "prims/scopedMemoryAccess.hpp"

 45 #include "runtime/arguments.hpp"
 46 #include "runtime/handles.inline.hpp"
 47 #include "runtime/interfaceSupport.inline.hpp"
 48 #include "runtime/javaCalls.hpp"
 49 #include "runtime/os.hpp"
 50 #include "runtime/sharedRuntime.hpp"
 51 #include "runtime/signature.hpp"
 52 #include "utilities/macros.hpp"
 53 #include "utilities/utf8.hpp"
 54 #if INCLUDE_JFR
 55 #include "jfr/jfr.hpp"
 56 #endif
 57 
 58 /*
 59 
 60 The JNI specification defines the mapping from a Java native method name to
 61 a C native library implementation function name as follows:
 62 
 63   The mapping produces a native method name by concatenating the following components
 64   derived from a `native` method declaration:

217 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
218 
219 static JNINativeMethod lookup_special_native_methods[] = {
220   { CC"Java_jdk_internal_misc_Unsafe_registerNatives",             NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
221   { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
222   { CC"Java_jdk_internal_foreign_abi_UpcallStubs_registerNatives",      NULL, FN_PTR(JVM_RegisterUpcallHandlerMethods) },
223   { CC"Java_jdk_internal_foreign_abi_UpcallLinker_registerNatives",      NULL, FN_PTR(JVM_RegisterUpcallLinkerMethods) },
224   { CC"Java_jdk_internal_foreign_abi_NativeEntryPoint_registerNatives",      NULL, FN_PTR(JVM_RegisterNativeEntryPointMethods) },
225   { CC"Java_jdk_internal_perf_Perf_registerNatives",               NULL, FN_PTR(JVM_RegisterPerfMethods)         },
226   { CC"Java_sun_hotspot_WhiteBox_registerNatives",                 NULL, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
227   { CC"Java_jdk_test_whitebox_WhiteBox_registerNatives",           NULL, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
228   { CC"Java_jdk_internal_vm_vector_VectorSupport_registerNatives", NULL, FN_PTR(JVM_RegisterVectorSupportMethods)},
229 #if INCLUDE_JVMCI
230   { CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime",            NULL, FN_PTR(JVM_GetJVMCIRuntime)             },
231   { CC"Java_jdk_vm_ci_hotspot_CompilerToVM_registerNatives",       NULL, FN_PTR(JVM_RegisterJVMCINatives)        },
232 #endif
233 #if INCLUDE_JFR
234   { CC"Java_jdk_jfr_internal_JVM_registerNatives",                 NULL, FN_PTR(jfr_register_natives)            },
235 #endif
236   { CC"Java_jdk_internal_misc_ScopedMemoryAccess_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscScopedMemoryAccessMethods) },

237 };
238 
239 static address lookup_special_native(const char* jni_name) {
240   int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
241   for (int i = 0; i < count; i++) {
242     // NB: To ignore the jni prefix and jni postfix strstr is used matching.
243     if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
244       return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
245     }
246   }
247   return NULL;
248 }
249 
250 address NativeLookup::lookup_style(const methodHandle& method, char* pure_name, const char* long_name, int args_size, bool os_style, TRAPS) {
251   address entry;
252   const char* jni_name = compute_complete_jni_name(pure_name, long_name, args_size, os_style);
253 
254 
255   // If the loader is null we have a system class, so we attempt a lookup in
256   // the native Java library. This takes care of any bootstrapping problems.

 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/systemDictionary.hpp"
 29 #include "classfile/vmClasses.hpp"
 30 #include "classfile/vmSymbols.hpp"
 31 #include "logging/log.hpp"
 32 #include "logging/logTag.hpp"
 33 #include "memory/oopFactory.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/klass.inline.hpp"
 37 #include "oops/method.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "oops/symbol.hpp"
 40 #include "prims/jvm_misc.hpp"
 41 #include "prims/jvmtiExport.hpp"
 42 #include "prims/nativeLookup.hpp"
 43 #include "prims/unsafe.hpp"
 44 #include "prims/scopedMemoryAccess.hpp"
 45 #include "prims/shipilevMagic.hpp"
 46 #include "runtime/arguments.hpp"
 47 #include "runtime/handles.inline.hpp"
 48 #include "runtime/interfaceSupport.inline.hpp"
 49 #include "runtime/javaCalls.hpp"
 50 #include "runtime/os.hpp"
 51 #include "runtime/sharedRuntime.hpp"
 52 #include "runtime/signature.hpp"
 53 #include "utilities/macros.hpp"
 54 #include "utilities/utf8.hpp"
 55 #if INCLUDE_JFR
 56 #include "jfr/jfr.hpp"
 57 #endif
 58 
 59 /*
 60 
 61 The JNI specification defines the mapping from a Java native method name to
 62 a C native library implementation function name as follows:
 63 
 64   The mapping produces a native method name by concatenating the following components
 65   derived from a `native` method declaration:

218 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
219 
220 static JNINativeMethod lookup_special_native_methods[] = {
221   { CC"Java_jdk_internal_misc_Unsafe_registerNatives",             NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
222   { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
223   { CC"Java_jdk_internal_foreign_abi_UpcallStubs_registerNatives",      NULL, FN_PTR(JVM_RegisterUpcallHandlerMethods) },
224   { CC"Java_jdk_internal_foreign_abi_UpcallLinker_registerNatives",      NULL, FN_PTR(JVM_RegisterUpcallLinkerMethods) },
225   { CC"Java_jdk_internal_foreign_abi_NativeEntryPoint_registerNatives",      NULL, FN_PTR(JVM_RegisterNativeEntryPointMethods) },
226   { CC"Java_jdk_internal_perf_Perf_registerNatives",               NULL, FN_PTR(JVM_RegisterPerfMethods)         },
227   { CC"Java_sun_hotspot_WhiteBox_registerNatives",                 NULL, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
228   { CC"Java_jdk_test_whitebox_WhiteBox_registerNatives",           NULL, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
229   { CC"Java_jdk_internal_vm_vector_VectorSupport_registerNatives", NULL, FN_PTR(JVM_RegisterVectorSupportMethods)},
230 #if INCLUDE_JVMCI
231   { CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime",            NULL, FN_PTR(JVM_GetJVMCIRuntime)             },
232   { CC"Java_jdk_vm_ci_hotspot_CompilerToVM_registerNatives",       NULL, FN_PTR(JVM_RegisterJVMCINatives)        },
233 #endif
234 #if INCLUDE_JFR
235   { CC"Java_jdk_jfr_internal_JVM_registerNatives",                 NULL, FN_PTR(jfr_register_natives)            },
236 #endif
237   { CC"Java_jdk_internal_misc_ScopedMemoryAccess_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscScopedMemoryAccessMethods) },
238   { CC"Java_net_shipilev_Magic_registerNatives",                   NULL, FN_PTR(JVM_RegisterNetShipilevMagicMethods) },
239 };
240 
241 static address lookup_special_native(const char* jni_name) {
242   int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
243   for (int i = 0; i < count; i++) {
244     // NB: To ignore the jni prefix and jni postfix strstr is used matching.
245     if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
246       return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
247     }
248   }
249   return NULL;
250 }
251 
252 address NativeLookup::lookup_style(const methodHandle& method, char* pure_name, const char* long_name, int args_size, bool os_style, TRAPS) {
253   address entry;
254   const char* jni_name = compute_complete_jni_name(pure_name, long_name, args_size, os_style);
255 
256 
257   // If the loader is null we have a system class, so we attempt a lookup in
258   // the native Java library. This takes care of any bootstrapping problems.
< prev index next >