Mercurial > hg > graal-compiler
annotate src/share/vm/prims/jni.cpp @ 2302:da091bb67459
7022037: Pause when exiting if debugger is attached on windows
Reviewed-by: dsamersoff, kamg, hosterda
author | sla |
---|---|
date | Mon, 28 Feb 2011 14:19:52 +0100 |
parents | 3582bf76420e |
children | d25d4ca69222 c7f3d0b4570f |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
27 #include "classfile/javaClasses.hpp" | |
28 #include "classfile/symbolTable.hpp" | |
29 #include "classfile/systemDictionary.hpp" | |
30 #include "classfile/vmSymbols.hpp" | |
31 #include "interpreter/linkResolver.hpp" | |
32 #include "memory/allocation.inline.hpp" | |
33 #include "memory/gcLocker.inline.hpp" | |
34 #include "memory/oopFactory.hpp" | |
35 #include "memory/universe.inline.hpp" | |
36 #include "oops/instanceKlass.hpp" | |
37 #include "oops/instanceOop.hpp" | |
38 #include "oops/markOop.hpp" | |
39 #include "oops/methodOop.hpp" | |
40 #include "oops/objArrayKlass.hpp" | |
41 #include "oops/objArrayOop.hpp" | |
42 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
43 #include "oops/symbol.hpp" |
1972 | 44 #include "oops/typeArrayKlass.hpp" |
45 #include "oops/typeArrayOop.hpp" | |
46 #include "prims/jni.h" | |
47 #include "prims/jniCheck.hpp" | |
48 #include "prims/jniFastGetField.hpp" | |
49 #include "prims/jvm.h" | |
50 #include "prims/jvm_misc.hpp" | |
51 #include "prims/jvmtiExport.hpp" | |
52 #include "prims/jvmtiThreadState.hpp" | |
53 #include "runtime/compilationPolicy.hpp" | |
54 #include "runtime/fieldDescriptor.hpp" | |
55 #include "runtime/fprofiler.hpp" | |
56 #include "runtime/handles.inline.hpp" | |
57 #include "runtime/interfaceSupport.hpp" | |
58 #include "runtime/java.hpp" | |
59 #include "runtime/javaCalls.hpp" | |
60 #include "runtime/jfieldIDWorkaround.hpp" | |
61 #include "runtime/reflection.hpp" | |
62 #include "runtime/sharedRuntime.hpp" | |
63 #include "runtime/signature.hpp" | |
64 #include "runtime/vm_operations.hpp" | |
65 #include "services/runtimeService.hpp" | |
66 #include "utilities/defaultStream.hpp" | |
67 #include "utilities/dtrace.hpp" | |
68 #include "utilities/events.hpp" | |
69 #include "utilities/histogram.hpp" | |
70 #ifdef TARGET_ARCH_x86 | |
71 # include "jniTypes_x86.hpp" | |
72 #endif | |
73 #ifdef TARGET_ARCH_sparc | |
74 # include "jniTypes_sparc.hpp" | |
75 #endif | |
76 #ifdef TARGET_ARCH_zero | |
77 # include "jniTypes_zero.hpp" | |
78 #endif | |
79 #ifdef TARGET_OS_FAMILY_linux | |
80 # include "os_linux.inline.hpp" | |
81 # include "thread_linux.inline.hpp" | |
82 #endif | |
83 #ifdef TARGET_OS_FAMILY_solaris | |
84 # include "os_solaris.inline.hpp" | |
85 # include "thread_solaris.inline.hpp" | |
86 #endif | |
87 #ifdef TARGET_OS_FAMILY_windows | |
88 # include "os_windows.inline.hpp" | |
89 # include "thread_windows.inline.hpp" | |
90 #endif | |
0 | 91 |
92 static jint CurrentVersion = JNI_VERSION_1_6; | |
93 | |
94 | |
95 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace | |
96 // '-return' probe regardless of the return path is taken out of the function. | |
97 // Methods that have multiple return paths use this to avoid having to | |
98 // instrument each return path. Methods that use CHECK or THROW must use this | |
99 // since those macros can cause an immedate uninstrumented return. | |
100 // | |
101 // In order to get the return value, a reference to the variable containing | |
102 // the return value must be passed to the contructor of the object, and | |
103 // the return value must be set before return (since the mark object has | |
104 // a reference to it). | |
105 // | |
106 // Example: | |
107 // DT_RETURN_MARK_DECL(SomeFunc, int); | |
108 // JNI_ENTRY(int, SomeFunc, ...) | |
109 // int return_value = 0; | |
110 // DT_RETURN_MARK(SomeFunc, int, (const int&)return_value); | |
111 // foo(CHECK_0) | |
112 // return_value = 5; | |
113 // return return_value; | |
114 // JNI_END | |
115 #define DT_RETURN_MARK_DECL(name, type) \ | |
116 HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type); \ | |
117 DTRACE_ONLY( \ | |
118 class DTraceReturnProbeMark_##name { \ | |
119 public: \ | |
120 const type& _ret_ref; \ | |
121 DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ | |
122 ~DTraceReturnProbeMark_##name() { \ | |
123 HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref); \ | |
124 } \ | |
125 } \ | |
126 ) | |
127 // Void functions are simpler since there's no return value | |
128 #define DT_VOID_RETURN_MARK_DECL(name) \ | |
129 HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return); \ | |
130 DTRACE_ONLY( \ | |
131 class DTraceReturnProbeMark_##name { \ | |
132 public: \ | |
133 ~DTraceReturnProbeMark_##name() { \ | |
134 HS_DTRACE_PROBE0(hotspot_jni, name##__return); \ | |
135 } \ | |
136 } \ | |
137 ) | |
138 | |
139 | |
140 // Place these macros in the function to mark the return. Non-void | |
141 // functions need the type and address of the return value. | |
142 #define DT_RETURN_MARK(name, type, ref) \ | |
143 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) ) | |
144 #define DT_VOID_RETURN_MARK(name) \ | |
145 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark ) | |
146 | |
147 | |
148 // Use these to select distinct code for floating-point vs. non-floating point | |
149 // situations. Used from within common macros where we need slightly | |
150 // different behavior for Float/Double | |
151 #define FP_SELECT_Boolean(intcode, fpcode) intcode | |
152 #define FP_SELECT_Byte(intcode, fpcode) intcode | |
153 #define FP_SELECT_Char(intcode, fpcode) intcode | |
154 #define FP_SELECT_Short(intcode, fpcode) intcode | |
155 #define FP_SELECT_Object(intcode, fpcode) intcode | |
156 #define FP_SELECT_Int(intcode, fpcode) intcode | |
157 #define FP_SELECT_Long(intcode, fpcode) intcode | |
158 #define FP_SELECT_Float(intcode, fpcode) fpcode | |
159 #define FP_SELECT_Double(intcode, fpcode) fpcode | |
160 #define FP_SELECT(TypeName, intcode, fpcode) \ | |
161 FP_SELECT_##TypeName(intcode, fpcode) | |
162 | |
163 #define COMMA , | |
164 | |
165 // Choose DT_RETURN_MARK macros based on the type: float/double -> void | |
166 // (dtrace doesn't do FP yet) | |
167 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \ | |
168 FP_SELECT(TypeName, \ | |
169 DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) ) | |
170 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \ | |
171 FP_SELECT(TypeName, \ | |
172 DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) ) | |
173 | |
174 | |
175 // out-of-line helpers for class jfieldIDWorkaround: | |
176 | |
177 bool jfieldIDWorkaround::is_valid_jfieldID(klassOop k, jfieldID id) { | |
178 if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) { | |
179 uintptr_t as_uint = (uintptr_t) id; | |
180 intptr_t offset = raw_instance_offset(id); | |
181 if (is_checked_jfieldID(id)) { | |
182 if (!klass_hash_ok(k, id)) { | |
183 return false; | |
184 } | |
185 } | |
186 return instanceKlass::cast(k)->contains_field_offset(offset); | |
187 } else { | |
188 JNIid* result = (JNIid*) id; | |
189 #ifdef ASSERT | |
190 return result != NULL && result->is_static_field_id(); | |
191 #else | |
192 return result != NULL; | |
193 #endif | |
194 } | |
195 } | |
196 | |
197 | |
198 intptr_t jfieldIDWorkaround::encode_klass_hash(klassOop k, intptr_t offset) { | |
199 if (offset <= small_offset_mask) { | |
200 klassOop field_klass = k; | |
201 klassOop super_klass = Klass::cast(field_klass)->super(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
202 // With compressed oops the most super class with nonstatic fields would |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
203 // be the owner of fields embedded in the header. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
204 while (instanceKlass::cast(super_klass)->has_nonstatic_fields() && |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
205 instanceKlass::cast(super_klass)->contains_field_offset(offset)) { |
0 | 206 field_klass = super_klass; // super contains the field also |
207 super_klass = Klass::cast(field_klass)->super(); | |
208 } | |
209 debug_only(No_Safepoint_Verifier nosafepoint;) | |
210 uintptr_t klass_hash = field_klass->identity_hash(); | |
211 return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place; | |
212 } else { | |
213 #if 0 | |
214 #ifndef PRODUCT | |
215 { | |
216 ResourceMark rm; | |
217 warning("VerifyJNIFields: long offset %d in %s", offset, Klass::cast(k)->external_name()); | |
218 } | |
219 #endif | |
220 #endif | |
221 return 0; | |
222 } | |
223 } | |
224 | |
225 bool jfieldIDWorkaround::klass_hash_ok(klassOop k, jfieldID id) { | |
226 uintptr_t as_uint = (uintptr_t) id; | |
227 intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask; | |
228 do { | |
229 debug_only(No_Safepoint_Verifier nosafepoint;) | |
230 // Could use a non-blocking query for identity_hash here... | |
231 if ((k->identity_hash() & klass_mask) == klass_hash) | |
232 return true; | |
233 k = Klass::cast(k)->super(); | |
234 } while (k != NULL); | |
235 return false; | |
236 } | |
237 | |
238 void jfieldIDWorkaround::verify_instance_jfieldID(klassOop k, jfieldID id) { | |
239 guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" ); | |
240 uintptr_t as_uint = (uintptr_t) id; | |
241 intptr_t offset = raw_instance_offset(id); | |
242 if (VerifyJNIFields) { | |
243 if (is_checked_jfieldID(id)) { | |
244 guarantee(klass_hash_ok(k, id), | |
245 "Bug in native code: jfieldID class must match object"); | |
246 } else { | |
247 #if 0 | |
248 #ifndef PRODUCT | |
249 if (Verbose) { | |
250 ResourceMark rm; | |
251 warning("VerifyJNIFields: unverified offset %d for %s", offset, Klass::cast(k)->external_name()); | |
252 } | |
253 #endif | |
254 #endif | |
255 } | |
256 } | |
257 guarantee(instanceKlass::cast(k)->contains_field_offset(offset), | |
258 "Bug in native code: jfieldID offset must address interior of object"); | |
259 } | |
260 | |
261 // Pick a reasonable higher bound for local capacity requested | |
262 // for EnsureLocalCapacity and PushLocalFrame. We don't want it too | |
263 // high because a test (or very unusual application) may try to allocate | |
264 // that many handles and run out of swap space. An implementation is | |
265 // permitted to allocate more handles than the ensured capacity, so this | |
266 // value is set high enough to prevent compatibility problems. | |
267 const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; | |
268 | |
269 | |
270 // Wrapper to trace JNI functions | |
271 | |
272 #ifdef ASSERT | |
273 Histogram* JNIHistogram; | |
274 static volatile jint JNIHistogram_lock = 0; | |
275 | |
276 class JNITraceWrapper : public StackObj { | |
277 public: | |
278 JNITraceWrapper(const char* format, ...) { | |
279 if (TraceJNICalls) { | |
280 va_list ap; | |
281 va_start(ap, format); | |
282 tty->print("JNI "); | |
283 tty->vprint_cr(format, ap); | |
284 va_end(ap); | |
285 } | |
286 } | |
287 }; | |
288 | |
289 class JNIHistogramElement : public HistogramElement { | |
290 public: | |
291 JNIHistogramElement(const char* name); | |
292 }; | |
293 | |
294 JNIHistogramElement::JNIHistogramElement(const char* elementName) { | |
295 _name = elementName; | |
296 uintx count = 0; | |
297 | |
298 while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) { | |
299 while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) { | |
300 count +=1; | |
301 if ( (WarnOnStalledSpinLock > 0) | |
302 && (count % WarnOnStalledSpinLock == 0)) { | |
303 warning("JNIHistogram_lock seems to be stalled"); | |
304 } | |
305 } | |
306 } | |
307 | |
308 | |
309 if(JNIHistogram == NULL) | |
310 JNIHistogram = new Histogram("JNI Call Counts",100); | |
311 | |
312 JNIHistogram->add_element(this); | |
313 Atomic::dec(&JNIHistogram_lock); | |
314 } | |
315 | |
316 #define JNICountWrapper(arg) \ | |
317 static JNIHistogramElement* e = new JNIHistogramElement(arg); \ | |
318 /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \ | |
319 if (e != NULL) e->increment_count() | |
320 #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg) | |
321 #else | |
322 #define JNIWrapper(arg) | |
323 #endif | |
324 | |
325 | |
326 // Implementation of JNI entries | |
327 | |
328 DT_RETURN_MARK_DECL(DefineClass, jclass); | |
329 | |
330 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef, | |
331 const jbyte *buf, jsize bufLen)) | |
332 JNIWrapper("DefineClass"); | |
333 | |
334 DTRACE_PROBE5(hotspot_jni, DefineClass__entry, | |
335 env, name, loaderRef, buf, bufLen); | |
336 jclass cls = NULL; | |
337 DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); | |
338 | |
339 // Since exceptions can be thrown, class initialization can take place | |
340 // if name is NULL no check for class name in .class stream has to be made. | |
341 if (name != NULL) { | |
342 const int str_len = (int)strlen(name); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
343 if (str_len > Symbol::max_length()) { |
0 | 344 // It's impossible to create this class; the name cannot fit |
345 // into the constant pool. | |
346 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); | |
347 } | |
348 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
349 TempNewSymbol class_name = SymbolTable::new_symbol(name, THREAD); |
0 | 350 |
351 ResourceMark rm(THREAD); | |
352 ClassFileStream st((u1*) buf, bufLen, NULL); | |
353 Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); | |
354 | |
355 if (UsePerfData && !class_loader.is_null()) { | |
356 // check whether the current caller thread holds the lock or not. | |
357 // If not, increment the corresponding counter | |
358 if (ObjectSynchronizer:: | |
359 query_lock_ownership((JavaThread*)THREAD, class_loader) != | |
360 ObjectSynchronizer::owner_self) { | |
361 ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); | |
362 } | |
363 } | |
364 klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
657
diff
changeset
|
365 Handle(), &st, true, |
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
657
diff
changeset
|
366 CHECK_NULL); |
0 | 367 |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
368 if (TraceClassResolution && k != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
369 trace_class_resolution(k); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
370 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
371 |
0 | 372 cls = (jclass)JNIHandles::make_local( |
373 env, Klass::cast(k)->java_mirror()); | |
374 return cls; | |
375 JNI_END | |
376 | |
377 | |
378 | |
379 static bool first_time_FindClass = true; | |
380 | |
381 DT_RETURN_MARK_DECL(FindClass, jclass); | |
382 | |
383 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name)) | |
384 JNIWrapper("FindClass"); | |
385 DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name); | |
386 | |
387 jclass result = NULL; | |
388 DT_RETURN_MARK(FindClass, jclass, (const jclass&)result); | |
389 | |
390 // Remember if we are the first invocation of jni_FindClass | |
391 bool first_time = first_time_FindClass; | |
392 first_time_FindClass = false; | |
393 | |
394 // Sanity check the name: it cannot be null or larger than the maximum size | |
395 // name we can fit in the constant pool. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
396 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
0 | 397 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
398 } | |
399 | |
400 //%note jni_3 | |
401 Handle loader; | |
402 Handle protection_domain; | |
403 // Find calling class | |
404 instanceKlassHandle k (THREAD, thread->security_get_caller_class(0)); | |
405 if (k.not_null()) { | |
406 loader = Handle(THREAD, k->class_loader()); | |
407 // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed | |
408 // in the correct class context. | |
409 if (loader.is_null() && | |
410 k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) { | |
411 JavaValue result(T_OBJECT); | |
412 JavaCalls::call_static(&result, k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
413 vmSymbols::getFromClass_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
414 vmSymbols::void_class_signature(), |
0 | 415 thread); |
416 if (HAS_PENDING_EXCEPTION) { | |
417 Handle ex(thread, thread->pending_exception()); | |
418 CLEAR_PENDING_EXCEPTION; | |
419 THROW_HANDLE_0(ex); | |
420 } | |
421 oop mirror = (oop) result.get_jobject(); | |
422 loader = Handle(THREAD, | |
423 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->class_loader()); | |
424 protection_domain = Handle(THREAD, | |
425 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->protection_domain()); | |
426 } | |
427 } else { | |
428 // We call ClassLoader.getSystemClassLoader to obtain the system class loader. | |
429 loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
430 } | |
431 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
432 TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
0 | 433 result = find_class_from_class_loader(env, sym, true, loader, |
434 protection_domain, true, thread); | |
435 | |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
436 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
437 trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
438 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
439 |
0 | 440 // If we were the first invocation of jni_FindClass, we enable compilation again |
441 // rather than just allowing invocation counter to overflow and decay. | |
442 // Controlled by flag DelayCompilationDuringStartup. | |
443 if (first_time && !CompileTheWorld) | |
444 CompilationPolicy::completed_vm_startup(); | |
445 | |
446 return result; | |
447 JNI_END | |
448 | |
449 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID); | |
450 | |
451 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method)) | |
452 JNIWrapper("FromReflectedMethod"); | |
453 DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method); | |
454 jmethodID ret = NULL; | |
455 DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret); | |
456 | |
457 // method is a handle to a java.lang.reflect.Method object | |
458 oop reflected = JNIHandles::resolve_non_null(method); | |
459 oop mirror = NULL; | |
460 int slot = 0; | |
461 | |
1142 | 462 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { |
0 | 463 mirror = java_lang_reflect_Constructor::clazz(reflected); |
464 slot = java_lang_reflect_Constructor::slot(reflected); | |
465 } else { | |
1142 | 466 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); |
0 | 467 mirror = java_lang_reflect_Method::clazz(reflected); |
468 slot = java_lang_reflect_Method::slot(reflected); | |
469 } | |
470 klassOop k = java_lang_Class::as_klassOop(mirror); | |
471 | |
472 KlassHandle k1(THREAD, k); | |
473 // Make sure class is initialized before handing id's out to methods | |
474 Klass::cast(k1())->initialize(CHECK_NULL); | |
475 methodOop m = instanceKlass::cast(k1())->method_with_idnum(slot); | |
476 ret = m==NULL? NULL : m->jmethod_id(); // return NULL if reflected method deleted | |
477 return ret; | |
478 JNI_END | |
479 | |
480 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID); | |
481 | |
482 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field)) | |
483 JNIWrapper("FromReflectedField"); | |
484 DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field); | |
485 jfieldID ret = NULL; | |
486 DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret); | |
487 | |
488 // field is a handle to a java.lang.reflect.Field object | |
489 oop reflected = JNIHandles::resolve_non_null(field); | |
490 oop mirror = java_lang_reflect_Field::clazz(reflected); | |
491 klassOop k = java_lang_Class::as_klassOop(mirror); | |
492 int slot = java_lang_reflect_Field::slot(reflected); | |
493 int modifiers = java_lang_reflect_Field::modifiers(reflected); | |
494 | |
495 KlassHandle k1(THREAD, k); | |
496 // Make sure class is initialized before handing id's out to fields | |
497 Klass::cast(k1())->initialize(CHECK_NULL); | |
498 | |
499 // First check if this is a static field | |
500 if (modifiers & JVM_ACC_STATIC) { | |
501 intptr_t offset = instanceKlass::cast(k1())->offset_from_fields( slot ); | |
502 JNIid* id = instanceKlass::cast(k1())->jni_id_for(offset); | |
503 assert(id != NULL, "corrupt Field object"); | |
504 debug_only(id->set_is_static_field_id();) | |
505 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
506 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
507 return ret; | |
508 } | |
509 | |
510 // The slot is the index of the field description in the field-array | |
511 // The jfieldID is the offset of the field within the object | |
512 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
513 intptr_t offset = instanceKlass::cast(k1())->offset_from_fields( slot ); | |
514 assert(instanceKlass::cast(k1())->contains_field_offset(offset), "stay within object"); | |
515 ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset); | |
516 return ret; | |
517 JNI_END | |
518 | |
519 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject); | |
520 | |
521 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic)) | |
522 JNIWrapper("ToReflectedMethod"); | |
523 DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic); | |
524 jobject ret = NULL; | |
525 DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret); | |
526 | |
527 methodHandle m (THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
528 assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); | |
529 oop reflection_method; | |
530 if (m->is_initializer()) { | |
531 reflection_method = Reflection::new_constructor(m, CHECK_NULL); | |
532 } else { | |
533 reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL); | |
534 } | |
535 ret = JNIHandles::make_local(env, reflection_method); | |
536 return ret; | |
537 JNI_END | |
538 | |
539 DT_RETURN_MARK_DECL(GetSuperclass, jclass); | |
540 | |
541 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub)) | |
542 JNIWrapper("GetSuperclass"); | |
543 DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub); | |
544 jclass obj = NULL; | |
545 DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj); | |
546 | |
547 oop mirror = JNIHandles::resolve_non_null(sub); | |
548 // primitive classes return NULL | |
549 if (java_lang_Class::is_primitive(mirror)) return NULL; | |
550 | |
551 // Rules of Class.getSuperClass as implemented by KLass::java_super: | |
552 // arrays return Object | |
553 // interfaces return NULL | |
554 // proper classes return Klass::super() | |
555 klassOop k = java_lang_Class::as_klassOop(mirror); | |
556 if (Klass::cast(k)->is_interface()) return NULL; | |
557 | |
558 // return mirror for superclass | |
559 klassOop super = Klass::cast(k)->java_super(); | |
560 // super2 is the value computed by the compiler's getSuperClass intrinsic: | |
561 debug_only(klassOop super2 = ( Klass::cast(k)->oop_is_javaArray() | |
1142 | 562 ? SystemDictionary::Object_klass() |
0 | 563 : Klass::cast(k)->super() ) ); |
564 assert(super == super2, | |
565 "java_super computation depends on interface, array, other super"); | |
566 obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(Klass::cast(super)->java_mirror()); | |
567 return obj; | |
568 JNI_END | |
569 | |
570 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super)) | |
571 JNIWrapper("IsSubclassOf"); | |
572 DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super); | |
573 oop sub_mirror = JNIHandles::resolve_non_null(sub); | |
574 oop super_mirror = JNIHandles::resolve_non_null(super); | |
575 if (java_lang_Class::is_primitive(sub_mirror) || | |
576 java_lang_Class::is_primitive(super_mirror)) { | |
577 jboolean ret = (sub_mirror == super_mirror); | |
578 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); | |
579 return ret; | |
580 } | |
581 klassOop sub_klass = java_lang_Class::as_klassOop(sub_mirror); | |
582 klassOop super_klass = java_lang_Class::as_klassOop(super_mirror); | |
583 assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom"); | |
584 jboolean ret = Klass::cast(sub_klass)->is_subtype_of(super_klass) ? | |
585 JNI_TRUE : JNI_FALSE; | |
586 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); | |
587 return ret; | |
588 JNI_END | |
589 | |
590 DT_RETURN_MARK_DECL(Throw, jint); | |
591 | |
592 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj)) | |
593 JNIWrapper("Throw"); | |
594 DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj); | |
595 jint ret = JNI_OK; | |
596 DT_RETURN_MARK(Throw, jint, (const jint&)ret); | |
597 | |
598 THROW_OOP_(JNIHandles::resolve(obj), JNI_OK); | |
599 ShouldNotReachHere(); | |
600 JNI_END | |
601 | |
602 DT_RETURN_MARK_DECL(ThrowNew, jint); | |
603 | |
604 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message)) | |
605 JNIWrapper("ThrowNew"); | |
606 DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message); | |
607 jint ret = JNI_OK; | |
608 DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret); | |
609 | |
610 instanceKlass* k = instanceKlass::cast(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
611 Symbol* name = k->name(); |
0 | 612 Handle class_loader (THREAD, k->class_loader()); |
613 Handle protection_domain (THREAD, k->protection_domain()); | |
614 THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK); | |
615 ShouldNotReachHere(); | |
616 JNI_END | |
617 | |
618 | |
619 // JNI functions only transform a pending async exception to a synchronous | |
620 // exception in ExceptionOccurred and ExceptionCheck calls, since | |
621 // delivering an async exception in other places won't change the native | |
622 // code's control flow and would be harmful when native code further calls | |
623 // JNI functions with a pending exception. Async exception is also checked | |
624 // during the call, so ExceptionOccurred/ExceptionCheck won't return | |
625 // false but deliver the async exception at the very end during | |
626 // state transition. | |
627 | |
628 static void jni_check_async_exceptions(JavaThread *thread) { | |
629 assert(thread == Thread::current(), "must be itself"); | |
630 thread->check_and_handle_async_exceptions(); | |
631 } | |
632 | |
633 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env)) | |
634 JNIWrapper("ExceptionOccurred"); | |
635 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env); | |
636 jni_check_async_exceptions(thread); | |
637 oop exception = thread->pending_exception(); | |
638 jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception); | |
639 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret); | |
640 return ret; | |
641 JNI_END | |
642 | |
643 | |
644 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env)) | |
645 JNIWrapper("ExceptionDescribe"); | |
646 DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env); | |
647 if (thread->has_pending_exception()) { | |
648 Handle ex(thread, thread->pending_exception()); | |
649 thread->clear_pending_exception(); | |
1142 | 650 if (ex->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 651 // Don't print anything if we are being killed. |
652 } else { | |
653 jio_fprintf(defaultStream::error_stream(), "Exception "); | |
654 if (thread != NULL && thread->threadObj() != NULL) { | |
655 ResourceMark rm(THREAD); | |
656 jio_fprintf(defaultStream::error_stream(), | |
657 "in thread \"%s\" ", thread->get_thread_name()); | |
658 } | |
1142 | 659 if (ex->is_a(SystemDictionary::Throwable_klass())) { |
0 | 660 JavaValue result(T_VOID); |
661 JavaCalls::call_virtual(&result, | |
662 ex, | |
663 KlassHandle(THREAD, | |
1142 | 664 SystemDictionary::Throwable_klass()), |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
665 vmSymbols::printStackTrace_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
666 vmSymbols::void_method_signature(), |
0 | 667 THREAD); |
668 // If an exception is thrown in the call it gets thrown away. Not much | |
669 // we can do with it. The native code that calls this, does not check | |
670 // for the exception - hence, it might still be in the thread when DestroyVM gets | |
671 // called, potentially causing a few asserts to trigger - since no pending exception | |
672 // is expected. | |
673 CLEAR_PENDING_EXCEPTION; | |
674 } else { | |
675 ResourceMark rm(THREAD); | |
676 jio_fprintf(defaultStream::error_stream(), | |
677 ". Uncaught exception of type %s.", | |
678 Klass::cast(ex->klass())->external_name()); | |
679 } | |
680 } | |
681 } | |
682 DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return); | |
683 JNI_END | |
684 | |
685 | |
686 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env)) | |
687 JNIWrapper("ExceptionClear"); | |
688 DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env); | |
689 | |
690 // The jni code might be using this API to clear java thrown exception. | |
691 // So just mark jvmti thread exception state as exception caught. | |
692 JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); | |
693 if (state != NULL && state->is_exception_detected()) { | |
694 state->set_exception_caught(); | |
695 } | |
696 thread->clear_pending_exception(); | |
697 DTRACE_PROBE(hotspot_jni, ExceptionClear__return); | |
698 JNI_END | |
699 | |
700 | |
701 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg)) | |
702 JNIWrapper("FatalError"); | |
703 DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg); | |
704 tty->print_cr("FATAL ERROR in native method: %s", msg); | |
705 thread->print_stack(); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
113
diff
changeset
|
706 os::abort(); // Dump core and abort |
0 | 707 JNI_END |
708 | |
709 | |
710 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) | |
711 JNIWrapper("PushLocalFrame"); | |
712 DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity); | |
713 //%note jni_11 | |
714 if (capacity < 0 && capacity > MAX_REASONABLE_LOCAL_CAPACITY) { | |
715 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); | |
716 return JNI_ERR; | |
717 } | |
718 JNIHandleBlock* old_handles = thread->active_handles(); | |
719 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); | |
720 assert(new_handles != NULL, "should not be NULL"); | |
721 new_handles->set_pop_frame_link(old_handles); | |
722 thread->set_active_handles(new_handles); | |
723 jint ret = JNI_OK; | |
724 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret); | |
725 return ret; | |
726 JNI_END | |
727 | |
728 | |
729 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result)) | |
730 JNIWrapper("PopLocalFrame"); | |
731 DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result); | |
732 //%note jni_11 | |
733 Handle result_handle(thread, JNIHandles::resolve(result)); | |
734 JNIHandleBlock* old_handles = thread->active_handles(); | |
735 JNIHandleBlock* new_handles = old_handles->pop_frame_link(); | |
736 if (new_handles != NULL) { | |
737 // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL. | |
738 // This way code will still work if PopLocalFrame is called without a corresponding | |
739 // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise | |
740 // the release_block call will release the blocks. | |
741 thread->set_active_handles(new_handles); | |
742 old_handles->set_pop_frame_link(NULL); // clear link we won't release new_handles below | |
743 JNIHandleBlock::release_block(old_handles, thread); // may block | |
744 result = JNIHandles::make_local(thread, result_handle()); | |
745 } | |
746 DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result); | |
747 return result; | |
748 JNI_END | |
749 | |
750 | |
751 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref)) | |
752 JNIWrapper("NewGlobalRef"); | |
753 DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref); | |
754 Handle ref_handle(thread, JNIHandles::resolve(ref)); | |
755 jobject ret = JNIHandles::make_global(ref_handle); | |
756 DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret); | |
757 return ret; | |
758 JNI_END | |
759 | |
760 // Must be JNI_ENTRY (with HandleMark) | |
761 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref)) | |
762 JNIWrapper("DeleteGlobalRef"); | |
763 DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref); | |
764 JNIHandles::destroy_global(ref); | |
765 DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return); | |
766 JNI_END | |
767 | |
768 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj)) | |
769 JNIWrapper("DeleteLocalRef"); | |
770 DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj); | |
771 JNIHandles::destroy_local(obj); | |
772 DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return); | |
773 JNI_END | |
774 | |
775 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2)) | |
776 JNIWrapper("IsSameObject"); | |
777 DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2); | |
778 oop a = JNIHandles::resolve(r1); | |
779 oop b = JNIHandles::resolve(r2); | |
780 jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE; | |
781 DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret); | |
782 return ret; | |
783 JNI_END | |
784 | |
785 | |
786 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref)) | |
787 JNIWrapper("NewLocalRef"); | |
788 DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref); | |
789 jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref)); | |
790 DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret); | |
791 return ret; | |
792 JNI_END | |
793 | |
794 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) | |
795 JNIWrapper("EnsureLocalCapacity"); | |
796 DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity); | |
797 jint ret; | |
798 if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { | |
799 ret = JNI_OK; | |
800 } else { | |
801 ret = JNI_ERR; | |
802 } | |
803 DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret); | |
804 return ret; | |
805 JNI_END | |
806 | |
807 // Return the Handle Type | |
808 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj)) | |
809 JNIWrapper("GetObjectRefType"); | |
810 DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj); | |
811 jobjectRefType ret; | |
812 if (JNIHandles::is_local_handle(thread, obj) || | |
813 JNIHandles::is_frame_handle(thread, obj)) | |
814 ret = JNILocalRefType; | |
815 else if (JNIHandles::is_global_handle(obj)) | |
816 ret = JNIGlobalRefType; | |
817 else if (JNIHandles::is_weak_global_handle(obj)) | |
818 ret = JNIWeakGlobalRefType; | |
819 else | |
820 ret = JNIInvalidRefType; | |
821 DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret); | |
822 return ret; | |
823 JNI_END | |
824 | |
825 | |
826 class JNI_ArgumentPusher : public SignatureIterator { | |
827 protected: | |
828 JavaCallArguments* _arguments; | |
829 | |
830 virtual void get_bool () = 0; | |
831 virtual void get_char () = 0; | |
832 virtual void get_short () = 0; | |
833 virtual void get_byte () = 0; | |
834 virtual void get_int () = 0; | |
835 virtual void get_long () = 0; | |
836 virtual void get_float () = 0; | |
837 virtual void get_double () = 0; | |
838 virtual void get_object () = 0; | |
839 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
840 JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) { |
0 | 841 this->_return_type = T_ILLEGAL; |
842 _arguments = NULL; | |
843 } | |
844 | |
845 public: | |
846 virtual void iterate( uint64_t fingerprint ) = 0; | |
847 | |
848 void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; } | |
849 | |
850 inline void do_bool() { if (!is_return_type()) get_bool(); } | |
851 inline void do_char() { if (!is_return_type()) get_char(); } | |
852 inline void do_short() { if (!is_return_type()) get_short(); } | |
853 inline void do_byte() { if (!is_return_type()) get_byte(); } | |
854 inline void do_int() { if (!is_return_type()) get_int(); } | |
855 inline void do_long() { if (!is_return_type()) get_long(); } | |
856 inline void do_float() { if (!is_return_type()) get_float(); } | |
857 inline void do_double() { if (!is_return_type()) get_double(); } | |
858 inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); } | |
859 inline void do_array(int begin, int end) { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array | |
860 inline void do_void() { } | |
861 | |
862 JavaCallArguments* arguments() { return _arguments; } | |
863 void push_receiver(Handle h) { _arguments->push_oop(h); } | |
864 }; | |
865 | |
866 | |
867 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher { | |
868 protected: | |
869 va_list _ap; | |
870 | |
871 inline void get_bool() { _arguments->push_int(va_arg(_ap, jint)); } // bool is coerced to int when using va_arg | |
872 inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg | |
873 inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg | |
874 inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg | |
875 inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); } | |
876 | |
877 // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests | |
878 | |
879 inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); } | |
880 inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg | |
881 inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); } | |
882 inline void get_object() { jobject l = va_arg(_ap, jobject); | |
883 _arguments->push_oop(Handle((oop *)l, false)); } | |
884 | |
885 inline void set_ap(va_list rap) { | |
886 #ifdef va_copy | |
887 va_copy(_ap, rap); | |
888 #elif defined (__va_copy) | |
889 __va_copy(_ap, rap); | |
890 #else | |
891 _ap = rap; | |
892 #endif | |
893 } | |
894 | |
895 public: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
896 JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
897 : JNI_ArgumentPusher(signature) { |
0 | 898 set_ap(rap); |
899 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
900 JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
901 : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
0 | 902 set_ap(rap); |
903 } | |
904 | |
905 // Optimized path if we have the bitvector form of signature | |
906 void iterate( uint64_t fingerprint ) { | |
907 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments | |
908 else { | |
909 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
910 result_feature_mask); | |
911 | |
912 assert(fingerprint, "Fingerprint should not be 0"); | |
913 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
914 while ( 1 ) { | |
915 switch ( fingerprint & parameter_feature_mask ) { | |
916 case bool_parm: | |
917 case char_parm: | |
918 case short_parm: | |
919 case byte_parm: | |
920 case int_parm: | |
921 get_int(); | |
922 break; | |
923 case obj_parm: | |
924 get_object(); | |
925 break; | |
926 case long_parm: | |
927 get_long(); | |
928 break; | |
929 case float_parm: | |
930 get_float(); | |
931 break; | |
932 case double_parm: | |
933 get_double(); | |
934 break; | |
935 case done_parm: | |
936 return; | |
937 break; | |
938 default: | |
939 ShouldNotReachHere(); | |
940 break; | |
941 } | |
942 fingerprint >>= parameter_feature_size; | |
943 } | |
944 } | |
945 } | |
946 }; | |
947 | |
948 | |
949 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher { | |
950 protected: | |
951 const jvalue *_ap; | |
952 | |
953 inline void get_bool() { _arguments->push_int((jint)(_ap++)->z); } | |
954 inline void get_char() { _arguments->push_int((jint)(_ap++)->c); } | |
955 inline void get_short() { _arguments->push_int((jint)(_ap++)->s); } | |
956 inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); } | |
957 inline void get_int() { _arguments->push_int((jint)(_ap++)->i); } | |
958 | |
959 inline void get_long() { _arguments->push_long((_ap++)->j); } | |
960 inline void get_float() { _arguments->push_float((_ap++)->f); } | |
961 inline void get_double() { _arguments->push_double((_ap++)->d);} | |
962 inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); } | |
963 | |
964 inline void set_ap(const jvalue *rap) { _ap = rap; } | |
965 | |
966 public: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
967 JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
968 : JNI_ArgumentPusher(signature) { |
0 | 969 set_ap(rap); |
970 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
971 JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
972 : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
0 | 973 set_ap(rap); |
974 } | |
975 | |
976 // Optimized path if we have the bitvector form of signature | |
977 void iterate( uint64_t fingerprint ) { | |
978 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments | |
979 else { | |
980 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
981 result_feature_mask); | |
982 assert(fingerprint, "Fingerprint should not be 0"); | |
983 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
984 while ( 1 ) { | |
985 switch ( fingerprint & parameter_feature_mask ) { | |
986 case bool_parm: | |
987 get_bool(); | |
988 break; | |
989 case char_parm: | |
990 get_char(); | |
991 break; | |
992 case short_parm: | |
993 get_short(); | |
994 break; | |
995 case byte_parm: | |
996 get_byte(); | |
997 break; | |
998 case int_parm: | |
999 get_int(); | |
1000 break; | |
1001 case obj_parm: | |
1002 get_object(); | |
1003 break; | |
1004 case long_parm: | |
1005 get_long(); | |
1006 break; | |
1007 case float_parm: | |
1008 get_float(); | |
1009 break; | |
1010 case double_parm: | |
1011 get_double(); | |
1012 break; | |
1013 case done_parm: | |
1014 return; | |
1015 break; | |
1016 default: | |
1017 ShouldNotReachHere(); | |
1018 break; | |
1019 } | |
1020 fingerprint >>= parameter_feature_size; | |
1021 } | |
1022 } | |
1023 } | |
1024 }; | |
1025 | |
1026 | |
1027 enum JNICallType { | |
1028 JNI_STATIC, | |
1029 JNI_VIRTUAL, | |
1030 JNI_NONVIRTUAL | |
1031 }; | |
1032 | |
1033 static methodHandle jni_resolve_interface_call(Handle recv, methodHandle method, TRAPS) { | |
1034 assert(!method.is_null() , "method should not be null"); | |
1035 | |
1036 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
1037 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
1038 KlassHandle spec_klass (THREAD, method->method_holder()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1039 Symbol* name = method->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1040 Symbol* signature = method->signature(); |
0 | 1041 CallInfo info; |
1042 LinkResolver::resolve_interface_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
1043 return info.selected_method(); | |
1044 } | |
1045 | |
1046 static methodHandle jni_resolve_virtual_call(Handle recv, methodHandle method, TRAPS) { | |
1047 assert(!method.is_null() , "method should not be null"); | |
1048 | |
1049 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
1050 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
1051 KlassHandle spec_klass (THREAD, method->method_holder()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1052 Symbol* name = method->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1053 Symbol* signature = method->signature(); |
0 | 1054 CallInfo info; |
1055 LinkResolver::resolve_virtual_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
1056 return info.selected_method(); | |
1057 } | |
1058 | |
1059 | |
1060 | |
1061 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
1062 methodHandle method(THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
1063 | |
1064 // Create object to hold arguments for the JavaCall, and associate it with | |
1065 // the jni parser | |
1066 ResourceMark rm(THREAD); | |
1067 int number_of_parameters = method->size_of_parameters(); | |
1068 JavaCallArguments java_args(number_of_parameters); | |
1069 args->set_java_argument_object(&java_args); | |
1070 | |
1071 assert(method->is_static(), "method should be static"); | |
1072 | |
1073 // Fill out JavaCallArguments object | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1074 args->iterate( Fingerprinter(method).fingerprint() ); |
0 | 1075 // Initialize result type |
1076 result->set_type(args->get_ret_type()); | |
1077 | |
1078 // Invoke the method. Result is returned as oop. | |
1079 JavaCalls::call(result, method, &java_args, CHECK); | |
1080 | |
1081 // Convert result | |
1082 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1083 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1084 } | |
1085 } | |
1086 | |
1087 | |
1088 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
1089 oop recv = JNIHandles::resolve(receiver); | |
1090 if (recv == NULL) { | |
1091 THROW(vmSymbols::java_lang_NullPointerException()); | |
1092 } | |
1093 Handle h_recv(THREAD, recv); | |
1094 | |
1095 int number_of_parameters; | |
1096 methodOop selected_method; | |
1097 { | |
1098 methodOop m = JNIHandles::resolve_jmethod_id(method_id); | |
1099 number_of_parameters = m->size_of_parameters(); | |
1100 klassOop holder = m->method_holder(); | |
1101 if (!(Klass::cast(holder))->is_interface()) { | |
1102 // non-interface call -- for that little speed boost, don't handlize | |
1103 debug_only(No_Safepoint_Verifier nosafepoint;) | |
1104 if (call_type == JNI_VIRTUAL) { | |
1105 // jni_GetMethodID makes sure class is linked and initialized | |
1106 // so m should have a valid vtable index. | |
1107 int vtbl_index = m->vtable_index(); | |
1108 if (vtbl_index != methodOopDesc::nonvirtual_vtable_index) { | |
1109 klassOop k = h_recv->klass(); | |
1110 // k might be an arrayKlassOop but all vtables start at | |
1111 // the same place. The cast is to avoid virtual call and assertion. | |
1112 instanceKlass *ik = (instanceKlass*)k->klass_part(); | |
1113 selected_method = ik->method_at_vtable(vtbl_index); | |
1114 } else { | |
1115 // final method | |
1116 selected_method = m; | |
1117 } | |
1118 } else { | |
1119 // JNI_NONVIRTUAL call | |
1120 selected_method = m; | |
1121 } | |
1122 } else { | |
1123 // interface call | |
1124 KlassHandle h_holder(THREAD, holder); | |
1125 | |
1126 int itbl_index = m->cached_itable_index(); | |
1127 if (itbl_index == -1) { | |
1128 itbl_index = klassItable::compute_itable_index(m); | |
1129 m->set_cached_itable_index(itbl_index); | |
1130 // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again | |
1131 } | |
1132 klassOop k = h_recv->klass(); | |
1133 selected_method = instanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); | |
1134 } | |
1135 } | |
1136 | |
1137 methodHandle method(THREAD, selected_method); | |
1138 | |
1139 // Create object to hold arguments for the JavaCall, and associate it with | |
1140 // the jni parser | |
1141 ResourceMark rm(THREAD); | |
1142 JavaCallArguments java_args(number_of_parameters); | |
1143 args->set_java_argument_object(&java_args); | |
1144 | |
1145 // handle arguments | |
1146 assert(!method->is_static(), "method should not be static"); | |
1147 args->push_receiver(h_recv); // Push jobject handle | |
1148 | |
1149 // Fill out JavaCallArguments object | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1150 args->iterate( Fingerprinter(method).fingerprint() ); |
0 | 1151 // Initialize result type |
1152 result->set_type(args->get_ret_type()); | |
1153 | |
1154 // Invoke the method. Result is returned as oop. | |
1155 JavaCalls::call(result, method, &java_args, CHECK); | |
1156 | |
1157 // Convert result | |
1158 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1159 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1160 } | |
1161 } | |
1162 | |
1163 | |
1164 static instanceOop alloc_object(jclass clazz, TRAPS) { | |
1165 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1166 Klass::cast(k())->check_valid_for_instantiation(false, CHECK_NULL); | |
1167 instanceKlass::cast(k())->initialize(CHECK_NULL); | |
1168 instanceOop ih = instanceKlass::cast(k())->allocate_instance(THREAD); | |
1169 return ih; | |
1170 } | |
1171 | |
1172 DT_RETURN_MARK_DECL(AllocObject, jobject); | |
1173 | |
1174 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz)) | |
1175 JNIWrapper("AllocObject"); | |
1176 | |
1177 DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz); | |
1178 jobject ret = NULL; | |
1179 DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); | |
1180 | |
1181 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1182 ret = JNIHandles::make_local(env, i); | |
1183 return ret; | |
1184 JNI_END | |
1185 | |
1186 DT_RETURN_MARK_DECL(NewObjectA, jobject); | |
1187 | |
1188 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args)) | |
1189 JNIWrapper("NewObjectA"); | |
1190 DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID); | |
1191 jobject obj = NULL; | |
1192 DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); | |
1193 | |
1194 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1195 obj = JNIHandles::make_local(env, i); | |
1196 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1197 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1198 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1199 return obj; | |
1200 JNI_END | |
1201 | |
1202 DT_RETURN_MARK_DECL(NewObjectV, jobject); | |
1203 | |
1204 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)) | |
1205 JNIWrapper("NewObjectV"); | |
1206 DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID); | |
1207 jobject obj = NULL; | |
1208 DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); | |
1209 | |
1210 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1211 obj = JNIHandles::make_local(env, i); | |
1212 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1213 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1214 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1215 return obj; | |
1216 JNI_END | |
1217 | |
1218 DT_RETURN_MARK_DECL(NewObject, jobject); | |
1219 | |
1220 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)) | |
1221 JNIWrapper("NewObject"); | |
1222 DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID); | |
1223 jobject obj = NULL; | |
1224 DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); | |
1225 | |
1226 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1227 obj = JNIHandles::make_local(env, i); | |
1228 va_list args; | |
1229 va_start(args, methodID); | |
1230 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1231 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1232 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1233 va_end(args); | |
1234 return obj; | |
1235 JNI_END | |
1236 | |
1237 | |
1238 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) | |
1239 JNIWrapper("GetObjectClass"); | |
1240 DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj); | |
1241 klassOop k = JNIHandles::resolve_non_null(obj)->klass(); | |
1242 jclass ret = | |
1243 (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror()); | |
1244 DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret); | |
1245 return ret; | |
1246 JNI_END | |
1247 | |
1248 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)) | |
1249 JNIWrapper("IsInstanceOf"); | |
1250 DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz); | |
1251 jboolean ret = JNI_TRUE; | |
1252 if (obj != NULL) { | |
1253 ret = JNI_FALSE; | |
1254 klassOop k = java_lang_Class::as_klassOop( | |
1255 JNIHandles::resolve_non_null(clazz)); | |
1256 if (k != NULL) { | |
1257 ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE; | |
1258 } | |
1259 } | |
1260 DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret); | |
1261 return ret; | |
1262 JNI_END | |
1263 | |
1264 | |
1265 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str, | |
1266 const char *sig, bool is_static, TRAPS) { | |
1267 // %%%% This code should probably just call into a method in the LinkResolver | |
1268 // | |
1269 // The class should have been loaded (we have an instance of the class | |
1270 // passed in) so the method and signature should already be in the symbol | |
1271 // table. If they're not there, the method doesn't exist. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1272 const char *name_to_probe = (name_str == NULL) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1273 ? vmSymbols::object_initializer_name()->as_C_string() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1274 : name_str; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1275 TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1276 TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1277 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1278 if (name == NULL || signature == NULL) { |
0 | 1279 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
1280 } | |
1281 | |
1282 // Throw a NoSuchMethodError exception if we have an instance of a | |
1283 // primitive java.lang.Class | |
1284 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) { | |
1285 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1286 } | |
1287 | |
1288 KlassHandle klass(THREAD, | |
1289 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1290 | |
1291 // Make sure class is linked and initialized before handing id's out to | |
1292 // methodOops. | |
1293 Klass::cast(klass())->initialize(CHECK_NULL); | |
1294 | |
1295 methodOop m; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1296 if (name == vmSymbols::object_initializer_name() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1297 name == vmSymbols::class_initializer_name()) { |
0 | 1298 // Never search superclasses for constructors |
1299 if (klass->oop_is_instance()) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1300 m = instanceKlass::cast(klass())->find_method(name, signature); |
0 | 1301 } else { |
1302 m = NULL; | |
1303 } | |
1304 } else { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1305 m = klass->lookup_method(name, signature); |
0 | 1306 // Look up interfaces |
1307 if (m == NULL && klass->oop_is_instance()) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1308 m = instanceKlass::cast(klass())->lookup_method_in_all_interfaces(name, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1309 signature); |
0 | 1310 } |
1311 } | |
1312 if (m == NULL || (m->is_static() != is_static)) { | |
1313 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1314 } | |
1315 return m->jmethod_id(); | |
1316 } | |
1317 | |
1318 | |
1319 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz, | |
1320 const char *name, const char *sig)) | |
1321 JNIWrapper("GetMethodID"); | |
1322 DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig); | |
1323 jmethodID ret = get_method_id(env, clazz, name, sig, false, thread); | |
1324 DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret); | |
1325 return ret; | |
1326 JNI_END | |
1327 | |
1328 | |
1329 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz, | |
1330 const char *name, const char *sig)) | |
1331 JNIWrapper("GetStaticMethodID"); | |
1332 DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig); | |
1333 jmethodID ret = get_method_id(env, clazz, name, sig, true, thread); | |
1334 DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret); | |
1335 return ret; | |
1336 JNI_END | |
1337 | |
1338 | |
1339 | |
1340 // | |
1341 // Calling Methods | |
1342 // | |
1343 | |
1344 | |
1345 #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \ | |
1346 \ | |
1347 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\ | |
1348 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\ | |
1349 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\ | |
1350 \ | |
1351 JNI_ENTRY(ResultType, \ | |
1352 jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ | |
1353 JNIWrapper("Call" XSTR(Result) "Method"); \ | |
1354 \ | |
1355 DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID);\ | |
1356 ResultType ret = 0;\ | |
1357 DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ | |
1358 (const ResultType&)ret);\ | |
1359 \ | |
1360 va_list args; \ | |
1361 va_start(args, methodID); \ | |
1362 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1363 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1364 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1365 va_end(args); \ | |
1366 ret = jvalue.get_##ResultType(); \ | |
1367 return ret;\ | |
1368 JNI_END \ | |
1369 \ | |
1370 \ | |
1371 JNI_ENTRY(ResultType, \ | |
1372 jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ | |
1373 JNIWrapper("Call" XSTR(Result) "MethodV"); \ | |
1374 \ | |
1375 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID);\ | |
1376 ResultType ret = 0;\ | |
1377 DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ | |
1378 (const ResultType&)ret);\ | |
1379 \ | |
1380 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1381 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1382 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1383 ret = jvalue.get_##ResultType(); \ | |
1384 return ret;\ | |
1385 JNI_END \ | |
1386 \ | |
1387 \ | |
1388 JNI_ENTRY(ResultType, \ | |
1389 jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ | |
1390 JNIWrapper("Call" XSTR(Result) "MethodA"); \ | |
1391 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID);\ | |
1392 ResultType ret = 0;\ | |
1393 DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ | |
1394 (const ResultType&)ret);\ | |
1395 \ | |
1396 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1397 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 1398 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1399 ret = jvalue.get_##ResultType(); \ | |
1400 return ret;\ | |
1401 JNI_END | |
1402 | |
1403 // the runtime type of subword integral basic types is integer | |
1404 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1405 DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE) | |
1406 DEFINE_CALLMETHOD(jchar, Char, T_CHAR) | |
1407 DEFINE_CALLMETHOD(jshort, Short, T_SHORT) | |
1408 | |
1409 DEFINE_CALLMETHOD(jobject, Object, T_OBJECT) | |
1410 DEFINE_CALLMETHOD(jint, Int, T_INT) | |
1411 DEFINE_CALLMETHOD(jlong, Long, T_LONG) | |
1412 DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT) | |
1413 DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE) | |
1414 | |
1415 DT_VOID_RETURN_MARK_DECL(CallVoidMethod); | |
1416 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV); | |
1417 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA); | |
1418 | |
1419 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)) | |
1420 JNIWrapper("CallVoidMethod"); | |
1421 DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID); | |
1422 DT_VOID_RETURN_MARK(CallVoidMethod); | |
1423 | |
1424 va_list args; | |
1425 va_start(args, methodID); | |
1426 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1427 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1428 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1429 va_end(args); | |
1430 JNI_END | |
1431 | |
1432 | |
1433 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) | |
1434 JNIWrapper("CallVoidMethodV"); | |
1435 DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID); | |
1436 DT_VOID_RETURN_MARK(CallVoidMethodV); | |
1437 | |
1438 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1439 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1440 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1441 JNI_END | |
1442 | |
1443 | |
1444 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) | |
1445 JNIWrapper("CallVoidMethodA"); | |
1446 DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID); | |
1447 DT_VOID_RETURN_MARK(CallVoidMethodA); | |
1448 | |
1449 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1450 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1451 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1452 JNI_END | |
1453 | |
1454 | |
1455 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \ | |
1456 \ | |
1457 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\ | |
1458 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\ | |
1459 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\ | |
1460 \ | |
1461 JNI_ENTRY(ResultType, \ | |
1462 jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ | |
1463 JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ | |
1464 \ | |
1465 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\ | |
1466 ResultType ret;\ | |
1467 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ | |
1468 (const ResultType&)ret);\ | |
1469 \ | |
1470 va_list args; \ | |
1471 va_start(args, methodID); \ | |
1472 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1473 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1474 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
1475 va_end(args); \ | |
1476 ret = jvalue.get_##ResultType(); \ | |
1477 return ret;\ | |
1478 JNI_END \ | |
1479 \ | |
1480 JNI_ENTRY(ResultType, \ | |
1481 jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ | |
1482 JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \ | |
1483 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\ | |
1484 ResultType ret;\ | |
1485 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ | |
1486 (const ResultType&)ret);\ | |
1487 \ | |
1488 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1489 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1490 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
1491 ret = jvalue.get_##ResultType(); \ | |
1492 return ret;\ | |
1493 JNI_END \ | |
1494 \ | |
1495 JNI_ENTRY(ResultType, \ | |
1496 jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
1497 JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ | |
1498 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\ | |
1499 ResultType ret;\ | |
1500 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ | |
1501 (const ResultType&)ret);\ | |
1502 \ | |
1503 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1504 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 1505 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
1506 ret = jvalue.get_##ResultType(); \ | |
1507 return ret;\ | |
1508 JNI_END | |
1509 | |
1510 // the runtime type of subword integral basic types is integer | |
1511 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1512 DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE) | |
1513 DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR) | |
1514 DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT) | |
1515 | |
1516 DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT) | |
1517 DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT) | |
1518 DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG) | |
1519 DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT) | |
1520 DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE) | |
1521 | |
1522 | |
1523 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod); | |
1524 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV); | |
1525 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA); | |
1526 | |
1527 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) | |
1528 JNIWrapper("CallNonvirtualVoidMethod"); | |
1529 | |
1530 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry, | |
1531 env, obj, cls, methodID); | |
1532 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod); | |
1533 | |
1534 va_list args; | |
1535 va_start(args, methodID); | |
1536 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1537 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1538 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
1539 va_end(args); | |
1540 JNI_END | |
1541 | |
1542 | |
1543 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) | |
1544 JNIWrapper("CallNonvirtualVoidMethodV"); | |
1545 | |
1546 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry, | |
1547 env, obj, cls, methodID); | |
1548 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV); | |
1549 | |
1550 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1551 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1552 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
1553 JNI_END | |
1554 | |
1555 | |
1556 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) | |
1557 JNIWrapper("CallNonvirtualVoidMethodA"); | |
1558 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry, | |
1559 env, obj, cls, methodID); | |
1560 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA); | |
1561 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1562 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1563 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
1564 JNI_END | |
1565 | |
1566 | |
1567 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \ | |
1568 \ | |
1569 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\ | |
1570 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\ | |
1571 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\ | |
1572 \ | |
1573 JNI_ENTRY(ResultType, \ | |
1574 jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ | |
1575 JNIWrapper("CallStatic" XSTR(Result) "Method"); \ | |
1576 \ | |
1577 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\ | |
1578 ResultType ret = 0;\ | |
1579 DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ | |
1580 (const ResultType&)ret);\ | |
1581 \ | |
1582 va_list args; \ | |
1583 va_start(args, methodID); \ | |
1584 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1585 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1586 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
1587 va_end(args); \ | |
1588 ret = jvalue.get_##ResultType(); \ | |
1589 return ret;\ | |
1590 JNI_END \ | |
1591 \ | |
1592 JNI_ENTRY(ResultType, \ | |
1593 jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ | |
1594 JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ | |
1595 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\ | |
1596 ResultType ret = 0;\ | |
1597 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ | |
1598 (const ResultType&)ret);\ | |
1599 \ | |
1600 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1601 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1602 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
1603 ret = jvalue.get_##ResultType(); \ | |
1604 return ret;\ | |
1605 JNI_END \ | |
1606 \ | |
1607 JNI_ENTRY(ResultType, \ | |
1608 jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
1609 JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ | |
1610 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\ | |
1611 ResultType ret = 0;\ | |
1612 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ | |
1613 (const ResultType&)ret);\ | |
1614 \ | |
1615 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1616 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 1617 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
1618 ret = jvalue.get_##ResultType(); \ | |
1619 return ret;\ | |
1620 JNI_END | |
1621 | |
1622 // the runtime type of subword integral basic types is integer | |
1623 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1624 DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE) | |
1625 DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR) | |
1626 DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT) | |
1627 | |
1628 DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT) | |
1629 DEFINE_CALLSTATICMETHOD(jint, Int, T_INT) | |
1630 DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG) | |
1631 DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT) | |
1632 DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE) | |
1633 | |
1634 | |
1635 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod); | |
1636 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV); | |
1637 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA); | |
1638 | |
1639 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)) | |
1640 JNIWrapper("CallStaticVoidMethod"); | |
1641 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID); | |
1642 DT_VOID_RETURN_MARK(CallStaticVoidMethod); | |
1643 | |
1644 va_list args; | |
1645 va_start(args, methodID); | |
1646 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1647 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1648 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
1649 va_end(args); | |
1650 JNI_END | |
1651 | |
1652 | |
1653 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) | |
1654 JNIWrapper("CallStaticVoidMethodV"); | |
1655 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID); | |
1656 DT_VOID_RETURN_MARK(CallStaticVoidMethodV); | |
1657 | |
1658 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1659 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1660 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
1661 JNI_END | |
1662 | |
1663 | |
1664 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) | |
1665 JNIWrapper("CallStaticVoidMethodA"); | |
1666 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID); | |
1667 DT_VOID_RETURN_MARK(CallStaticVoidMethodA); | |
1668 | |
1669 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1670 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1671 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
1672 JNI_END | |
1673 | |
1674 | |
1675 // | |
1676 // Accessing Fields | |
1677 // | |
1678 | |
1679 | |
1680 DT_RETURN_MARK_DECL(GetFieldID, jfieldID); | |
1681 | |
1682 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz, | |
1683 const char *name, const char *sig)) | |
1684 JNIWrapper("GetFieldID"); | |
1685 DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig); | |
1686 jfieldID ret = 0; | |
1687 DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret); | |
1688 | |
1689 // The class should have been loaded (we have an instance of the class | |
1690 // passed in) so the field and signature should already be in the symbol | |
1691 // table. If they're not there, the field doesn't exist. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1692 TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1693 TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1694 if (fieldname == NULL || signame == NULL) { |
0 | 1695 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
1696 } | |
1697 KlassHandle k(THREAD, | |
1698 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1699 // Make sure class is initialized before handing id's out to fields | |
1700 Klass::cast(k())->initialize(CHECK_NULL); | |
1701 | |
1702 fieldDescriptor fd; | |
1703 if (!Klass::cast(k())->oop_is_instance() || | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1704 !instanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) { |
0 | 1705 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
1706 } | |
1707 | |
1708 // A jfieldID for a non-static field is simply the offset of the field within the instanceOop | |
1709 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
1710 ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset()); | |
1711 return ret; | |
1712 JNI_END | |
1713 | |
1714 | |
1715 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)) | |
1716 JNIWrapper("GetObjectField"); | |
1717 DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID); | |
1718 oop o = JNIHandles::resolve_non_null(obj); | |
1719 klassOop k = o->klass(); | |
1720 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1721 // Keep JVMTI addition small and only check enabled flag here. | |
1722 // jni_GetField_probe() assumes that is okay to create handles. | |
1723 if (JvmtiExport::should_post_field_access()) { | |
1724 o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); | |
1725 } | |
1726 jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); | |
1727 DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); | |
1728 return ret; | |
1729 JNI_END | |
1730 | |
1731 | |
1732 #define DEFINE_GETFIELD(Return,Fieldname,Result) \ | |
1733 \ | |
1734 DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\ | |
1735 \ | |
1736 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ | |
1737 JNIWrapper("Get" XSTR(Result) "Field"); \ | |
1738 \ | |
1739 DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\ | |
1740 Return ret = 0;\ | |
1741 DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ | |
1742 \ | |
1743 oop o = JNIHandles::resolve_non_null(obj); \ | |
1744 klassOop k = o->klass(); \ | |
1745 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
1746 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1747 /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ | |
1748 /* and creates a ResetNoHandleMark. */ \ | |
1749 if (JvmtiExport::should_post_field_access()) { \ | |
1750 o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ | |
1751 } \ | |
1752 ret = o->Fieldname##_field(offset); \ | |
1753 return ret; \ | |
1754 JNI_END | |
1755 | |
1756 DEFINE_GETFIELD(jboolean, bool, Boolean) | |
1757 DEFINE_GETFIELD(jbyte, byte, Byte) | |
1758 DEFINE_GETFIELD(jchar, char, Char) | |
1759 DEFINE_GETFIELD(jshort, short, Short) | |
1760 DEFINE_GETFIELD(jint, int, Int) | |
1761 DEFINE_GETFIELD(jlong, long, Long) | |
1762 DEFINE_GETFIELD(jfloat, float, Float) | |
1763 DEFINE_GETFIELD(jdouble, double, Double) | |
1764 | |
1765 address jni_GetBooleanField_addr() { | |
1766 return (address)jni_GetBooleanField; | |
1767 } | |
1768 address jni_GetByteField_addr() { | |
1769 return (address)jni_GetByteField; | |
1770 } | |
1771 address jni_GetCharField_addr() { | |
1772 return (address)jni_GetCharField; | |
1773 } | |
1774 address jni_GetShortField_addr() { | |
1775 return (address)jni_GetShortField; | |
1776 } | |
1777 address jni_GetIntField_addr() { | |
1778 return (address)jni_GetIntField; | |
1779 } | |
1780 address jni_GetLongField_addr() { | |
1781 return (address)jni_GetLongField; | |
1782 } | |
1783 address jni_GetFloatField_addr() { | |
1784 return (address)jni_GetFloatField; | |
1785 } | |
1786 address jni_GetDoubleField_addr() { | |
1787 return (address)jni_GetDoubleField; | |
1788 } | |
1789 | |
1790 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)) | |
1791 JNIWrapper("SetObjectField"); | |
1792 DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value); | |
1793 oop o = JNIHandles::resolve_non_null(obj); | |
1794 klassOop k = o->klass(); | |
1795 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1796 // Keep JVMTI addition small and only check enabled flag here. | |
1797 // jni_SetField_probe_nh() assumes that is not okay to create handles | |
1798 // and creates a ResetNoHandleMark. | |
1799 if (JvmtiExport::should_post_field_modification()) { | |
1800 jvalue field_value; | |
1801 field_value.l = value; | |
1802 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value); | |
1803 } | |
1804 o->obj_field_put(offset, JNIHandles::resolve(value)); | |
1805 DTRACE_PROBE(hotspot_jni, SetObjectField__return); | |
1806 JNI_END | |
1807 | |
1808 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \ | |
1809 \ | |
1810 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ | |
1811 JNIWrapper("Set" XSTR(Result) "Field"); \ | |
1812 \ | |
1813 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, Set##Result##Field__entry, \ | |
1814 ( JNIEnv*, jobject, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
1815 HS_DTRACE_PROBE_N(hotspot_jni, Set##Result##Field__entry, \ | |
1816 ( env, obj, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
1817 \ | |
1818 oop o = JNIHandles::resolve_non_null(obj); \ | |
1819 klassOop k = o->klass(); \ | |
1820 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
1821 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1822 /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ | |
1823 /* and creates a ResetNoHandleMark. */ \ | |
1824 if (JvmtiExport::should_post_field_modification()) { \ | |
1825 jvalue field_value; \ | |
1826 field_value.unionType = value; \ | |
1827 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ | |
1828 } \ | |
1829 o->Fieldname##_field_put(offset, value); \ | |
1830 DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\ | |
1831 JNI_END | |
1832 | |
1833 DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z) | |
1834 DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b) | |
1835 DEFINE_SETFIELD(jchar, char, Char, 'C', c) | |
1836 DEFINE_SETFIELD(jshort, short, Short, 'S', s) | |
1837 DEFINE_SETFIELD(jint, int, Int, 'I', i) | |
1838 DEFINE_SETFIELD(jlong, long, Long, 'J', j) | |
1839 DEFINE_SETFIELD(jfloat, float, Float, 'F', f) | |
1840 DEFINE_SETFIELD(jdouble, double, Double, 'D', d) | |
1841 | |
1842 DT_RETURN_MARK_DECL(ToReflectedField, jobject); | |
1843 | |
1844 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)) | |
1845 JNIWrapper("ToReflectedField"); | |
1846 DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry, | |
1847 env, cls, fieldID, isStatic); | |
1848 jobject ret = NULL; | |
1849 DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret); | |
1850 | |
1851 fieldDescriptor fd; | |
1852 bool found = false; | |
1853 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)); | |
1854 | |
1855 assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID"); | |
1856 | |
1857 if (isStatic) { | |
1858 // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop. | |
1859 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1860 assert(id->is_static_field_id(), "invalid static field id"); | |
1861 found = instanceKlass::cast(id->holder())->find_local_field_from_offset(id->offset(), true, &fd); | |
1862 } else { | |
1863 // Non-static field. The fieldID is really the offset of the field within the instanceOop. | |
1864 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
1865 found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); | |
1866 } | |
1867 assert(found, "bad fieldID passed into jni_ToReflectedField"); | |
1868 oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); | |
1869 ret = JNIHandles::make_local(env, reflected); | |
1870 return ret; | |
1871 JNI_END | |
1872 | |
1873 | |
1874 // | |
1875 // Accessing Static Fields | |
1876 // | |
1877 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID); | |
1878 | |
1879 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz, | |
1880 const char *name, const char *sig)) | |
1881 JNIWrapper("GetStaticFieldID"); | |
1882 DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig); | |
1883 jfieldID ret = NULL; | |
1884 DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret); | |
1885 | |
1886 // The class should have been loaded (we have an instance of the class | |
1887 // passed in) so the field and signature should already be in the symbol | |
1888 // table. If they're not there, the field doesn't exist. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1889 TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1890 TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1891 if (fieldname == NULL || signame == NULL) { |
0 | 1892 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
1893 } | |
1894 KlassHandle k(THREAD, | |
1895 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1896 // Make sure class is initialized before handing id's out to static fields | |
1897 Klass::cast(k())->initialize(CHECK_NULL); | |
1898 | |
1899 fieldDescriptor fd; | |
1900 if (!Klass::cast(k())->oop_is_instance() || | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1901 !instanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) { |
0 | 1902 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
1903 } | |
1904 | |
1905 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
1906 JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset()); | |
1907 debug_only(id->set_is_static_field_id();) | |
1908 | |
1909 debug_only(int first_offset = instanceKlass::cast(fd.field_holder())->offset_of_static_fields();) | |
1910 debug_only(int end_offset = first_offset + (instanceKlass::cast(fd.field_holder())->static_field_size() * wordSize);) | |
1911 assert(id->offset() >= first_offset && id->offset() < end_offset, "invalid static field offset"); | |
1912 | |
1913 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
1914 return ret; | |
1915 JNI_END | |
1916 | |
1917 | |
1918 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)) | |
1919 JNIWrapper("GetStaticObjectField"); | |
1920 DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID); | |
1921 #ifndef JNICHECK_KERNEL | |
1922 DEBUG_ONLY(klassOop param_k = jniCheck::validate_class(thread, clazz);) | |
1923 #endif // JNICHECK_KERNEL | |
1924 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1925 assert(id->is_static_field_id(), "invalid static field id"); | |
1926 // Keep JVMTI addition small and only check enabled flag here. | |
1927 // jni_GetField_probe() assumes that is okay to create handles. | |
1928 if (JvmtiExport::should_post_field_access()) { | |
1929 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); | |
1930 } | |
1931 jobject ret = JNIHandles::make_local(id->holder()->obj_field(id->offset())); | |
1932 DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); | |
1933 return ret; | |
1934 JNI_END | |
1935 | |
1936 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ | |
1937 \ | |
1938 DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\ | |
1939 \ | |
1940 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ | |
1941 JNIWrapper("GetStatic" XSTR(Result) "Field"); \ | |
1942 DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\ | |
1943 Return ret = 0;\ | |
1944 DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ | |
1945 (const Return&)ret);\ | |
1946 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
1947 assert(id->is_static_field_id(), "invalid static field id"); \ | |
1948 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1949 /* jni_GetField_probe() assumes that is okay to create handles. */ \ | |
1950 if (JvmtiExport::should_post_field_access()) { \ | |
1951 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ | |
1952 } \ | |
1953 ret = id->holder()-> Fieldname##_field (id->offset()); \ | |
1954 return ret;\ | |
1955 JNI_END | |
1956 | |
1957 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) | |
1958 DEFINE_GETSTATICFIELD(jbyte, byte, Byte) | |
1959 DEFINE_GETSTATICFIELD(jchar, char, Char) | |
1960 DEFINE_GETSTATICFIELD(jshort, short, Short) | |
1961 DEFINE_GETSTATICFIELD(jint, int, Int) | |
1962 DEFINE_GETSTATICFIELD(jlong, long, Long) | |
1963 DEFINE_GETSTATICFIELD(jfloat, float, Float) | |
1964 DEFINE_GETSTATICFIELD(jdouble, double, Double) | |
1965 | |
1966 | |
1967 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)) | |
1968 JNIWrapper("SetStaticObjectField"); | |
1969 DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value); | |
1970 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
1971 assert(id->is_static_field_id(), "invalid static field id"); | |
1972 // Keep JVMTI addition small and only check enabled flag here. | |
1973 // jni_SetField_probe() assumes that is okay to create handles. | |
1974 if (JvmtiExport::should_post_field_modification()) { | |
1975 jvalue field_value; | |
1976 field_value.l = value; | |
1977 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); | |
1978 } | |
1979 id->holder()->obj_field_put(id->offset(), JNIHandles::resolve(value)); | |
1980 DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); | |
1981 JNI_END | |
1982 | |
1983 | |
1984 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ | |
1985 \ | |
1986 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ | |
1987 JNIWrapper("SetStatic" XSTR(Result) "Field"); \ | |
1988 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, SetStatic##Result##Field__entry,\ | |
1989 ( JNIEnv*, jclass, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
1990 HS_DTRACE_PROBE_N(hotspot_jni, SetStatic##Result##Field__entry, \ | |
1991 ( env, clazz, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
1992 \ | |
1993 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
1994 assert(id->is_static_field_id(), "invalid static field id"); \ | |
1995 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
1996 /* jni_SetField_probe() assumes that is okay to create handles. */ \ | |
1997 if (JvmtiExport::should_post_field_modification()) { \ | |
1998 jvalue field_value; \ | |
1999 field_value.unionType = value; \ | |
2000 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ | |
2001 } \ | |
2002 id->holder()-> Fieldname##_field_put (id->offset(), value); \ | |
2003 DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ | |
2004 JNI_END | |
2005 | |
2006 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) | |
2007 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) | |
2008 DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c) | |
2009 DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s) | |
2010 DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i) | |
2011 DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j) | |
2012 DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f) | |
2013 DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d) | |
2014 | |
2015 | |
2016 // | |
2017 // String Operations | |
2018 // | |
2019 | |
2020 // Unicode Interface | |
2021 | |
2022 DT_RETURN_MARK_DECL(NewString, jstring); | |
2023 | |
2024 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len)) | |
2025 JNIWrapper("NewString"); | |
2026 DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len); | |
2027 jstring ret = NULL; | |
2028 DT_RETURN_MARK(NewString, jstring, (const jstring&)ret); | |
2029 oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL); | |
2030 ret = (jstring) JNIHandles::make_local(env, string); | |
2031 return ret; | |
2032 JNI_END | |
2033 | |
2034 | |
2035 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string)) | |
2036 JNIWrapper("GetStringLength"); | |
2037 DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string); | |
2038 jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string)); | |
2039 DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret); | |
2040 return ret; | |
2041 JNI_END | |
2042 | |
2043 | |
2044 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars( | |
2045 JNIEnv *env, jstring string, jboolean *isCopy)) | |
2046 JNIWrapper("GetStringChars"); | |
2047 DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy); | |
2048 //%note jni_5 | |
2049 if (isCopy != NULL) { | |
2050 *isCopy = JNI_TRUE; | |
2051 } | |
2052 oop s = JNIHandles::resolve_non_null(string); | |
2053 int s_len = java_lang_String::length(s); | |
2054 typeArrayOop s_value = java_lang_String::value(s); | |
2055 int s_offset = java_lang_String::offset(s); | |
2056 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination | |
2057 if (s_len > 0) { | |
2058 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); | |
2059 } | |
2060 buf[s_len] = 0; | |
2061 DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf); | |
2062 return buf; | |
2063 JNI_END | |
2064 | |
2065 | |
2066 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)) | |
2067 JNIWrapper("ReleaseStringChars"); | |
2068 DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars); | |
2069 //%note jni_6 | |
2070 if (chars != NULL) { | |
2071 // Since String objects are supposed to be immutable, don't copy any | |
2072 // new data back. A bad user will have to go after the char array. | |
2073 FreeHeap((void*) chars); | |
2074 } | |
2075 DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return); | |
2076 JNI_END | |
2077 | |
2078 | |
2079 // UTF Interface | |
2080 | |
2081 DT_RETURN_MARK_DECL(NewStringUTF, jstring); | |
2082 | |
2083 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes)) | |
2084 JNIWrapper("NewStringUTF"); | |
2085 DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes); | |
2086 jstring ret; | |
2087 DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret); | |
2088 | |
2089 oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL); | |
2090 ret = (jstring) JNIHandles::make_local(env, result); | |
2091 return ret; | |
2092 JNI_END | |
2093 | |
2094 | |
2095 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string)) | |
2096 JNIWrapper("GetStringUTFLength"); | |
2097 DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string); | |
2098 jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string)); | |
2099 DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret); | |
2100 return ret; | |
2101 JNI_END | |
2102 | |
2103 | |
2104 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)) | |
2105 JNIWrapper("GetStringUTFChars"); | |
2106 DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy); | |
1989
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
2107 oop java_string = JNIHandles::resolve_non_null(string); |
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
2108 size_t length = java_lang_String::utf8_length(java_string); |
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
2109 char* result = AllocateHeap(length + 1, "GetStringUTFChars"); |
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
2110 java_lang_String::as_utf8_string(java_string, result, (int) length + 1); |
0 | 2111 if (isCopy != NULL) *isCopy = JNI_TRUE; |
2112 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); | |
2113 return result; | |
2114 JNI_END | |
2115 | |
2116 | |
2117 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars)) | |
2118 JNIWrapper("ReleaseStringUTFChars"); | |
2119 DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars); | |
2120 if (chars != NULL) { | |
2121 FreeHeap((char*) chars); | |
2122 } | |
2123 DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return); | |
2124 JNI_END | |
2125 | |
2126 | |
2127 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array)) | |
2128 JNIWrapper("GetArrayLength"); | |
2129 DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array); | |
2130 arrayOop a = arrayOop(JNIHandles::resolve_non_null(array)); | |
2131 assert(a->is_array(), "must be array"); | |
2132 jsize ret = a->length(); | |
2133 DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret); | |
2134 return ret; | |
2135 JNI_END | |
2136 | |
2137 | |
2138 // | |
2139 // Object Array Operations | |
2140 // | |
2141 | |
2142 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray); | |
2143 | |
2144 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)) | |
2145 JNIWrapper("NewObjectArray"); | |
2146 DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement); | |
2147 jobjectArray ret = NULL; | |
2148 DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret); | |
2149 KlassHandle ek(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(elementClass))); | |
2150 klassOop ako = Klass::cast(ek())->array_klass(CHECK_NULL); | |
2151 KlassHandle ak = KlassHandle(THREAD, ako); | |
2152 objArrayKlass::cast(ak())->initialize(CHECK_NULL); | |
2153 objArrayOop result = objArrayKlass::cast(ak())->allocate(length, CHECK_NULL); | |
2154 oop initial_value = JNIHandles::resolve(initialElement); | |
2155 if (initial_value != NULL) { // array already initialized with NULL | |
2156 for (int index = 0; index < length; index++) { | |
2157 result->obj_at_put(index, initial_value); | |
2158 } | |
2159 } | |
2160 ret = (jobjectArray) JNIHandles::make_local(env, result); | |
2161 return ret; | |
2162 JNI_END | |
2163 | |
2164 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject); | |
2165 | |
2166 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)) | |
2167 JNIWrapper("GetObjectArrayElement"); | |
2168 DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index); | |
2169 jobject ret = NULL; | |
2170 DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret); | |
2171 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
2172 if (a->is_within_bounds(index)) { | |
1034
08780c8a9f04
6893483: DTrace probe return values for a couple JNI methods are wrong
kamg
parents:
973
diff
changeset
|
2173 ret = JNIHandles::make_local(env, a->obj_at(index)); |
0 | 2174 return ret; |
2175 } else { | |
2176 char buf[jintAsStringSize]; | |
2177 sprintf(buf, "%d", index); | |
2178 THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
2179 } | |
2180 JNI_END | |
2181 | |
2182 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement); | |
2183 | |
2184 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value)) | |
2185 JNIWrapper("SetObjectArrayElement"); | |
2186 DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value); | |
2187 DT_VOID_RETURN_MARK(SetObjectArrayElement); | |
2188 | |
2189 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
2190 oop v = JNIHandles::resolve(value); | |
2191 if (a->is_within_bounds(index)) { | |
2192 if (v == NULL || v->is_a(objArrayKlass::cast(a->klass())->element_klass())) { | |
2193 a->obj_at_put(index, v); | |
2194 } else { | |
2195 THROW(vmSymbols::java_lang_ArrayStoreException()); | |
2196 } | |
2197 } else { | |
2198 char buf[jintAsStringSize]; | |
2199 sprintf(buf, "%d", index); | |
2200 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
2201 } | |
2202 JNI_END | |
2203 | |
2204 | |
2205 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \ | |
2206 \ | |
1034
08780c8a9f04
6893483: DTrace probe return values for a couple JNI methods are wrong
kamg
parents:
973
diff
changeset
|
2207 DT_RETURN_MARK_DECL(New##Result##Array, Return);\ |
0 | 2208 \ |
2209 JNI_ENTRY(Return, \ | |
2210 jni_New##Result##Array(JNIEnv *env, jsize len)) \ | |
2211 JNIWrapper("New" XSTR(Result) "Array"); \ | |
2212 DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\ | |
2213 Return ret = NULL;\ | |
1034
08780c8a9f04
6893483: DTrace probe return values for a couple JNI methods are wrong
kamg
parents:
973
diff
changeset
|
2214 DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
0 | 2215 \ |
2216 oop obj= oopFactory::Allocator(len, CHECK_0); \ | |
2217 ret = (Return) JNIHandles::make_local(env, obj); \ | |
2218 return ret;\ | |
2219 JNI_END | |
2220 | |
2221 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean) | |
2222 DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte) | |
2223 DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short) | |
2224 DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char) | |
2225 DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int) | |
2226 DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) | |
2227 DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) | |
2228 DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) | |
2229 | |
2230 | |
2231 // Return an address which will fault if the caller writes to it. | |
2232 | |
2233 static char* get_bad_address() { | |
2234 static char* bad_address = NULL; | |
2235 if (bad_address == NULL) { | |
2236 size_t size = os::vm_allocation_granularity(); | |
2237 bad_address = os::reserve_memory(size); | |
2238 if (bad_address != NULL) { | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
237
diff
changeset
|
2239 os::protect_memory(bad_address, size, os::MEM_PROT_READ, |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
237
diff
changeset
|
2240 /*is_committed*/false); |
0 | 2241 } |
2242 } | |
2243 return bad_address; | |
2244 } | |
2245 | |
2246 | |
2247 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \ | |
2248 \ | |
2249 JNI_QUICK_ENTRY(ElementType*, \ | |
2250 jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ | |
2251 JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ | |
2252 DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\ | |
2253 /* allocate an chunk of memory in c land */ \ | |
2254 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2255 ElementType* result; \ | |
2256 int len = a->length(); \ | |
2257 if (len == 0) { \ | |
2258 /* Empty array: legal but useless, can't return NULL. \ | |
2259 * Return a pointer to something useless. \ | |
2260 * Avoid asserts in typeArrayOop. */ \ | |
2261 result = (ElementType*)get_bad_address(); \ | |
2262 } else { \ | |
2263 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | |
2264 /* copy the array to the c chunk */ \ | |
2265 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | |
2266 } \ | |
2267 if (isCopy) *isCopy = JNI_TRUE; \ | |
2268 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ | |
2269 return result; \ | |
2270 JNI_END | |
2271 | |
2272 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
2273 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
2274 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
2275 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
2276 DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
2277 DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
2278 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
2279 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
2280 | |
2281 | |
2282 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \ | |
2283 \ | |
2284 JNI_QUICK_ENTRY(void, \ | |
2285 jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ | |
2286 ElementType *buf, jint mode)) \ | |
2287 JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ | |
2288 DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\ | |
2289 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2290 int len = a->length(); \ | |
2291 if (len != 0) { /* Empty array: nothing to free or copy. */ \ | |
2292 if ((mode == 0) || (mode == JNI_COMMIT)) { \ | |
2293 memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ | |
2294 } \ | |
2295 if ((mode == 0) || (mode == JNI_ABORT)) { \ | |
2296 FreeHeap(buf); \ | |
2297 } \ | |
2298 } \ | |
2299 DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\ | |
2300 JNI_END | |
2301 | |
2302 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
2303 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
2304 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
2305 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
2306 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
2307 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
2308 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
2309 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
2310 | |
2311 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ | |
2312 DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\ | |
2313 \ | |
2314 JNI_ENTRY(void, \ | |
2315 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
2316 jsize len, ElementType *buf)) \ | |
2317 JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ | |
2318 DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
2319 DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ | |
2320 typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2321 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ | |
2322 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
2323 } else { \ | |
2324 if (len > 0) { \ | |
2325 int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ | |
2326 memcpy((u_char*) buf, \ | |
2327 (u_char*) src->Tag##_at_addr(start), \ | |
2328 len << sc); \ | |
2329 } \ | |
2330 } \ | |
2331 JNI_END | |
2332 | |
2333 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool) | |
2334 DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
2335 DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
2336 DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
2337 DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int) | |
2338 DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
2339 DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
2340 DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
2341 | |
2342 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ | |
2343 DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\ | |
2344 \ | |
2345 JNI_ENTRY(void, \ | |
2346 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
2347 jsize len, const ElementType *buf)) \ | |
2348 JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ | |
2349 DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
2350 DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ | |
2351 typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
2352 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ | |
2353 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
2354 } else { \ | |
2355 if (len > 0) { \ | |
2356 int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ | |
2357 memcpy((u_char*) dst->Tag##_at_addr(start), \ | |
2358 (u_char*) buf, \ | |
2359 len << sc); \ | |
2360 } \ | |
2361 } \ | |
2362 JNI_END | |
2363 | |
2364 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool) | |
2365 DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
2366 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
2367 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
2368 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int) | |
2369 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
2370 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
2371 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
2372 | |
2373 | |
2374 // | |
2375 // Interception of natives | |
2376 // | |
2377 | |
2378 // The RegisterNatives call being attempted tried to register with a method that | |
2379 // is not native. Ask JVM TI what prefixes have been specified. Then check | |
2380 // to see if the native method is now wrapped with the prefixes. See the | |
2381 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. | |
2382 static methodOop find_prefixed_native(KlassHandle k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2383 Symbol* name, Symbol* signature, TRAPS) { |
0 | 2384 ResourceMark rm(THREAD); |
2385 methodOop method; | |
2386 int name_len = name->utf8_length(); | |
2387 char* name_str = name->as_utf8(); | |
2388 int prefix_count; | |
2389 char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); | |
2390 for (int i = 0; i < prefix_count; i++) { | |
2391 char* prefix = prefixes[i]; | |
2392 int prefix_len = (int)strlen(prefix); | |
2393 | |
2394 // try adding this prefix to the method name and see if it matches another method name | |
2395 int trial_len = name_len + prefix_len; | |
2396 char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1); | |
2397 strcpy(trial_name_str, prefix); | |
2398 strcat(trial_name_str, name_str); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2399 TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2400 if (trial_name == NULL) { |
0 | 2401 continue; // no such symbol, so this prefix wasn't used, try the next prefix |
2402 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2403 method = Klass::cast(k())->lookup_method(trial_name, signature); |
0 | 2404 if (method == NULL) { |
2405 continue; // signature doesn't match, try the next prefix | |
2406 } | |
2407 if (method->is_native()) { | |
2408 method->set_is_prefixed_native(); | |
2409 return method; // wahoo, we found a prefixed version of the method, return it | |
2410 } | |
2411 // found as non-native, so prefix is good, add it, probably just need more prefixes | |
2412 name_len = trial_len; | |
2413 name_str = trial_name_str; | |
2414 } | |
2415 return NULL; // not found | |
2416 } | |
2417 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2418 static bool register_native(KlassHandle k, Symbol* name, Symbol* signature, address entry, TRAPS) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2419 methodOop method = Klass::cast(k())->lookup_method(name, signature); |
0 | 2420 if (method == NULL) { |
2421 ResourceMark rm; | |
2422 stringStream st; | |
2423 st.print("Method %s name or signature does not match", | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2424 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
0 | 2425 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
2426 } | |
2427 if (!method->is_native()) { | |
2428 // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) | |
2429 method = find_prefixed_native(k, name, signature, THREAD); | |
2430 if (method == NULL) { | |
2431 ResourceMark rm; | |
2432 stringStream st; | |
2433 st.print("Method %s is not declared as native", | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2434 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
0 | 2435 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
2436 } | |
2437 } | |
2438 | |
2439 if (entry != NULL) { | |
2440 method->set_native_function(entry, | |
2441 methodOopDesc::native_bind_event_is_interesting); | |
2442 } else { | |
2443 method->clear_native_function(); | |
2444 } | |
2445 if (PrintJNIResolving) { | |
2446 ResourceMark rm(THREAD); | |
2447 tty->print_cr("[Registering JNI native method %s.%s]", | |
2448 Klass::cast(method->method_holder())->external_name(), | |
2449 method->name()->as_C_string()); | |
2450 } | |
2451 return true; | |
2452 } | |
2453 | |
2454 DT_RETURN_MARK_DECL(RegisterNatives, jint); | |
2455 | |
2456 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz, | |
2457 const JNINativeMethod *methods, | |
2458 jint nMethods)) | |
2459 JNIWrapper("RegisterNatives"); | |
2460 DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods); | |
2461 jint ret = 0; | |
2462 DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret); | |
2463 | |
2464 KlassHandle h_k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
2465 | |
2466 for (int index = 0; index < nMethods; index++) { | |
2467 const char* meth_name = methods[index].name; | |
2468 const char* meth_sig = methods[index].signature; | |
2469 int meth_name_len = (int)strlen(meth_name); | |
2470 | |
2471 // The class should have been loaded (we have an instance of the class | |
2472 // passed in) so the method and signature should already be in the symbol | |
2473 // table. If they're not there, the method doesn't exist. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2474 TempNewSymbol name = SymbolTable::probe(meth_name, meth_name_len); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2475 TempNewSymbol signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2476 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2477 if (name == NULL || signature == NULL) { |
0 | 2478 ResourceMark rm; |
2479 stringStream st; | |
2480 st.print("Method %s.%s%s not found", Klass::cast(h_k())->external_name(), meth_name, meth_sig); | |
2481 // Must return negative value on failure | |
2482 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1); | |
2483 } | |
2484 | |
2485 bool res = register_native(h_k, name, signature, | |
2486 (address) methods[index].fnPtr, THREAD); | |
2487 if (!res) { | |
2488 ret = -1; | |
2489 break; | |
2490 } | |
2491 } | |
2492 return ret; | |
2493 JNI_END | |
2494 | |
2495 | |
2496 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz)) | |
2497 JNIWrapper("UnregisterNatives"); | |
2498 DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz); | |
2499 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz)); | |
2500 //%note jni_2 | |
2501 if (Klass::cast(k)->oop_is_instance()) { | |
2502 for (int index = 0; index < instanceKlass::cast(k)->methods()->length(); index++) { | |
2503 methodOop m = methodOop(instanceKlass::cast(k)->methods()->obj_at(index)); | |
2504 if (m->is_native()) { | |
2505 m->clear_native_function(); | |
2506 m->set_signature_handler(NULL); | |
2507 } | |
2508 } | |
2509 } | |
2510 DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0); | |
2511 return 0; | |
2512 JNI_END | |
2513 | |
2514 // | |
2515 // Monitor functions | |
2516 // | |
2517 | |
2518 DT_RETURN_MARK_DECL(MonitorEnter, jint); | |
2519 | |
2520 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj)) | |
2521 DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj); | |
2522 jint ret = JNI_ERR; | |
2523 DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret); | |
2524 | |
2525 // If the object is null, we can't do anything with it | |
2526 if (jobj == NULL) { | |
2527 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
2528 } | |
2529 | |
2530 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
2531 ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR)); | |
2532 ret = JNI_OK; | |
2533 return ret; | |
2534 JNI_END | |
2535 | |
2536 DT_RETURN_MARK_DECL(MonitorExit, jint); | |
2537 | |
2538 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj)) | |
2539 DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj); | |
2540 jint ret = JNI_ERR; | |
2541 DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret); | |
2542 | |
2543 // Don't do anything with a null object | |
2544 if (jobj == NULL) { | |
2545 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
2546 } | |
2547 | |
2548 Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); | |
2549 ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR)); | |
2550 | |
2551 ret = JNI_OK; | |
2552 return ret; | |
2553 JNI_END | |
2554 | |
2555 // | |
2556 // Extensions | |
2557 // | |
2558 | |
2559 DT_VOID_RETURN_MARK_DECL(GetStringRegion); | |
2560 | |
2561 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf)) | |
2562 JNIWrapper("GetStringRegion"); | |
2563 DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf); | |
2564 DT_VOID_RETURN_MARK(GetStringRegion); | |
2565 oop s = JNIHandles::resolve_non_null(string); | |
2566 int s_len = java_lang_String::length(s); | |
2567 if (start < 0 || len < 0 || start + len > s_len) { | |
2568 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
2569 } else { | |
2570 if (len > 0) { | |
2571 int s_offset = java_lang_String::offset(s); | |
2572 typeArrayOop s_value = java_lang_String::value(s); | |
2573 memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len); | |
2574 } | |
2575 } | |
2576 JNI_END | |
2577 | |
2578 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion); | |
2579 | |
2580 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf)) | |
2581 JNIWrapper("GetStringUTFRegion"); | |
2582 DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf); | |
2583 DT_VOID_RETURN_MARK(GetStringUTFRegion); | |
2584 oop s = JNIHandles::resolve_non_null(string); | |
2585 int s_len = java_lang_String::length(s); | |
2586 if (start < 0 || len < 0 || start + len > s_len) { | |
2587 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
2588 } else { | |
2589 //%note jni_7 | |
2590 if (len > 0) { | |
2591 ResourceMark rm(THREAD); | |
2592 char *utf_region = java_lang_String::as_utf8_string(s, start, len); | |
2593 int utf_len = (int)strlen(utf_region); | |
2594 memcpy(buf, utf_region, utf_len); | |
2595 buf[utf_len] = 0; | |
2596 } else { | |
2597 // JDK null-terminates the buffer even in len is zero | |
2598 if (buf != NULL) { | |
2599 buf[0] = 0; | |
2600 } | |
2601 } | |
2602 } | |
2603 JNI_END | |
2604 | |
2605 | |
2606 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)) | |
2607 JNIWrapper("GetPrimitiveArrayCritical"); | |
2608 DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy); | |
2609 GC_locker::lock_critical(thread); | |
2610 if (isCopy != NULL) { | |
2611 *isCopy = JNI_FALSE; | |
2612 } | |
2613 oop a = JNIHandles::resolve_non_null(array); | |
2614 assert(a->is_array(), "just checking"); | |
2615 BasicType type; | |
2616 if (a->is_objArray()) { | |
2617 type = T_OBJECT; | |
2618 } else { | |
2619 type = typeArrayKlass::cast(a->klass())->element_type(); | |
2620 } | |
2621 void* ret = arrayOop(a)->base(type); | |
2622 DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret); | |
2623 return ret; | |
2624 JNI_END | |
2625 | |
2626 | |
2627 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)) | |
2628 JNIWrapper("ReleasePrimitiveArrayCritical"); | |
2629 DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode); | |
2630 // The array, carray and mode arguments are ignored | |
2631 GC_locker::unlock_critical(thread); | |
2632 DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return); | |
2633 JNI_END | |
2634 | |
2635 | |
2636 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)) | |
2637 JNIWrapper("GetStringCritical"); | |
2638 DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy); | |
2639 GC_locker::lock_critical(thread); | |
2640 if (isCopy != NULL) { | |
2641 *isCopy = JNI_FALSE; | |
2642 } | |
2643 oop s = JNIHandles::resolve_non_null(string); | |
2644 int s_len = java_lang_String::length(s); | |
2645 typeArrayOop s_value = java_lang_String::value(s); | |
2646 int s_offset = java_lang_String::offset(s); | |
2647 const jchar* ret; | |
2648 if (s_len > 0) { | |
2649 ret = s_value->char_at_addr(s_offset); | |
2650 } else { | |
2651 ret = (jchar*) s_value->base(T_CHAR); | |
2652 } | |
2653 DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret); | |
2654 return ret; | |
2655 JNI_END | |
2656 | |
2657 | |
2658 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars)) | |
2659 JNIWrapper("ReleaseStringCritical"); | |
2660 DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars); | |
2661 // The str and chars arguments are ignored | |
2662 GC_locker::unlock_critical(thread); | |
2663 DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return); | |
2664 JNI_END | |
2665 | |
2666 | |
2667 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) | |
2668 JNIWrapper("jni_NewWeakGlobalRef"); | |
2669 DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref); | |
2670 Handle ref_handle(thread, JNIHandles::resolve(ref)); | |
2671 jweak ret = JNIHandles::make_weak_global(ref_handle); | |
2672 DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret); | |
2673 return ret; | |
2674 JNI_END | |
2675 | |
2676 // Must be JNI_ENTRY (with HandleMark) | |
2677 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref)) | |
2678 JNIWrapper("jni_DeleteWeakGlobalRef"); | |
2679 DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref); | |
2680 JNIHandles::destroy_weak_global(ref); | |
2681 DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return); | |
2682 JNI_END | |
2683 | |
2684 | |
2685 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env)) | |
2686 JNIWrapper("jni_ExceptionCheck"); | |
2687 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env); | |
2688 jni_check_async_exceptions(thread); | |
2689 jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE; | |
2690 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret); | |
2691 return ret; | |
2692 JNI_END | |
2693 | |
2694 | |
2695 // Initialization state for three routines below relating to | |
2696 // java.nio.DirectBuffers | |
2697 static jint directBufferSupportInitializeStarted = 0; | |
2698 static volatile jint directBufferSupportInitializeEnded = 0; | |
2699 static volatile jint directBufferSupportInitializeFailed = 0; | |
2700 static jclass bufferClass = NULL; | |
2701 static jclass directBufferClass = NULL; | |
2702 static jclass directByteBufferClass = NULL; | |
2703 static jmethodID directByteBufferConstructor = NULL; | |
2704 static jfieldID directBufferAddressField = NULL; | |
2705 static jfieldID bufferCapacityField = NULL; | |
2706 | |
2707 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) { | |
2708 Handle loader; // null (bootstrap) loader | |
2709 Handle protection_domain; // null protection domain | |
2710 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2711 TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2712 jclass result = find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2713 |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2714 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2715 trace_class_resolution(java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(result))); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2716 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
2717 return result; |
0 | 2718 } |
2719 | |
2720 // These lookups are done with the NULL (bootstrap) ClassLoader to | |
2721 // circumvent any security checks that would be done by jni_FindClass. | |
2722 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env)) | |
2723 { | |
2724 if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; } | |
2725 if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; } | |
2726 if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; } | |
2727 return true; | |
2728 } | |
2729 JNI_END | |
2730 | |
2731 | |
2732 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) { | |
2733 if (directBufferSupportInitializeFailed) { | |
2734 return false; | |
2735 } | |
2736 | |
2737 if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) { | |
2738 if (!lookupDirectBufferClasses(env)) { | |
2739 directBufferSupportInitializeFailed = 1; | |
2740 return false; | |
2741 } | |
2742 | |
2743 // Make global references for these | |
2744 bufferClass = (jclass) env->NewGlobalRef(bufferClass); | |
2745 directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); | |
2746 directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); | |
2747 | |
2748 // Get needed field and method IDs | |
2749 directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V"); | |
2750 directBufferAddressField = env->GetFieldID(bufferClass, "address", "J"); | |
2751 bufferCapacityField = env->GetFieldID(bufferClass, "capacity", "I"); | |
2752 | |
2753 if ((directByteBufferConstructor == NULL) || | |
2754 (directBufferAddressField == NULL) || | |
2755 (bufferCapacityField == NULL)) { | |
2756 directBufferSupportInitializeFailed = 1; | |
2757 return false; | |
2758 } | |
2759 | |
2760 directBufferSupportInitializeEnded = 1; | |
2761 } else { | |
2762 while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) { | |
521
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2763 // Set state as yield_all can call os:sleep. On Solaris, yield_all calls |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2764 // os::sleep which requires the VM state transition. On other platforms, it |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2765 // is not necessary. The following call to change the VM state is purposely |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2766 // put inside the loop to avoid potential deadlock when multiple threads |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2767 // try to call this method. See 6791815 for more details. |
4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
xlu
parents:
477
diff
changeset
|
2768 ThreadInVMfromNative tivn(thread); |
0 | 2769 os::yield_all(); |
2770 } | |
2771 } | |
2772 | |
2773 return !directBufferSupportInitializeFailed; | |
2774 } | |
2775 | |
2776 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity) | |
2777 { | |
2778 // thread_from_jni_environment() will block if VM is gone. | |
2779 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2780 | |
2781 JNIWrapper("jni_NewDirectByteBuffer"); | |
2782 DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity); | |
2783 | |
2784 if (!directBufferSupportInitializeEnded) { | |
2785 if (!initializeDirectBufferSupport(env, thread)) { | |
2786 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL); | |
2787 return NULL; | |
2788 } | |
2789 } | |
2790 | |
2791 // Being paranoid about accidental sign extension on address | |
2792 jlong addr = (jlong) ((uintptr_t) address); | |
2793 // NOTE that package-private DirectByteBuffer constructor currently | |
2794 // takes int capacity | |
2795 jint cap = (jint) capacity; | |
2796 jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap); | |
2797 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret); | |
2798 return ret; | |
2799 } | |
2800 | |
2801 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*); | |
2802 | |
2803 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) | |
2804 { | |
2805 // thread_from_jni_environment() will block if VM is gone. | |
2806 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2807 | |
2808 JNIWrapper("jni_GetDirectBufferAddress"); | |
2809 DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf); | |
2810 void* ret = NULL; | |
2811 DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret); | |
2812 | |
2813 if (!directBufferSupportInitializeEnded) { | |
2814 if (!initializeDirectBufferSupport(env, thread)) { | |
2815 return 0; | |
2816 } | |
2817 } | |
2818 | |
2819 if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) { | |
2820 return 0; | |
2821 } | |
2822 | |
2823 ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField); | |
2824 return ret; | |
2825 } | |
2826 | |
2827 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong); | |
2828 | |
2829 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf) | |
2830 { | |
2831 // thread_from_jni_environment() will block if VM is gone. | |
2832 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
2833 | |
2834 JNIWrapper("jni_GetDirectBufferCapacity"); | |
2835 DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf); | |
2836 jlong ret = -1; | |
2837 DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret); | |
2838 | |
2839 if (!directBufferSupportInitializeEnded) { | |
2840 if (!initializeDirectBufferSupport(env, thread)) { | |
2841 ret = 0; | |
2842 return ret; | |
2843 } | |
2844 } | |
2845 | |
2846 if (buf == NULL) { | |
2847 return -1; | |
2848 } | |
2849 | |
2850 if (!env->IsInstanceOf(buf, directBufferClass)) { | |
2851 return -1; | |
2852 } | |
2853 | |
2854 // NOTE that capacity is currently an int in the implementation | |
2855 ret = env->GetIntField(buf, bufferCapacityField); | |
2856 return ret; | |
2857 } | |
2858 | |
2859 | |
2860 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env)) | |
2861 JNIWrapper("GetVersion"); | |
2862 DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env); | |
2863 DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion); | |
2864 return CurrentVersion; | |
2865 JNI_END | |
2866 | |
2867 extern struct JavaVM_ main_vm; | |
2868 | |
2869 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm)) | |
2870 JNIWrapper("jni_GetJavaVM"); | |
2871 DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm); | |
2872 *vm = (JavaVM *)(&main_vm); | |
2873 DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK); | |
2874 return JNI_OK; | |
2875 JNI_END | |
2876 | |
2877 // Structure containing all jni functions | |
2878 struct JNINativeInterface_ jni_NativeInterface = { | |
2879 NULL, | |
2880 NULL, | |
2881 NULL, | |
2882 | |
2883 NULL, | |
2884 | |
2885 jni_GetVersion, | |
2886 | |
2887 jni_DefineClass, | |
2888 jni_FindClass, | |
2889 | |
2890 jni_FromReflectedMethod, | |
2891 jni_FromReflectedField, | |
2892 | |
2893 jni_ToReflectedMethod, | |
2894 | |
2895 jni_GetSuperclass, | |
2896 jni_IsAssignableFrom, | |
2897 | |
2898 jni_ToReflectedField, | |
2899 | |
2900 jni_Throw, | |
2901 jni_ThrowNew, | |
2902 jni_ExceptionOccurred, | |
2903 jni_ExceptionDescribe, | |
2904 jni_ExceptionClear, | |
2905 jni_FatalError, | |
2906 | |
2907 jni_PushLocalFrame, | |
2908 jni_PopLocalFrame, | |
2909 | |
2910 jni_NewGlobalRef, | |
2911 jni_DeleteGlobalRef, | |
2912 jni_DeleteLocalRef, | |
2913 jni_IsSameObject, | |
2914 | |
2915 jni_NewLocalRef, | |
2916 jni_EnsureLocalCapacity, | |
2917 | |
2918 jni_AllocObject, | |
2919 jni_NewObject, | |
2920 jni_NewObjectV, | |
2921 jni_NewObjectA, | |
2922 | |
2923 jni_GetObjectClass, | |
2924 jni_IsInstanceOf, | |
2925 | |
2926 jni_GetMethodID, | |
2927 | |
2928 jni_CallObjectMethod, | |
2929 jni_CallObjectMethodV, | |
2930 jni_CallObjectMethodA, | |
2931 jni_CallBooleanMethod, | |
2932 jni_CallBooleanMethodV, | |
2933 jni_CallBooleanMethodA, | |
2934 jni_CallByteMethod, | |
2935 jni_CallByteMethodV, | |
2936 jni_CallByteMethodA, | |
2937 jni_CallCharMethod, | |
2938 jni_CallCharMethodV, | |
2939 jni_CallCharMethodA, | |
2940 jni_CallShortMethod, | |
2941 jni_CallShortMethodV, | |
2942 jni_CallShortMethodA, | |
2943 jni_CallIntMethod, | |
2944 jni_CallIntMethodV, | |
2945 jni_CallIntMethodA, | |
2946 jni_CallLongMethod, | |
2947 jni_CallLongMethodV, | |
2948 jni_CallLongMethodA, | |
2949 jni_CallFloatMethod, | |
2950 jni_CallFloatMethodV, | |
2951 jni_CallFloatMethodA, | |
2952 jni_CallDoubleMethod, | |
2953 jni_CallDoubleMethodV, | |
2954 jni_CallDoubleMethodA, | |
2955 jni_CallVoidMethod, | |
2956 jni_CallVoidMethodV, | |
2957 jni_CallVoidMethodA, | |
2958 | |
2959 jni_CallNonvirtualObjectMethod, | |
2960 jni_CallNonvirtualObjectMethodV, | |
2961 jni_CallNonvirtualObjectMethodA, | |
2962 jni_CallNonvirtualBooleanMethod, | |
2963 jni_CallNonvirtualBooleanMethodV, | |
2964 jni_CallNonvirtualBooleanMethodA, | |
2965 jni_CallNonvirtualByteMethod, | |
2966 jni_CallNonvirtualByteMethodV, | |
2967 jni_CallNonvirtualByteMethodA, | |
2968 jni_CallNonvirtualCharMethod, | |
2969 jni_CallNonvirtualCharMethodV, | |
2970 jni_CallNonvirtualCharMethodA, | |
2971 jni_CallNonvirtualShortMethod, | |
2972 jni_CallNonvirtualShortMethodV, | |
2973 jni_CallNonvirtualShortMethodA, | |
2974 jni_CallNonvirtualIntMethod, | |
2975 jni_CallNonvirtualIntMethodV, | |
2976 jni_CallNonvirtualIntMethodA, | |
2977 jni_CallNonvirtualLongMethod, | |
2978 jni_CallNonvirtualLongMethodV, | |
2979 jni_CallNonvirtualLongMethodA, | |
2980 jni_CallNonvirtualFloatMethod, | |
2981 jni_CallNonvirtualFloatMethodV, | |
2982 jni_CallNonvirtualFloatMethodA, | |
2983 jni_CallNonvirtualDoubleMethod, | |
2984 jni_CallNonvirtualDoubleMethodV, | |
2985 jni_CallNonvirtualDoubleMethodA, | |
2986 jni_CallNonvirtualVoidMethod, | |
2987 jni_CallNonvirtualVoidMethodV, | |
2988 jni_CallNonvirtualVoidMethodA, | |
2989 | |
2990 jni_GetFieldID, | |
2991 | |
2992 jni_GetObjectField, | |
2993 jni_GetBooleanField, | |
2994 jni_GetByteField, | |
2995 jni_GetCharField, | |
2996 jni_GetShortField, | |
2997 jni_GetIntField, | |
2998 jni_GetLongField, | |
2999 jni_GetFloatField, | |
3000 jni_GetDoubleField, | |
3001 | |
3002 jni_SetObjectField, | |
3003 jni_SetBooleanField, | |
3004 jni_SetByteField, | |
3005 jni_SetCharField, | |
3006 jni_SetShortField, | |
3007 jni_SetIntField, | |
3008 jni_SetLongField, | |
3009 jni_SetFloatField, | |
3010 jni_SetDoubleField, | |
3011 | |
3012 jni_GetStaticMethodID, | |
3013 | |
3014 jni_CallStaticObjectMethod, | |
3015 jni_CallStaticObjectMethodV, | |
3016 jni_CallStaticObjectMethodA, | |
3017 jni_CallStaticBooleanMethod, | |
3018 jni_CallStaticBooleanMethodV, | |
3019 jni_CallStaticBooleanMethodA, | |
3020 jni_CallStaticByteMethod, | |
3021 jni_CallStaticByteMethodV, | |
3022 jni_CallStaticByteMethodA, | |
3023 jni_CallStaticCharMethod, | |
3024 jni_CallStaticCharMethodV, | |
3025 jni_CallStaticCharMethodA, | |
3026 jni_CallStaticShortMethod, | |
3027 jni_CallStaticShortMethodV, | |
3028 jni_CallStaticShortMethodA, | |
3029 jni_CallStaticIntMethod, | |
3030 jni_CallStaticIntMethodV, | |
3031 jni_CallStaticIntMethodA, | |
3032 jni_CallStaticLongMethod, | |
3033 jni_CallStaticLongMethodV, | |
3034 jni_CallStaticLongMethodA, | |
3035 jni_CallStaticFloatMethod, | |
3036 jni_CallStaticFloatMethodV, | |
3037 jni_CallStaticFloatMethodA, | |
3038 jni_CallStaticDoubleMethod, | |
3039 jni_CallStaticDoubleMethodV, | |
3040 jni_CallStaticDoubleMethodA, | |
3041 jni_CallStaticVoidMethod, | |
3042 jni_CallStaticVoidMethodV, | |
3043 jni_CallStaticVoidMethodA, | |
3044 | |
3045 jni_GetStaticFieldID, | |
3046 | |
3047 jni_GetStaticObjectField, | |
3048 jni_GetStaticBooleanField, | |
3049 jni_GetStaticByteField, | |
3050 jni_GetStaticCharField, | |
3051 jni_GetStaticShortField, | |
3052 jni_GetStaticIntField, | |
3053 jni_GetStaticLongField, | |
3054 jni_GetStaticFloatField, | |
3055 jni_GetStaticDoubleField, | |
3056 | |
3057 jni_SetStaticObjectField, | |
3058 jni_SetStaticBooleanField, | |
3059 jni_SetStaticByteField, | |
3060 jni_SetStaticCharField, | |
3061 jni_SetStaticShortField, | |
3062 jni_SetStaticIntField, | |
3063 jni_SetStaticLongField, | |
3064 jni_SetStaticFloatField, | |
3065 jni_SetStaticDoubleField, | |
3066 | |
3067 jni_NewString, | |
3068 jni_GetStringLength, | |
3069 jni_GetStringChars, | |
3070 jni_ReleaseStringChars, | |
3071 | |
3072 jni_NewStringUTF, | |
3073 jni_GetStringUTFLength, | |
3074 jni_GetStringUTFChars, | |
3075 jni_ReleaseStringUTFChars, | |
3076 | |
3077 jni_GetArrayLength, | |
3078 | |
3079 jni_NewObjectArray, | |
3080 jni_GetObjectArrayElement, | |
3081 jni_SetObjectArrayElement, | |
3082 | |
3083 jni_NewBooleanArray, | |
3084 jni_NewByteArray, | |
3085 jni_NewCharArray, | |
3086 jni_NewShortArray, | |
3087 jni_NewIntArray, | |
3088 jni_NewLongArray, | |
3089 jni_NewFloatArray, | |
3090 jni_NewDoubleArray, | |
3091 | |
3092 jni_GetBooleanArrayElements, | |
3093 jni_GetByteArrayElements, | |
3094 jni_GetCharArrayElements, | |
3095 jni_GetShortArrayElements, | |
3096 jni_GetIntArrayElements, | |
3097 jni_GetLongArrayElements, | |
3098 jni_GetFloatArrayElements, | |
3099 jni_GetDoubleArrayElements, | |
3100 | |
3101 jni_ReleaseBooleanArrayElements, | |
3102 jni_ReleaseByteArrayElements, | |
3103 jni_ReleaseCharArrayElements, | |
3104 jni_ReleaseShortArrayElements, | |
3105 jni_ReleaseIntArrayElements, | |
3106 jni_ReleaseLongArrayElements, | |
3107 jni_ReleaseFloatArrayElements, | |
3108 jni_ReleaseDoubleArrayElements, | |
3109 | |
3110 jni_GetBooleanArrayRegion, | |
3111 jni_GetByteArrayRegion, | |
3112 jni_GetCharArrayRegion, | |
3113 jni_GetShortArrayRegion, | |
3114 jni_GetIntArrayRegion, | |
3115 jni_GetLongArrayRegion, | |
3116 jni_GetFloatArrayRegion, | |
3117 jni_GetDoubleArrayRegion, | |
3118 | |
3119 jni_SetBooleanArrayRegion, | |
3120 jni_SetByteArrayRegion, | |
3121 jni_SetCharArrayRegion, | |
3122 jni_SetShortArrayRegion, | |
3123 jni_SetIntArrayRegion, | |
3124 jni_SetLongArrayRegion, | |
3125 jni_SetFloatArrayRegion, | |
3126 jni_SetDoubleArrayRegion, | |
3127 | |
3128 jni_RegisterNatives, | |
3129 jni_UnregisterNatives, | |
3130 | |
3131 jni_MonitorEnter, | |
3132 jni_MonitorExit, | |
3133 | |
3134 jni_GetJavaVM, | |
3135 | |
3136 jni_GetStringRegion, | |
3137 jni_GetStringUTFRegion, | |
3138 | |
3139 jni_GetPrimitiveArrayCritical, | |
3140 jni_ReleasePrimitiveArrayCritical, | |
3141 | |
3142 jni_GetStringCritical, | |
3143 jni_ReleaseStringCritical, | |
3144 | |
3145 jni_NewWeakGlobalRef, | |
3146 jni_DeleteWeakGlobalRef, | |
3147 | |
3148 jni_ExceptionCheck, | |
3149 | |
3150 jni_NewDirectByteBuffer, | |
3151 jni_GetDirectBufferAddress, | |
3152 jni_GetDirectBufferCapacity, | |
3153 | |
3154 // New 1_6 features | |
3155 | |
3156 jni_GetObjectRefType | |
3157 }; | |
3158 | |
3159 | |
3160 // For jvmti use to modify jni function table. | |
3161 // Java threads in native contiues to run until it is transitioned | |
3162 // to VM at safepoint. Before the transition or before it is blocked | |
3163 // for safepoint it may access jni function table. VM could crash if | |
3164 // any java thread access the jni function table in the middle of memcpy. | |
3165 // To avoid this each function pointers are copied automically. | |
3166 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) { | |
3167 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
3168 intptr_t *a = (intptr_t *) jni_functions(); | |
3169 intptr_t *b = (intptr_t *) new_jni_NativeInterface; | |
3170 for (uint i=0; i < sizeof(struct JNINativeInterface_)/sizeof(void *); i++) { | |
3171 Atomic::store_ptr(*b++, a++); | |
3172 } | |
3173 } | |
3174 | |
3175 void quicken_jni_functions() { | |
3176 // Replace Get<Primitive>Field with fast versions | |
3177 if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access() | |
3178 && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls | |
3179 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2) | |
3180 // windows x86 currently needs SEH wrapper and the gain of the fast | |
3181 // versions currently isn't certain for server vm on uniprocessor. | |
3182 && os::is_MP() | |
3183 #endif | |
3184 ) { | |
3185 address func; | |
3186 func = JNI_FastGetField::generate_fast_get_boolean_field(); | |
3187 if (func != (address)-1) { | |
3188 jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func; | |
3189 } | |
3190 func = JNI_FastGetField::generate_fast_get_byte_field(); | |
3191 if (func != (address)-1) { | |
3192 jni_NativeInterface.GetByteField = (GetByteField_t)func; | |
3193 } | |
3194 func = JNI_FastGetField::generate_fast_get_char_field(); | |
3195 if (func != (address)-1) { | |
3196 jni_NativeInterface.GetCharField = (GetCharField_t)func; | |
3197 } | |
3198 func = JNI_FastGetField::generate_fast_get_short_field(); | |
3199 if (func != (address)-1) { | |
3200 jni_NativeInterface.GetShortField = (GetShortField_t)func; | |
3201 } | |
3202 func = JNI_FastGetField::generate_fast_get_int_field(); | |
3203 if (func != (address)-1) { | |
3204 jni_NativeInterface.GetIntField = (GetIntField_t)func; | |
3205 } | |
3206 func = JNI_FastGetField::generate_fast_get_long_field(); | |
3207 if (func != (address)-1) { | |
3208 jni_NativeInterface.GetLongField = (GetLongField_t)func; | |
3209 } | |
3210 func = JNI_FastGetField::generate_fast_get_float_field(); | |
3211 if (func != (address)-1) { | |
3212 jni_NativeInterface.GetFloatField = (GetFloatField_t)func; | |
3213 } | |
3214 func = JNI_FastGetField::generate_fast_get_double_field(); | |
3215 if (func != (address)-1) { | |
3216 jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func; | |
3217 } | |
3218 } | |
3219 } | |
3220 | |
3221 // Returns the function structure | |
3222 struct JNINativeInterface_* jni_functions() { | |
3223 #ifndef JNICHECK_KERNEL | |
3224 if (CheckJNICalls) return jni_functions_check(); | |
3225 #else // JNICHECK_KERNEL | |
3226 if (CheckJNICalls) warning("-Xcheck:jni is not supported in kernel vm."); | |
3227 #endif // JNICHECK_KERNEL | |
3228 return &jni_NativeInterface; | |
3229 } | |
3230 | |
3231 // Returns the function structure | |
3232 struct JNINativeInterface_* jni_functions_nocheck() { | |
3233 return &jni_NativeInterface; | |
3234 } | |
3235 | |
3236 | |
3237 // Invocation API | |
3238 | |
3239 | |
3240 // Forward declaration | |
3241 extern const struct JNIInvokeInterface_ jni_InvokeInterface; | |
3242 | |
3243 // Global invocation API vars | |
3244 volatile jint vm_created = 0; | |
3245 // Indicate whether it is safe to recreate VM | |
3246 volatile jint safe_to_recreate_vm = 1; | |
3247 struct JavaVM_ main_vm = {&jni_InvokeInterface}; | |
3248 | |
3249 | |
3250 #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ | |
3251 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; | |
3252 | |
3253 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); | |
3254 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint); | |
3255 | |
3256 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { | |
3257 HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_); | |
3258 JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_; | |
3259 jint ret = JNI_ERR; | |
3260 DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret); | |
3261 | |
3262 if (Threads::is_supported_jni_version(args->version)) { | |
3263 ret = JNI_OK; | |
3264 } | |
3265 // 1.1 style no longer supported in hotspot. | |
3266 // According the JNI spec, we should update args->version on return. | |
3267 // We also use the structure to communicate with launcher about default | |
3268 // stack size. | |
3269 if (args->version == JNI_VERSION_1_1) { | |
3270 args->version = JNI_VERSION_1_2; | |
3271 // javaStackSize is int in arguments structure | |
3272 assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow"); | |
3273 args->javaStackSize = (jint)(ThreadStackSize * K); | |
3274 } | |
3275 return ret; | |
3276 } | |
3277 | |
3278 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); | |
3279 DT_RETURN_MARK_DECL(CreateJavaVM, jint); | |
3280 | |
3281 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) { | |
3282 HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); | |
3283 | |
3284 jint result = JNI_ERR; | |
3285 DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result); | |
3286 | |
1078 | 3287 // We're about to use Atomic::xchg for synchronization. Some Zero |
3288 // platforms use the GCC builtin __sync_lock_test_and_set for this, | |
3289 // but __sync_lock_test_and_set is not guaranteed to do what we want | |
3290 // on all architectures. So we check it works before relying on it. | |
3291 #if defined(ZERO) && defined(ASSERT) | |
3292 { | |
3293 jint a = 0xcafebabe; | |
3294 jint b = Atomic::xchg(0xdeadbeef, &a); | |
3295 void *c = &a; | |
3296 void *d = Atomic::xchg_ptr(&b, &c); | |
1132 | 3297 assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works"); |
1078 | 3298 assert(c == &b && d == &a, "Atomic::xchg_ptr() works"); |
3299 } | |
3300 #endif // ZERO && ASSERT | |
3301 | |
0 | 3302 // At the moment it's only possible to have one Java VM, |
3303 // since some of the runtime state is in global variables. | |
3304 | |
3305 // We cannot use our mutex locks here, since they only work on | |
3306 // Threads. We do an atomic compare and exchange to ensure only | |
3307 // one thread can call this method at a time | |
3308 | |
3309 // We use Atomic::xchg rather than Atomic::add/dec since on some platforms | |
3310 // the add/dec implementations are dependent on whether we are running | |
3311 // on a multiprocessor, and at this stage of initialization the os::is_MP | |
3312 // function used to determine this will always return false. Atomic::xchg | |
3313 // does not have this problem. | |
3314 if (Atomic::xchg(1, &vm_created) == 1) { | |
3315 return JNI_ERR; // already created, or create attempt in progress | |
3316 } | |
3317 if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) { | |
3318 return JNI_ERR; // someone tried and failed and retry not allowed. | |
3319 } | |
3320 | |
3321 assert(vm_created == 1, "vm_created is true during the creation"); | |
3322 | |
3323 /** | |
3324 * Certain errors during initialization are recoverable and do not | |
3325 * prevent this method from being called again at a later time | |
3326 * (perhaps with different arguments). However, at a certain | |
3327 * point during initialization if an error occurs we cannot allow | |
3328 * this function to be called again (or it will crash). In those | |
3329 * situations, the 'canTryAgain' flag is set to false, which atomically | |
3330 * sets safe_to_recreate_vm to 1, such that any new call to | |
3331 * JNI_CreateJavaVM will immediately fail using the above logic. | |
3332 */ | |
3333 bool can_try_again = true; | |
3334 | |
3335 result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again); | |
3336 if (result == JNI_OK) { | |
3337 JavaThread *thread = JavaThread::current(); | |
3338 /* thread is thread_in_vm here */ | |
3339 *vm = (JavaVM *)(&main_vm); | |
3340 *(JNIEnv**)penv = thread->jni_environment(); | |
3341 | |
3342 // Tracks the time application was running before GC | |
3343 RuntimeService::record_application_start(); | |
3344 | |
3345 // Notify JVMTI | |
3346 if (JvmtiExport::should_post_thread_life()) { | |
3347 JvmtiExport::post_thread_start(thread); | |
3348 } | |
3349 // Check if we should compile all classes on bootclasspath | |
3350 NOT_PRODUCT(if (CompileTheWorld) ClassLoader::compile_the_world();) | |
3351 // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. | |
3352 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3353 } else { | |
3354 if (can_try_again) { | |
3355 // reset safe_to_recreate_vm to 1 so that retrial would be possible | |
3356 safe_to_recreate_vm = 1; | |
3357 } | |
3358 | |
3359 // Creation failed. We must reset vm_created | |
3360 *vm = 0; | |
3361 *(JNIEnv**)penv = 0; | |
3362 // reset vm_created last to avoid race condition. Use OrderAccess to | |
3363 // control both compiler and architectural-based reordering. | |
3364 OrderAccess::release_store(&vm_created, 0); | |
3365 } | |
3366 | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1290
diff
changeset
|
3367 NOT_PRODUCT(test_error_handler(ErrorHandlerTest)); |
0 | 3368 return result; |
3369 } | |
3370 | |
3371 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \ | |
3372 JavaVM**, jsize, jsize*); | |
3373 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint); | |
3374 | |
3375 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) { | |
3376 // See bug 4367188, the wrapper can sometimes cause VM crashes | |
3377 // JNIWrapper("GetCreatedJavaVMs"); | |
3378 HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \ | |
3379 vm_buf, bufLen, numVMs); | |
3380 if (vm_created) { | |
3381 if (numVMs != NULL) *numVMs = 1; | |
3382 if (bufLen > 0) *vm_buf = (JavaVM *)(&main_vm); | |
3383 } else { | |
3384 if (numVMs != NULL) *numVMs = 0; | |
3385 } | |
3386 HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK); | |
3387 return JNI_OK; | |
3388 } | |
3389 | |
3390 extern "C" { | |
3391 | |
3392 DT_RETURN_MARK_DECL(DestroyJavaVM, jint); | |
3393 | |
3394 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) { | |
3395 DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm); | |
3396 jint res = JNI_ERR; | |
3397 DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res); | |
3398 | |
3399 if (!vm_created) { | |
3400 res = JNI_ERR; | |
3401 return res; | |
3402 } | |
3403 | |
3404 JNIWrapper("DestroyJavaVM"); | |
3405 JNIEnv *env; | |
3406 JavaVMAttachArgs destroyargs; | |
3407 destroyargs.version = CurrentVersion; | |
3408 destroyargs.name = (char *)"DestroyJavaVM"; | |
3409 destroyargs.group = NULL; | |
3410 res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs); | |
3411 if (res != JNI_OK) { | |
3412 return res; | |
3413 } | |
3414 | |
3415 // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. | |
3416 JavaThread* thread = JavaThread::current(); | |
3417 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
3418 if (Threads::destroy_vm()) { | |
3419 // Should not change thread state, VM is gone | |
3420 vm_created = false; | |
3421 res = JNI_OK; | |
3422 return res; | |
3423 } else { | |
3424 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3425 res = JNI_ERR; | |
3426 return res; | |
3427 } | |
3428 } | |
3429 | |
3430 | |
3431 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) { | |
3432 JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args; | |
3433 | |
3434 // Check below commented out from JDK1.2fcs as well | |
3435 /* | |
3436 if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) { | |
3437 return JNI_EVERSION; | |
3438 } | |
3439 */ | |
3440 | |
3441 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
3442 if (t != NULL) { | |
3443 // If the thread has been attached this operation is a no-op | |
3444 *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment(); | |
3445 return JNI_OK; | |
3446 } | |
3447 | |
3448 // Create a thread and mark it as attaching so it will be skipped by the | |
3449 // ThreadsListEnumerator - see CR 6404306 | |
3450 JavaThread* thread = new JavaThread(true); | |
3451 | |
3452 // Set correct safepoint info. The thread is going to call into Java when | |
3453 // initializing the Java level thread object. Hence, the correct state must | |
3454 // be set in order for the Safepoint code to deal with it correctly. | |
3455 thread->set_thread_state(_thread_in_vm); | |
3456 // Must do this before initialize_thread_local_storage | |
3457 thread->record_stack_base_and_size(); | |
1290
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
3458 |
0 | 3459 thread->initialize_thread_local_storage(); |
3460 | |
3461 if (!os::create_attached_thread(thread)) { | |
3462 delete thread; | |
3463 return JNI_ERR; | |
3464 } | |
1290
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
3465 // Enable stack overflow checks |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
3466 thread->create_stack_guard_pages(); |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
3467 |
0 | 3468 thread->initialize_tlab(); |
3469 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
3470 thread->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
3471 |
0 | 3472 // Crucial that we do not have a safepoint check for this thread, since it has |
3473 // not been added to the Thread list yet. | |
3474 { Threads_lock->lock_without_safepoint_check(); | |
3475 // This must be inside this lock in order to get FullGCALot to work properly, i.e., to | |
3476 // avoid this thread trying to do a GC before it is added to the thread-list | |
3477 thread->set_active_handles(JNIHandleBlock::allocate_block()); | |
3478 Threads::add(thread, daemon); | |
3479 Threads_lock->unlock(); | |
3480 } | |
3481 // Create thread group and name info from attach arguments | |
3482 oop group = NULL; | |
3483 char* thread_name = NULL; | |
3484 if (args != NULL && Threads::is_supported_jni_version(args->version)) { | |
3485 group = JNIHandles::resolve(args->group); | |
3486 thread_name = args->name; // may be NULL | |
3487 } | |
3488 if (group == NULL) group = Universe::main_thread_group(); | |
3489 | |
3490 // Create Java level thread object and attach it to this thread | |
3491 bool attach_failed = false; | |
3492 { | |
3493 EXCEPTION_MARK; | |
3494 HandleMark hm(THREAD); | |
3495 Handle thread_group(THREAD, group); | |
3496 thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD); | |
3497 if (HAS_PENDING_EXCEPTION) { | |
3498 CLEAR_PENDING_EXCEPTION; | |
3499 // cleanup outside the handle mark. | |
3500 attach_failed = true; | |
3501 } | |
3502 } | |
3503 | |
3504 if (attach_failed) { | |
3505 // Added missing cleanup | |
3506 thread->cleanup_failed_attach_current_thread(); | |
3507 return JNI_ERR; | |
3508 } | |
3509 | |
3510 // mark the thread as no longer attaching | |
3511 // this uses a fence to push the change through so we don't have | |
3512 // to regrab the threads_lock | |
3513 thread->set_attached(); | |
3514 | |
3515 // Set java thread status. | |
3516 java_lang_Thread::set_thread_status(thread->threadObj(), | |
3517 java_lang_Thread::RUNNABLE); | |
3518 | |
3519 // Notify the debugger | |
3520 if (JvmtiExport::should_post_thread_life()) { | |
3521 JvmtiExport::post_thread_start(thread); | |
3522 } | |
3523 | |
3524 *(JNIEnv**)penv = thread->jni_environment(); | |
3525 | |
3526 // Now leaving the VM, so change thread_state. This is normally automatically taken care | |
3527 // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by | |
3528 // using ThreadStateTransition::transition, we do a callback to the safepoint code if | |
3529 // needed. | |
3530 | |
3531 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
3532 | |
3533 // Perform any platform dependent FPU setup | |
3534 os::setup_fpu(); | |
3535 | |
3536 return JNI_OK; | |
3537 } | |
3538 | |
3539 | |
3540 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) { | |
3541 DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args); | |
3542 if (!vm_created) { | |
3543 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR); | |
3544 return JNI_ERR; | |
3545 } | |
3546 | |
3547 JNIWrapper("AttachCurrentThread"); | |
3548 jint ret = attach_current_thread(vm, penv, _args, false); | |
3549 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret); | |
3550 return ret; | |
3551 } | |
3552 | |
3553 | |
3554 jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { | |
3555 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm); | |
3556 VM_Exit::block_if_vm_exited(); | |
3557 | |
3558 JNIWrapper("DetachCurrentThread"); | |
3559 | |
3560 // If the thread has been deattacted the operations is a no-op | |
3561 if (ThreadLocalStorage::thread() == NULL) { | |
3562 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); | |
3563 return JNI_OK; | |
3564 } | |
3565 | |
3566 JavaThread* thread = JavaThread::current(); | |
3567 if (thread->has_last_Java_frame()) { | |
3568 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR); | |
3569 // Can't detach a thread that's running java, that can't work. | |
3570 return JNI_ERR; | |
3571 } | |
3572 | |
3573 // Safepoint support. Have to do call-back to safepoint code, if in the | |
3574 // middel of a safepoint operation | |
3575 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
3576 | |
3577 // XXX: Note that JavaThread::exit() call below removes the guards on the | |
3578 // stack pages set up via enable_stack_{red,yellow}_zone() calls | |
3579 // above in jni_AttachCurrentThread. Unfortunately, while the setting | |
3580 // of the guards is visible in jni_AttachCurrentThread above, | |
3581 // the removal of the guards is buried below in JavaThread::exit() | |
3582 // here. The abstraction should be more symmetrically either exposed | |
3583 // or hidden (e.g. it could probably be hidden in the same | |
3584 // (platform-dependent) methods where we do alternate stack | |
3585 // maintenance work?) | |
3586 thread->exit(false, JavaThread::jni_detach); | |
3587 delete thread; | |
3588 | |
3589 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); | |
3590 return JNI_OK; | |
3591 } | |
3592 | |
3593 DT_RETURN_MARK_DECL(GetEnv, jint); | |
3594 | |
3595 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) { | |
3596 DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version); | |
3597 jint ret = JNI_ERR; | |
3598 DT_RETURN_MARK(GetEnv, jint, (const jint&)ret); | |
3599 | |
3600 if (!vm_created) { | |
3601 *penv = NULL; | |
3602 ret = JNI_EDETACHED; | |
3603 return ret; | |
3604 } | |
3605 | |
3606 if (JvmtiExport::is_jvmti_version(version)) { | |
3607 ret = JvmtiExport::get_jvmti_interface(vm, penv, version); | |
3608 return ret; | |
3609 } | |
3610 | |
3611 #ifndef JVMPI_VERSION_1 | |
3612 // need these in order to be polite about older agents | |
3613 #define JVMPI_VERSION_1 ((jint)0x10000001) | |
3614 #define JVMPI_VERSION_1_1 ((jint)0x10000002) | |
3615 #define JVMPI_VERSION_1_2 ((jint)0x10000003) | |
3616 #endif // !JVMPI_VERSION_1 | |
3617 | |
3618 Thread* thread = ThreadLocalStorage::thread(); | |
3619 if (thread != NULL && thread->is_Java_thread()) { | |
3620 if (Threads::is_supported_jni_version_including_1_1(version)) { | |
3621 *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment(); | |
3622 ret = JNI_OK; | |
3623 return ret; | |
3624 | |
3625 } else if (version == JVMPI_VERSION_1 || | |
3626 version == JVMPI_VERSION_1_1 || | |
3627 version == JVMPI_VERSION_1_2) { | |
3628 tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported."); | |
3629 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
3630 ret = JNI_EVERSION; | |
3631 return ret; | |
3632 } else if (JvmtiExport::is_jvmdi_version(version)) { | |
3633 tty->print_cr("FATAL ERROR: JVMDI is no longer supported."); | |
3634 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
3635 ret = JNI_EVERSION; | |
3636 return ret; | |
3637 } else { | |
3638 *penv = NULL; | |
3639 ret = JNI_EVERSION; | |
3640 return ret; | |
3641 } | |
3642 } else { | |
3643 *penv = NULL; | |
3644 ret = JNI_EDETACHED; | |
3645 return ret; | |
3646 } | |
3647 } | |
3648 | |
3649 | |
3650 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) { | |
3651 DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args); | |
3652 if (!vm_created) { | |
3653 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR); | |
3654 return JNI_ERR; | |
3655 } | |
3656 | |
3657 JNIWrapper("AttachCurrentThreadAsDaemon"); | |
3658 jint ret = attach_current_thread(vm, penv, _args, true); | |
3659 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret); | |
3660 return ret; | |
3661 } | |
3662 | |
3663 | |
3664 } // End extern "C" | |
3665 | |
3666 const struct JNIInvokeInterface_ jni_InvokeInterface = { | |
3667 NULL, | |
3668 NULL, | |
3669 NULL, | |
3670 | |
3671 jni_DestroyJavaVM, | |
3672 jni_AttachCurrentThread, | |
3673 jni_DetachCurrentThread, | |
3674 jni_GetEnv, | |
3675 jni_AttachCurrentThreadAsDaemon | |
3676 }; |