< prev index next >

src/share/vm/prims/nativeLookup.cpp

Print this page
rev 8910 : full patch for jfr
   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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  *


 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);


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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  *


 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 #if INCLUDE_TRACE
 140   { CC"Java_jdk_jfr_internal_JVM_registerNatives",                 NULL, TRACE_REGISTER_NATIVES                  },
 141 #endif
 142 };
 143 
 144 static address lookup_special_native(char* jni_name) {
 145   int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod);
 146   for (int i = 0; i < count; i++) {
 147     // NB: To ignore the jni prefix and jni postfix strstr is used matching.
 148     if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) {
 149       return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr);
 150     }
 151   }
 152   return NULL;
 153 }
 154 
 155 address NativeLookup::lookup_style(methodHandle method, char* pure_name, const char* long_name, int args_size, bool os_style, bool& in_base_library, TRAPS) {
 156   address entry;
 157   // Compute complete JNI name for style
 158   stringStream st;
 159   if (os_style) os::print_jni_name_prefix_on(&st, args_size);
 160   st.print_raw(pure_name);
 161   st.print_raw(long_name);


< prev index next >