< prev index next >

src/hotspot/share/prims/nativeLookup.cpp

Print this page

 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/jvmtiAgentList.hpp"
 41 #include "prims/jvm_misc.hpp"
 42 #include "prims/jvmtiExport.hpp"
 43 #include "prims/nativeLookup.hpp"
 44 #include "prims/unsafe.hpp"
 45 #include "prims/scopedMemoryAccess.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:

220 
221 static JNINativeMethod lookup_special_native_methods[] = {
222   { CC"Java_jdk_internal_misc_Unsafe_registerNatives",             nullptr, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
223   { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", nullptr, FN_PTR(JVM_RegisterMethodHandleMethods) },
224   { CC"Java_jdk_internal_foreign_abi_UpcallStubs_registerNatives",      nullptr, FN_PTR(JVM_RegisterUpcallHandlerMethods) },
225   { CC"Java_jdk_internal_foreign_abi_UpcallLinker_registerNatives",      nullptr, FN_PTR(JVM_RegisterUpcallLinkerMethods) },
226   { CC"Java_jdk_internal_foreign_abi_NativeEntryPoint_registerNatives",      nullptr, FN_PTR(JVM_RegisterNativeEntryPointMethods) },
227   { CC"Java_jdk_internal_perf_Perf_registerNatives",               nullptr, FN_PTR(JVM_RegisterPerfMethods)         },
228   { CC"Java_sun_hotspot_WhiteBox_registerNatives",                 nullptr, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
229   { CC"Java_jdk_test_whitebox_WhiteBox_registerNatives",           nullptr, FN_PTR(JVM_RegisterWhiteBoxMethods)     },
230   { CC"Java_jdk_internal_vm_vector_VectorSupport_registerNatives", nullptr, FN_PTR(JVM_RegisterVectorSupportMethods)},
231 #if INCLUDE_JVMCI
232   { CC"Java_jdk_vm_ci_runtime_JVMCI_initializeRuntime",            nullptr, FN_PTR(JVM_GetJVMCIRuntime)             },
233   { CC"Java_jdk_vm_ci_services_Services_readSystemPropertiesInfo", nullptr, FN_PTR(JVM_ReadSystemPropertiesInfo)    },
234   { CC"Java_jdk_vm_ci_hotspot_CompilerToVM_registerNatives",       nullptr, FN_PTR(JVM_RegisterJVMCINatives)        },
235 #endif
236 #if INCLUDE_JFR
237   { CC"Java_jdk_jfr_internal_JVM_registerNatives",                 nullptr, FN_PTR(jfr_register_natives)            },
238 #endif
239   { CC"Java_jdk_internal_misc_ScopedMemoryAccess_registerNatives", nullptr, FN_PTR(JVM_RegisterJDKInternalMiscScopedMemoryAccessMethods) },

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

 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/jvmtiAgentList.hpp"
 41 #include "prims/jvm_misc.hpp"
 42 #include "prims/jvmtiExport.hpp"
 43 #include "prims/nativeLookup.hpp"
 44 #include "prims/unsafe.hpp"
 45 #include "prims/scopedMemoryAccess.hpp"
 46 #include "prims/shipilevMagic.hpp"
 47 #include "runtime/arguments.hpp"
 48 #include "runtime/handles.inline.hpp"
 49 #include "runtime/interfaceSupport.inline.hpp"
 50 #include "runtime/javaCalls.hpp"
 51 #include "runtime/os.hpp"
 52 #include "runtime/sharedRuntime.hpp"
 53 #include "runtime/signature.hpp"
 54 #include "utilities/macros.hpp"
 55 #include "utilities/utf8.hpp"
 56 #if INCLUDE_JFR
 57 #include "jfr/jfr.hpp"
 58 #endif
 59 
 60 /*
 61 
 62 The JNI specification defines the mapping from a Java native method name to
 63 a C native library implementation function name as follows:
 64 
 65   The mapping produces a native method name by concatenating the following components
 66   derived from a `native` method declaration:

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