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 *
142 };
143
144 static address lookup_special_native(const 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(const methodHandle& method, char* pure_name, const char* long_name, int args_size, bool os_style, bool& in_base_library, TRAPS) {
156 address entry;
157 const char* jni_name = compute_complete_jni_name(pure_name, long_name, args_size, os_style);
158
159
160 // If the loader is null we have a system class, so we attempt a lookup in
161 // the native Java library. This takes care of any bootstrapping problems.
162 // Note: It is critical for bootstrapping that Java_java_lang_ClassLoader_00024NativeLibrary_find
163 // gets found the first time around - otherwise an infinite loop can occure. This is
164 // another VM/library dependency
165 Handle loader(THREAD, method->method_holder()->class_loader());
166 if (loader.is_null()) {
167 entry = lookup_special_native(jni_name);
168 if (entry == NULL) {
169 entry = (address) os::dll_lookup(os::native_java_library(), jni_name);
170 }
171 if (entry != NULL) {
172 in_base_library = true;
173 return entry;
174 }
175 }
176
177 // Otherwise call static method findNative in ClassLoader
178 Klass* klass = SystemDictionary::ClassLoader_klass();
179 Handle name_arg = java_lang_String::create_from_str(jni_name, CHECK_NULL);
180
181 JavaValue result(T_LONG);
182 JavaCalls::call_static(&result,
|
1 /*
2 * Copyright (c) 1997, 2020, 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 *
142 };
143
144 static address lookup_special_native(const 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(const methodHandle& method, char* pure_name, const char* long_name, int args_size, bool os_style, bool& in_base_library, TRAPS) {
156 address entry;
157 const char* jni_name = compute_complete_jni_name(pure_name, long_name, args_size, os_style);
158
159
160 // If the loader is null we have a system class, so we attempt a lookup in
161 // the native Java library. This takes care of any bootstrapping problems.
162 // Note: It is critical for bootstrapping that Java_java_lang_ClassLoader_findNative
163 // gets found the first time around - otherwise an infinite loop can occure. This is
164 // another VM/library dependency
165 Handle loader(THREAD, method->method_holder()->class_loader());
166 if (loader.is_null()) {
167 entry = lookup_special_native(jni_name);
168 if (entry == NULL) {
169 entry = (address) os::dll_lookup(os::native_java_library(), jni_name);
170 }
171 if (entry != NULL) {
172 in_base_library = true;
173 return entry;
174 }
175 }
176
177 // Otherwise call static method findNative in ClassLoader
178 Klass* klass = SystemDictionary::ClassLoader_klass();
179 Handle name_arg = java_lang_String::create_from_str(jni_name, CHECK_NULL);
180
181 JavaValue result(T_LONG);
182 JavaCalls::call_static(&result,
|