Mercurial > hg > truffle
annotate src/share/vm/prims/jni.cpp @ 5130:ab038e0d6b43
Merge
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 21 Mar 2012 11:28:22 +0100 |
parents | 33df1aeaebbf |
children | 120820e30baa |
rev | line source |
---|---|
0 | 1 /* |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
2 * Copyright (c) 1997, 2011, 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" | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4368
diff
changeset
|
32 #ifdef GRAAL |
2925
b78b4ae0757c
Also call Compiler shutdown hook in case of System.exit call. Draft VMExits.Sandbox class.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2901
diff
changeset
|
33 #include "graal/graalCompiler.hpp" |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4368
diff
changeset
|
34 #endif |
3249
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
35 #ifndef SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
36 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
37 #endif // SERIALGC |
1972 | 38 #include "memory/allocation.inline.hpp" |
39 #include "memory/gcLocker.inline.hpp" | |
40 #include "memory/oopFactory.hpp" | |
41 #include "memory/universe.inline.hpp" | |
42 #include "oops/instanceKlass.hpp" | |
43 #include "oops/instanceOop.hpp" | |
44 #include "oops/markOop.hpp" | |
45 #include "oops/methodOop.hpp" | |
46 #include "oops/objArrayKlass.hpp" | |
47 #include "oops/objArrayOop.hpp" | |
48 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
49 #include "oops/symbol.hpp" |
1972 | 50 #include "oops/typeArrayKlass.hpp" |
51 #include "oops/typeArrayOop.hpp" | |
52 #include "prims/jni.h" | |
53 #include "prims/jniCheck.hpp" | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
54 #include "prims/jniExport.hpp" |
1972 | 55 #include "prims/jniFastGetField.hpp" |
56 #include "prims/jvm.h" | |
57 #include "prims/jvm_misc.hpp" | |
58 #include "prims/jvmtiExport.hpp" | |
59 #include "prims/jvmtiThreadState.hpp" | |
60 #include "runtime/compilationPolicy.hpp" | |
61 #include "runtime/fieldDescriptor.hpp" | |
62 #include "runtime/fprofiler.hpp" | |
63 #include "runtime/handles.inline.hpp" | |
64 #include "runtime/interfaceSupport.hpp" | |
65 #include "runtime/java.hpp" | |
66 #include "runtime/javaCalls.hpp" | |
67 #include "runtime/jfieldIDWorkaround.hpp" | |
68 #include "runtime/reflection.hpp" | |
69 #include "runtime/sharedRuntime.hpp" | |
70 #include "runtime/signature.hpp" | |
71 #include "runtime/vm_operations.hpp" | |
72 #include "services/runtimeService.hpp" | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
73 #include "trace/tracing.hpp" |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
74 #include "trace/traceEventTypes.hpp" |
1972 | 75 #include "utilities/defaultStream.hpp" |
76 #include "utilities/dtrace.hpp" | |
77 #include "utilities/events.hpp" | |
78 #include "utilities/histogram.hpp" | |
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 | |
3960 | 91 #ifdef TARGET_OS_FAMILY_bsd |
92 # include "os_bsd.inline.hpp" | |
93 # include "thread_bsd.inline.hpp" | |
94 #endif | |
0 | 95 |
96 static jint CurrentVersion = JNI_VERSION_1_6; | |
97 | |
98 | |
99 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace | |
100 // '-return' probe regardless of the return path is taken out of the function. | |
101 // Methods that have multiple return paths use this to avoid having to | |
102 // instrument each return path. Methods that use CHECK or THROW must use this | |
103 // since those macros can cause an immedate uninstrumented return. | |
104 // | |
105 // In order to get the return value, a reference to the variable containing | |
106 // the return value must be passed to the contructor of the object, and | |
107 // the return value must be set before return (since the mark object has | |
108 // a reference to it). | |
109 // | |
110 // Example: | |
111 // DT_RETURN_MARK_DECL(SomeFunc, int); | |
112 // JNI_ENTRY(int, SomeFunc, ...) | |
113 // int return_value = 0; | |
114 // DT_RETURN_MARK(SomeFunc, int, (const int&)return_value); | |
115 // foo(CHECK_0) | |
116 // return_value = 5; | |
117 // return return_value; | |
118 // JNI_END | |
4006 | 119 #ifndef USDT2 |
0 | 120 #define DT_RETURN_MARK_DECL(name, type) \ |
121 HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type); \ | |
122 DTRACE_ONLY( \ | |
123 class DTraceReturnProbeMark_##name { \ | |
124 public: \ | |
125 const type& _ret_ref; \ | |
126 DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ | |
127 ~DTraceReturnProbeMark_##name() { \ | |
128 HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref); \ | |
129 } \ | |
130 } \ | |
131 ) | |
132 // Void functions are simpler since there's no return value | |
133 #define DT_VOID_RETURN_MARK_DECL(name) \ | |
134 HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return); \ | |
135 DTRACE_ONLY( \ | |
136 class DTraceReturnProbeMark_##name { \ | |
137 public: \ | |
138 ~DTraceReturnProbeMark_##name() { \ | |
139 HS_DTRACE_PROBE0(hotspot_jni, name##__return); \ | |
140 } \ | |
141 } \ | |
142 ) | |
143 | |
4006 | 144 #else /* USDT2 */ |
145 | |
146 #define DT_RETURN_MARK_DECL(name, type, probe) \ | |
147 DTRACE_ONLY( \ | |
148 class DTraceReturnProbeMark_##name { \ | |
149 public: \ | |
150 const type& _ret_ref; \ | |
151 DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ | |
152 ~DTraceReturnProbeMark_##name() { \ | |
153 probe; \ | |
154 } \ | |
155 } \ | |
156 ) | |
157 // Void functions are simpler since there's no return value | |
158 #define DT_VOID_RETURN_MARK_DECL(name, probe) \ | |
159 DTRACE_ONLY( \ | |
160 class DTraceReturnProbeMark_##name { \ | |
161 public: \ | |
162 ~DTraceReturnProbeMark_##name() { \ | |
163 probe; \ | |
164 } \ | |
165 } \ | |
166 ) | |
167 #endif /* USDT2 */ | |
0 | 168 |
169 // Place these macros in the function to mark the return. Non-void | |
170 // functions need the type and address of the return value. | |
171 #define DT_RETURN_MARK(name, type, ref) \ | |
172 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) ) | |
173 #define DT_VOID_RETURN_MARK(name) \ | |
174 DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark ) | |
175 | |
176 | |
177 // Use these to select distinct code for floating-point vs. non-floating point | |
178 // situations. Used from within common macros where we need slightly | |
179 // different behavior for Float/Double | |
180 #define FP_SELECT_Boolean(intcode, fpcode) intcode | |
181 #define FP_SELECT_Byte(intcode, fpcode) intcode | |
182 #define FP_SELECT_Char(intcode, fpcode) intcode | |
183 #define FP_SELECT_Short(intcode, fpcode) intcode | |
184 #define FP_SELECT_Object(intcode, fpcode) intcode | |
185 #define FP_SELECT_Int(intcode, fpcode) intcode | |
186 #define FP_SELECT_Long(intcode, fpcode) intcode | |
187 #define FP_SELECT_Float(intcode, fpcode) fpcode | |
188 #define FP_SELECT_Double(intcode, fpcode) fpcode | |
189 #define FP_SELECT(TypeName, intcode, fpcode) \ | |
190 FP_SELECT_##TypeName(intcode, fpcode) | |
191 | |
192 #define COMMA , | |
193 | |
194 // Choose DT_RETURN_MARK macros based on the type: float/double -> void | |
195 // (dtrace doesn't do FP yet) | |
4006 | 196 #ifndef USDT2 |
0 | 197 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \ |
198 FP_SELECT(TypeName, \ | |
199 DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) ) | |
4006 | 200 #else /* USDT2 */ |
201 #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe) \ | |
202 FP_SELECT(TypeName, \ | |
203 DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) ) | |
204 #endif /* USDT2 */ | |
0 | 205 #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \ |
206 FP_SELECT(TypeName, \ | |
207 DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) ) | |
208 | |
209 | |
210 // out-of-line helpers for class jfieldIDWorkaround: | |
211 | |
212 bool jfieldIDWorkaround::is_valid_jfieldID(klassOop k, jfieldID id) { | |
213 if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) { | |
214 uintptr_t as_uint = (uintptr_t) id; | |
215 intptr_t offset = raw_instance_offset(id); | |
216 if (is_checked_jfieldID(id)) { | |
217 if (!klass_hash_ok(k, id)) { | |
218 return false; | |
219 } | |
220 } | |
221 return instanceKlass::cast(k)->contains_field_offset(offset); | |
222 } else { | |
223 JNIid* result = (JNIid*) id; | |
224 #ifdef ASSERT | |
225 return result != NULL && result->is_static_field_id(); | |
226 #else | |
227 return result != NULL; | |
228 #endif | |
229 } | |
230 } | |
231 | |
232 | |
233 intptr_t jfieldIDWorkaround::encode_klass_hash(klassOop k, intptr_t offset) { | |
234 if (offset <= small_offset_mask) { | |
235 klassOop field_klass = k; | |
236 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
|
237 // 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
|
238 // 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
|
239 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
|
240 instanceKlass::cast(super_klass)->contains_field_offset(offset)) { |
0 | 241 field_klass = super_klass; // super contains the field also |
242 super_klass = Klass::cast(field_klass)->super(); | |
243 } | |
244 debug_only(No_Safepoint_Verifier nosafepoint;) | |
245 uintptr_t klass_hash = field_klass->identity_hash(); | |
246 return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place; | |
247 } else { | |
248 #if 0 | |
249 #ifndef PRODUCT | |
250 { | |
251 ResourceMark rm; | |
252 warning("VerifyJNIFields: long offset %d in %s", offset, Klass::cast(k)->external_name()); | |
253 } | |
254 #endif | |
255 #endif | |
256 return 0; | |
257 } | |
258 } | |
259 | |
260 bool jfieldIDWorkaround::klass_hash_ok(klassOop k, jfieldID id) { | |
261 uintptr_t as_uint = (uintptr_t) id; | |
262 intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask; | |
263 do { | |
264 debug_only(No_Safepoint_Verifier nosafepoint;) | |
265 // Could use a non-blocking query for identity_hash here... | |
266 if ((k->identity_hash() & klass_mask) == klass_hash) | |
267 return true; | |
268 k = Klass::cast(k)->super(); | |
269 } while (k != NULL); | |
270 return false; | |
271 } | |
272 | |
273 void jfieldIDWorkaround::verify_instance_jfieldID(klassOop k, jfieldID id) { | |
274 guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" ); | |
275 uintptr_t as_uint = (uintptr_t) id; | |
276 intptr_t offset = raw_instance_offset(id); | |
277 if (VerifyJNIFields) { | |
278 if (is_checked_jfieldID(id)) { | |
279 guarantee(klass_hash_ok(k, id), | |
280 "Bug in native code: jfieldID class must match object"); | |
281 } else { | |
282 #if 0 | |
283 #ifndef PRODUCT | |
284 if (Verbose) { | |
285 ResourceMark rm; | |
286 warning("VerifyJNIFields: unverified offset %d for %s", offset, Klass::cast(k)->external_name()); | |
287 } | |
288 #endif | |
289 #endif | |
290 } | |
291 } | |
292 guarantee(instanceKlass::cast(k)->contains_field_offset(offset), | |
293 "Bug in native code: jfieldID offset must address interior of object"); | |
294 } | |
295 | |
296 // Pick a reasonable higher bound for local capacity requested | |
297 // for EnsureLocalCapacity and PushLocalFrame. We don't want it too | |
298 // high because a test (or very unusual application) may try to allocate | |
299 // that many handles and run out of swap space. An implementation is | |
300 // permitted to allocate more handles than the ensured capacity, so this | |
301 // value is set high enough to prevent compatibility problems. | |
302 const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; | |
303 | |
304 | |
305 // Wrapper to trace JNI functions | |
306 | |
307 #ifdef ASSERT | |
308 Histogram* JNIHistogram; | |
309 static volatile jint JNIHistogram_lock = 0; | |
310 | |
311 class JNITraceWrapper : public StackObj { | |
312 public: | |
313 JNITraceWrapper(const char* format, ...) { | |
314 if (TraceJNICalls) { | |
315 va_list ap; | |
316 va_start(ap, format); | |
317 tty->print("JNI "); | |
318 tty->vprint_cr(format, ap); | |
319 va_end(ap); | |
320 } | |
321 } | |
322 }; | |
323 | |
324 class JNIHistogramElement : public HistogramElement { | |
325 public: | |
326 JNIHistogramElement(const char* name); | |
327 }; | |
328 | |
329 JNIHistogramElement::JNIHistogramElement(const char* elementName) { | |
330 _name = elementName; | |
331 uintx count = 0; | |
332 | |
333 while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) { | |
334 while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) { | |
335 count +=1; | |
336 if ( (WarnOnStalledSpinLock > 0) | |
337 && (count % WarnOnStalledSpinLock == 0)) { | |
338 warning("JNIHistogram_lock seems to be stalled"); | |
339 } | |
340 } | |
341 } | |
342 | |
343 | |
344 if(JNIHistogram == NULL) | |
345 JNIHistogram = new Histogram("JNI Call Counts",100); | |
346 | |
347 JNIHistogram->add_element(this); | |
348 Atomic::dec(&JNIHistogram_lock); | |
349 } | |
350 | |
351 #define JNICountWrapper(arg) \ | |
352 static JNIHistogramElement* e = new JNIHistogramElement(arg); \ | |
353 /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \ | |
354 if (e != NULL) e->increment_count() | |
355 #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg) | |
356 #else | |
357 #define JNIWrapper(arg) | |
358 #endif | |
359 | |
360 | |
361 // Implementation of JNI entries | |
362 | |
4006 | 363 #ifndef USDT2 |
0 | 364 DT_RETURN_MARK_DECL(DefineClass, jclass); |
4006 | 365 #else /* USDT2 */ |
366 DT_RETURN_MARK_DECL(DefineClass, jclass | |
367 , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref)); | |
368 #endif /* USDT2 */ | |
0 | 369 |
370 JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef, | |
371 const jbyte *buf, jsize bufLen)) | |
372 JNIWrapper("DefineClass"); | |
373 | |
4006 | 374 #ifndef USDT2 |
0 | 375 DTRACE_PROBE5(hotspot_jni, DefineClass__entry, |
376 env, name, loaderRef, buf, bufLen); | |
4006 | 377 #else /* USDT2 */ |
378 HOTSPOT_JNI_DEFINECLASS_ENTRY( | |
379 env, (char*) name, loaderRef, (char*) buf, bufLen); | |
380 #endif /* USDT2 */ | |
0 | 381 jclass cls = NULL; |
382 DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); | |
383 | |
384 // Since exceptions can be thrown, class initialization can take place | |
385 // if name is NULL no check for class name in .class stream has to be made. | |
386 if (name != NULL) { | |
387 const int str_len = (int)strlen(name); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
388 if (str_len > Symbol::max_length()) { |
0 | 389 // It's impossible to create this class; the name cannot fit |
390 // into the constant pool. | |
391 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); | |
392 } | |
393 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
394 TempNewSymbol class_name = SymbolTable::new_symbol(name, THREAD); |
0 | 395 |
396 ResourceMark rm(THREAD); | |
397 ClassFileStream st((u1*) buf, bufLen, NULL); | |
398 Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); | |
399 | |
400 if (UsePerfData && !class_loader.is_null()) { | |
401 // check whether the current caller thread holds the lock or not. | |
402 // If not, increment the corresponding counter | |
403 if (ObjectSynchronizer:: | |
404 query_lock_ownership((JavaThread*)THREAD, class_loader) != | |
405 ObjectSynchronizer::owner_self) { | |
406 ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); | |
407 } | |
408 } | |
409 klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
657
diff
changeset
|
410 Handle(), &st, true, |
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
657
diff
changeset
|
411 CHECK_NULL); |
0 | 412 |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
413 if (TraceClassResolution && k != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
414 trace_class_resolution(k); |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
415 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
416 |
0 | 417 cls = (jclass)JNIHandles::make_local( |
418 env, Klass::cast(k)->java_mirror()); | |
419 return cls; | |
420 JNI_END | |
421 | |
422 | |
423 | |
424 static bool first_time_FindClass = true; | |
425 | |
4006 | 426 #ifndef USDT2 |
0 | 427 DT_RETURN_MARK_DECL(FindClass, jclass); |
4006 | 428 #else /* USDT2 */ |
429 DT_RETURN_MARK_DECL(FindClass, jclass | |
430 , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref)); | |
431 #endif /* USDT2 */ | |
0 | 432 |
433 JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name)) | |
434 JNIWrapper("FindClass"); | |
4006 | 435 #ifndef USDT2 |
0 | 436 DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name); |
4006 | 437 #else /* USDT2 */ |
438 HOTSPOT_JNI_FINDCLASS_ENTRY( | |
439 env, (char *)name); | |
440 #endif /* USDT2 */ | |
0 | 441 |
442 jclass result = NULL; | |
443 DT_RETURN_MARK(FindClass, jclass, (const jclass&)result); | |
444 | |
445 // Remember if we are the first invocation of jni_FindClass | |
446 bool first_time = first_time_FindClass; | |
447 first_time_FindClass = false; | |
448 | |
449 // Sanity check the name: it cannot be null or larger than the maximum size | |
450 // 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
|
451 if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
0 | 452 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
453 } | |
454 | |
455 //%note jni_3 | |
456 Handle loader; | |
457 Handle protection_domain; | |
458 // Find calling class | |
459 instanceKlassHandle k (THREAD, thread->security_get_caller_class(0)); | |
460 if (k.not_null()) { | |
461 loader = Handle(THREAD, k->class_loader()); | |
462 // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed | |
463 // in the correct class context. | |
464 if (loader.is_null() && | |
465 k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) { | |
466 JavaValue result(T_OBJECT); | |
467 JavaCalls::call_static(&result, k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
468 vmSymbols::getFromClass_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
469 vmSymbols::void_class_signature(), |
0 | 470 thread); |
471 if (HAS_PENDING_EXCEPTION) { | |
472 Handle ex(thread, thread->pending_exception()); | |
473 CLEAR_PENDING_EXCEPTION; | |
474 THROW_HANDLE_0(ex); | |
475 } | |
476 oop mirror = (oop) result.get_jobject(); | |
477 loader = Handle(THREAD, | |
478 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->class_loader()); | |
479 protection_domain = Handle(THREAD, | |
480 instanceKlass::cast(java_lang_Class::as_klassOop(mirror))->protection_domain()); | |
481 } | |
482 } else { | |
483 // We call ClassLoader.getSystemClassLoader to obtain the system class loader. | |
484 loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
485 } | |
486 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
487 TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
0 | 488 result = find_class_from_class_loader(env, sym, true, loader, |
489 protection_domain, true, thread); | |
490 | |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
491 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
492 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
|
493 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
494 |
0 | 495 // If we were the first invocation of jni_FindClass, we enable compilation again |
496 // rather than just allowing invocation counter to overflow and decay. | |
497 // Controlled by flag DelayCompilationDuringStartup. | |
498 if (first_time && !CompileTheWorld) | |
499 CompilationPolicy::completed_vm_startup(); | |
500 | |
501 return result; | |
502 JNI_END | |
503 | |
4006 | 504 #ifndef USDT2 |
0 | 505 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID); |
4006 | 506 #else /* USDT2 */ |
507 DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID | |
508 , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref)); | |
509 #endif /* USDT2 */ | |
0 | 510 |
511 JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method)) | |
512 JNIWrapper("FromReflectedMethod"); | |
4006 | 513 #ifndef USDT2 |
0 | 514 DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method); |
4006 | 515 #else /* USDT2 */ |
516 HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY( | |
517 env, method); | |
518 #endif /* USDT2 */ | |
0 | 519 jmethodID ret = NULL; |
520 DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret); | |
521 | |
522 // method is a handle to a java.lang.reflect.Method object | |
523 oop reflected = JNIHandles::resolve_non_null(method); | |
524 oop mirror = NULL; | |
525 int slot = 0; | |
526 | |
1142 | 527 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { |
0 | 528 mirror = java_lang_reflect_Constructor::clazz(reflected); |
529 slot = java_lang_reflect_Constructor::slot(reflected); | |
530 } else { | |
1142 | 531 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); |
0 | 532 mirror = java_lang_reflect_Method::clazz(reflected); |
533 slot = java_lang_reflect_Method::slot(reflected); | |
534 } | |
535 klassOop k = java_lang_Class::as_klassOop(mirror); | |
536 | |
537 KlassHandle k1(THREAD, k); | |
538 // Make sure class is initialized before handing id's out to methods | |
539 Klass::cast(k1())->initialize(CHECK_NULL); | |
540 methodOop m = instanceKlass::cast(k1())->method_with_idnum(slot); | |
541 ret = m==NULL? NULL : m->jmethod_id(); // return NULL if reflected method deleted | |
542 return ret; | |
543 JNI_END | |
544 | |
4006 | 545 #ifndef USDT2 |
0 | 546 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID); |
4006 | 547 #else /* USDT2 */ |
548 DT_RETURN_MARK_DECL(FromReflectedField, jfieldID | |
549 , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref)); | |
550 #endif /* USDT2 */ | |
0 | 551 |
552 JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field)) | |
553 JNIWrapper("FromReflectedField"); | |
4006 | 554 #ifndef USDT2 |
0 | 555 DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field); |
4006 | 556 #else /* USDT2 */ |
557 HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY( | |
558 env, field); | |
559 #endif /* USDT2 */ | |
0 | 560 jfieldID ret = NULL; |
561 DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret); | |
562 | |
563 // field is a handle to a java.lang.reflect.Field object | |
564 oop reflected = JNIHandles::resolve_non_null(field); | |
565 oop mirror = java_lang_reflect_Field::clazz(reflected); | |
566 klassOop k = java_lang_Class::as_klassOop(mirror); | |
567 int slot = java_lang_reflect_Field::slot(reflected); | |
568 int modifiers = java_lang_reflect_Field::modifiers(reflected); | |
569 | |
570 KlassHandle k1(THREAD, k); | |
571 // Make sure class is initialized before handing id's out to fields | |
572 Klass::cast(k1())->initialize(CHECK_NULL); | |
573 | |
574 // First check if this is a static field | |
575 if (modifiers & JVM_ACC_STATIC) { | |
3938 | 576 intptr_t offset = instanceKlass::cast(k1())->field_offset( slot ); |
0 | 577 JNIid* id = instanceKlass::cast(k1())->jni_id_for(offset); |
578 assert(id != NULL, "corrupt Field object"); | |
579 debug_only(id->set_is_static_field_id();) | |
580 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
581 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
582 return ret; | |
583 } | |
584 | |
585 // The slot is the index of the field description in the field-array | |
586 // The jfieldID is the offset of the field within the object | |
587 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
3938 | 588 intptr_t offset = instanceKlass::cast(k1())->field_offset( slot ); |
0 | 589 assert(instanceKlass::cast(k1())->contains_field_offset(offset), "stay within object"); |
590 ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset); | |
591 return ret; | |
592 JNI_END | |
593 | |
4006 | 594 #ifndef USDT2 |
0 | 595 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject); |
4006 | 596 #else /* USDT2 */ |
597 DT_RETURN_MARK_DECL(ToReflectedMethod, jobject | |
598 , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref)); | |
599 #endif /* USDT2 */ | |
0 | 600 |
601 JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic)) | |
602 JNIWrapper("ToReflectedMethod"); | |
4006 | 603 #ifndef USDT2 |
0 | 604 DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic); |
4006 | 605 #else /* USDT2 */ |
606 HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY( | |
607 env, cls, (uintptr_t) method_id, isStatic); | |
608 #endif /* USDT2 */ | |
0 | 609 jobject ret = NULL; |
610 DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret); | |
611 | |
612 methodHandle m (THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
613 assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); | |
614 oop reflection_method; | |
615 if (m->is_initializer()) { | |
616 reflection_method = Reflection::new_constructor(m, CHECK_NULL); | |
617 } else { | |
618 reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL); | |
619 } | |
620 ret = JNIHandles::make_local(env, reflection_method); | |
621 return ret; | |
622 JNI_END | |
623 | |
4006 | 624 #ifndef USDT2 |
0 | 625 DT_RETURN_MARK_DECL(GetSuperclass, jclass); |
4006 | 626 #else /* USDT2 */ |
627 DT_RETURN_MARK_DECL(GetSuperclass, jclass | |
628 , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref)); | |
629 #endif /* USDT2 */ | |
0 | 630 |
631 JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub)) | |
632 JNIWrapper("GetSuperclass"); | |
4006 | 633 #ifndef USDT2 |
0 | 634 DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub); |
4006 | 635 #else /* USDT2 */ |
636 HOTSPOT_JNI_GETSUPERCLASS_ENTRY( | |
637 env, sub); | |
638 #endif /* USDT2 */ | |
0 | 639 jclass obj = NULL; |
640 DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj); | |
641 | |
642 oop mirror = JNIHandles::resolve_non_null(sub); | |
643 // primitive classes return NULL | |
644 if (java_lang_Class::is_primitive(mirror)) return NULL; | |
645 | |
646 // Rules of Class.getSuperClass as implemented by KLass::java_super: | |
647 // arrays return Object | |
648 // interfaces return NULL | |
649 // proper classes return Klass::super() | |
650 klassOop k = java_lang_Class::as_klassOop(mirror); | |
651 if (Klass::cast(k)->is_interface()) return NULL; | |
652 | |
653 // return mirror for superclass | |
654 klassOop super = Klass::cast(k)->java_super(); | |
655 // super2 is the value computed by the compiler's getSuperClass intrinsic: | |
656 debug_only(klassOop super2 = ( Klass::cast(k)->oop_is_javaArray() | |
1142 | 657 ? SystemDictionary::Object_klass() |
0 | 658 : Klass::cast(k)->super() ) ); |
659 assert(super == super2, | |
660 "java_super computation depends on interface, array, other super"); | |
661 obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(Klass::cast(super)->java_mirror()); | |
662 return obj; | |
663 JNI_END | |
664 | |
665 JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super)) | |
666 JNIWrapper("IsSubclassOf"); | |
4006 | 667 #ifndef USDT2 |
0 | 668 DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super); |
4006 | 669 #else /* USDT2 */ |
670 HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY( | |
671 env, sub, super); | |
672 #endif /* USDT2 */ | |
0 | 673 oop sub_mirror = JNIHandles::resolve_non_null(sub); |
674 oop super_mirror = JNIHandles::resolve_non_null(super); | |
675 if (java_lang_Class::is_primitive(sub_mirror) || | |
676 java_lang_Class::is_primitive(super_mirror)) { | |
677 jboolean ret = (sub_mirror == super_mirror); | |
4006 | 678 #ifndef USDT2 |
0 | 679 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
4006 | 680 #else /* USDT2 */ |
681 HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( | |
682 ret); | |
683 #endif /* USDT2 */ | |
0 | 684 return ret; |
685 } | |
686 klassOop sub_klass = java_lang_Class::as_klassOop(sub_mirror); | |
687 klassOop super_klass = java_lang_Class::as_klassOop(super_mirror); | |
688 assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom"); | |
689 jboolean ret = Klass::cast(sub_klass)->is_subtype_of(super_klass) ? | |
690 JNI_TRUE : JNI_FALSE; | |
4006 | 691 #ifndef USDT2 |
0 | 692 DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
4006 | 693 #else /* USDT2 */ |
694 HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( | |
695 ret); | |
696 #endif /* USDT2 */ | |
0 | 697 return ret; |
698 JNI_END | |
699 | |
4006 | 700 #ifndef USDT2 |
0 | 701 DT_RETURN_MARK_DECL(Throw, jint); |
4006 | 702 #else /* USDT2 */ |
703 DT_RETURN_MARK_DECL(Throw, jint | |
704 , HOTSPOT_JNI_THROW_RETURN(_ret_ref)); | |
705 #endif /* USDT2 */ | |
0 | 706 |
707 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj)) | |
708 JNIWrapper("Throw"); | |
4006 | 709 #ifndef USDT2 |
0 | 710 DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj); |
4006 | 711 #else /* USDT2 */ |
712 HOTSPOT_JNI_THROW_ENTRY( | |
713 env, obj); | |
714 #endif /* USDT2 */ | |
0 | 715 jint ret = JNI_OK; |
716 DT_RETURN_MARK(Throw, jint, (const jint&)ret); | |
717 | |
718 THROW_OOP_(JNIHandles::resolve(obj), JNI_OK); | |
719 ShouldNotReachHere(); | |
720 JNI_END | |
721 | |
4006 | 722 #ifndef USDT2 |
0 | 723 DT_RETURN_MARK_DECL(ThrowNew, jint); |
4006 | 724 #else /* USDT2 */ |
725 DT_RETURN_MARK_DECL(ThrowNew, jint | |
726 , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref)); | |
727 #endif /* USDT2 */ | |
0 | 728 |
729 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message)) | |
730 JNIWrapper("ThrowNew"); | |
4006 | 731 #ifndef USDT2 |
0 | 732 DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message); |
4006 | 733 #else /* USDT2 */ |
734 HOTSPOT_JNI_THROWNEW_ENTRY( | |
735 env, clazz, (char *) message); | |
736 #endif /* USDT2 */ | |
0 | 737 jint ret = JNI_OK; |
738 DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret); | |
739 | |
740 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
|
741 Symbol* name = k->name(); |
0 | 742 Handle class_loader (THREAD, k->class_loader()); |
743 Handle protection_domain (THREAD, k->protection_domain()); | |
744 THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK); | |
745 ShouldNotReachHere(); | |
746 JNI_END | |
747 | |
748 | |
749 // JNI functions only transform a pending async exception to a synchronous | |
750 // exception in ExceptionOccurred and ExceptionCheck calls, since | |
751 // delivering an async exception in other places won't change the native | |
752 // code's control flow and would be harmful when native code further calls | |
753 // JNI functions with a pending exception. Async exception is also checked | |
754 // during the call, so ExceptionOccurred/ExceptionCheck won't return | |
755 // false but deliver the async exception at the very end during | |
756 // state transition. | |
757 | |
758 static void jni_check_async_exceptions(JavaThread *thread) { | |
759 assert(thread == Thread::current(), "must be itself"); | |
760 thread->check_and_handle_async_exceptions(); | |
761 } | |
762 | |
763 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env)) | |
764 JNIWrapper("ExceptionOccurred"); | |
4006 | 765 #ifndef USDT2 |
0 | 766 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env); |
4006 | 767 #else /* USDT2 */ |
768 HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY( | |
769 env); | |
770 #endif /* USDT2 */ | |
0 | 771 jni_check_async_exceptions(thread); |
772 oop exception = thread->pending_exception(); | |
773 jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception); | |
4006 | 774 #ifndef USDT2 |
0 | 775 DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret); |
4006 | 776 #else /* USDT2 */ |
777 HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN( | |
778 ret); | |
779 #endif /* USDT2 */ | |
0 | 780 return ret; |
781 JNI_END | |
782 | |
783 | |
784 JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env)) | |
785 JNIWrapper("ExceptionDescribe"); | |
4006 | 786 #ifndef USDT2 |
0 | 787 DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env); |
4006 | 788 #else /* USDT2 */ |
789 HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY( | |
790 env); | |
791 #endif /* USDT2 */ | |
0 | 792 if (thread->has_pending_exception()) { |
793 Handle ex(thread, thread->pending_exception()); | |
794 thread->clear_pending_exception(); | |
1142 | 795 if (ex->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 796 // Don't print anything if we are being killed. |
797 } else { | |
798 jio_fprintf(defaultStream::error_stream(), "Exception "); | |
799 if (thread != NULL && thread->threadObj() != NULL) { | |
800 ResourceMark rm(THREAD); | |
801 jio_fprintf(defaultStream::error_stream(), | |
802 "in thread \"%s\" ", thread->get_thread_name()); | |
803 } | |
1142 | 804 if (ex->is_a(SystemDictionary::Throwable_klass())) { |
0 | 805 JavaValue result(T_VOID); |
806 JavaCalls::call_virtual(&result, | |
807 ex, | |
808 KlassHandle(THREAD, | |
1142 | 809 SystemDictionary::Throwable_klass()), |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
810 vmSymbols::printStackTrace_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
811 vmSymbols::void_method_signature(), |
0 | 812 THREAD); |
813 // If an exception is thrown in the call it gets thrown away. Not much | |
814 // we can do with it. The native code that calls this, does not check | |
815 // for the exception - hence, it might still be in the thread when DestroyVM gets | |
816 // called, potentially causing a few asserts to trigger - since no pending exception | |
817 // is expected. | |
818 CLEAR_PENDING_EXCEPTION; | |
819 } else { | |
820 ResourceMark rm(THREAD); | |
821 jio_fprintf(defaultStream::error_stream(), | |
822 ". Uncaught exception of type %s.", | |
823 Klass::cast(ex->klass())->external_name()); | |
824 } | |
825 } | |
826 } | |
4006 | 827 #ifndef USDT2 |
0 | 828 DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return); |
4006 | 829 #else /* USDT2 */ |
830 HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN( | |
831 ); | |
832 #endif /* USDT2 */ | |
0 | 833 JNI_END |
834 | |
835 | |
836 JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env)) | |
837 JNIWrapper("ExceptionClear"); | |
4006 | 838 #ifndef USDT2 |
0 | 839 DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env); |
4006 | 840 #else /* USDT2 */ |
841 HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY( | |
842 env); | |
843 #endif /* USDT2 */ | |
0 | 844 |
845 // The jni code might be using this API to clear java thrown exception. | |
846 // So just mark jvmti thread exception state as exception caught. | |
847 JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); | |
848 if (state != NULL && state->is_exception_detected()) { | |
849 state->set_exception_caught(); | |
850 } | |
851 thread->clear_pending_exception(); | |
4006 | 852 #ifndef USDT2 |
0 | 853 DTRACE_PROBE(hotspot_jni, ExceptionClear__return); |
4006 | 854 #else /* USDT2 */ |
855 HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN( | |
856 ); | |
857 #endif /* USDT2 */ | |
0 | 858 JNI_END |
859 | |
860 | |
861 JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg)) | |
862 JNIWrapper("FatalError"); | |
4006 | 863 #ifndef USDT2 |
0 | 864 DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg); |
4006 | 865 #else /* USDT2 */ |
866 HOTSPOT_JNI_FATALERROR_ENTRY( | |
867 env, (char *) msg); | |
868 #endif /* USDT2 */ | |
0 | 869 tty->print_cr("FATAL ERROR in native method: %s", msg); |
870 thread->print_stack(); | |
227
8d852b81e775
6694099: Hotspot vm_exit_out_of_memory should dump core
poonam
parents:
113
diff
changeset
|
871 os::abort(); // Dump core and abort |
0 | 872 JNI_END |
873 | |
874 | |
875 JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) | |
876 JNIWrapper("PushLocalFrame"); | |
4006 | 877 #ifndef USDT2 |
0 | 878 DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity); |
4006 | 879 #else /* USDT2 */ |
880 HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY( | |
881 env, capacity); | |
882 #endif /* USDT2 */ | |
0 | 883 //%note jni_11 |
884 if (capacity < 0 && capacity > MAX_REASONABLE_LOCAL_CAPACITY) { | |
4006 | 885 #ifndef USDT2 |
0 | 886 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); |
4006 | 887 #else /* USDT2 */ |
888 HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( | |
889 (uint32_t)JNI_ERR); | |
890 #endif /* USDT2 */ | |
0 | 891 return JNI_ERR; |
892 } | |
893 JNIHandleBlock* old_handles = thread->active_handles(); | |
894 JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); | |
895 assert(new_handles != NULL, "should not be NULL"); | |
896 new_handles->set_pop_frame_link(old_handles); | |
897 thread->set_active_handles(new_handles); | |
898 jint ret = JNI_OK; | |
4006 | 899 #ifndef USDT2 |
0 | 900 DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret); |
4006 | 901 #else /* USDT2 */ |
902 HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( | |
903 ret); | |
904 #endif /* USDT2 */ | |
0 | 905 return ret; |
906 JNI_END | |
907 | |
908 | |
909 JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result)) | |
910 JNIWrapper("PopLocalFrame"); | |
4006 | 911 #ifndef USDT2 |
0 | 912 DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result); |
4006 | 913 #else /* USDT2 */ |
914 HOTSPOT_JNI_POPLOCALFRAME_ENTRY( | |
915 env, result); | |
916 #endif /* USDT2 */ | |
0 | 917 //%note jni_11 |
918 Handle result_handle(thread, JNIHandles::resolve(result)); | |
919 JNIHandleBlock* old_handles = thread->active_handles(); | |
920 JNIHandleBlock* new_handles = old_handles->pop_frame_link(); | |
921 if (new_handles != NULL) { | |
922 // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL. | |
923 // This way code will still work if PopLocalFrame is called without a corresponding | |
924 // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise | |
925 // the release_block call will release the blocks. | |
926 thread->set_active_handles(new_handles); | |
927 old_handles->set_pop_frame_link(NULL); // clear link we won't release new_handles below | |
928 JNIHandleBlock::release_block(old_handles, thread); // may block | |
929 result = JNIHandles::make_local(thread, result_handle()); | |
930 } | |
4006 | 931 #ifndef USDT2 |
0 | 932 DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result); |
4006 | 933 #else /* USDT2 */ |
934 HOTSPOT_JNI_POPLOCALFRAME_RETURN( | |
935 result); | |
936 #endif /* USDT2 */ | |
0 | 937 return result; |
938 JNI_END | |
939 | |
940 | |
941 JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref)) | |
942 JNIWrapper("NewGlobalRef"); | |
4006 | 943 #ifndef USDT2 |
0 | 944 DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref); |
4006 | 945 #else /* USDT2 */ |
946 HOTSPOT_JNI_NEWGLOBALREF_ENTRY( | |
947 env, ref); | |
948 #endif /* USDT2 */ | |
0 | 949 Handle ref_handle(thread, JNIHandles::resolve(ref)); |
950 jobject ret = JNIHandles::make_global(ref_handle); | |
4006 | 951 #ifndef USDT2 |
0 | 952 DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret); |
4006 | 953 #else /* USDT2 */ |
954 HOTSPOT_JNI_NEWGLOBALREF_RETURN( | |
955 ret); | |
956 #endif /* USDT2 */ | |
0 | 957 return ret; |
958 JNI_END | |
959 | |
960 // Must be JNI_ENTRY (with HandleMark) | |
961 JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref)) | |
962 JNIWrapper("DeleteGlobalRef"); | |
4006 | 963 #ifndef USDT2 |
0 | 964 DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref); |
4006 | 965 #else /* USDT2 */ |
966 HOTSPOT_JNI_DELETEGLOBALREF_ENTRY( | |
967 env, ref); | |
968 #endif /* USDT2 */ | |
0 | 969 JNIHandles::destroy_global(ref); |
4006 | 970 #ifndef USDT2 |
0 | 971 DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return); |
4006 | 972 #else /* USDT2 */ |
973 HOTSPOT_JNI_DELETEGLOBALREF_RETURN( | |
974 ); | |
975 #endif /* USDT2 */ | |
0 | 976 JNI_END |
977 | |
978 JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj)) | |
979 JNIWrapper("DeleteLocalRef"); | |
4006 | 980 #ifndef USDT2 |
0 | 981 DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj); |
4006 | 982 #else /* USDT2 */ |
983 HOTSPOT_JNI_DELETELOCALREF_ENTRY( | |
984 env, obj); | |
985 #endif /* USDT2 */ | |
0 | 986 JNIHandles::destroy_local(obj); |
4006 | 987 #ifndef USDT2 |
0 | 988 DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return); |
4006 | 989 #else /* USDT2 */ |
990 HOTSPOT_JNI_DELETELOCALREF_RETURN( | |
991 ); | |
992 #endif /* USDT2 */ | |
0 | 993 JNI_END |
994 | |
995 JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2)) | |
996 JNIWrapper("IsSameObject"); | |
4006 | 997 #ifndef USDT2 |
0 | 998 DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2); |
4006 | 999 #else /* USDT2 */ |
1000 HOTSPOT_JNI_ISSAMEOBJECT_ENTRY( | |
1001 env, r1, r2); | |
1002 #endif /* USDT2 */ | |
0 | 1003 oop a = JNIHandles::resolve(r1); |
1004 oop b = JNIHandles::resolve(r2); | |
1005 jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE; | |
4006 | 1006 #ifndef USDT2 |
0 | 1007 DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret); |
4006 | 1008 #else /* USDT2 */ |
1009 HOTSPOT_JNI_ISSAMEOBJECT_RETURN( | |
1010 ret); | |
1011 #endif /* USDT2 */ | |
0 | 1012 return ret; |
1013 JNI_END | |
1014 | |
1015 | |
1016 JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref)) | |
1017 JNIWrapper("NewLocalRef"); | |
4006 | 1018 #ifndef USDT2 |
0 | 1019 DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref); |
4006 | 1020 #else /* USDT2 */ |
1021 HOTSPOT_JNI_NEWLOCALREF_ENTRY( | |
1022 env, ref); | |
1023 #endif /* USDT2 */ | |
0 | 1024 jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref)); |
4006 | 1025 #ifndef USDT2 |
0 | 1026 DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret); |
4006 | 1027 #else /* USDT2 */ |
1028 HOTSPOT_JNI_NEWLOCALREF_RETURN( | |
1029 ret); | |
1030 #endif /* USDT2 */ | |
0 | 1031 return ret; |
1032 JNI_END | |
1033 | |
1034 JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) | |
1035 JNIWrapper("EnsureLocalCapacity"); | |
4006 | 1036 #ifndef USDT2 |
0 | 1037 DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity); |
4006 | 1038 #else /* USDT2 */ |
1039 HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY( | |
1040 env, capacity); | |
1041 #endif /* USDT2 */ | |
0 | 1042 jint ret; |
1043 if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { | |
1044 ret = JNI_OK; | |
1045 } else { | |
1046 ret = JNI_ERR; | |
1047 } | |
4006 | 1048 #ifndef USDT2 |
0 | 1049 DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret); |
4006 | 1050 #else /* USDT2 */ |
1051 HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN( | |
1052 ret); | |
1053 #endif /* USDT2 */ | |
0 | 1054 return ret; |
1055 JNI_END | |
1056 | |
1057 // Return the Handle Type | |
1058 JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj)) | |
1059 JNIWrapper("GetObjectRefType"); | |
4006 | 1060 #ifndef USDT2 |
0 | 1061 DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj); |
4006 | 1062 #else /* USDT2 */ |
1063 HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY( | |
1064 env, obj); | |
1065 #endif /* USDT2 */ | |
0 | 1066 jobjectRefType ret; |
1067 if (JNIHandles::is_local_handle(thread, obj) || | |
1068 JNIHandles::is_frame_handle(thread, obj)) | |
1069 ret = JNILocalRefType; | |
1070 else if (JNIHandles::is_global_handle(obj)) | |
1071 ret = JNIGlobalRefType; | |
1072 else if (JNIHandles::is_weak_global_handle(obj)) | |
1073 ret = JNIWeakGlobalRefType; | |
1074 else | |
1075 ret = JNIInvalidRefType; | |
4006 | 1076 #ifndef USDT2 |
0 | 1077 DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret); |
4006 | 1078 #else /* USDT2 */ |
1079 HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN( | |
1080 (void *) ret); | |
1081 #endif /* USDT2 */ | |
0 | 1082 return ret; |
1083 JNI_END | |
1084 | |
1085 | |
1086 class JNI_ArgumentPusher : public SignatureIterator { | |
1087 protected: | |
1088 JavaCallArguments* _arguments; | |
1089 | |
1090 virtual void get_bool () = 0; | |
1091 virtual void get_char () = 0; | |
1092 virtual void get_short () = 0; | |
1093 virtual void get_byte () = 0; | |
1094 virtual void get_int () = 0; | |
1095 virtual void get_long () = 0; | |
1096 virtual void get_float () = 0; | |
1097 virtual void get_double () = 0; | |
1098 virtual void get_object () = 0; | |
1099 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1100 JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) { |
0 | 1101 this->_return_type = T_ILLEGAL; |
1102 _arguments = NULL; | |
1103 } | |
1104 | |
1105 public: | |
1106 virtual void iterate( uint64_t fingerprint ) = 0; | |
1107 | |
1108 void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; } | |
1109 | |
1110 inline void do_bool() { if (!is_return_type()) get_bool(); } | |
1111 inline void do_char() { if (!is_return_type()) get_char(); } | |
1112 inline void do_short() { if (!is_return_type()) get_short(); } | |
1113 inline void do_byte() { if (!is_return_type()) get_byte(); } | |
1114 inline void do_int() { if (!is_return_type()) get_int(); } | |
1115 inline void do_long() { if (!is_return_type()) get_long(); } | |
1116 inline void do_float() { if (!is_return_type()) get_float(); } | |
1117 inline void do_double() { if (!is_return_type()) get_double(); } | |
1118 inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); } | |
1119 inline void do_array(int begin, int end) { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array | |
1120 inline void do_void() { } | |
1121 | |
1122 JavaCallArguments* arguments() { return _arguments; } | |
1123 void push_receiver(Handle h) { _arguments->push_oop(h); } | |
1124 }; | |
1125 | |
1126 | |
1127 class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher { | |
1128 protected: | |
1129 va_list _ap; | |
1130 | |
1131 inline void get_bool() { _arguments->push_int(va_arg(_ap, jint)); } // bool is coerced to int when using va_arg | |
1132 inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg | |
1133 inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg | |
1134 inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg | |
1135 inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); } | |
1136 | |
1137 // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests | |
1138 | |
1139 inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); } | |
1140 inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg | |
1141 inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); } | |
1142 inline void get_object() { jobject l = va_arg(_ap, jobject); | |
1143 _arguments->push_oop(Handle((oop *)l, false)); } | |
1144 | |
1145 inline void set_ap(va_list rap) { | |
1146 #ifdef va_copy | |
1147 va_copy(_ap, rap); | |
1148 #elif defined (__va_copy) | |
1149 __va_copy(_ap, rap); | |
1150 #else | |
1151 _ap = rap; | |
1152 #endif | |
1153 } | |
1154 | |
1155 public: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1156 JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1157 : JNI_ArgumentPusher(signature) { |
0 | 1158 set_ap(rap); |
1159 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1160 JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1161 : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
0 | 1162 set_ap(rap); |
1163 } | |
1164 | |
1165 // Optimized path if we have the bitvector form of signature | |
1166 void iterate( uint64_t fingerprint ) { | |
1167 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments | |
1168 else { | |
1169 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
1170 result_feature_mask); | |
1171 | |
1172 assert(fingerprint, "Fingerprint should not be 0"); | |
1173 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
1174 while ( 1 ) { | |
1175 switch ( fingerprint & parameter_feature_mask ) { | |
1176 case bool_parm: | |
1177 case char_parm: | |
1178 case short_parm: | |
1179 case byte_parm: | |
1180 case int_parm: | |
1181 get_int(); | |
1182 break; | |
1183 case obj_parm: | |
1184 get_object(); | |
1185 break; | |
1186 case long_parm: | |
1187 get_long(); | |
1188 break; | |
1189 case float_parm: | |
1190 get_float(); | |
1191 break; | |
1192 case double_parm: | |
1193 get_double(); | |
1194 break; | |
1195 case done_parm: | |
1196 return; | |
1197 break; | |
1198 default: | |
1199 ShouldNotReachHere(); | |
1200 break; | |
1201 } | |
1202 fingerprint >>= parameter_feature_size; | |
1203 } | |
1204 } | |
1205 } | |
1206 }; | |
1207 | |
1208 | |
1209 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher { | |
1210 protected: | |
1211 const jvalue *_ap; | |
1212 | |
1213 inline void get_bool() { _arguments->push_int((jint)(_ap++)->z); } | |
1214 inline void get_char() { _arguments->push_int((jint)(_ap++)->c); } | |
1215 inline void get_short() { _arguments->push_int((jint)(_ap++)->s); } | |
1216 inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); } | |
1217 inline void get_int() { _arguments->push_int((jint)(_ap++)->i); } | |
1218 | |
1219 inline void get_long() { _arguments->push_long((_ap++)->j); } | |
1220 inline void get_float() { _arguments->push_float((_ap++)->f); } | |
1221 inline void get_double() { _arguments->push_double((_ap++)->d);} | |
1222 inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); } | |
1223 | |
1224 inline void set_ap(const jvalue *rap) { _ap = rap; } | |
1225 | |
1226 public: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1227 JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1228 : JNI_ArgumentPusher(signature) { |
0 | 1229 set_ap(rap); |
1230 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1231 JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1232 : JNI_ArgumentPusher(JNIHandles::resolve_jmethod_id(method_id)->signature()) { |
0 | 1233 set_ap(rap); |
1234 } | |
1235 | |
1236 // Optimized path if we have the bitvector form of signature | |
1237 void iterate( uint64_t fingerprint ) { | |
1238 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments | |
1239 else { | |
1240 _return_type = (BasicType)((fingerprint >> static_feature_size) & | |
1241 result_feature_mask); | |
1242 assert(fingerprint, "Fingerprint should not be 0"); | |
1243 fingerprint = fingerprint >> (static_feature_size + result_feature_size); | |
1244 while ( 1 ) { | |
1245 switch ( fingerprint & parameter_feature_mask ) { | |
1246 case bool_parm: | |
1247 get_bool(); | |
1248 break; | |
1249 case char_parm: | |
1250 get_char(); | |
1251 break; | |
1252 case short_parm: | |
1253 get_short(); | |
1254 break; | |
1255 case byte_parm: | |
1256 get_byte(); | |
1257 break; | |
1258 case int_parm: | |
1259 get_int(); | |
1260 break; | |
1261 case obj_parm: | |
1262 get_object(); | |
1263 break; | |
1264 case long_parm: | |
1265 get_long(); | |
1266 break; | |
1267 case float_parm: | |
1268 get_float(); | |
1269 break; | |
1270 case double_parm: | |
1271 get_double(); | |
1272 break; | |
1273 case done_parm: | |
1274 return; | |
1275 break; | |
1276 default: | |
1277 ShouldNotReachHere(); | |
1278 break; | |
1279 } | |
1280 fingerprint >>= parameter_feature_size; | |
1281 } | |
1282 } | |
1283 } | |
1284 }; | |
1285 | |
1286 | |
1287 enum JNICallType { | |
1288 JNI_STATIC, | |
1289 JNI_VIRTUAL, | |
1290 JNI_NONVIRTUAL | |
1291 }; | |
1292 | |
1293 static methodHandle jni_resolve_interface_call(Handle recv, methodHandle method, TRAPS) { | |
1294 assert(!method.is_null() , "method should not be null"); | |
1295 | |
1296 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
1297 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
1298 KlassHandle spec_klass (THREAD, method->method_holder()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1299 Symbol* name = method->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1300 Symbol* signature = method->signature(); |
0 | 1301 CallInfo info; |
1302 LinkResolver::resolve_interface_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
1303 return info.selected_method(); | |
1304 } | |
1305 | |
1306 static methodHandle jni_resolve_virtual_call(Handle recv, methodHandle method, TRAPS) { | |
1307 assert(!method.is_null() , "method should not be null"); | |
1308 | |
1309 KlassHandle recv_klass; // Default to NULL (use of ?: can confuse gcc) | |
1310 if (recv.not_null()) recv_klass = KlassHandle(THREAD, recv->klass()); | |
1311 KlassHandle spec_klass (THREAD, method->method_holder()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1312 Symbol* name = method->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1313 Symbol* signature = method->signature(); |
0 | 1314 CallInfo info; |
1315 LinkResolver::resolve_virtual_call(info, recv, recv_klass, spec_klass, name, signature, KlassHandle(), false, true, CHECK_(methodHandle())); | |
1316 return info.selected_method(); | |
1317 } | |
1318 | |
1319 | |
1320 | |
1321 static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
1322 methodHandle method(THREAD, JNIHandles::resolve_jmethod_id(method_id)); | |
1323 | |
1324 // Create object to hold arguments for the JavaCall, and associate it with | |
1325 // the jni parser | |
1326 ResourceMark rm(THREAD); | |
1327 int number_of_parameters = method->size_of_parameters(); | |
1328 JavaCallArguments java_args(number_of_parameters); | |
1329 args->set_java_argument_object(&java_args); | |
1330 | |
1331 assert(method->is_static(), "method should be static"); | |
1332 | |
1333 // Fill out JavaCallArguments object | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1334 args->iterate( Fingerprinter(method).fingerprint() ); |
0 | 1335 // Initialize result type |
1336 result->set_type(args->get_ret_type()); | |
1337 | |
1338 // Invoke the method. Result is returned as oop. | |
1339 JavaCalls::call(result, method, &java_args, CHECK); | |
1340 | |
1341 // Convert result | |
1342 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1343 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1344 } | |
1345 } | |
1346 | |
1347 | |
1348 static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { | |
1349 oop recv = JNIHandles::resolve(receiver); | |
1350 if (recv == NULL) { | |
1351 THROW(vmSymbols::java_lang_NullPointerException()); | |
1352 } | |
1353 Handle h_recv(THREAD, recv); | |
1354 | |
1355 int number_of_parameters; | |
1356 methodOop selected_method; | |
1357 { | |
1358 methodOop m = JNIHandles::resolve_jmethod_id(method_id); | |
1359 number_of_parameters = m->size_of_parameters(); | |
1360 klassOop holder = m->method_holder(); | |
1361 if (!(Klass::cast(holder))->is_interface()) { | |
1362 // non-interface call -- for that little speed boost, don't handlize | |
1363 debug_only(No_Safepoint_Verifier nosafepoint;) | |
1364 if (call_type == JNI_VIRTUAL) { | |
1365 // jni_GetMethodID makes sure class is linked and initialized | |
1366 // so m should have a valid vtable index. | |
1367 int vtbl_index = m->vtable_index(); | |
1368 if (vtbl_index != methodOopDesc::nonvirtual_vtable_index) { | |
1369 klassOop k = h_recv->klass(); | |
1370 // k might be an arrayKlassOop but all vtables start at | |
1371 // the same place. The cast is to avoid virtual call and assertion. | |
1372 instanceKlass *ik = (instanceKlass*)k->klass_part(); | |
1373 selected_method = ik->method_at_vtable(vtbl_index); | |
1374 } else { | |
1375 // final method | |
1376 selected_method = m; | |
1377 } | |
1378 } else { | |
1379 // JNI_NONVIRTUAL call | |
1380 selected_method = m; | |
1381 } | |
1382 } else { | |
1383 // interface call | |
1384 KlassHandle h_holder(THREAD, holder); | |
1385 | |
1386 int itbl_index = m->cached_itable_index(); | |
1387 if (itbl_index == -1) { | |
1388 itbl_index = klassItable::compute_itable_index(m); | |
1389 m->set_cached_itable_index(itbl_index); | |
1390 // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again | |
1391 } | |
1392 klassOop k = h_recv->klass(); | |
1393 selected_method = instanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); | |
1394 } | |
1395 } | |
1396 | |
1397 methodHandle method(THREAD, selected_method); | |
1398 | |
1399 // Create object to hold arguments for the JavaCall, and associate it with | |
1400 // the jni parser | |
1401 ResourceMark rm(THREAD); | |
1402 JavaCallArguments java_args(number_of_parameters); | |
1403 args->set_java_argument_object(&java_args); | |
1404 | |
1405 // handle arguments | |
1406 assert(!method->is_static(), "method should not be static"); | |
1407 args->push_receiver(h_recv); // Push jobject handle | |
1408 | |
1409 // Fill out JavaCallArguments object | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1410 args->iterate( Fingerprinter(method).fingerprint() ); |
0 | 1411 // Initialize result type |
1412 result->set_type(args->get_ret_type()); | |
1413 | |
1414 // Invoke the method. Result is returned as oop. | |
1415 JavaCalls::call(result, method, &java_args, CHECK); | |
1416 | |
1417 // Convert result | |
1418 if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { | |
1419 result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); | |
1420 } | |
1421 } | |
1422 | |
1423 | |
1424 static instanceOop alloc_object(jclass clazz, TRAPS) { | |
1425 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1426 Klass::cast(k())->check_valid_for_instantiation(false, CHECK_NULL); | |
1427 instanceKlass::cast(k())->initialize(CHECK_NULL); | |
1428 instanceOop ih = instanceKlass::cast(k())->allocate_instance(THREAD); | |
1429 return ih; | |
1430 } | |
1431 | |
4006 | 1432 #ifndef USDT2 |
0 | 1433 DT_RETURN_MARK_DECL(AllocObject, jobject); |
4006 | 1434 #else /* USDT2 */ |
1435 DT_RETURN_MARK_DECL(AllocObject, jobject | |
1436 , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref)); | |
1437 #endif /* USDT2 */ | |
0 | 1438 |
1439 JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz)) | |
1440 JNIWrapper("AllocObject"); | |
1441 | |
4006 | 1442 #ifndef USDT2 |
0 | 1443 DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz); |
4006 | 1444 #else /* USDT2 */ |
1445 HOTSPOT_JNI_ALLOCOBJECT_ENTRY( | |
1446 env, clazz); | |
1447 #endif /* USDT2 */ | |
0 | 1448 jobject ret = NULL; |
1449 DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); | |
1450 | |
1451 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1452 ret = JNIHandles::make_local(env, i); | |
1453 return ret; | |
1454 JNI_END | |
1455 | |
4006 | 1456 #ifndef USDT2 |
0 | 1457 DT_RETURN_MARK_DECL(NewObjectA, jobject); |
4006 | 1458 #else /* USDT2 */ |
1459 DT_RETURN_MARK_DECL(NewObjectA, jobject | |
1460 , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref)); | |
1461 #endif /* USDT2 */ | |
0 | 1462 |
1463 JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args)) | |
1464 JNIWrapper("NewObjectA"); | |
4006 | 1465 #ifndef USDT2 |
0 | 1466 DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID); |
4006 | 1467 #else /* USDT2 */ |
1468 HOTSPOT_JNI_NEWOBJECTA_ENTRY( | |
1469 env, clazz, (uintptr_t) methodID); | |
1470 #endif /* USDT2 */ | |
0 | 1471 jobject obj = NULL; |
1472 DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); | |
1473 | |
1474 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1475 obj = JNIHandles::make_local(env, i); | |
1476 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1477 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1478 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1479 return obj; | |
1480 JNI_END | |
1481 | |
4006 | 1482 #ifndef USDT2 |
0 | 1483 DT_RETURN_MARK_DECL(NewObjectV, jobject); |
4006 | 1484 #else /* USDT2 */ |
1485 DT_RETURN_MARK_DECL(NewObjectV, jobject | |
1486 , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref)); | |
1487 #endif /* USDT2 */ | |
0 | 1488 |
1489 JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)) | |
1490 JNIWrapper("NewObjectV"); | |
4006 | 1491 #ifndef USDT2 |
0 | 1492 DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID); |
4006 | 1493 #else /* USDT2 */ |
1494 HOTSPOT_JNI_NEWOBJECTV_ENTRY( | |
1495 env, clazz, (uintptr_t) methodID); | |
1496 #endif /* USDT2 */ | |
0 | 1497 jobject obj = NULL; |
1498 DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); | |
1499 | |
1500 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1501 obj = JNIHandles::make_local(env, i); | |
1502 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1503 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1504 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1505 return obj; | |
1506 JNI_END | |
1507 | |
4006 | 1508 #ifndef USDT2 |
0 | 1509 DT_RETURN_MARK_DECL(NewObject, jobject); |
4006 | 1510 #else /* USDT2 */ |
1511 DT_RETURN_MARK_DECL(NewObject, jobject | |
1512 , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref)); | |
1513 #endif /* USDT2 */ | |
0 | 1514 |
1515 JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)) | |
1516 JNIWrapper("NewObject"); | |
4006 | 1517 #ifndef USDT2 |
0 | 1518 DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID); |
4006 | 1519 #else /* USDT2 */ |
1520 HOTSPOT_JNI_NEWOBJECT_ENTRY( | |
1521 env, clazz, (uintptr_t) methodID); | |
1522 #endif /* USDT2 */ | |
0 | 1523 jobject obj = NULL; |
1524 DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); | |
1525 | |
1526 instanceOop i = alloc_object(clazz, CHECK_NULL); | |
1527 obj = JNIHandles::make_local(env, i); | |
1528 va_list args; | |
1529 va_start(args, methodID); | |
1530 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1531 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1532 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
1533 va_end(args); | |
1534 return obj; | |
1535 JNI_END | |
1536 | |
1537 | |
1538 JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) | |
1539 JNIWrapper("GetObjectClass"); | |
4006 | 1540 #ifndef USDT2 |
0 | 1541 DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj); |
4006 | 1542 #else /* USDT2 */ |
1543 HOTSPOT_JNI_GETOBJECTCLASS_ENTRY( | |
1544 env, obj); | |
1545 #endif /* USDT2 */ | |
0 | 1546 klassOop k = JNIHandles::resolve_non_null(obj)->klass(); |
1547 jclass ret = | |
1548 (jclass) JNIHandles::make_local(env, Klass::cast(k)->java_mirror()); | |
4006 | 1549 #ifndef USDT2 |
0 | 1550 DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret); |
4006 | 1551 #else /* USDT2 */ |
1552 HOTSPOT_JNI_GETOBJECTCLASS_RETURN( | |
1553 ret); | |
1554 #endif /* USDT2 */ | |
0 | 1555 return ret; |
1556 JNI_END | |
1557 | |
1558 JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)) | |
1559 JNIWrapper("IsInstanceOf"); | |
4006 | 1560 #ifndef USDT2 |
0 | 1561 DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz); |
4006 | 1562 #else /* USDT2 */ |
1563 HOTSPOT_JNI_ISINSTANCEOF_ENTRY( | |
1564 env, obj, clazz); | |
1565 #endif /* USDT2 */ | |
0 | 1566 jboolean ret = JNI_TRUE; |
1567 if (obj != NULL) { | |
1568 ret = JNI_FALSE; | |
1569 klassOop k = java_lang_Class::as_klassOop( | |
1570 JNIHandles::resolve_non_null(clazz)); | |
1571 if (k != NULL) { | |
1572 ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE; | |
1573 } | |
1574 } | |
4006 | 1575 #ifndef USDT2 |
0 | 1576 DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret); |
4006 | 1577 #else /* USDT2 */ |
1578 HOTSPOT_JNI_ISINSTANCEOF_RETURN( | |
1579 ret); | |
1580 #endif /* USDT2 */ | |
0 | 1581 return ret; |
1582 JNI_END | |
1583 | |
1584 | |
1585 static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str, | |
1586 const char *sig, bool is_static, TRAPS) { | |
1587 // %%%% This code should probably just call into a method in the LinkResolver | |
1588 // | |
1589 // The class should have been loaded (we have an instance of the class | |
1590 // passed in) so the method and signature should already be in the symbol | |
1591 // 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
|
1592 const char *name_to_probe = (name_str == NULL) |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1593 ? vmSymbols::object_initializer_name()->as_C_string() |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1594 : name_str; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1595 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
|
1596 TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1597 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1598 if (name == NULL || signature == NULL) { |
0 | 1599 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
1600 } | |
1601 | |
1602 // Throw a NoSuchMethodError exception if we have an instance of a | |
1603 // primitive java.lang.Class | |
1604 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) { | |
1605 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1606 } | |
1607 | |
1608 KlassHandle klass(THREAD, | |
1609 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
1610 | |
1611 // Make sure class is linked and initialized before handing id's out to | |
1612 // methodOops. | |
1613 Klass::cast(klass())->initialize(CHECK_NULL); | |
1614 | |
1615 methodOop m; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1616 if (name == vmSymbols::object_initializer_name() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1617 name == vmSymbols::class_initializer_name()) { |
0 | 1618 // Never search superclasses for constructors |
1619 if (klass->oop_is_instance()) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1620 m = instanceKlass::cast(klass())->find_method(name, signature); |
0 | 1621 } else { |
1622 m = NULL; | |
1623 } | |
1624 } else { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1625 m = klass->lookup_method(name, signature); |
0 | 1626 // Look up interfaces |
1627 if (m == NULL && klass->oop_is_instance()) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1628 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
|
1629 signature); |
0 | 1630 } |
1631 } | |
1632 if (m == NULL || (m->is_static() != is_static)) { | |
1633 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); | |
1634 } | |
1635 return m->jmethod_id(); | |
1636 } | |
1637 | |
1638 | |
1639 JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz, | |
1640 const char *name, const char *sig)) | |
1641 JNIWrapper("GetMethodID"); | |
4006 | 1642 #ifndef USDT2 |
0 | 1643 DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig); |
4006 | 1644 #else /* USDT2 */ |
1645 HOTSPOT_JNI_GETMETHODID_ENTRY( | |
1646 env, clazz, (char *) name, (char *) sig); | |
1647 #endif /* USDT2 */ | |
0 | 1648 jmethodID ret = get_method_id(env, clazz, name, sig, false, thread); |
4006 | 1649 #ifndef USDT2 |
0 | 1650 DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret); |
4006 | 1651 #else /* USDT2 */ |
1652 HOTSPOT_JNI_GETMETHODID_RETURN( | |
1653 (uintptr_t) ret); | |
1654 #endif /* USDT2 */ | |
0 | 1655 return ret; |
1656 JNI_END | |
1657 | |
1658 | |
1659 JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz, | |
1660 const char *name, const char *sig)) | |
1661 JNIWrapper("GetStaticMethodID"); | |
4006 | 1662 #ifndef USDT2 |
0 | 1663 DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig); |
4006 | 1664 #else /* USDT2 */ |
1665 HOTSPOT_JNI_GETSTATICMETHODID_ENTRY( | |
1666 env, (char *) clazz, (char *) name, (char *)sig); | |
1667 #endif /* USDT2 */ | |
0 | 1668 jmethodID ret = get_method_id(env, clazz, name, sig, true, thread); |
4006 | 1669 #ifndef USDT2 |
0 | 1670 DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret); |
4006 | 1671 #else /* USDT2 */ |
1672 HOTSPOT_JNI_GETSTATICMETHODID_RETURN( | |
1673 (uintptr_t) ret); | |
1674 #endif /* USDT2 */ | |
0 | 1675 return ret; |
1676 JNI_END | |
1677 | |
1678 | |
1679 | |
1680 // | |
1681 // Calling Methods | |
1682 // | |
1683 | |
4006 | 1684 #ifndef USDT2 |
0 | 1685 #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \ |
1686 \ | |
1687 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\ | |
1688 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\ | |
1689 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\ | |
1690 \ | |
1691 JNI_ENTRY(ResultType, \ | |
1692 jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ | |
1693 JNIWrapper("Call" XSTR(Result) "Method"); \ | |
1694 \ | |
4006 | 1695 DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID); \ |
0 | 1696 ResultType ret = 0;\ |
1697 DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ | |
1698 (const ResultType&)ret);\ | |
1699 \ | |
1700 va_list args; \ | |
1701 va_start(args, methodID); \ | |
1702 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1703 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1704 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1705 va_end(args); \ | |
1706 ret = jvalue.get_##ResultType(); \ | |
1707 return ret;\ | |
1708 JNI_END \ | |
1709 \ | |
1710 \ | |
1711 JNI_ENTRY(ResultType, \ | |
1712 jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ | |
1713 JNIWrapper("Call" XSTR(Result) "MethodV"); \ | |
1714 \ | |
4006 | 1715 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID); \ |
0 | 1716 ResultType ret = 0;\ |
1717 DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ | |
1718 (const ResultType&)ret);\ | |
1719 \ | |
1720 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1721 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1722 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1723 ret = jvalue.get_##ResultType(); \ | |
1724 return ret;\ | |
1725 JNI_END \ | |
1726 \ | |
1727 \ | |
1728 JNI_ENTRY(ResultType, \ | |
1729 jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ | |
1730 JNIWrapper("Call" XSTR(Result) "MethodA"); \ | |
4006 | 1731 DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID); \ |
0 | 1732 ResultType ret = 0;\ |
1733 DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ | |
1734 (const ResultType&)ret);\ | |
1735 \ | |
1736 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1737 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 1738 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
1739 ret = jvalue.get_##ResultType(); \ | |
1740 return ret;\ | |
1741 JNI_END | |
1742 | |
1743 // the runtime type of subword integral basic types is integer | |
1744 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN) | |
1745 DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE) | |
1746 DEFINE_CALLMETHOD(jchar, Char, T_CHAR) | |
1747 DEFINE_CALLMETHOD(jshort, Short, T_SHORT) | |
1748 | |
1749 DEFINE_CALLMETHOD(jobject, Object, T_OBJECT) | |
1750 DEFINE_CALLMETHOD(jint, Int, T_INT) | |
1751 DEFINE_CALLMETHOD(jlong, Long, T_LONG) | |
1752 DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT) | |
1753 DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE) | |
1754 | |
1755 DT_VOID_RETURN_MARK_DECL(CallVoidMethod); | |
1756 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV); | |
1757 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA); | |
1758 | |
4006 | 1759 #else /* USDT2 */ |
1760 | |
1761 #define DEFINE_CALLMETHOD(ResultType, Result, Tag \ | |
1762 , EntryProbe, ReturnProbe) \ | |
1763 \ | |
1764 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \ | |
1765 , ReturnProbe); \ | |
1766 \ | |
1767 JNI_ENTRY(ResultType, \ | |
1768 jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ | |
1769 JNIWrapper("Call" XSTR(Result) "Method"); \ | |
1770 \ | |
1771 EntryProbe; \ | |
1772 ResultType ret = 0;\ | |
1773 DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ | |
1774 (const ResultType&)ret);\ | |
1775 \ | |
1776 va_list args; \ | |
1777 va_start(args, methodID); \ | |
1778 JavaValue jvalue(Tag); \ | |
1779 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
1780 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1781 va_end(args); \ | |
1782 ret = jvalue.get_##ResultType(); \ | |
1783 return ret;\ | |
1784 JNI_END | |
1785 | |
1786 // the runtime type of subword integral basic types is integer | |
1787 DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN | |
1788 , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1789 HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) | |
1790 DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE | |
1791 , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1792 HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) | |
1793 DEFINE_CALLMETHOD(jchar, Char, T_CHAR | |
1794 , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1795 HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) | |
1796 DEFINE_CALLMETHOD(jshort, Short, T_SHORT | |
1797 , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1798 HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) | |
1799 | |
1800 DEFINE_CALLMETHOD(jobject, Object, T_OBJECT | |
1801 , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1802 HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) | |
1803 DEFINE_CALLMETHOD(jint, Int, T_INT, | |
1804 HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1805 HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) | |
1806 DEFINE_CALLMETHOD(jlong, Long, T_LONG | |
1807 , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1808 HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) | |
1809 // Float and double probes don't return value because dtrace doesn't currently support it | |
1810 DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT | |
1811 , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1812 HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) | |
1813 DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE | |
1814 , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1815 HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) | |
1816 | |
1817 #define DEFINE_CALLMETHODV(ResultType, Result, Tag \ | |
1818 , EntryProbe, ReturnProbe) \ | |
1819 \ | |
1820 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \ | |
1821 , ReturnProbe); \ | |
1822 \ | |
1823 JNI_ENTRY(ResultType, \ | |
1824 jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ | |
1825 JNIWrapper("Call" XSTR(Result) "MethodV"); \ | |
1826 \ | |
1827 EntryProbe;\ | |
1828 ResultType ret = 0;\ | |
1829 DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ | |
1830 (const ResultType&)ret);\ | |
1831 \ | |
1832 JavaValue jvalue(Tag); \ | |
1833 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
1834 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1835 ret = jvalue.get_##ResultType(); \ | |
1836 return ret;\ | |
1837 JNI_END | |
1838 | |
1839 // the runtime type of subword integral basic types is integer | |
1840 DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN | |
1841 , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1842 HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) | |
1843 DEFINE_CALLMETHODV(jbyte, Byte, T_BYTE | |
1844 , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1845 HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) | |
1846 DEFINE_CALLMETHODV(jchar, Char, T_CHAR | |
1847 , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1848 HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) | |
1849 DEFINE_CALLMETHODV(jshort, Short, T_SHORT | |
1850 , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1851 HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) | |
1852 | |
1853 DEFINE_CALLMETHODV(jobject, Object, T_OBJECT | |
1854 , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1855 HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) | |
1856 DEFINE_CALLMETHODV(jint, Int, T_INT, | |
1857 HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1858 HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) | |
1859 DEFINE_CALLMETHODV(jlong, Long, T_LONG | |
1860 , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1861 HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) | |
1862 // Float and double probes don't return value because dtrace doesn't currently support it | |
1863 DEFINE_CALLMETHODV(jfloat, Float, T_FLOAT | |
1864 , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1865 HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) | |
1866 DEFINE_CALLMETHODV(jdouble, Double, T_DOUBLE | |
1867 , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1868 HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) | |
1869 | |
1870 #define DEFINE_CALLMETHODA(ResultType, Result, Tag \ | |
1871 , EntryProbe, ReturnProbe) \ | |
1872 \ | |
1873 DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \ | |
1874 , ReturnProbe); \ | |
1875 \ | |
1876 JNI_ENTRY(ResultType, \ | |
1877 jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ | |
1878 JNIWrapper("Call" XSTR(Result) "MethodA"); \ | |
1879 EntryProbe; \ | |
1880 ResultType ret = 0;\ | |
1881 DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ | |
1882 (const ResultType&)ret);\ | |
1883 \ | |
1884 JavaValue jvalue(Tag); \ | |
1885 JNI_ArgumentPusherArray ap(methodID, args); \ | |
1886 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ | |
1887 ret = jvalue.get_##ResultType(); \ | |
1888 return ret;\ | |
1889 JNI_END | |
1890 | |
1891 // the runtime type of subword integral basic types is integer | |
1892 DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN | |
1893 , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1894 HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) | |
1895 DEFINE_CALLMETHODA(jbyte, Byte, T_BYTE | |
1896 , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1897 HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) | |
1898 DEFINE_CALLMETHODA(jchar, Char, T_CHAR | |
1899 , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1900 HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) | |
1901 DEFINE_CALLMETHODA(jshort, Short, T_SHORT | |
1902 , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1903 HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) | |
1904 | |
1905 DEFINE_CALLMETHODA(jobject, Object, T_OBJECT | |
1906 , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1907 HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) | |
1908 DEFINE_CALLMETHODA(jint, Int, T_INT, | |
1909 HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1910 HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) | |
1911 DEFINE_CALLMETHODA(jlong, Long, T_LONG | |
1912 , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1913 HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) | |
1914 // Float and double probes don't return value because dtrace doesn't currently support it | |
1915 DEFINE_CALLMETHODA(jfloat, Float, T_FLOAT | |
1916 , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1917 HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) | |
1918 DEFINE_CALLMETHODA(jdouble, Double, T_DOUBLE | |
1919 , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), | |
1920 HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) | |
1921 | |
1922 DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN()); | |
1923 DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN()); | |
1924 DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN()); | |
1925 | |
1926 #endif /* USDT2 */ | |
1927 | |
0 | 1928 JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)) |
1929 JNIWrapper("CallVoidMethod"); | |
4006 | 1930 #ifndef USDT2 |
0 | 1931 DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID); |
4006 | 1932 #else /* USDT2 */ |
1933 HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY( | |
1934 env, obj, (uintptr_t) methodID); | |
1935 #endif /* USDT2 */ | |
0 | 1936 DT_VOID_RETURN_MARK(CallVoidMethod); |
1937 | |
1938 va_list args; | |
1939 va_start(args, methodID); | |
1940 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1941 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1942 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1943 va_end(args); | |
1944 JNI_END | |
1945 | |
1946 | |
1947 JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) | |
1948 JNIWrapper("CallVoidMethodV"); | |
4006 | 1949 #ifndef USDT2 |
0 | 1950 DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID); |
4006 | 1951 #else /* USDT2 */ |
1952 HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY( | |
1953 env, obj, (uintptr_t) methodID); | |
1954 #endif /* USDT2 */ | |
0 | 1955 DT_VOID_RETURN_MARK(CallVoidMethodV); |
1956 | |
1957 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1958 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 1959 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1960 JNI_END | |
1961 | |
1962 | |
1963 JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) | |
1964 JNIWrapper("CallVoidMethodA"); | |
4006 | 1965 #ifndef USDT2 |
0 | 1966 DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID); |
4006 | 1967 #else /* USDT2 */ |
1968 HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY( | |
1969 env, obj, (uintptr_t) methodID); | |
1970 #endif /* USDT2 */ | |
0 | 1971 DT_VOID_RETURN_MARK(CallVoidMethodA); |
1972 | |
1973 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1974 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 1975 jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
1976 JNI_END | |
1977 | |
1978 | |
4006 | 1979 #ifndef USDT2 |
0 | 1980 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \ |
1981 \ | |
1982 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\ | |
1983 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\ | |
1984 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\ | |
1985 \ | |
1986 JNI_ENTRY(ResultType, \ | |
1987 jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ | |
1988 JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ | |
1989 \ | |
1990 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\ | |
1991 ResultType ret;\ | |
1992 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ | |
1993 (const ResultType&)ret);\ | |
1994 \ | |
1995 va_list args; \ | |
1996 va_start(args, methodID); \ | |
1997 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
1998 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 1999 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
2000 va_end(args); \ | |
2001 ret = jvalue.get_##ResultType(); \ | |
2002 return ret;\ | |
2003 JNI_END \ | |
2004 \ | |
2005 JNI_ENTRY(ResultType, \ | |
2006 jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ | |
2007 JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \ | |
2008 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\ | |
2009 ResultType ret;\ | |
2010 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ | |
2011 (const ResultType&)ret);\ | |
2012 \ | |
2013 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2014 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 2015 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
2016 ret = jvalue.get_##ResultType(); \ | |
2017 return ret;\ | |
2018 JNI_END \ | |
2019 \ | |
2020 JNI_ENTRY(ResultType, \ | |
2021 jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
2022 JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ | |
2023 DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\ | |
2024 ResultType ret;\ | |
2025 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ | |
2026 (const ResultType&)ret);\ | |
2027 \ | |
2028 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2029 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 2030 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
2031 ret = jvalue.get_##ResultType(); \ | |
2032 return ret;\ | |
2033 JNI_END | |
2034 | |
2035 // the runtime type of subword integral basic types is integer | |
2036 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN) | |
2037 DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE) | |
2038 DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR) | |
2039 DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT) | |
2040 | |
2041 DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT) | |
2042 DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT) | |
2043 DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG) | |
2044 DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT) | |
2045 DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE) | |
2046 | |
2047 | |
2048 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod); | |
2049 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV); | |
2050 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA); | |
2051 | |
4006 | 2052 #else /* USDT2 */ |
2053 | |
2054 #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \ | |
2055 , EntryProbe, ReturnProbe) \ | |
2056 \ | |
2057 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \ | |
2058 , ReturnProbe);\ | |
2059 \ | |
2060 JNI_ENTRY(ResultType, \ | |
2061 jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ | |
2062 JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ | |
2063 \ | |
2064 EntryProbe;\ | |
2065 ResultType ret;\ | |
2066 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ | |
2067 (const ResultType&)ret);\ | |
2068 \ | |
2069 va_list args; \ | |
2070 va_start(args, methodID); \ | |
2071 JavaValue jvalue(Tag); \ | |
2072 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
2073 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
2074 va_end(args); \ | |
2075 ret = jvalue.get_##ResultType(); \ | |
2076 return ret;\ | |
2077 JNI_END | |
2078 | |
2079 // the runtime type of subword integral basic types is integer | |
2080 DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN | |
2081 , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2082 HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref)) | |
2083 DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE | |
2084 , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2085 HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref)) | |
2086 DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR | |
2087 , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2088 HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref)) | |
2089 DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT | |
2090 , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2091 HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref)) | |
2092 | |
2093 DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT | |
2094 , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2095 HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref)) | |
2096 DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT | |
2097 , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2098 HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref)) | |
2099 DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG | |
2100 , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2101 // Float and double probes don't return value because dtrace doesn't currently support it | |
2102 HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref)) | |
2103 DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT | |
2104 , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2105 HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN()) | |
2106 DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE | |
2107 , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2108 HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN()) | |
2109 | |
2110 #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \ | |
2111 , EntryProbe, ReturnProbe) \ | |
2112 \ | |
2113 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \ | |
2114 , ReturnProbe);\ | |
2115 \ | |
2116 JNI_ENTRY(ResultType, \ | |
2117 jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ | |
2118 JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \ | |
2119 \ | |
2120 EntryProbe;\ | |
2121 ResultType ret;\ | |
2122 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ | |
2123 (const ResultType&)ret);\ | |
2124 \ | |
2125 JavaValue jvalue(Tag); \ | |
2126 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
2127 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
2128 ret = jvalue.get_##ResultType(); \ | |
2129 return ret;\ | |
2130 JNI_END | |
2131 | |
2132 // the runtime type of subword integral basic types is integer | |
2133 DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN | |
2134 , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2135 HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref)) | |
2136 DEFINE_CALLNONVIRTUALMETHODV(jbyte, Byte, T_BYTE | |
2137 , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2138 HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref)) | |
2139 DEFINE_CALLNONVIRTUALMETHODV(jchar, Char, T_CHAR | |
2140 , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2141 HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref)) | |
2142 DEFINE_CALLNONVIRTUALMETHODV(jshort, Short, T_SHORT | |
2143 , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2144 HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref)) | |
2145 | |
2146 DEFINE_CALLNONVIRTUALMETHODV(jobject, Object, T_OBJECT | |
2147 , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2148 HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref)) | |
2149 DEFINE_CALLNONVIRTUALMETHODV(jint, Int, T_INT | |
2150 , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2151 HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref)) | |
2152 DEFINE_CALLNONVIRTUALMETHODV(jlong, Long, T_LONG | |
2153 , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2154 // Float and double probes don't return value because dtrace doesn't currently support it | |
2155 HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref)) | |
2156 DEFINE_CALLNONVIRTUALMETHODV(jfloat, Float, T_FLOAT | |
2157 , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2158 HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN()) | |
2159 DEFINE_CALLNONVIRTUALMETHODV(jdouble, Double, T_DOUBLE | |
2160 , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2161 HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN()) | |
2162 | |
2163 #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \ | |
2164 , EntryProbe, ReturnProbe) \ | |
2165 \ | |
2166 DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \ | |
2167 , ReturnProbe);\ | |
2168 \ | |
2169 JNI_ENTRY(ResultType, \ | |
2170 jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
2171 JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ | |
2172 \ | |
2173 EntryProbe;\ | |
2174 ResultType ret;\ | |
2175 DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ | |
2176 (const ResultType&)ret);\ | |
2177 \ | |
2178 JavaValue jvalue(Tag); \ | |
2179 JNI_ArgumentPusherArray ap(methodID, args); \ | |
2180 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ | |
2181 ret = jvalue.get_##ResultType(); \ | |
2182 return ret;\ | |
2183 JNI_END | |
2184 | |
2185 // the runtime type of subword integral basic types is integer | |
2186 DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN | |
2187 , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2188 HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref)) | |
2189 DEFINE_CALLNONVIRTUALMETHODA(jbyte, Byte, T_BYTE | |
2190 , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2191 HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref)) | |
2192 DEFINE_CALLNONVIRTUALMETHODA(jchar, Char, T_CHAR | |
2193 , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2194 HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref)) | |
2195 DEFINE_CALLNONVIRTUALMETHODA(jshort, Short, T_SHORT | |
2196 , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2197 HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref)) | |
2198 | |
2199 DEFINE_CALLNONVIRTUALMETHODA(jobject, Object, T_OBJECT | |
2200 , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2201 HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref)) | |
2202 DEFINE_CALLNONVIRTUALMETHODA(jint, Int, T_INT | |
2203 , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2204 HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref)) | |
2205 DEFINE_CALLNONVIRTUALMETHODA(jlong, Long, T_LONG | |
2206 , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2207 // Float and double probes don't return value because dtrace doesn't currently support it | |
2208 HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref)) | |
2209 DEFINE_CALLNONVIRTUALMETHODA(jfloat, Float, T_FLOAT | |
2210 , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2211 HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN()) | |
2212 DEFINE_CALLNONVIRTUALMETHODA(jdouble, Double, T_DOUBLE | |
2213 , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), | |
2214 HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN()) | |
2215 | |
2216 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod | |
2217 , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN()); | |
2218 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV | |
2219 , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN()); | |
2220 DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA | |
2221 , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN()); | |
2222 #endif /* USDT2 */ | |
2223 | |
0 | 2224 JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) |
2225 JNIWrapper("CallNonvirtualVoidMethod"); | |
2226 | |
4006 | 2227 #ifndef USDT2 |
0 | 2228 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry, |
2229 env, obj, cls, methodID); | |
4006 | 2230 #else /* USDT2 */ |
2231 HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY( | |
2232 env, obj, cls, (uintptr_t) methodID); | |
2233 #endif /* USDT2 */ | |
0 | 2234 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod); |
2235 | |
2236 va_list args; | |
2237 va_start(args, methodID); | |
2238 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2239 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 2240 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
2241 va_end(args); | |
2242 JNI_END | |
2243 | |
2244 | |
2245 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) | |
2246 JNIWrapper("CallNonvirtualVoidMethodV"); | |
2247 | |
4006 | 2248 #ifndef USDT2 |
0 | 2249 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry, |
2250 env, obj, cls, methodID); | |
4006 | 2251 #else /* USDT2 */ |
2252 HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY( | |
2253 env, obj, cls, (uintptr_t) methodID); | |
2254 #endif /* USDT2 */ | |
0 | 2255 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV); |
2256 | |
2257 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2258 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 2259 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
2260 JNI_END | |
2261 | |
2262 | |
2263 JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) | |
2264 JNIWrapper("CallNonvirtualVoidMethodA"); | |
4006 | 2265 #ifndef USDT2 |
0 | 2266 DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry, |
2267 env, obj, cls, methodID); | |
4006 | 2268 #else /* USDT2 */ |
2269 HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY( | |
2270 env, obj, cls, (uintptr_t) methodID); | |
2271 #endif /* USDT2 */ | |
0 | 2272 DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA); |
2273 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2274 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 2275 jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
2276 JNI_END | |
2277 | |
2278 | |
4006 | 2279 #ifndef USDT2 |
0 | 2280 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \ |
2281 \ | |
2282 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\ | |
2283 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\ | |
2284 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\ | |
2285 \ | |
2286 JNI_ENTRY(ResultType, \ | |
2287 jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ | |
2288 JNIWrapper("CallStatic" XSTR(Result) "Method"); \ | |
2289 \ | |
2290 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\ | |
2291 ResultType ret = 0;\ | |
2292 DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ | |
2293 (const ResultType&)ret);\ | |
2294 \ | |
2295 va_list args; \ | |
2296 va_start(args, methodID); \ | |
2297 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2298 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 2299 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
2300 va_end(args); \ | |
2301 ret = jvalue.get_##ResultType(); \ | |
2302 return ret;\ | |
2303 JNI_END \ | |
2304 \ | |
2305 JNI_ENTRY(ResultType, \ | |
2306 jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ | |
2307 JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ | |
2308 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\ | |
2309 ResultType ret = 0;\ | |
2310 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ | |
2311 (const ResultType&)ret);\ | |
2312 \ | |
2313 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2314 JNI_ArgumentPusherVaArg ap(methodID, args); \ |
0 | 2315 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
2316 ret = jvalue.get_##ResultType(); \ | |
2317 return ret;\ | |
2318 JNI_END \ | |
2319 \ | |
2320 JNI_ENTRY(ResultType, \ | |
2321 jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
2322 JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ | |
2323 DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\ | |
2324 ResultType ret = 0;\ | |
2325 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ | |
2326 (const ResultType&)ret);\ | |
2327 \ | |
2328 JavaValue jvalue(Tag); \ | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2329 JNI_ArgumentPusherArray ap(methodID, args); \ |
0 | 2330 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
2331 ret = jvalue.get_##ResultType(); \ | |
2332 return ret;\ | |
2333 JNI_END | |
2334 | |
2335 // the runtime type of subword integral basic types is integer | |
2336 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN) | |
2337 DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE) | |
2338 DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR) | |
2339 DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT) | |
2340 | |
2341 DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT) | |
2342 DEFINE_CALLSTATICMETHOD(jint, Int, T_INT) | |
2343 DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG) | |
2344 DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT) | |
2345 DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE) | |
2346 | |
2347 | |
2348 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod); | |
2349 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV); | |
2350 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA); | |
2351 | |
4006 | 2352 #else /* USDT2 */ |
2353 | |
2354 #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \ | |
2355 , EntryProbe, ResultProbe) \ | |
2356 \ | |
2357 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \ | |
2358 , ResultProbe); \ | |
2359 \ | |
2360 JNI_ENTRY(ResultType, \ | |
2361 jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ | |
2362 JNIWrapper("CallStatic" XSTR(Result) "Method"); \ | |
2363 \ | |
2364 EntryProbe; \ | |
2365 ResultType ret = 0;\ | |
2366 DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ | |
2367 (const ResultType&)ret);\ | |
2368 \ | |
2369 va_list args; \ | |
2370 va_start(args, methodID); \ | |
2371 JavaValue jvalue(Tag); \ | |
2372 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
2373 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
2374 va_end(args); \ | |
2375 ret = jvalue.get_##ResultType(); \ | |
2376 return ret;\ | |
2377 JNI_END | |
2378 | |
2379 // the runtime type of subword integral basic types is integer | |
2380 DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN | |
2381 , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2382 HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref)); | |
2383 DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE | |
2384 , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2385 HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref)); | |
2386 DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR | |
2387 , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2388 HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref)); | |
2389 DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT | |
2390 , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2391 HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref)); | |
2392 | |
2393 DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT | |
2394 , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2395 HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref)); | |
2396 DEFINE_CALLSTATICMETHOD(jint, Int, T_INT | |
2397 , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2398 HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref)); | |
2399 DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG | |
2400 , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2401 HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref)); | |
2402 // Float and double probes don't return value because dtrace doesn't currently support it | |
2403 DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT | |
2404 , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2405 HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN()); | |
2406 DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE | |
2407 , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), | |
2408 HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN()); | |
2409 | |
2410 #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \ | |
2411 , EntryProbe, ResultProbe) \ | |
2412 \ | |
2413 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \ | |
2414 , ResultProbe); \ | |
2415 \ | |
2416 JNI_ENTRY(ResultType, \ | |
2417 jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ | |
2418 JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ | |
2419 \ | |
2420 EntryProbe; \ | |
2421 ResultType ret = 0;\ | |
2422 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ | |
2423 (const ResultType&)ret);\ | |
2424 \ | |
2425 JavaValue jvalue(Tag); \ | |
2426 JNI_ArgumentPusherVaArg ap(methodID, args); \ | |
2427 /* Make sure class is initialized before trying to invoke its method */ \ | |
2428 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls))); \ | |
2429 Klass::cast(k())->initialize(CHECK_0); \ | |
2430 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
2431 va_end(args); \ | |
2432 ret = jvalue.get_##ResultType(); \ | |
2433 return ret;\ | |
2434 JNI_END | |
2435 | |
2436 // the runtime type of subword integral basic types is integer | |
2437 DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN | |
2438 , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2439 HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref)); | |
2440 DEFINE_CALLSTATICMETHODV(jbyte, Byte, T_BYTE | |
2441 , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2442 HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref)); | |
2443 DEFINE_CALLSTATICMETHODV(jchar, Char, T_CHAR | |
2444 , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2445 HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref)); | |
2446 DEFINE_CALLSTATICMETHODV(jshort, Short, T_SHORT | |
2447 , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2448 HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref)); | |
2449 | |
2450 DEFINE_CALLSTATICMETHODV(jobject, Object, T_OBJECT | |
2451 , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2452 HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref)); | |
2453 DEFINE_CALLSTATICMETHODV(jint, Int, T_INT | |
2454 , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2455 HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref)); | |
2456 DEFINE_CALLSTATICMETHODV(jlong, Long, T_LONG | |
2457 , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2458 HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref)); | |
2459 // Float and double probes don't return value because dtrace doesn't currently support it | |
2460 DEFINE_CALLSTATICMETHODV(jfloat, Float, T_FLOAT | |
2461 , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2462 HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN()); | |
2463 DEFINE_CALLSTATICMETHODV(jdouble, Double, T_DOUBLE | |
2464 , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), | |
2465 HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN()); | |
2466 | |
2467 #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \ | |
2468 , EntryProbe, ResultProbe) \ | |
2469 \ | |
2470 DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \ | |
2471 , ResultProbe); \ | |
2472 \ | |
2473 JNI_ENTRY(ResultType, \ | |
2474 jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ | |
2475 JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ | |
2476 \ | |
2477 EntryProbe; \ | |
2478 ResultType ret = 0;\ | |
2479 DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ | |
2480 (const ResultType&)ret);\ | |
2481 \ | |
2482 JavaValue jvalue(Tag); \ | |
2483 JNI_ArgumentPusherArray ap(methodID, args); \ | |
2484 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ | |
2485 ret = jvalue.get_##ResultType(); \ | |
2486 return ret;\ | |
2487 JNI_END | |
2488 | |
2489 // the runtime type of subword integral basic types is integer | |
2490 DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN | |
2491 , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2492 HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref)); | |
2493 DEFINE_CALLSTATICMETHODA(jbyte, Byte, T_BYTE | |
2494 , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2495 HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref)); | |
2496 DEFINE_CALLSTATICMETHODA(jchar, Char, T_CHAR | |
2497 , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2498 HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref)); | |
2499 DEFINE_CALLSTATICMETHODA(jshort, Short, T_SHORT | |
2500 , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2501 HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref)); | |
2502 | |
2503 DEFINE_CALLSTATICMETHODA(jobject, Object, T_OBJECT | |
2504 , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2505 HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref)); | |
2506 DEFINE_CALLSTATICMETHODA(jint, Int, T_INT | |
2507 , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2508 HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref)); | |
2509 DEFINE_CALLSTATICMETHODA(jlong, Long, T_LONG | |
2510 , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2511 HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref)); | |
2512 // Float and double probes don't return value because dtrace doesn't currently support it | |
2513 DEFINE_CALLSTATICMETHODA(jfloat, Float, T_FLOAT | |
2514 , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2515 HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN()); | |
2516 DEFINE_CALLSTATICMETHODA(jdouble, Double, T_DOUBLE | |
2517 , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), | |
2518 HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN()); | |
2519 | |
2520 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod | |
2521 , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN()); | |
2522 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV | |
2523 , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN()); | |
2524 DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA | |
2525 , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN()); | |
2526 #endif /* USDT2 */ | |
2527 | |
0 | 2528 JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)) |
2529 JNIWrapper("CallStaticVoidMethod"); | |
4006 | 2530 #ifndef USDT2 |
0 | 2531 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID); |
4006 | 2532 #else /* USDT2 */ |
2533 HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY( | |
2534 env, cls, (uintptr_t) methodID); | |
2535 #endif /* USDT2 */ | |
0 | 2536 DT_VOID_RETURN_MARK(CallStaticVoidMethod); |
2537 | |
2538 va_list args; | |
2539 va_start(args, methodID); | |
2540 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2541 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 2542 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
2543 va_end(args); | |
2544 JNI_END | |
2545 | |
2546 | |
2547 JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) | |
2548 JNIWrapper("CallStaticVoidMethodV"); | |
4006 | 2549 #ifndef USDT2 |
0 | 2550 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID); |
4006 | 2551 #else /* USDT2 */ |
2552 HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY( | |
2553 env, cls, (uintptr_t) methodID); | |
2554 #endif /* USDT2 */ | |
0 | 2555 DT_VOID_RETURN_MARK(CallStaticVoidMethodV); |
2556 | |
2557 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2558 JNI_ArgumentPusherVaArg ap(methodID, args); |
0 | 2559 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
2560 JNI_END | |
2561 | |
2562 | |
2563 JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) | |
2564 JNIWrapper("CallStaticVoidMethodA"); | |
4006 | 2565 #ifndef USDT2 |
0 | 2566 DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID); |
4006 | 2567 #else /* USDT2 */ |
2568 HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY( | |
2569 env, cls, (uintptr_t) methodID); | |
2570 #endif /* USDT2 */ | |
0 | 2571 DT_VOID_RETURN_MARK(CallStaticVoidMethodA); |
2572 | |
2573 JavaValue jvalue(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2574 JNI_ArgumentPusherArray ap(methodID, args); |
0 | 2575 jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
2576 JNI_END | |
2577 | |
2578 | |
2579 // | |
2580 // Accessing Fields | |
2581 // | |
2582 | |
2583 | |
4006 | 2584 #ifndef USDT2 |
0 | 2585 DT_RETURN_MARK_DECL(GetFieldID, jfieldID); |
4006 | 2586 #else /* USDT2 */ |
2587 DT_RETURN_MARK_DECL(GetFieldID, jfieldID | |
2588 , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref)); | |
2589 #endif /* USDT2 */ | |
0 | 2590 |
2591 JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz, | |
2592 const char *name, const char *sig)) | |
2593 JNIWrapper("GetFieldID"); | |
4006 | 2594 #ifndef USDT2 |
0 | 2595 DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig); |
4006 | 2596 #else /* USDT2 */ |
2597 HOTSPOT_JNI_GETFIELDID_ENTRY( | |
2598 env, clazz, (char *) name, (char *) sig); | |
2599 #endif /* USDT2 */ | |
0 | 2600 jfieldID ret = 0; |
2601 DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret); | |
2602 | |
2603 // The class should have been loaded (we have an instance of the class | |
2604 // passed in) so the field and signature should already be in the symbol | |
2605 // 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
|
2606 TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2607 TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2608 if (fieldname == NULL || signame == NULL) { |
0 | 2609 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
2610 } | |
2611 KlassHandle k(THREAD, | |
2612 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
2613 // Make sure class is initialized before handing id's out to fields | |
2614 Klass::cast(k())->initialize(CHECK_NULL); | |
2615 | |
2616 fieldDescriptor fd; | |
2617 if (!Klass::cast(k())->oop_is_instance() || | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2618 !instanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) { |
0 | 2619 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
2620 } | |
2621 | |
2622 // A jfieldID for a non-static field is simply the offset of the field within the instanceOop | |
2623 // It may also have hash bits for k, if VerifyJNIFields is turned on. | |
2624 ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset()); | |
2625 return ret; | |
2626 JNI_END | |
2627 | |
2628 | |
2629 JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)) | |
2630 JNIWrapper("GetObjectField"); | |
4006 | 2631 #ifndef USDT2 |
0 | 2632 DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID); |
4006 | 2633 #else /* USDT2 */ |
2634 HOTSPOT_JNI_GETOBJECTFIELD_ENTRY( | |
2635 env, obj, (uintptr_t) fieldID); | |
2636 #endif /* USDT2 */ | |
0 | 2637 oop o = JNIHandles::resolve_non_null(obj); |
2638 klassOop k = o->klass(); | |
2639 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
2640 // Keep JVMTI addition small and only check enabled flag here. | |
2641 // jni_GetField_probe() assumes that is okay to create handles. | |
2642 if (JvmtiExport::should_post_field_access()) { | |
2643 o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); | |
2644 } | |
2645 jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); | |
3249
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2646 #ifndef SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2647 // If G1 is enabled and we are accessing the value of the referent |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2648 // field in a reference object then we need to register a non-null |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2649 // referent with the SATB barrier. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2650 if (UseG1GC) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2651 bool needs_barrier = false; |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2652 |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2653 if (ret != NULL && |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2654 offset == java_lang_ref_Reference::referent_offset && |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2655 instanceKlass::cast(k)->reference_type() != REF_NONE) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2656 assert(instanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2657 needs_barrier = true; |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2658 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2659 |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2660 if (needs_barrier) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2661 oop referent = JNIHandles::resolve(ret); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2662 G1SATBCardTableModRefBS::enqueue(referent); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2663 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2664 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
2665 #endif // SERIALGC |
4006 | 2666 #ifndef USDT2 |
0 | 2667 DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); |
4006 | 2668 #else /* USDT2 */ |
2669 HOTSPOT_JNI_GETOBJECTFIELD_RETURN( | |
2670 ret); | |
2671 #endif /* USDT2 */ | |
0 | 2672 return ret; |
2673 JNI_END | |
2674 | |
2675 | |
4006 | 2676 #ifndef USDT2 |
0 | 2677 #define DEFINE_GETFIELD(Return,Fieldname,Result) \ |
2678 \ | |
2679 DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\ | |
2680 \ | |
2681 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ | |
2682 JNIWrapper("Get" XSTR(Result) "Field"); \ | |
2683 \ | |
2684 DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\ | |
2685 Return ret = 0;\ | |
2686 DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ | |
2687 \ | |
2688 oop o = JNIHandles::resolve_non_null(obj); \ | |
2689 klassOop k = o->klass(); \ | |
2690 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
2691 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
2692 /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ | |
2693 /* and creates a ResetNoHandleMark. */ \ | |
2694 if (JvmtiExport::should_post_field_access()) { \ | |
2695 o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ | |
2696 } \ | |
2697 ret = o->Fieldname##_field(offset); \ | |
2698 return ret; \ | |
2699 JNI_END | |
2700 | |
2701 DEFINE_GETFIELD(jboolean, bool, Boolean) | |
2702 DEFINE_GETFIELD(jbyte, byte, Byte) | |
2703 DEFINE_GETFIELD(jchar, char, Char) | |
2704 DEFINE_GETFIELD(jshort, short, Short) | |
2705 DEFINE_GETFIELD(jint, int, Int) | |
2706 DEFINE_GETFIELD(jlong, long, Long) | |
2707 DEFINE_GETFIELD(jfloat, float, Float) | |
2708 DEFINE_GETFIELD(jdouble, double, Double) | |
2709 | |
4006 | 2710 #else /* USDT2 */ |
2711 | |
2712 #define DEFINE_GETFIELD(Return,Fieldname,Result \ | |
2713 , EntryProbe, ReturnProbe) \ | |
2714 \ | |
2715 DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \ | |
2716 , ReturnProbe); \ | |
2717 \ | |
2718 JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ | |
2719 JNIWrapper("Get" XSTR(Result) "Field"); \ | |
2720 \ | |
2721 EntryProbe; \ | |
2722 Return ret = 0;\ | |
2723 DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ | |
2724 \ | |
2725 oop o = JNIHandles::resolve_non_null(obj); \ | |
2726 klassOop k = o->klass(); \ | |
2727 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
2728 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
2729 /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ | |
2730 /* and creates a ResetNoHandleMark. */ \ | |
2731 if (JvmtiExport::should_post_field_access()) { \ | |
2732 o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ | |
2733 } \ | |
2734 ret = o->Fieldname##_field(offset); \ | |
2735 return ret; \ | |
2736 JNI_END | |
2737 | |
2738 DEFINE_GETFIELD(jboolean, bool, Boolean | |
2739 , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2740 HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref)) | |
2741 DEFINE_GETFIELD(jbyte, byte, Byte | |
2742 , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2743 HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref)) | |
2744 DEFINE_GETFIELD(jchar, char, Char | |
2745 , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2746 HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref)) | |
2747 DEFINE_GETFIELD(jshort, short, Short | |
2748 , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2749 HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref)) | |
2750 DEFINE_GETFIELD(jint, int, Int | |
2751 , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2752 HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref)) | |
2753 DEFINE_GETFIELD(jlong, long, Long | |
2754 , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2755 HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref)) | |
2756 // Float and double probes don't return value because dtrace doesn't currently support it | |
2757 DEFINE_GETFIELD(jfloat, float, Float | |
2758 , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2759 HOTSPOT_JNI_GETFLOATFIELD_RETURN()) | |
2760 DEFINE_GETFIELD(jdouble, double, Double | |
2761 , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2762 HOTSPOT_JNI_GETDOUBLEFIELD_RETURN()) | |
2763 #endif /* USDT2 */ | |
2764 | |
0 | 2765 address jni_GetBooleanField_addr() { |
2766 return (address)jni_GetBooleanField; | |
2767 } | |
2768 address jni_GetByteField_addr() { | |
2769 return (address)jni_GetByteField; | |
2770 } | |
2771 address jni_GetCharField_addr() { | |
2772 return (address)jni_GetCharField; | |
2773 } | |
2774 address jni_GetShortField_addr() { | |
2775 return (address)jni_GetShortField; | |
2776 } | |
2777 address jni_GetIntField_addr() { | |
2778 return (address)jni_GetIntField; | |
2779 } | |
2780 address jni_GetLongField_addr() { | |
2781 return (address)jni_GetLongField; | |
2782 } | |
2783 address jni_GetFloatField_addr() { | |
2784 return (address)jni_GetFloatField; | |
2785 } | |
2786 address jni_GetDoubleField_addr() { | |
2787 return (address)jni_GetDoubleField; | |
2788 } | |
2789 | |
2790 JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)) | |
2791 JNIWrapper("SetObjectField"); | |
4006 | 2792 #ifndef USDT2 |
0 | 2793 DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value); |
4006 | 2794 #else /* USDT2 */ |
2795 HOTSPOT_JNI_SETOBJECTFIELD_ENTRY( | |
2796 env, obj, (uintptr_t) fieldID, value); | |
2797 #endif /* USDT2 */ | |
0 | 2798 oop o = JNIHandles::resolve_non_null(obj); |
2799 klassOop k = o->klass(); | |
2800 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
2801 // Keep JVMTI addition small and only check enabled flag here. | |
2802 // jni_SetField_probe_nh() assumes that is not okay to create handles | |
2803 // and creates a ResetNoHandleMark. | |
2804 if (JvmtiExport::should_post_field_modification()) { | |
2805 jvalue field_value; | |
2806 field_value.l = value; | |
2807 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value); | |
2808 } | |
2809 o->obj_field_put(offset, JNIHandles::resolve(value)); | |
4006 | 2810 #ifndef USDT2 |
0 | 2811 DTRACE_PROBE(hotspot_jni, SetObjectField__return); |
4006 | 2812 #else /* USDT2 */ |
2813 HOTSPOT_JNI_SETOBJECTFIELD_RETURN( | |
2814 ); | |
2815 #endif /* USDT2 */ | |
0 | 2816 JNI_END |
2817 | |
4006 | 2818 #ifndef USDT2 |
0 | 2819 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
2820 \ | |
2821 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ | |
2822 JNIWrapper("Set" XSTR(Result) "Field"); \ | |
2823 \ | |
2824 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, Set##Result##Field__entry, \ | |
2825 ( JNIEnv*, jobject, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
2826 HS_DTRACE_PROBE_N(hotspot_jni, Set##Result##Field__entry, \ | |
2827 ( env, obj, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
2828 \ | |
2829 oop o = JNIHandles::resolve_non_null(obj); \ | |
2830 klassOop k = o->klass(); \ | |
2831 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
2832 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
2833 /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ | |
2834 /* and creates a ResetNoHandleMark. */ \ | |
2835 if (JvmtiExport::should_post_field_modification()) { \ | |
2836 jvalue field_value; \ | |
2837 field_value.unionType = value; \ | |
2838 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ | |
2839 } \ | |
2840 o->Fieldname##_field_put(offset, value); \ | |
2841 DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\ | |
2842 JNI_END | |
2843 | |
2844 DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z) | |
2845 DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b) | |
2846 DEFINE_SETFIELD(jchar, char, Char, 'C', c) | |
2847 DEFINE_SETFIELD(jshort, short, Short, 'S', s) | |
2848 DEFINE_SETFIELD(jint, int, Int, 'I', i) | |
2849 DEFINE_SETFIELD(jlong, long, Long, 'J', j) | |
2850 DEFINE_SETFIELD(jfloat, float, Float, 'F', f) | |
2851 DEFINE_SETFIELD(jdouble, double, Double, 'D', d) | |
2852 | |
4006 | 2853 #else /* USDT2 */ |
2854 | |
2855 #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \ | |
2856 , EntryProbe, ReturnProbe) \ | |
2857 \ | |
2858 JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ | |
2859 JNIWrapper("Set" XSTR(Result) "Field"); \ | |
2860 \ | |
2861 EntryProbe; \ | |
2862 \ | |
2863 oop o = JNIHandles::resolve_non_null(obj); \ | |
2864 klassOop k = o->klass(); \ | |
2865 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ | |
2866 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
2867 /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ | |
2868 /* and creates a ResetNoHandleMark. */ \ | |
2869 if (JvmtiExport::should_post_field_modification()) { \ | |
2870 jvalue field_value; \ | |
2871 field_value.unionType = value; \ | |
2872 o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ | |
2873 } \ | |
2874 o->Fieldname##_field_put(offset, value); \ | |
2875 ReturnProbe; \ | |
2876 JNI_END | |
2877 | |
2878 DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z | |
2879 , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2880 HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) | |
2881 DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b | |
2882 , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2883 HOTSPOT_JNI_SETBYTEFIELD_RETURN()) | |
2884 DEFINE_SETFIELD(jchar, char, Char, 'C', c | |
2885 , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2886 HOTSPOT_JNI_SETCHARFIELD_RETURN()) | |
2887 DEFINE_SETFIELD(jshort, short, Short, 'S', s | |
2888 , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2889 HOTSPOT_JNI_SETSHORTFIELD_RETURN()) | |
2890 DEFINE_SETFIELD(jint, int, Int, 'I', i | |
2891 , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2892 HOTSPOT_JNI_SETINTFIELD_RETURN()) | |
2893 DEFINE_SETFIELD(jlong, long, Long, 'J', j | |
2894 , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), | |
2895 HOTSPOT_JNI_SETLONGFIELD_RETURN()) | |
2896 // Float and double probes don't return value because dtrace doesn't currently support it | |
2897 DEFINE_SETFIELD(jfloat, float, Float, 'F', f | |
2898 , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2899 HOTSPOT_JNI_SETFLOATFIELD_RETURN()) | |
2900 DEFINE_SETFIELD(jdouble, double, Double, 'D', d | |
2901 , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), | |
2902 HOTSPOT_JNI_SETDOUBLEFIELD_RETURN()) | |
2903 #endif /* USDT2 */ | |
2904 | |
2905 #ifndef USDT2 | |
0 | 2906 DT_RETURN_MARK_DECL(ToReflectedField, jobject); |
4006 | 2907 #else /* USDT2 */ |
2908 DT_RETURN_MARK_DECL(ToReflectedField, jobject | |
2909 , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref)); | |
2910 #endif /* USDT2 */ | |
0 | 2911 |
2912 JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)) | |
2913 JNIWrapper("ToReflectedField"); | |
4006 | 2914 #ifndef USDT2 |
0 | 2915 DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry, |
2916 env, cls, fieldID, isStatic); | |
4006 | 2917 #else /* USDT2 */ |
2918 HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY( | |
2919 env, cls, (uintptr_t) fieldID, isStatic); | |
2920 #endif /* USDT2 */ | |
0 | 2921 jobject ret = NULL; |
2922 DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret); | |
2923 | |
2924 fieldDescriptor fd; | |
2925 bool found = false; | |
2926 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(cls)); | |
2927 | |
2928 assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID"); | |
2929 | |
2930 if (isStatic) { | |
2931 // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop. | |
2932 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
2933 assert(id->is_static_field_id(), "invalid static field id"); | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
2934 found = id->find_local_field(&fd); |
0 | 2935 } else { |
2936 // Non-static field. The fieldID is really the offset of the field within the instanceOop. | |
2937 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); | |
2938 found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); | |
2939 } | |
2940 assert(found, "bad fieldID passed into jni_ToReflectedField"); | |
2941 oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); | |
2942 ret = JNIHandles::make_local(env, reflected); | |
2943 return ret; | |
2944 JNI_END | |
2945 | |
2946 | |
2947 // | |
2948 // Accessing Static Fields | |
2949 // | |
4006 | 2950 #ifndef USDT2 |
0 | 2951 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID); |
4006 | 2952 #else /* USDT2 */ |
2953 DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID | |
2954 , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref)); | |
2955 #endif /* USDT2 */ | |
0 | 2956 |
2957 JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz, | |
2958 const char *name, const char *sig)) | |
2959 JNIWrapper("GetStaticFieldID"); | |
4006 | 2960 #ifndef USDT2 |
0 | 2961 DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig); |
4006 | 2962 #else /* USDT2 */ |
2963 HOTSPOT_JNI_GETSTATICFIELDID_ENTRY( | |
2964 env, clazz, (char *) name, (char *) sig); | |
2965 #endif /* USDT2 */ | |
0 | 2966 jfieldID ret = NULL; |
2967 DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret); | |
2968 | |
2969 // The class should have been loaded (we have an instance of the class | |
2970 // passed in) so the field and signature should already be in the symbol | |
2971 // 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
|
2972 TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2973 TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2974 if (fieldname == NULL || signame == NULL) { |
0 | 2975 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
2976 } | |
2977 KlassHandle k(THREAD, | |
2978 java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
2979 // Make sure class is initialized before handing id's out to static fields | |
2980 Klass::cast(k())->initialize(CHECK_NULL); | |
2981 | |
2982 fieldDescriptor fd; | |
2983 if (!Klass::cast(k())->oop_is_instance() || | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
2984 !instanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) { |
0 | 2985 THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
2986 } | |
2987 | |
2988 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop | |
2989 JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset()); | |
2990 debug_only(id->set_is_static_field_id();) | |
2991 | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
2992 debug_only(id->verify(fd.field_holder())); |
0 | 2993 |
2994 ret = jfieldIDWorkaround::to_static_jfieldID(id); | |
2995 return ret; | |
2996 JNI_END | |
2997 | |
2998 | |
2999 JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)) | |
3000 JNIWrapper("GetStaticObjectField"); | |
4006 | 3001 #ifndef USDT2 |
0 | 3002 DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID); |
4006 | 3003 #else /* USDT2 */ |
3004 HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY( | |
3005 env, clazz, (uintptr_t) fieldID); | |
3006 #endif /* USDT2 */ | |
0 | 3007 #ifndef JNICHECK_KERNEL |
3008 DEBUG_ONLY(klassOop param_k = jniCheck::validate_class(thread, clazz);) | |
3009 #endif // JNICHECK_KERNEL | |
3010 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); | |
3011 assert(id->is_static_field_id(), "invalid static field id"); | |
3012 // Keep JVMTI addition small and only check enabled flag here. | |
3013 // jni_GetField_probe() assumes that is okay to create handles. | |
3014 if (JvmtiExport::should_post_field_access()) { | |
3015 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); | |
3016 } | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
3017 jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset())); |
4006 | 3018 #ifndef USDT2 |
0 | 3019 DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); |
4006 | 3020 #else /* USDT2 */ |
3021 HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN( | |
3022 ret); | |
3023 #endif /* USDT2 */ | |
0 | 3024 return ret; |
3025 JNI_END | |
3026 | |
4006 | 3027 #ifndef USDT2 |
0 | 3028 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ |
3029 \ | |
3030 DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\ | |
3031 \ | |
3032 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ | |
3033 JNIWrapper("GetStatic" XSTR(Result) "Field"); \ | |
3034 DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\ | |
3035 Return ret = 0;\ | |
3036 DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ | |
3037 (const Return&)ret);\ | |
3038 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
3039 assert(id->is_static_field_id(), "invalid static field id"); \ | |
3040 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
3041 /* jni_GetField_probe() assumes that is okay to create handles. */ \ | |
3042 if (JvmtiExport::should_post_field_access()) { \ | |
3043 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ | |
3044 } \ | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
3045 ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ |
0 | 3046 return ret;\ |
3047 JNI_END | |
3048 | |
3049 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) | |
3050 DEFINE_GETSTATICFIELD(jbyte, byte, Byte) | |
3051 DEFINE_GETSTATICFIELD(jchar, char, Char) | |
3052 DEFINE_GETSTATICFIELD(jshort, short, Short) | |
3053 DEFINE_GETSTATICFIELD(jint, int, Int) | |
3054 DEFINE_GETSTATICFIELD(jlong, long, Long) | |
3055 DEFINE_GETSTATICFIELD(jfloat, float, Float) | |
3056 DEFINE_GETSTATICFIELD(jdouble, double, Double) | |
3057 | |
4006 | 3058 #else /* USDT2 */ |
3059 | |
3060 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \ | |
3061 , EntryProbe, ReturnProbe) \ | |
3062 \ | |
3063 DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \ | |
3064 , ReturnProbe); \ | |
3065 \ | |
3066 JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ | |
3067 JNIWrapper("GetStatic" XSTR(Result) "Field"); \ | |
3068 EntryProbe; \ | |
3069 Return ret = 0;\ | |
3070 DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ | |
3071 (const Return&)ret);\ | |
3072 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
3073 assert(id->is_static_field_id(), "invalid static field id"); \ | |
3074 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
3075 /* jni_GetField_probe() assumes that is okay to create handles. */ \ | |
3076 if (JvmtiExport::should_post_field_access()) { \ | |
3077 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ | |
3078 } \ | |
3079 ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ | |
3080 return ret;\ | |
3081 JNI_END | |
3082 | |
3083 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean | |
3084 , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref)) | |
3085 DEFINE_GETSTATICFIELD(jbyte, byte, Byte | |
3086 , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref) ) | |
3087 DEFINE_GETSTATICFIELD(jchar, char, Char | |
3088 , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref) ) | |
3089 DEFINE_GETSTATICFIELD(jshort, short, Short | |
3090 , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref) ) | |
3091 DEFINE_GETSTATICFIELD(jint, int, Int | |
3092 , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref) ) | |
3093 DEFINE_GETSTATICFIELD(jlong, long, Long | |
3094 , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref) ) | |
3095 // Float and double probes don't return value because dtrace doesn't currently support it | |
3096 DEFINE_GETSTATICFIELD(jfloat, float, Float | |
3097 , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN() ) | |
3098 DEFINE_GETSTATICFIELD(jdouble, double, Double | |
3099 , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN() ) | |
3100 #endif /* USDT2 */ | |
0 | 3101 |
3102 JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)) | |
3103 JNIWrapper("SetStaticObjectField"); | |
4006 | 3104 #ifndef USDT2 |
0 | 3105 DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value); |
4006 | 3106 #else /* USDT2 */ |
3107 HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY( | |
3108 env, clazz, (uintptr_t) fieldID, value); | |
3109 #endif /* USDT2 */ | |
0 | 3110 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
3111 assert(id->is_static_field_id(), "invalid static field id"); | |
3112 // Keep JVMTI addition small and only check enabled flag here. | |
3113 // jni_SetField_probe() assumes that is okay to create handles. | |
3114 if (JvmtiExport::should_post_field_modification()) { | |
3115 jvalue field_value; | |
3116 field_value.l = value; | |
3117 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); | |
3118 } | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
3119 id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value)); |
4006 | 3120 #ifndef USDT2 |
0 | 3121 DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); |
4006 | 3122 #else /* USDT2 */ |
3123 HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN( | |
3124 ); | |
3125 #endif /* USDT2 */ | |
0 | 3126 JNI_END |
3127 | |
3128 | |
4006 | 3129 #ifndef USDT2 |
0 | 3130 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
3131 \ | |
3132 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ | |
3133 JNIWrapper("SetStatic" XSTR(Result) "Field"); \ | |
3134 HS_DTRACE_PROBE_CDECL_N(hotspot_jni, SetStatic##Result##Field__entry,\ | |
3135 ( JNIEnv*, jclass, jfieldID FP_SELECT_##Result(COMMA Argument,/*empty*/) ) ); \ | |
3136 HS_DTRACE_PROBE_N(hotspot_jni, SetStatic##Result##Field__entry, \ | |
3137 ( env, clazz, fieldID FP_SELECT_##Result(COMMA value,/*empty*/) ) ); \ | |
3138 \ | |
3139 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
3140 assert(id->is_static_field_id(), "invalid static field id"); \ | |
3141 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
3142 /* jni_SetField_probe() assumes that is okay to create handles. */ \ | |
3143 if (JvmtiExport::should_post_field_modification()) { \ | |
3144 jvalue field_value; \ | |
3145 field_value.unionType = value; \ | |
3146 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ | |
3147 } \ | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2177
diff
changeset
|
3148 id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ |
0 | 3149 DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ |
3150 JNI_END | |
3151 | |
3152 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) | |
3153 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) | |
3154 DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c) | |
3155 DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s) | |
3156 DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i) | |
3157 DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j) | |
3158 DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f) | |
3159 DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d) | |
3160 | |
4006 | 3161 #else /* USDT2 */ |
3162 | |
3163 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \ | |
3164 , EntryProbe, ReturnProbe) \ | |
3165 \ | |
3166 JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ | |
3167 JNIWrapper("SetStatic" XSTR(Result) "Field"); \ | |
3168 EntryProbe; \ | |
3169 \ | |
3170 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ | |
3171 assert(id->is_static_field_id(), "invalid static field id"); \ | |
3172 /* Keep JVMTI addition small and only check enabled flag here. */ \ | |
3173 /* jni_SetField_probe() assumes that is okay to create handles. */ \ | |
3174 if (JvmtiExport::should_post_field_modification()) { \ | |
3175 jvalue field_value; \ | |
3176 field_value.unionType = value; \ | |
3177 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ | |
3178 } \ | |
3179 id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ | |
3180 ReturnProbe;\ | |
3181 JNI_END | |
3182 | |
3183 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z | |
3184 , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value), | |
3185 HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) | |
3186 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b | |
3187 , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), | |
3188 HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN()) | |
3189 DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c | |
3190 , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), | |
3191 HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN()) | |
3192 DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s | |
3193 , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), | |
3194 HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN()) | |
3195 DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i | |
3196 , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), | |
3197 HOTSPOT_JNI_SETSTATICINTFIELD_RETURN()) | |
3198 DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j | |
3199 , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), | |
3200 HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN()) | |
3201 // Float and double probes don't return value because dtrace doesn't currently support it | |
3202 DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f | |
3203 , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), | |
3204 HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN()) | |
3205 DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d | |
3206 , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), | |
3207 HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN()) | |
3208 #endif /* USDT2 */ | |
0 | 3209 |
3210 // | |
3211 // String Operations | |
3212 // | |
3213 | |
3214 // Unicode Interface | |
3215 | |
4006 | 3216 #ifndef USDT2 |
0 | 3217 DT_RETURN_MARK_DECL(NewString, jstring); |
4006 | 3218 #else /* USDT2 */ |
3219 DT_RETURN_MARK_DECL(NewString, jstring | |
3220 , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref)); | |
3221 #endif /* USDT2 */ | |
0 | 3222 |
3223 JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len)) | |
3224 JNIWrapper("NewString"); | |
4006 | 3225 #ifndef USDT2 |
0 | 3226 DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len); |
4006 | 3227 #else /* USDT2 */ |
3228 HOTSPOT_JNI_NEWSTRING_ENTRY( | |
3229 env, (uint16_t *) unicodeChars, len); | |
3230 #endif /* USDT2 */ | |
0 | 3231 jstring ret = NULL; |
3232 DT_RETURN_MARK(NewString, jstring, (const jstring&)ret); | |
3233 oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL); | |
3234 ret = (jstring) JNIHandles::make_local(env, string); | |
3235 return ret; | |
3236 JNI_END | |
3237 | |
3238 | |
3239 JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string)) | |
3240 JNIWrapper("GetStringLength"); | |
4006 | 3241 #ifndef USDT2 |
0 | 3242 DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string); |
4006 | 3243 #else /* USDT2 */ |
3244 HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY( | |
3245 env, string); | |
3246 #endif /* USDT2 */ | |
0 | 3247 jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string)); |
4006 | 3248 #ifndef USDT2 |
0 | 3249 DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret); |
4006 | 3250 #else /* USDT2 */ |
3251 HOTSPOT_JNI_GETSTRINGLENGTH_RETURN( | |
3252 ret); | |
3253 #endif /* USDT2 */ | |
0 | 3254 return ret; |
3255 JNI_END | |
3256 | |
3257 | |
3258 JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars( | |
3259 JNIEnv *env, jstring string, jboolean *isCopy)) | |
3260 JNIWrapper("GetStringChars"); | |
4006 | 3261 #ifndef USDT2 |
0 | 3262 DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy); |
4006 | 3263 #else /* USDT2 */ |
3264 HOTSPOT_JNI_GETSTRINGCHARS_ENTRY( | |
3265 env, string, (uintptr_t *) isCopy); | |
3266 #endif /* USDT2 */ | |
0 | 3267 //%note jni_5 |
3268 if (isCopy != NULL) { | |
3269 *isCopy = JNI_TRUE; | |
3270 } | |
3271 oop s = JNIHandles::resolve_non_null(string); | |
3272 int s_len = java_lang_String::length(s); | |
3273 typeArrayOop s_value = java_lang_String::value(s); | |
3274 int s_offset = java_lang_String::offset(s); | |
3275 jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len + 1); // add one for zero termination | |
3276 if (s_len > 0) { | |
3277 memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); | |
3278 } | |
3279 buf[s_len] = 0; | |
4006 | 3280 #ifndef USDT2 |
0 | 3281 DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf); |
4006 | 3282 #else /* USDT2 */ |
3283 HOTSPOT_JNI_GETSTRINGCHARS_RETURN( | |
3284 buf); | |
3285 #endif /* USDT2 */ | |
0 | 3286 return buf; |
3287 JNI_END | |
3288 | |
3289 | |
3290 JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)) | |
3291 JNIWrapper("ReleaseStringChars"); | |
4006 | 3292 #ifndef USDT2 |
0 | 3293 DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars); |
4006 | 3294 #else /* USDT2 */ |
3295 HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY( | |
3296 env, str, (uint16_t *) chars); | |
3297 #endif /* USDT2 */ | |
0 | 3298 //%note jni_6 |
3299 if (chars != NULL) { | |
3300 // Since String objects are supposed to be immutable, don't copy any | |
3301 // new data back. A bad user will have to go after the char array. | |
3302 FreeHeap((void*) chars); | |
3303 } | |
4006 | 3304 #ifndef USDT2 |
0 | 3305 DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return); |
4006 | 3306 #else /* USDT2 */ |
3307 HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN( | |
3308 ); | |
3309 #endif /* USDT2 */ | |
0 | 3310 JNI_END |
3311 | |
3312 | |
3313 // UTF Interface | |
3314 | |
4006 | 3315 #ifndef USDT2 |
0 | 3316 DT_RETURN_MARK_DECL(NewStringUTF, jstring); |
4006 | 3317 #else /* USDT2 */ |
3318 DT_RETURN_MARK_DECL(NewStringUTF, jstring | |
3319 , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref)); | |
3320 #endif /* USDT2 */ | |
0 | 3321 |
3322 JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes)) | |
3323 JNIWrapper("NewStringUTF"); | |
4006 | 3324 #ifndef USDT2 |
0 | 3325 DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes); |
4006 | 3326 #else /* USDT2 */ |
3327 HOTSPOT_JNI_NEWSTRINGUTF_ENTRY( | |
3328 env, (char *) bytes); | |
3329 #endif /* USDT2 */ | |
0 | 3330 jstring ret; |
3331 DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret); | |
3332 | |
3333 oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL); | |
3334 ret = (jstring) JNIHandles::make_local(env, result); | |
3335 return ret; | |
3336 JNI_END | |
3337 | |
3338 | |
3339 JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string)) | |
3340 JNIWrapper("GetStringUTFLength"); | |
4006 | 3341 #ifndef USDT2 |
0 | 3342 DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string); |
4006 | 3343 #else /* USDT2 */ |
3344 HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY( | |
3345 env, string); | |
3346 #endif /* USDT2 */ | |
0 | 3347 jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string)); |
4006 | 3348 #ifndef USDT2 |
0 | 3349 DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret); |
4006 | 3350 #else /* USDT2 */ |
3351 HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN( | |
3352 ret); | |
3353 #endif /* USDT2 */ | |
0 | 3354 return ret; |
3355 JNI_END | |
3356 | |
3357 | |
3358 JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)) | |
3359 JNIWrapper("GetStringUTFChars"); | |
4006 | 3360 #ifndef USDT2 |
0 | 3361 DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy); |
4006 | 3362 #else /* USDT2 */ |
3363 HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( | |
3364 env, string, (uintptr_t *) isCopy); | |
3365 #endif /* USDT2 */ | |
1989
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
3366 oop java_string = JNIHandles::resolve_non_null(string); |
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
3367 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
|
3368 char* result = AllocateHeap(length + 1, "GetStringUTFChars"); |
017cd8bce8a8
6539281: -Xcheck:jni should validate char* argument to ReleaseStringUTFChars
sla
parents:
1980
diff
changeset
|
3369 java_lang_String::as_utf8_string(java_string, result, (int) length + 1); |
0 | 3370 if (isCopy != NULL) *isCopy = JNI_TRUE; |
4006 | 3371 #ifndef USDT2 |
0 | 3372 DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); |
4006 | 3373 #else /* USDT2 */ |
3374 HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN( | |
3375 result); | |
3376 #endif /* USDT2 */ | |
0 | 3377 return result; |
3378 JNI_END | |
3379 | |
3380 | |
3381 JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars)) | |
3382 JNIWrapper("ReleaseStringUTFChars"); | |
4006 | 3383 #ifndef USDT2 |
0 | 3384 DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars); |
4006 | 3385 #else /* USDT2 */ |
3386 HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY( | |
3387 env, str, (char *) chars); | |
3388 #endif /* USDT2 */ | |
0 | 3389 if (chars != NULL) { |
3390 FreeHeap((char*) chars); | |
3391 } | |
4006 | 3392 #ifndef USDT2 |
0 | 3393 DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return); |
4006 | 3394 #else /* USDT2 */ |
3395 HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN( | |
3396 ); | |
3397 #endif /* USDT2 */ | |
0 | 3398 JNI_END |
3399 | |
3400 | |
3401 JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array)) | |
3402 JNIWrapper("GetArrayLength"); | |
4006 | 3403 #ifndef USDT2 |
0 | 3404 DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array); |
4006 | 3405 #else /* USDT2 */ |
3406 HOTSPOT_JNI_GETARRAYLENGTH_ENTRY( | |
3407 env, array); | |
3408 #endif /* USDT2 */ | |
0 | 3409 arrayOop a = arrayOop(JNIHandles::resolve_non_null(array)); |
3410 assert(a->is_array(), "must be array"); | |
3411 jsize ret = a->length(); | |
4006 | 3412 #ifndef USDT2 |
0 | 3413 DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret); |
4006 | 3414 #else /* USDT2 */ |
3415 HOTSPOT_JNI_GETARRAYLENGTH_RETURN( | |
3416 ret); | |
3417 #endif /* USDT2 */ | |
0 | 3418 return ret; |
3419 JNI_END | |
3420 | |
3421 | |
3422 // | |
3423 // Object Array Operations | |
3424 // | |
3425 | |
4006 | 3426 #ifndef USDT2 |
0 | 3427 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray); |
4006 | 3428 #else /* USDT2 */ |
3429 DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray | |
3430 , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref)); | |
3431 #endif /* USDT2 */ | |
0 | 3432 |
3433 JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)) | |
3434 JNIWrapper("NewObjectArray"); | |
4006 | 3435 #ifndef USDT2 |
0 | 3436 DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement); |
4006 | 3437 #else /* USDT2 */ |
3438 HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY( | |
3439 env, length, elementClass, initialElement); | |
3440 #endif /* USDT2 */ | |
0 | 3441 jobjectArray ret = NULL; |
3442 DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret); | |
3443 KlassHandle ek(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(elementClass))); | |
3444 klassOop ako = Klass::cast(ek())->array_klass(CHECK_NULL); | |
3445 KlassHandle ak = KlassHandle(THREAD, ako); | |
3446 objArrayKlass::cast(ak())->initialize(CHECK_NULL); | |
3447 objArrayOop result = objArrayKlass::cast(ak())->allocate(length, CHECK_NULL); | |
3448 oop initial_value = JNIHandles::resolve(initialElement); | |
3449 if (initial_value != NULL) { // array already initialized with NULL | |
3450 for (int index = 0; index < length; index++) { | |
3451 result->obj_at_put(index, initial_value); | |
3452 } | |
3453 } | |
3454 ret = (jobjectArray) JNIHandles::make_local(env, result); | |
3455 return ret; | |
3456 JNI_END | |
3457 | |
4006 | 3458 #ifndef USDT2 |
0 | 3459 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject); |
4006 | 3460 #else /* USDT2 */ |
3461 DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject | |
3462 , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref)); | |
3463 #endif /* USDT2 */ | |
0 | 3464 |
3465 JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)) | |
3466 JNIWrapper("GetObjectArrayElement"); | |
4006 | 3467 #ifndef USDT2 |
0 | 3468 DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index); |
4006 | 3469 #else /* USDT2 */ |
3470 HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY( | |
3471 env, array, index); | |
3472 #endif /* USDT2 */ | |
0 | 3473 jobject ret = NULL; |
3474 DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret); | |
3475 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
3476 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
|
3477 ret = JNIHandles::make_local(env, a->obj_at(index)); |
0 | 3478 return ret; |
3479 } else { | |
3480 char buf[jintAsStringSize]; | |
3481 sprintf(buf, "%d", index); | |
3482 THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
3483 } | |
3484 JNI_END | |
3485 | |
4006 | 3486 #ifndef USDT2 |
0 | 3487 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement); |
4006 | 3488 #else /* USDT2 */ |
3489 DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement | |
3490 , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN()); | |
3491 #endif /* USDT2 */ | |
0 | 3492 |
3493 JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value)) | |
3494 JNIWrapper("SetObjectArrayElement"); | |
4006 | 3495 #ifndef USDT2 |
0 | 3496 DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value); |
4006 | 3497 #else /* USDT2 */ |
3498 HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY( | |
3499 env, array, index, value); | |
3500 #endif /* USDT2 */ | |
0 | 3501 DT_VOID_RETURN_MARK(SetObjectArrayElement); |
3502 | |
3503 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); | |
3504 oop v = JNIHandles::resolve(value); | |
3505 if (a->is_within_bounds(index)) { | |
3506 if (v == NULL || v->is_a(objArrayKlass::cast(a->klass())->element_klass())) { | |
3507 a->obj_at_put(index, v); | |
3508 } else { | |
3509 THROW(vmSymbols::java_lang_ArrayStoreException()); | |
3510 } | |
3511 } else { | |
3512 char buf[jintAsStringSize]; | |
3513 sprintf(buf, "%d", index); | |
3514 THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); | |
3515 } | |
3516 JNI_END | |
3517 | |
3518 | |
4006 | 3519 #ifndef USDT2 |
0 | 3520 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \ |
3521 \ | |
4006 | 3522 DT_RETURN_MARK_DECL(New##Result##Array, Return); \ |
0 | 3523 \ |
3524 JNI_ENTRY(Return, \ | |
3525 jni_New##Result##Array(JNIEnv *env, jsize len)) \ | |
3526 JNIWrapper("New" XSTR(Result) "Array"); \ | |
3527 DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\ | |
3528 Return ret = NULL;\ | |
1034
08780c8a9f04
6893483: DTrace probe return values for a couple JNI methods are wrong
kamg
parents:
973
diff
changeset
|
3529 DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
0 | 3530 \ |
3531 oop obj= oopFactory::Allocator(len, CHECK_0); \ | |
3532 ret = (Return) JNIHandles::make_local(env, obj); \ | |
3533 return ret;\ | |
3534 JNI_END | |
3535 | |
3536 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean) | |
3537 DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte) | |
3538 DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short) | |
3539 DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char) | |
3540 DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int) | |
3541 DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) | |
3542 DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) | |
3543 DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) | |
3544 | |
4006 | 3545 #else /* USDT2 */ |
3546 | |
3547 #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \ | |
3548 ,EntryProbe,ReturnProbe) \ | |
3549 \ | |
3550 DT_RETURN_MARK_DECL(New##Result##Array, Return \ | |
3551 , ReturnProbe); \ | |
3552 \ | |
3553 JNI_ENTRY(Return, \ | |
3554 jni_New##Result##Array(JNIEnv *env, jsize len)) \ | |
3555 JNIWrapper("New" XSTR(Result) "Array"); \ | |
3556 EntryProbe; \ | |
3557 Return ret = NULL;\ | |
3558 DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ | |
3559 \ | |
3560 oop obj= oopFactory::Allocator(len, CHECK_0); \ | |
3561 ret = (Return) JNIHandles::make_local(env, obj); \ | |
3562 return ret;\ | |
3563 JNI_END | |
3564 | |
3565 DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean, | |
3566 HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len), | |
3567 HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref)) | |
3568 DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte, | |
3569 HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len), | |
3570 HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref)) | |
3571 DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short, | |
3572 HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len), | |
3573 HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref)) | |
3574 DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char, | |
3575 HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len), | |
3576 HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref)) | |
3577 DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int, | |
3578 HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len), | |
3579 HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref)) | |
3580 DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long, | |
3581 HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len), | |
3582 HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref)) | |
3583 DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float, | |
3584 HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len), | |
3585 HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref)) | |
3586 DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double, | |
3587 HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len), | |
3588 HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref)) | |
3589 #endif /* USDT2 */ | |
0 | 3590 |
3591 // Return an address which will fault if the caller writes to it. | |
3592 | |
3593 static char* get_bad_address() { | |
3594 static char* bad_address = NULL; | |
3595 if (bad_address == NULL) { | |
3596 size_t size = os::vm_allocation_granularity(); | |
3597 bad_address = os::reserve_memory(size); | |
3598 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
|
3599 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
|
3600 /*is_committed*/false); |
0 | 3601 } |
3602 } | |
3603 return bad_address; | |
3604 } | |
3605 | |
3606 | |
4006 | 3607 #ifndef USDT2 |
0 | 3608 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \ |
3609 \ | |
3610 JNI_QUICK_ENTRY(ElementType*, \ | |
3611 jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ | |
3612 JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ | |
3613 DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\ | |
3614 /* allocate an chunk of memory in c land */ \ | |
3615 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3616 ElementType* result; \ | |
3617 int len = a->length(); \ | |
3618 if (len == 0) { \ | |
3619 /* Empty array: legal but useless, can't return NULL. \ | |
3620 * Return a pointer to something useless. \ | |
3621 * Avoid asserts in typeArrayOop. */ \ | |
3622 result = (ElementType*)get_bad_address(); \ | |
3623 } else { \ | |
3624 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | |
3625 /* copy the array to the c chunk */ \ | |
3626 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | |
3627 } \ | |
3628 if (isCopy) *isCopy = JNI_TRUE; \ | |
3629 DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ | |
3630 return result; \ | |
3631 JNI_END | |
3632 | |
3633 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
3634 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
3635 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
3636 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
3637 DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
3638 DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
3639 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
3640 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
3641 | |
4006 | 3642 #else /* USDT2 */ |
3643 | |
3644 #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \ | |
3645 , EntryProbe, ReturnProbe) \ | |
3646 \ | |
3647 JNI_QUICK_ENTRY(ElementType*, \ | |
3648 jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ | |
3649 JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ | |
3650 EntryProbe; \ | |
3651 /* allocate an chunk of memory in c land */ \ | |
3652 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3653 ElementType* result; \ | |
3654 int len = a->length(); \ | |
3655 if (len == 0) { \ | |
3656 /* Empty array: legal but useless, can't return NULL. \ | |
3657 * Return a pointer to something useless. \ | |
3658 * Avoid asserts in typeArrayOop. */ \ | |
3659 result = (ElementType*)get_bad_address(); \ | |
3660 } else { \ | |
3661 result = NEW_C_HEAP_ARRAY(ElementType, len); \ | |
3662 /* copy the array to the c chunk */ \ | |
3663 memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ | |
3664 } \ | |
3665 if (isCopy) *isCopy = JNI_TRUE; \ | |
3666 ReturnProbe; \ | |
3667 return result; \ | |
3668 JNI_END | |
3669 | |
3670 DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool | |
3671 , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3672 HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result)) | |
3673 DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte | |
3674 , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3675 HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result)) | |
3676 DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short | |
3677 , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), | |
3678 HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result)) | |
3679 DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char | |
3680 , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), | |
3681 HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result)) | |
3682 DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int | |
3683 , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3684 HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result)) | |
3685 DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long | |
3686 , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3687 HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result))) | |
3688 // Float and double probes don't return value because dtrace doesn't currently support it | |
3689 DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float | |
3690 , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3691 HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result)) | |
3692 DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double | |
3693 , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), | |
3694 HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result)) | |
3695 #endif /* USDT2 */ | |
3696 | |
3697 #ifndef USDT2 | |
0 | 3698 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \ |
3699 \ | |
3700 JNI_QUICK_ENTRY(void, \ | |
3701 jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ | |
3702 ElementType *buf, jint mode)) \ | |
3703 JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ | |
3704 DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\ | |
3705 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3706 int len = a->length(); \ | |
3707 if (len != 0) { /* Empty array: nothing to free or copy. */ \ | |
3708 if ((mode == 0) || (mode == JNI_COMMIT)) { \ | |
3709 memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ | |
3710 } \ | |
3711 if ((mode == 0) || (mode == JNI_ABORT)) { \ | |
3712 FreeHeap(buf); \ | |
3713 } \ | |
3714 } \ | |
3715 DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\ | |
3716 JNI_END | |
3717 | |
3718 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) | |
3719 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) | |
3720 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) | |
3721 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) | |
3722 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int) | |
3723 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long) | |
3724 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) | |
3725 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) | |
3726 | |
4006 | 3727 #else /* USDT2 */ |
3728 | |
3729 #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \ | |
3730 , EntryProbe, ReturnProbe);\ | |
3731 \ | |
3732 JNI_QUICK_ENTRY(void, \ | |
3733 jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ | |
3734 ElementType *buf, jint mode)) \ | |
3735 JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ | |
3736 EntryProbe; \ | |
3737 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3738 int len = a->length(); \ | |
3739 if (len != 0) { /* Empty array: nothing to free or copy. */ \ | |
3740 if ((mode == 0) || (mode == JNI_COMMIT)) { \ | |
3741 memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ | |
3742 } \ | |
3743 if ((mode == 0) || (mode == JNI_ABORT)) { \ | |
3744 FreeHeap(buf); \ | |
3745 } \ | |
3746 } \ | |
3747 ReturnProbe; \ | |
3748 JNI_END | |
3749 | |
3750 DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool | |
3751 , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), | |
3752 HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN()) | |
3753 DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte | |
3754 , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode), | |
3755 HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN()) | |
3756 DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short | |
3757 , HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), | |
3758 HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN()) | |
3759 DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char | |
3760 , HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), | |
3761 HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN()) | |
3762 DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int | |
3763 , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode), | |
3764 HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN()) | |
3765 DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long | |
3766 , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), | |
3767 HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN()) | |
3768 DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float | |
3769 , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode), | |
3770 HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN()) | |
3771 DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double | |
3772 , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode), | |
3773 HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN()) | |
3774 #endif /* USDT2 */ | |
3775 | |
3776 #ifndef USDT2 | |
0 | 3777 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
3778 DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\ | |
3779 \ | |
3780 JNI_ENTRY(void, \ | |
3781 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
3782 jsize len, ElementType *buf)) \ | |
3783 JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ | |
3784 DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
3785 DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ | |
3786 typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3787 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ | |
3788 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
3789 } else { \ | |
3790 if (len > 0) { \ | |
3791 int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ | |
3792 memcpy((u_char*) buf, \ | |
3793 (u_char*) src->Tag##_at_addr(start), \ | |
3794 len << sc); \ | |
3795 } \ | |
3796 } \ | |
3797 JNI_END | |
3798 | |
3799 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool) | |
3800 DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
3801 DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
3802 DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
3803 DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int) | |
3804 DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
3805 DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
3806 DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
3807 | |
4006 | 3808 #else /* USDT2 */ |
3809 | |
3810 #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ | |
3811 , EntryProbe, ReturnProbe); \ | |
3812 DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \ | |
3813 , ReturnProbe); \ | |
3814 \ | |
3815 JNI_ENTRY(void, \ | |
3816 jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
3817 jsize len, ElementType *buf)) \ | |
3818 JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ | |
3819 EntryProbe; \ | |
3820 DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ | |
3821 typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3822 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ | |
3823 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
3824 } else { \ | |
3825 if (len > 0) { \ | |
3826 int sc = typeArrayKlass::cast(src->klass())->log2_element_size(); \ | |
3827 memcpy((u_char*) buf, \ | |
3828 (u_char*) src->Tag##_at_addr(start), \ | |
3829 len << sc); \ | |
3830 } \ | |
3831 } \ | |
3832 JNI_END | |
3833 | |
3834 DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool | |
3835 , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), | |
3836 HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN()); | |
3837 DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte | |
3838 , HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), | |
3839 HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN()); | |
3840 DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short | |
3841 , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), | |
3842 HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN()); | |
3843 DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char | |
3844 , HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf), | |
3845 HOTSPOT_JNI_GETCHARARRAYREGION_RETURN()); | |
3846 DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int | |
3847 , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf), | |
3848 HOTSPOT_JNI_GETINTARRAYREGION_RETURN()); | |
3849 DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long | |
3850 , HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), | |
3851 HOTSPOT_JNI_GETLONGARRAYREGION_RETURN()); | |
3852 DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float | |
3853 , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), | |
3854 HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN()); | |
3855 DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double | |
3856 , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), | |
3857 HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN()); | |
3858 #endif /* USDT2 */ | |
3859 | |
3860 #ifndef USDT2 | |
0 | 3861 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
3862 DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\ | |
3863 \ | |
3864 JNI_ENTRY(void, \ | |
3865 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
3866 jsize len, const ElementType *buf)) \ | |
3867 JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ | |
3868 DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\ | |
3869 DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ | |
3870 typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3871 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ | |
3872 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
3873 } else { \ | |
3874 if (len > 0) { \ | |
3875 int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ | |
3876 memcpy((u_char*) dst->Tag##_at_addr(start), \ | |
3877 (u_char*) buf, \ | |
3878 len << sc); \ | |
3879 } \ | |
3880 } \ | |
3881 JNI_END | |
3882 | |
3883 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool) | |
3884 DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) | |
3885 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short) | |
3886 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char) | |
3887 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int) | |
3888 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long) | |
3889 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) | |
3890 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) | |
3891 | |
4006 | 3892 #else /* USDT2 */ |
3893 | |
3894 #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ | |
3895 , EntryProbe, ReturnProbe); \ | |
3896 DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \ | |
3897 ,ReturnProbe); \ | |
3898 \ | |
3899 JNI_ENTRY(void, \ | |
3900 jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ | |
3901 jsize len, const ElementType *buf)) \ | |
3902 JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ | |
3903 EntryProbe; \ | |
3904 DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ | |
3905 typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ | |
3906 if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ | |
3907 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ | |
3908 } else { \ | |
3909 if (len > 0) { \ | |
3910 int sc = typeArrayKlass::cast(dst->klass())->log2_element_size(); \ | |
3911 memcpy((u_char*) dst->Tag##_at_addr(start), \ | |
3912 (u_char*) buf, \ | |
3913 len << sc); \ | |
3914 } \ | |
3915 } \ | |
3916 JNI_END | |
3917 | |
3918 DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool | |
3919 , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf), | |
3920 HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN()) | |
3921 DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte | |
3922 , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), | |
3923 HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN()) | |
3924 DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short | |
3925 , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), | |
3926 HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN()) | |
3927 DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char | |
3928 , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), | |
3929 HOTSPOT_JNI_SETCHARARRAYREGION_RETURN()) | |
3930 DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int | |
3931 , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf), | |
3932 HOTSPOT_JNI_SETINTARRAYREGION_RETURN()) | |
3933 DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long | |
3934 , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), | |
3935 HOTSPOT_JNI_SETLONGARRAYREGION_RETURN()) | |
3936 DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float | |
3937 , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), | |
3938 HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN()) | |
3939 DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double | |
3940 , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), | |
3941 HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN()) | |
3942 #endif /* USDT2 */ | |
3943 | |
0 | 3944 |
3945 // | |
3946 // Interception of natives | |
3947 // | |
3948 | |
3949 // The RegisterNatives call being attempted tried to register with a method that | |
3950 // is not native. Ask JVM TI what prefixes have been specified. Then check | |
3951 // to see if the native method is now wrapped with the prefixes. See the | |
3952 // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. | |
3953 static methodOop find_prefixed_native(KlassHandle k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
3954 Symbol* name, Symbol* signature, TRAPS) { |
0 | 3955 ResourceMark rm(THREAD); |
3956 methodOop method; | |
3957 int name_len = name->utf8_length(); | |
3958 char* name_str = name->as_utf8(); | |
3959 int prefix_count; | |
3960 char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); | |
3961 for (int i = 0; i < prefix_count; i++) { | |
3962 char* prefix = prefixes[i]; | |
3963 int prefix_len = (int)strlen(prefix); | |
3964 | |
3965 // try adding this prefix to the method name and see if it matches another method name | |
3966 int trial_len = name_len + prefix_len; | |
3967 char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1); | |
3968 strcpy(trial_name_str, prefix); | |
3969 strcat(trial_name_str, name_str); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
3970 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
|
3971 if (trial_name == NULL) { |
0 | 3972 continue; // no such symbol, so this prefix wasn't used, try the next prefix |
3973 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
3974 method = Klass::cast(k())->lookup_method(trial_name, signature); |
0 | 3975 if (method == NULL) { |
3976 continue; // signature doesn't match, try the next prefix | |
3977 } | |
3978 if (method->is_native()) { | |
3979 method->set_is_prefixed_native(); | |
3980 return method; // wahoo, we found a prefixed version of the method, return it | |
3981 } | |
3982 // found as non-native, so prefix is good, add it, probably just need more prefixes | |
3983 name_len = trial_len; | |
3984 name_str = trial_name_str; | |
3985 } | |
3986 return NULL; // not found | |
3987 } | |
3988 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
3989 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
|
3990 methodOop method = Klass::cast(k())->lookup_method(name, signature); |
0 | 3991 if (method == NULL) { |
3992 ResourceMark rm; | |
3993 stringStream st; | |
3994 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
|
3995 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
0 | 3996 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
3997 } | |
3998 if (!method->is_native()) { | |
3999 // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) | |
4000 method = find_prefixed_native(k, name, signature, THREAD); | |
4001 if (method == NULL) { | |
4002 ResourceMark rm; | |
4003 stringStream st; | |
4004 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
|
4005 methodOopDesc::name_and_sig_as_C_string(Klass::cast(k()), name, signature)); |
0 | 4006 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
4007 } | |
4008 } | |
4009 | |
4010 if (entry != NULL) { | |
4011 method->set_native_function(entry, | |
4012 methodOopDesc::native_bind_event_is_interesting); | |
4013 } else { | |
4014 method->clear_native_function(); | |
4015 } | |
4016 if (PrintJNIResolving) { | |
4017 ResourceMark rm(THREAD); | |
4018 tty->print_cr("[Registering JNI native method %s.%s]", | |
4019 Klass::cast(method->method_holder())->external_name(), | |
4020 method->name()->as_C_string()); | |
4021 } | |
4022 return true; | |
4023 } | |
4024 | |
4006 | 4025 #ifndef USDT2 |
0 | 4026 DT_RETURN_MARK_DECL(RegisterNatives, jint); |
4006 | 4027 #else /* USDT2 */ |
4028 DT_RETURN_MARK_DECL(RegisterNatives, jint | |
4029 , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref)); | |
4030 #endif /* USDT2 */ | |
0 | 4031 |
4032 JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz, | |
4033 const JNINativeMethod *methods, | |
4034 jint nMethods)) | |
4035 JNIWrapper("RegisterNatives"); | |
4006 | 4036 #ifndef USDT2 |
0 | 4037 DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods); |
4006 | 4038 #else /* USDT2 */ |
4039 HOTSPOT_JNI_REGISTERNATIVES_ENTRY( | |
4040 env, clazz, (void *) methods, nMethods); | |
4041 #endif /* USDT2 */ | |
0 | 4042 jint ret = 0; |
4043 DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret); | |
4044 | |
4045 KlassHandle h_k(thread, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
4046 | |
4047 for (int index = 0; index < nMethods; index++) { | |
4048 const char* meth_name = methods[index].name; | |
4049 const char* meth_sig = methods[index].signature; | |
4050 int meth_name_len = (int)strlen(meth_name); | |
4051 | |
4052 // The class should have been loaded (we have an instance of the class | |
4053 // passed in) so the method and signature should already be in the symbol | |
4054 // 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
|
4055 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
|
4056 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
|
4057 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
4058 if (name == NULL || signature == NULL) { |
0 | 4059 ResourceMark rm; |
4060 stringStream st; | |
4061 st.print("Method %s.%s%s not found", Klass::cast(h_k())->external_name(), meth_name, meth_sig); | |
4062 // Must return negative value on failure | |
4063 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1); | |
4064 } | |
4065 | |
4066 bool res = register_native(h_k, name, signature, | |
4067 (address) methods[index].fnPtr, THREAD); | |
4068 if (!res) { | |
4069 ret = -1; | |
4070 break; | |
4071 } | |
4072 } | |
4073 return ret; | |
4074 JNI_END | |
4075 | |
4076 | |
4077 JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz)) | |
4078 JNIWrapper("UnregisterNatives"); | |
4006 | 4079 #ifndef USDT2 |
0 | 4080 DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz); |
4006 | 4081 #else /* USDT2 */ |
4082 HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY( | |
4083 env, clazz); | |
4084 #endif /* USDT2 */ | |
0 | 4085 klassOop k = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz)); |
4086 //%note jni_2 | |
4087 if (Klass::cast(k)->oop_is_instance()) { | |
4088 for (int index = 0; index < instanceKlass::cast(k)->methods()->length(); index++) { | |
4089 methodOop m = methodOop(instanceKlass::cast(k)->methods()->obj_at(index)); | |
4090 if (m->is_native()) { | |
4091 m->clear_native_function(); | |
4092 m->set_signature_handler(NULL); | |
4093 } | |
4094 } | |
4095 } | |
4006 | 4096 #ifndef USDT2 |
0 | 4097 DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0); |
4006 | 4098 #else /* USDT2 */ |
4099 HOTSPOT_JNI_UNREGISTERNATIVES_RETURN( | |
4100 0); | |
4101 #endif /* USDT2 */ | |
0 | 4102 return 0; |
4103 JNI_END | |
4104 | |
4105 // | |
4106 // Monitor functions | |
4107 // | |
4108 | |
4006 | 4109 #ifndef USDT2 |
0 | 4110 DT_RETURN_MARK_DECL(MonitorEnter, jint); |
4006 | 4111 #else /* USDT2 */ |
4112 DT_RETURN_MARK_DECL(MonitorEnter, jint | |
4113 , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref)); | |
4114 #endif /* USDT2 */ | |
0 | 4115 |
4116 JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj)) | |
4006 | 4117 #ifndef USDT2 |
0 | 4118 DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj); |
4006 | 4119 #else /* USDT2 */ |
4120 HOTSPOT_JNI_MONITORENTER_ENTRY( | |
4121 env, jobj); | |
4122 #endif /* USDT2 */ | |
0 | 4123 jint ret = JNI_ERR; |
4124 DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret); | |
4125 | |
4126 // If the object is null, we can't do anything with it | |
4127 if (jobj == NULL) { | |
4128 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
4129 } | |
4130 | |
4131 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
4132 ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR)); | |
4133 ret = JNI_OK; | |
4134 return ret; | |
4135 JNI_END | |
4136 | |
4006 | 4137 #ifndef USDT2 |
0 | 4138 DT_RETURN_MARK_DECL(MonitorExit, jint); |
4006 | 4139 #else /* USDT2 */ |
4140 DT_RETURN_MARK_DECL(MonitorExit, jint | |
4141 , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref)); | |
4142 #endif /* USDT2 */ | |
0 | 4143 |
4144 JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj)) | |
4006 | 4145 #ifndef USDT2 |
0 | 4146 DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj); |
4006 | 4147 #else /* USDT2 */ |
4148 HOTSPOT_JNI_MONITOREXIT_ENTRY( | |
4149 env, jobj); | |
4150 #endif /* USDT2 */ | |
0 | 4151 jint ret = JNI_ERR; |
4152 DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret); | |
4153 | |
4154 // Don't do anything with a null object | |
4155 if (jobj == NULL) { | |
4156 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); | |
4157 } | |
4158 | |
4159 Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); | |
4160 ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR)); | |
4161 | |
4162 ret = JNI_OK; | |
4163 return ret; | |
4164 JNI_END | |
4165 | |
4166 // | |
4167 // Extensions | |
4168 // | |
4169 | |
4006 | 4170 #ifndef USDT2 |
0 | 4171 DT_VOID_RETURN_MARK_DECL(GetStringRegion); |
4006 | 4172 #else /* USDT2 */ |
4173 DT_VOID_RETURN_MARK_DECL(GetStringRegion | |
4174 , HOTSPOT_JNI_GETSTRINGREGION_RETURN()); | |
4175 #endif /* USDT2 */ | |
0 | 4176 |
4177 JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf)) | |
4178 JNIWrapper("GetStringRegion"); | |
4006 | 4179 #ifndef USDT2 |
0 | 4180 DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf); |
4006 | 4181 #else /* USDT2 */ |
4182 HOTSPOT_JNI_GETSTRINGREGION_ENTRY( | |
4183 env, string, start, len, buf); | |
4184 #endif /* USDT2 */ | |
0 | 4185 DT_VOID_RETURN_MARK(GetStringRegion); |
4186 oop s = JNIHandles::resolve_non_null(string); | |
4187 int s_len = java_lang_String::length(s); | |
4188 if (start < 0 || len < 0 || start + len > s_len) { | |
4189 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
4190 } else { | |
4191 if (len > 0) { | |
4192 int s_offset = java_lang_String::offset(s); | |
4193 typeArrayOop s_value = java_lang_String::value(s); | |
4194 memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len); | |
4195 } | |
4196 } | |
4197 JNI_END | |
4198 | |
4006 | 4199 #ifndef USDT2 |
0 | 4200 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion); |
4006 | 4201 #else /* USDT2 */ |
4202 DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion | |
4203 , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN()); | |
4204 #endif /* USDT2 */ | |
0 | 4205 |
4206 JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf)) | |
4207 JNIWrapper("GetStringUTFRegion"); | |
4006 | 4208 #ifndef USDT2 |
0 | 4209 DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf); |
4006 | 4210 #else /* USDT2 */ |
4211 HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY( | |
4212 env, string, start, len, buf); | |
4213 #endif /* USDT2 */ | |
0 | 4214 DT_VOID_RETURN_MARK(GetStringUTFRegion); |
4215 oop s = JNIHandles::resolve_non_null(string); | |
4216 int s_len = java_lang_String::length(s); | |
4217 if (start < 0 || len < 0 || start + len > s_len) { | |
4218 THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); | |
4219 } else { | |
4220 //%note jni_7 | |
4221 if (len > 0) { | |
4222 ResourceMark rm(THREAD); | |
4223 char *utf_region = java_lang_String::as_utf8_string(s, start, len); | |
4224 int utf_len = (int)strlen(utf_region); | |
4225 memcpy(buf, utf_region, utf_len); | |
4226 buf[utf_len] = 0; | |
4227 } else { | |
4228 // JDK null-terminates the buffer even in len is zero | |
4229 if (buf != NULL) { | |
4230 buf[0] = 0; | |
4231 } | |
4232 } | |
4233 } | |
4234 JNI_END | |
4235 | |
4236 | |
4237 JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)) | |
4238 JNIWrapper("GetPrimitiveArrayCritical"); | |
4006 | 4239 #ifndef USDT2 |
0 | 4240 DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy); |
4006 | 4241 #else /* USDT2 */ |
4242 HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY( | |
4243 env, array, (uintptr_t *) isCopy); | |
4244 #endif /* USDT2 */ | |
0 | 4245 GC_locker::lock_critical(thread); |
4246 if (isCopy != NULL) { | |
4247 *isCopy = JNI_FALSE; | |
4248 } | |
4249 oop a = JNIHandles::resolve_non_null(array); | |
4250 assert(a->is_array(), "just checking"); | |
4251 BasicType type; | |
4252 if (a->is_objArray()) { | |
4253 type = T_OBJECT; | |
4254 } else { | |
4255 type = typeArrayKlass::cast(a->klass())->element_type(); | |
4256 } | |
4257 void* ret = arrayOop(a)->base(type); | |
4006 | 4258 #ifndef USDT2 |
0 | 4259 DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret); |
4006 | 4260 #else /* USDT2 */ |
4261 HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN( | |
4262 ret); | |
4263 #endif /* USDT2 */ | |
0 | 4264 return ret; |
4265 JNI_END | |
4266 | |
4267 | |
4268 JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)) | |
4269 JNIWrapper("ReleasePrimitiveArrayCritical"); | |
4006 | 4270 #ifndef USDT2 |
0 | 4271 DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode); |
4006 | 4272 #else /* USDT2 */ |
4273 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY( | |
4274 env, array, carray, mode); | |
4275 #endif /* USDT2 */ | |
0 | 4276 // The array, carray and mode arguments are ignored |
4277 GC_locker::unlock_critical(thread); | |
4006 | 4278 #ifndef USDT2 |
0 | 4279 DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return); |
4006 | 4280 #else /* USDT2 */ |
4281 HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN( | |
4282 ); | |
4283 #endif /* USDT2 */ | |
0 | 4284 JNI_END |
4285 | |
4286 | |
4287 JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)) | |
4288 JNIWrapper("GetStringCritical"); | |
4006 | 4289 #ifndef USDT2 |
0 | 4290 DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy); |
4006 | 4291 #else /* USDT2 */ |
4292 HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY( | |
4293 env, string, (uintptr_t *) isCopy); | |
4294 #endif /* USDT2 */ | |
0 | 4295 GC_locker::lock_critical(thread); |
4296 if (isCopy != NULL) { | |
4297 *isCopy = JNI_FALSE; | |
4298 } | |
4299 oop s = JNIHandles::resolve_non_null(string); | |
4300 int s_len = java_lang_String::length(s); | |
4301 typeArrayOop s_value = java_lang_String::value(s); | |
4302 int s_offset = java_lang_String::offset(s); | |
4303 const jchar* ret; | |
4304 if (s_len > 0) { | |
4305 ret = s_value->char_at_addr(s_offset); | |
4306 } else { | |
4307 ret = (jchar*) s_value->base(T_CHAR); | |
4308 } | |
4006 | 4309 #ifndef USDT2 |
0 | 4310 DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret); |
4006 | 4311 #else /* USDT2 */ |
4312 HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN( | |
4313 (uint16_t *) ret); | |
4314 #endif /* USDT2 */ | |
0 | 4315 return ret; |
4316 JNI_END | |
4317 | |
4318 | |
4319 JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars)) | |
4320 JNIWrapper("ReleaseStringCritical"); | |
4006 | 4321 #ifndef USDT2 |
0 | 4322 DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars); |
4006 | 4323 #else /* USDT2 */ |
4324 HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY( | |
4325 env, str, (uint16_t *) chars); | |
4326 #endif /* USDT2 */ | |
0 | 4327 // The str and chars arguments are ignored |
4328 GC_locker::unlock_critical(thread); | |
4006 | 4329 #ifndef USDT2 |
0 | 4330 DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return); |
4006 | 4331 #else /* USDT2 */ |
4332 HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN( | |
4333 ); | |
4334 #endif /* USDT2 */ | |
0 | 4335 JNI_END |
4336 | |
4337 | |
4338 JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) | |
4339 JNIWrapper("jni_NewWeakGlobalRef"); | |
4006 | 4340 #ifndef USDT2 |
0 | 4341 DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref); |
4006 | 4342 #else /* USDT2 */ |
4343 HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY( | |
4344 env, ref); | |
4345 #endif /* USDT2 */ | |
0 | 4346 Handle ref_handle(thread, JNIHandles::resolve(ref)); |
4347 jweak ret = JNIHandles::make_weak_global(ref_handle); | |
4006 | 4348 #ifndef USDT2 |
0 | 4349 DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret); |
4006 | 4350 #else /* USDT2 */ |
4351 HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN( | |
4352 ret); | |
4353 #endif /* USDT2 */ | |
0 | 4354 return ret; |
4355 JNI_END | |
4356 | |
4357 // Must be JNI_ENTRY (with HandleMark) | |
4358 JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref)) | |
4359 JNIWrapper("jni_DeleteWeakGlobalRef"); | |
4006 | 4360 #ifndef USDT2 |
0 | 4361 DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref); |
4006 | 4362 #else /* USDT2 */ |
4363 HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY( | |
4364 env, ref); | |
4365 #endif /* USDT2 */ | |
0 | 4366 JNIHandles::destroy_weak_global(ref); |
4006 | 4367 #ifndef USDT2 |
0 | 4368 DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return); |
4006 | 4369 #else /* USDT2 */ |
4370 HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN( | |
4371 ); | |
4372 #endif /* USDT2 */ | |
0 | 4373 JNI_END |
4374 | |
4375 | |
4376 JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env)) | |
4377 JNIWrapper("jni_ExceptionCheck"); | |
4006 | 4378 #ifndef USDT2 |
0 | 4379 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env); |
4006 | 4380 #else /* USDT2 */ |
4381 HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY( | |
4382 env); | |
4383 #endif /* USDT2 */ | |
0 | 4384 jni_check_async_exceptions(thread); |
4385 jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE; | |
4006 | 4386 #ifndef USDT2 |
0 | 4387 DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret); |
4006 | 4388 #else /* USDT2 */ |
4389 HOTSPOT_JNI_EXCEPTIONCHECK_RETURN( | |
4390 ret); | |
4391 #endif /* USDT2 */ | |
0 | 4392 return ret; |
4393 JNI_END | |
4394 | |
4395 | |
4396 // Initialization state for three routines below relating to | |
4397 // java.nio.DirectBuffers | |
4398 static jint directBufferSupportInitializeStarted = 0; | |
4399 static volatile jint directBufferSupportInitializeEnded = 0; | |
4400 static volatile jint directBufferSupportInitializeFailed = 0; | |
4401 static jclass bufferClass = NULL; | |
4402 static jclass directBufferClass = NULL; | |
4403 static jclass directByteBufferClass = NULL; | |
4404 static jmethodID directByteBufferConstructor = NULL; | |
4405 static jfieldID directBufferAddressField = NULL; | |
4406 static jfieldID bufferCapacityField = NULL; | |
4407 | |
4408 static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) { | |
4409 Handle loader; // null (bootstrap) loader | |
4410 Handle protection_domain; // null protection domain | |
4411 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1989
diff
changeset
|
4412 TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
4413 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
|
4414 |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
4415 if (TraceClassResolution && result != NULL) { |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
4416 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
|
4417 } |
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
579
diff
changeset
|
4418 return result; |
0 | 4419 } |
4420 | |
4421 // These lookups are done with the NULL (bootstrap) ClassLoader to | |
4422 // circumvent any security checks that would be done by jni_FindClass. | |
4423 JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env)) | |
4424 { | |
4425 if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; } | |
4426 if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; } | |
4427 if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; } | |
4428 return true; | |
4429 } | |
4430 JNI_END | |
4431 | |
4432 | |
4433 static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) { | |
4434 if (directBufferSupportInitializeFailed) { | |
4435 return false; | |
4436 } | |
4437 | |
4438 if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) { | |
4439 if (!lookupDirectBufferClasses(env)) { | |
4440 directBufferSupportInitializeFailed = 1; | |
4441 return false; | |
4442 } | |
4443 | |
4444 // Make global references for these | |
4445 bufferClass = (jclass) env->NewGlobalRef(bufferClass); | |
4446 directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); | |
4447 directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); | |
4448 | |
4449 // Get needed field and method IDs | |
4450 directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V"); | |
4451 directBufferAddressField = env->GetFieldID(bufferClass, "address", "J"); | |
4452 bufferCapacityField = env->GetFieldID(bufferClass, "capacity", "I"); | |
4453 | |
4454 if ((directByteBufferConstructor == NULL) || | |
4455 (directBufferAddressField == NULL) || | |
4456 (bufferCapacityField == NULL)) { | |
4457 directBufferSupportInitializeFailed = 1; | |
4458 return false; | |
4459 } | |
4460 | |
4461 directBufferSupportInitializeEnded = 1; | |
4462 } else { | |
4463 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
|
4464 // 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
|
4465 // 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
|
4466 // 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
|
4467 // 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
|
4468 // 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
|
4469 ThreadInVMfromNative tivn(thread); |
0 | 4470 os::yield_all(); |
4471 } | |
4472 } | |
4473 | |
4474 return !directBufferSupportInitializeFailed; | |
4475 } | |
4476 | |
4477 extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity) | |
4478 { | |
4479 // thread_from_jni_environment() will block if VM is gone. | |
4480 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
4481 | |
4482 JNIWrapper("jni_NewDirectByteBuffer"); | |
4006 | 4483 #ifndef USDT2 |
0 | 4484 DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity); |
4006 | 4485 #else /* USDT2 */ |
4486 HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY( | |
4487 env, address, capacity); | |
4488 #endif /* USDT2 */ | |
0 | 4489 |
4490 if (!directBufferSupportInitializeEnded) { | |
4491 if (!initializeDirectBufferSupport(env, thread)) { | |
4006 | 4492 #ifndef USDT2 |
0 | 4493 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL); |
4006 | 4494 #else /* USDT2 */ |
4495 HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( | |
4496 NULL); | |
4497 #endif /* USDT2 */ | |
0 | 4498 return NULL; |
4499 } | |
4500 } | |
4501 | |
4502 // Being paranoid about accidental sign extension on address | |
4503 jlong addr = (jlong) ((uintptr_t) address); | |
4504 // NOTE that package-private DirectByteBuffer constructor currently | |
4505 // takes int capacity | |
4506 jint cap = (jint) capacity; | |
4507 jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap); | |
4006 | 4508 #ifndef USDT2 |
0 | 4509 DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret); |
4006 | 4510 #else /* USDT2 */ |
4511 HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( | |
4512 ret); | |
4513 #endif /* USDT2 */ | |
0 | 4514 return ret; |
4515 } | |
4516 | |
4006 | 4517 #ifndef USDT2 |
0 | 4518 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*); |
4006 | 4519 #else /* USDT2 */ |
4520 DT_RETURN_MARK_DECL(GetDirectBufferAddress, void* | |
4521 , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref)); | |
4522 #endif /* USDT2 */ | |
0 | 4523 |
4524 extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) | |
4525 { | |
4526 // thread_from_jni_environment() will block if VM is gone. | |
4527 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
4528 | |
4529 JNIWrapper("jni_GetDirectBufferAddress"); | |
4006 | 4530 #ifndef USDT2 |
0 | 4531 DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf); |
4006 | 4532 #else /* USDT2 */ |
4533 HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY( | |
4534 env, buf); | |
4535 #endif /* USDT2 */ | |
0 | 4536 void* ret = NULL; |
4537 DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret); | |
4538 | |
4539 if (!directBufferSupportInitializeEnded) { | |
4540 if (!initializeDirectBufferSupport(env, thread)) { | |
4541 return 0; | |
4542 } | |
4543 } | |
4544 | |
4545 if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) { | |
4546 return 0; | |
4547 } | |
4548 | |
4549 ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField); | |
4550 return ret; | |
4551 } | |
4552 | |
4006 | 4553 #ifndef USDT2 |
0 | 4554 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong); |
4006 | 4555 #else /* USDT2 */ |
4556 DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong | |
4557 , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref)); | |
4558 #endif /* USDT2 */ | |
0 | 4559 |
4560 extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf) | |
4561 { | |
4562 // thread_from_jni_environment() will block if VM is gone. | |
4563 JavaThread* thread = JavaThread::thread_from_jni_environment(env); | |
4564 | |
4565 JNIWrapper("jni_GetDirectBufferCapacity"); | |
4006 | 4566 #ifndef USDT2 |
0 | 4567 DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf); |
4006 | 4568 #else /* USDT2 */ |
4569 HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY( | |
4570 env, buf); | |
4571 #endif /* USDT2 */ | |
0 | 4572 jlong ret = -1; |
4573 DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret); | |
4574 | |
4575 if (!directBufferSupportInitializeEnded) { | |
4576 if (!initializeDirectBufferSupport(env, thread)) { | |
4577 ret = 0; | |
4578 return ret; | |
4579 } | |
4580 } | |
4581 | |
4582 if (buf == NULL) { | |
4583 return -1; | |
4584 } | |
4585 | |
4586 if (!env->IsInstanceOf(buf, directBufferClass)) { | |
4587 return -1; | |
4588 } | |
4589 | |
4590 // NOTE that capacity is currently an int in the implementation | |
4591 ret = env->GetIntField(buf, bufferCapacityField); | |
4592 return ret; | |
4593 } | |
4594 | |
4595 | |
4596 JNI_LEAF(jint, jni_GetVersion(JNIEnv *env)) | |
4597 JNIWrapper("GetVersion"); | |
4006 | 4598 #ifndef USDT2 |
0 | 4599 DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env); |
4006 | 4600 #else /* USDT2 */ |
4601 HOTSPOT_JNI_GETVERSION_ENTRY( | |
4602 env); | |
4603 #endif /* USDT2 */ | |
4604 #ifndef USDT2 | |
0 | 4605 DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion); |
4006 | 4606 #else /* USDT2 */ |
4607 HOTSPOT_JNI_GETVERSION_RETURN( | |
4608 CurrentVersion); | |
4609 #endif /* USDT2 */ | |
0 | 4610 return CurrentVersion; |
4611 JNI_END | |
4612 | |
4613 extern struct JavaVM_ main_vm; | |
4614 | |
4615 JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm)) | |
4616 JNIWrapper("jni_GetJavaVM"); | |
4006 | 4617 #ifndef USDT2 |
0 | 4618 DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm); |
4006 | 4619 #else /* USDT2 */ |
4620 HOTSPOT_JNI_GETJAVAVM_ENTRY( | |
4621 env, (void **) vm); | |
4622 #endif /* USDT2 */ | |
0 | 4623 *vm = (JavaVM *)(&main_vm); |
4006 | 4624 #ifndef USDT2 |
0 | 4625 DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK); |
4006 | 4626 #else /* USDT2 */ |
4627 HOTSPOT_JNI_GETJAVAVM_RETURN( | |
4628 JNI_OK); | |
4629 #endif /* USDT2 */ | |
0 | 4630 return JNI_OK; |
4631 JNI_END | |
4632 | |
4633 // Structure containing all jni functions | |
4634 struct JNINativeInterface_ jni_NativeInterface = { | |
4635 NULL, | |
4636 NULL, | |
4637 NULL, | |
4638 | |
4639 NULL, | |
4640 | |
4641 jni_GetVersion, | |
4642 | |
4643 jni_DefineClass, | |
4644 jni_FindClass, | |
4645 | |
4646 jni_FromReflectedMethod, | |
4647 jni_FromReflectedField, | |
4648 | |
4649 jni_ToReflectedMethod, | |
4650 | |
4651 jni_GetSuperclass, | |
4652 jni_IsAssignableFrom, | |
4653 | |
4654 jni_ToReflectedField, | |
4655 | |
4656 jni_Throw, | |
4657 jni_ThrowNew, | |
4658 jni_ExceptionOccurred, | |
4659 jni_ExceptionDescribe, | |
4660 jni_ExceptionClear, | |
4661 jni_FatalError, | |
4662 | |
4663 jni_PushLocalFrame, | |
4664 jni_PopLocalFrame, | |
4665 | |
4666 jni_NewGlobalRef, | |
4667 jni_DeleteGlobalRef, | |
4668 jni_DeleteLocalRef, | |
4669 jni_IsSameObject, | |
4670 | |
4671 jni_NewLocalRef, | |
4672 jni_EnsureLocalCapacity, | |
4673 | |
4674 jni_AllocObject, | |
4675 jni_NewObject, | |
4676 jni_NewObjectV, | |
4677 jni_NewObjectA, | |
4678 | |
4679 jni_GetObjectClass, | |
4680 jni_IsInstanceOf, | |
4681 | |
4682 jni_GetMethodID, | |
4683 | |
4684 jni_CallObjectMethod, | |
4685 jni_CallObjectMethodV, | |
4686 jni_CallObjectMethodA, | |
4687 jni_CallBooleanMethod, | |
4688 jni_CallBooleanMethodV, | |
4689 jni_CallBooleanMethodA, | |
4690 jni_CallByteMethod, | |
4691 jni_CallByteMethodV, | |
4692 jni_CallByteMethodA, | |
4693 jni_CallCharMethod, | |
4694 jni_CallCharMethodV, | |
4695 jni_CallCharMethodA, | |
4696 jni_CallShortMethod, | |
4697 jni_CallShortMethodV, | |
4698 jni_CallShortMethodA, | |
4699 jni_CallIntMethod, | |
4700 jni_CallIntMethodV, | |
4701 jni_CallIntMethodA, | |
4702 jni_CallLongMethod, | |
4703 jni_CallLongMethodV, | |
4704 jni_CallLongMethodA, | |
4705 jni_CallFloatMethod, | |
4706 jni_CallFloatMethodV, | |
4707 jni_CallFloatMethodA, | |
4708 jni_CallDoubleMethod, | |
4709 jni_CallDoubleMethodV, | |
4710 jni_CallDoubleMethodA, | |
4711 jni_CallVoidMethod, | |
4712 jni_CallVoidMethodV, | |
4713 jni_CallVoidMethodA, | |
4714 | |
4715 jni_CallNonvirtualObjectMethod, | |
4716 jni_CallNonvirtualObjectMethodV, | |
4717 jni_CallNonvirtualObjectMethodA, | |
4718 jni_CallNonvirtualBooleanMethod, | |
4719 jni_CallNonvirtualBooleanMethodV, | |
4720 jni_CallNonvirtualBooleanMethodA, | |
4721 jni_CallNonvirtualByteMethod, | |
4722 jni_CallNonvirtualByteMethodV, | |
4723 jni_CallNonvirtualByteMethodA, | |
4724 jni_CallNonvirtualCharMethod, | |
4725 jni_CallNonvirtualCharMethodV, | |
4726 jni_CallNonvirtualCharMethodA, | |
4727 jni_CallNonvirtualShortMethod, | |
4728 jni_CallNonvirtualShortMethodV, | |
4729 jni_CallNonvirtualShortMethodA, | |
4730 jni_CallNonvirtualIntMethod, | |
4731 jni_CallNonvirtualIntMethodV, | |
4732 jni_CallNonvirtualIntMethodA, | |
4733 jni_CallNonvirtualLongMethod, | |
4734 jni_CallNonvirtualLongMethodV, | |
4735 jni_CallNonvirtualLongMethodA, | |
4736 jni_CallNonvirtualFloatMethod, | |
4737 jni_CallNonvirtualFloatMethodV, | |
4738 jni_CallNonvirtualFloatMethodA, | |
4739 jni_CallNonvirtualDoubleMethod, | |
4740 jni_CallNonvirtualDoubleMethodV, | |
4741 jni_CallNonvirtualDoubleMethodA, | |
4742 jni_CallNonvirtualVoidMethod, | |
4743 jni_CallNonvirtualVoidMethodV, | |
4744 jni_CallNonvirtualVoidMethodA, | |
4745 | |
4746 jni_GetFieldID, | |
4747 | |
4748 jni_GetObjectField, | |
4749 jni_GetBooleanField, | |
4750 jni_GetByteField, | |
4751 jni_GetCharField, | |
4752 jni_GetShortField, | |
4753 jni_GetIntField, | |
4754 jni_GetLongField, | |
4755 jni_GetFloatField, | |
4756 jni_GetDoubleField, | |
4757 | |
4758 jni_SetObjectField, | |
4759 jni_SetBooleanField, | |
4760 jni_SetByteField, | |
4761 jni_SetCharField, | |
4762 jni_SetShortField, | |
4763 jni_SetIntField, | |
4764 jni_SetLongField, | |
4765 jni_SetFloatField, | |
4766 jni_SetDoubleField, | |
4767 | |
4768 jni_GetStaticMethodID, | |
4769 | |
4770 jni_CallStaticObjectMethod, | |
4771 jni_CallStaticObjectMethodV, | |
4772 jni_CallStaticObjectMethodA, | |
4773 jni_CallStaticBooleanMethod, | |
4774 jni_CallStaticBooleanMethodV, | |
4775 jni_CallStaticBooleanMethodA, | |
4776 jni_CallStaticByteMethod, | |
4777 jni_CallStaticByteMethodV, | |
4778 jni_CallStaticByteMethodA, | |
4779 jni_CallStaticCharMethod, | |
4780 jni_CallStaticCharMethodV, | |
4781 jni_CallStaticCharMethodA, | |
4782 jni_CallStaticShortMethod, | |
4783 jni_CallStaticShortMethodV, | |
4784 jni_CallStaticShortMethodA, | |
4785 jni_CallStaticIntMethod, | |
4786 jni_CallStaticIntMethodV, | |
4787 jni_CallStaticIntMethodA, | |
4788 jni_CallStaticLongMethod, | |
4789 jni_CallStaticLongMethodV, | |
4790 jni_CallStaticLongMethodA, | |
4791 jni_CallStaticFloatMethod, | |
4792 jni_CallStaticFloatMethodV, | |
4793 jni_CallStaticFloatMethodA, | |
4794 jni_CallStaticDoubleMethod, | |
4795 jni_CallStaticDoubleMethodV, | |
4796 jni_CallStaticDoubleMethodA, | |
4797 jni_CallStaticVoidMethod, | |
4798 jni_CallStaticVoidMethodV, | |
4799 jni_CallStaticVoidMethodA, | |
4800 | |
4801 jni_GetStaticFieldID, | |
4802 | |
4803 jni_GetStaticObjectField, | |
4804 jni_GetStaticBooleanField, | |
4805 jni_GetStaticByteField, | |
4806 jni_GetStaticCharField, | |
4807 jni_GetStaticShortField, | |
4808 jni_GetStaticIntField, | |
4809 jni_GetStaticLongField, | |
4810 jni_GetStaticFloatField, | |
4811 jni_GetStaticDoubleField, | |
4812 | |
4813 jni_SetStaticObjectField, | |
4814 jni_SetStaticBooleanField, | |
4815 jni_SetStaticByteField, | |
4816 jni_SetStaticCharField, | |
4817 jni_SetStaticShortField, | |
4818 jni_SetStaticIntField, | |
4819 jni_SetStaticLongField, | |
4820 jni_SetStaticFloatField, | |
4821 jni_SetStaticDoubleField, | |
4822 | |
4823 jni_NewString, | |
4824 jni_GetStringLength, | |
4825 jni_GetStringChars, | |
4826 jni_ReleaseStringChars, | |
4827 | |
4828 jni_NewStringUTF, | |
4829 jni_GetStringUTFLength, | |
4830 jni_GetStringUTFChars, | |
4831 jni_ReleaseStringUTFChars, | |
4832 | |
4833 jni_GetArrayLength, | |
4834 | |
4835 jni_NewObjectArray, | |
4836 jni_GetObjectArrayElement, | |
4837 jni_SetObjectArrayElement, | |
4838 | |
4839 jni_NewBooleanArray, | |
4840 jni_NewByteArray, | |
4841 jni_NewCharArray, | |
4842 jni_NewShortArray, | |
4843 jni_NewIntArray, | |
4844 jni_NewLongArray, | |
4845 jni_NewFloatArray, | |
4846 jni_NewDoubleArray, | |
4847 | |
4848 jni_GetBooleanArrayElements, | |
4849 jni_GetByteArrayElements, | |
4850 jni_GetCharArrayElements, | |
4851 jni_GetShortArrayElements, | |
4852 jni_GetIntArrayElements, | |
4853 jni_GetLongArrayElements, | |
4854 jni_GetFloatArrayElements, | |
4855 jni_GetDoubleArrayElements, | |
4856 | |
4857 jni_ReleaseBooleanArrayElements, | |
4858 jni_ReleaseByteArrayElements, | |
4859 jni_ReleaseCharArrayElements, | |
4860 jni_ReleaseShortArrayElements, | |
4861 jni_ReleaseIntArrayElements, | |
4862 jni_ReleaseLongArrayElements, | |
4863 jni_ReleaseFloatArrayElements, | |
4864 jni_ReleaseDoubleArrayElements, | |
4865 | |
4866 jni_GetBooleanArrayRegion, | |
4867 jni_GetByteArrayRegion, | |
4868 jni_GetCharArrayRegion, | |
4869 jni_GetShortArrayRegion, | |
4870 jni_GetIntArrayRegion, | |
4871 jni_GetLongArrayRegion, | |
4872 jni_GetFloatArrayRegion, | |
4873 jni_GetDoubleArrayRegion, | |
4874 | |
4875 jni_SetBooleanArrayRegion, | |
4876 jni_SetByteArrayRegion, | |
4877 jni_SetCharArrayRegion, | |
4878 jni_SetShortArrayRegion, | |
4879 jni_SetIntArrayRegion, | |
4880 jni_SetLongArrayRegion, | |
4881 jni_SetFloatArrayRegion, | |
4882 jni_SetDoubleArrayRegion, | |
4883 | |
4884 jni_RegisterNatives, | |
4885 jni_UnregisterNatives, | |
4886 | |
4887 jni_MonitorEnter, | |
4888 jni_MonitorExit, | |
4889 | |
4890 jni_GetJavaVM, | |
4891 | |
4892 jni_GetStringRegion, | |
4893 jni_GetStringUTFRegion, | |
4894 | |
4895 jni_GetPrimitiveArrayCritical, | |
4896 jni_ReleasePrimitiveArrayCritical, | |
4897 | |
4898 jni_GetStringCritical, | |
4899 jni_ReleaseStringCritical, | |
4900 | |
4901 jni_NewWeakGlobalRef, | |
4902 jni_DeleteWeakGlobalRef, | |
4903 | |
4904 jni_ExceptionCheck, | |
4905 | |
4906 jni_NewDirectByteBuffer, | |
4907 jni_GetDirectBufferAddress, | |
4908 jni_GetDirectBufferCapacity, | |
4909 | |
4910 // New 1_6 features | |
4911 | |
4912 jni_GetObjectRefType | |
4913 }; | |
4914 | |
4915 | |
4916 // For jvmti use to modify jni function table. | |
4917 // Java threads in native contiues to run until it is transitioned | |
4918 // to VM at safepoint. Before the transition or before it is blocked | |
4919 // for safepoint it may access jni function table. VM could crash if | |
4920 // any java thread access the jni function table in the middle of memcpy. | |
4921 // To avoid this each function pointers are copied automically. | |
4922 void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) { | |
4923 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
4924 intptr_t *a = (intptr_t *) jni_functions(); | |
4925 intptr_t *b = (intptr_t *) new_jni_NativeInterface; | |
4926 for (uint i=0; i < sizeof(struct JNINativeInterface_)/sizeof(void *); i++) { | |
4927 Atomic::store_ptr(*b++, a++); | |
4928 } | |
4929 } | |
4930 | |
4931 void quicken_jni_functions() { | |
4932 // Replace Get<Primitive>Field with fast versions | |
4933 if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access() | |
4934 && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls | |
4935 #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2) | |
4936 // windows x86 currently needs SEH wrapper and the gain of the fast | |
4937 // versions currently isn't certain for server vm on uniprocessor. | |
4938 && os::is_MP() | |
4939 #endif | |
4940 ) { | |
4941 address func; | |
4942 func = JNI_FastGetField::generate_fast_get_boolean_field(); | |
4943 if (func != (address)-1) { | |
4944 jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func; | |
4945 } | |
4946 func = JNI_FastGetField::generate_fast_get_byte_field(); | |
4947 if (func != (address)-1) { | |
4948 jni_NativeInterface.GetByteField = (GetByteField_t)func; | |
4949 } | |
4950 func = JNI_FastGetField::generate_fast_get_char_field(); | |
4951 if (func != (address)-1) { | |
4952 jni_NativeInterface.GetCharField = (GetCharField_t)func; | |
4953 } | |
4954 func = JNI_FastGetField::generate_fast_get_short_field(); | |
4955 if (func != (address)-1) { | |
4956 jni_NativeInterface.GetShortField = (GetShortField_t)func; | |
4957 } | |
4958 func = JNI_FastGetField::generate_fast_get_int_field(); | |
4959 if (func != (address)-1) { | |
4960 jni_NativeInterface.GetIntField = (GetIntField_t)func; | |
4961 } | |
4962 func = JNI_FastGetField::generate_fast_get_long_field(); | |
4963 if (func != (address)-1) { | |
4964 jni_NativeInterface.GetLongField = (GetLongField_t)func; | |
4965 } | |
4966 func = JNI_FastGetField::generate_fast_get_float_field(); | |
4967 if (func != (address)-1) { | |
4968 jni_NativeInterface.GetFloatField = (GetFloatField_t)func; | |
4969 } | |
4970 func = JNI_FastGetField::generate_fast_get_double_field(); | |
4971 if (func != (address)-1) { | |
4972 jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func; | |
4973 } | |
4974 } | |
4975 } | |
4976 | |
4977 // Returns the function structure | |
4978 struct JNINativeInterface_* jni_functions() { | |
4979 #ifndef JNICHECK_KERNEL | |
4980 if (CheckJNICalls) return jni_functions_check(); | |
4981 #else // JNICHECK_KERNEL | |
4982 if (CheckJNICalls) warning("-Xcheck:jni is not supported in kernel vm."); | |
4983 #endif // JNICHECK_KERNEL | |
4984 return &jni_NativeInterface; | |
4985 } | |
4986 | |
4987 // Returns the function structure | |
4988 struct JNINativeInterface_* jni_functions_nocheck() { | |
4989 return &jni_NativeInterface; | |
4990 } | |
4991 | |
4992 | |
4993 // Invocation API | |
4994 | |
4995 | |
4996 // Forward declaration | |
4997 extern const struct JNIInvokeInterface_ jni_InvokeInterface; | |
4998 | |
4999 // Global invocation API vars | |
5000 volatile jint vm_created = 0; | |
5001 // Indicate whether it is safe to recreate VM | |
5002 volatile jint safe_to_recreate_vm = 1; | |
5003 struct JavaVM_ main_vm = {&jni_InvokeInterface}; | |
5004 | |
5005 | |
5006 #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ | |
5007 enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; | |
5008 | |
4006 | 5009 #ifndef USDT2 |
0 | 5010 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); |
5011 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint); | |
4006 | 5012 #else /* USDT2 */ |
5013 DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint | |
5014 , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref)); | |
5015 #endif /* USDT2 */ | |
0 | 5016 |
5017 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { | |
4006 | 5018 #ifndef USDT2 |
0 | 5019 HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_); |
4006 | 5020 #else /* USDT2 */ |
5021 HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY( | |
5022 args_); | |
5023 #endif /* USDT2 */ | |
0 | 5024 JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_; |
5025 jint ret = JNI_ERR; | |
5026 DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret); | |
5027 | |
5028 if (Threads::is_supported_jni_version(args->version)) { | |
5029 ret = JNI_OK; | |
5030 } | |
5031 // 1.1 style no longer supported in hotspot. | |
5032 // According the JNI spec, we should update args->version on return. | |
5033 // We also use the structure to communicate with launcher about default | |
5034 // stack size. | |
5035 if (args->version == JNI_VERSION_1_1) { | |
5036 args->version = JNI_VERSION_1_2; | |
5037 // javaStackSize is int in arguments structure | |
5038 assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow"); | |
5039 args->javaStackSize = (jint)(ThreadStackSize * K); | |
5040 } | |
5041 return ret; | |
5042 } | |
5043 | |
3779 | 5044 #ifndef PRODUCT |
5045 | |
4708 | 5046 #include "gc_interface/collectedHeap.hpp" |
3779 | 5047 #include "utilities/quickSort.hpp" |
5048 | |
4708 | 5049 #define run_unit_test(unit_test_function_call) \ |
5050 tty->print_cr("Running test: " #unit_test_function_call); \ | |
5051 unit_test_function_call | |
5052 | |
3779 | 5053 void execute_internal_vm_tests() { |
5054 if (ExecuteInternalVMTests) { | |
4708 | 5055 tty->print_cr("Running internal VM tests"); |
5056 run_unit_test(arrayOopDesc::test_max_array_length()); | |
5057 run_unit_test(CollectedHeap::test_is_in()); | |
5058 run_unit_test(QuickSort::test_quick_sort()); | |
4070
6fd81579526f
7102044: G1: VM crashes with assert(old_end != new_end) failed: don't call this otherwise
brutisso
parents:
4006
diff
changeset
|
5059 tty->print_cr("All internal VM tests passed"); |
3779 | 5060 } |
5061 } | |
5062 | |
4708 | 5063 #undef run_unit_test |
5064 | |
3779 | 5065 #endif |
5066 | |
4006 | 5067 #ifndef USDT2 |
0 | 5068 HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
5069 DT_RETURN_MARK_DECL(CreateJavaVM, jint); | |
4006 | 5070 #else /* USDT2 */ |
5071 DT_RETURN_MARK_DECL(CreateJavaVM, jint | |
5072 , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref)); | |
5073 #endif /* USDT2 */ | |
0 | 5074 |
5075 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) { | |
4006 | 5076 #ifndef USDT2 |
0 | 5077 HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
4006 | 5078 #else /* USDT2 */ |
5079 HOTSPOT_JNI_CREATEJAVAVM_ENTRY( | |
5080 (void **) vm, penv, args); | |
5081 #endif /* USDT2 */ | |
0 | 5082 |
5083 jint result = JNI_ERR; | |
5084 DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result); | |
5085 | |
1078 | 5086 // We're about to use Atomic::xchg for synchronization. Some Zero |
5087 // platforms use the GCC builtin __sync_lock_test_and_set for this, | |
5088 // but __sync_lock_test_and_set is not guaranteed to do what we want | |
5089 // on all architectures. So we check it works before relying on it. | |
5090 #if defined(ZERO) && defined(ASSERT) | |
5091 { | |
5092 jint a = 0xcafebabe; | |
5093 jint b = Atomic::xchg(0xdeadbeef, &a); | |
5094 void *c = &a; | |
5095 void *d = Atomic::xchg_ptr(&b, &c); | |
1132 | 5096 assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works"); |
1078 | 5097 assert(c == &b && d == &a, "Atomic::xchg_ptr() works"); |
5098 } | |
5099 #endif // ZERO && ASSERT | |
5100 | |
0 | 5101 // At the moment it's only possible to have one Java VM, |
5102 // since some of the runtime state is in global variables. | |
5103 | |
5104 // We cannot use our mutex locks here, since they only work on | |
5105 // Threads. We do an atomic compare and exchange to ensure only | |
5106 // one thread can call this method at a time | |
5107 | |
5108 // We use Atomic::xchg rather than Atomic::add/dec since on some platforms | |
5109 // the add/dec implementations are dependent on whether we are running | |
5110 // on a multiprocessor, and at this stage of initialization the os::is_MP | |
5111 // function used to determine this will always return false. Atomic::xchg | |
5112 // does not have this problem. | |
5113 if (Atomic::xchg(1, &vm_created) == 1) { | |
5114 return JNI_ERR; // already created, or create attempt in progress | |
5115 } | |
5116 if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) { | |
5117 return JNI_ERR; // someone tried and failed and retry not allowed. | |
5118 } | |
5119 | |
5120 assert(vm_created == 1, "vm_created is true during the creation"); | |
5121 | |
5122 /** | |
5123 * Certain errors during initialization are recoverable and do not | |
5124 * prevent this method from being called again at a later time | |
5125 * (perhaps with different arguments). However, at a certain | |
5126 * point during initialization if an error occurs we cannot allow | |
5127 * this function to be called again (or it will crash). In those | |
5128 * situations, the 'canTryAgain' flag is set to false, which atomically | |
5129 * sets safe_to_recreate_vm to 1, such that any new call to | |
5130 * JNI_CreateJavaVM will immediately fail using the above logic. | |
5131 */ | |
5132 bool can_try_again = true; | |
5133 | |
5134 result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again); | |
5135 if (result == JNI_OK) { | |
5136 JavaThread *thread = JavaThread::current(); | |
5137 /* thread is thread_in_vm here */ | |
5138 *vm = (JavaVM *)(&main_vm); | |
5139 *(JNIEnv**)penv = thread->jni_environment(); | |
5140 | |
4368
d8d6b3de346b
Add another #ifdef GRAAL
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4137
diff
changeset
|
5141 #ifdef GRAAL |
3650
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3540
diff
changeset
|
5142 GraalCompiler* compiler = GraalCompiler::instance(); |
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3540
diff
changeset
|
5143 ciObjectFactory::initialize(); |
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3540
diff
changeset
|
5144 compiler->initialize(); |
4368
d8d6b3de346b
Add another #ifdef GRAAL
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4137
diff
changeset
|
5145 #endif |
3650
0e8a2a629afb
Pass-by compilation broker.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3540
diff
changeset
|
5146 |
0 | 5147 // Tracks the time application was running before GC |
5148 RuntimeService::record_application_start(); | |
5149 | |
5150 // Notify JVMTI | |
5151 if (JvmtiExport::should_post_thread_life()) { | |
5152 JvmtiExport::post_thread_start(thread); | |
5153 } | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5154 |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5155 EVENT_BEGIN(TraceEventThreadStart, event); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5156 EVENT_COMMIT(event, |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5157 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(thread->threadObj()))); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5158 |
0 | 5159 // Check if we should compile all classes on bootclasspath |
5160 NOT_PRODUCT(if (CompileTheWorld) ClassLoader::compile_the_world();) | |
5161 // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. | |
5162 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
5163 } else { | |
5164 if (can_try_again) { | |
5165 // reset safe_to_recreate_vm to 1 so that retrial would be possible | |
5166 safe_to_recreate_vm = 1; | |
5167 } | |
5168 | |
5169 // Creation failed. We must reset vm_created | |
5170 *vm = 0; | |
5171 *(JNIEnv**)penv = 0; | |
5172 // reset vm_created last to avoid race condition. Use OrderAccess to | |
5173 // control both compiler and architectural-based reordering. | |
5174 OrderAccess::release_store(&vm_created, 0); | |
5175 } | |
5176 | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1290
diff
changeset
|
5177 NOT_PRODUCT(test_error_handler(ErrorHandlerTest)); |
3779 | 5178 NOT_PRODUCT(execute_internal_vm_tests()); |
0 | 5179 return result; |
5180 } | |
5181 | |
4006 | 5182 #ifndef USDT2 |
0 | 5183 HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
5184 JavaVM**, jsize, jsize*); | |
5185 HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint); | |
4006 | 5186 #endif /* !USDT2 */ |
0 | 5187 |
5188 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) { | |
5189 // See bug 4367188, the wrapper can sometimes cause VM crashes | |
5190 // JNIWrapper("GetCreatedJavaVMs"); | |
4006 | 5191 #ifndef USDT2 |
0 | 5192 HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
5193 vm_buf, bufLen, numVMs); | |
4006 | 5194 #else /* USDT2 */ |
5195 HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY( | |
5196 (void **) vm_buf, bufLen, (uintptr_t *) numVMs); | |
5197 #endif /* USDT2 */ | |
0 | 5198 if (vm_created) { |
5199 if (numVMs != NULL) *numVMs = 1; | |
5200 if (bufLen > 0) *vm_buf = (JavaVM *)(&main_vm); | |
5201 } else { | |
5202 if (numVMs != NULL) *numVMs = 0; | |
5203 } | |
4006 | 5204 #ifndef USDT2 |
0 | 5205 HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK); |
4006 | 5206 #else /* USDT2 */ |
5207 HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN( | |
5208 JNI_OK); | |
5209 #endif /* USDT2 */ | |
0 | 5210 return JNI_OK; |
5211 } | |
5212 | |
5213 extern "C" { | |
5214 | |
4006 | 5215 #ifndef USDT2 |
0 | 5216 DT_RETURN_MARK_DECL(DestroyJavaVM, jint); |
4006 | 5217 #else /* USDT2 */ |
5218 DT_RETURN_MARK_DECL(DestroyJavaVM, jint | |
5219 , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref)); | |
5220 #endif /* USDT2 */ | |
0 | 5221 |
5222 jint JNICALL jni_DestroyJavaVM(JavaVM *vm) { | |
4006 | 5223 #ifndef USDT2 |
0 | 5224 DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm); |
4006 | 5225 #else /* USDT2 */ |
5226 HOTSPOT_JNI_DESTROYJAVAVM_ENTRY( | |
5227 vm); | |
5228 #endif /* USDT2 */ | |
0 | 5229 jint res = JNI_ERR; |
5230 DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res); | |
5231 | |
5232 if (!vm_created) { | |
5233 res = JNI_ERR; | |
5234 return res; | |
5235 } | |
5236 | |
5237 JNIWrapper("DestroyJavaVM"); | |
5238 JNIEnv *env; | |
5239 JavaVMAttachArgs destroyargs; | |
5240 destroyargs.version = CurrentVersion; | |
5241 destroyargs.name = (char *)"DestroyJavaVM"; | |
5242 destroyargs.group = NULL; | |
5243 res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs); | |
5244 if (res != JNI_OK) { | |
5245 return res; | |
5246 } | |
5247 | |
5248 // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. | |
5249 JavaThread* thread = JavaThread::current(); | |
5250 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
5251 if (Threads::destroy_vm()) { | |
5252 // Should not change thread state, VM is gone | |
5253 vm_created = false; | |
5254 res = JNI_OK; | |
5255 return res; | |
5256 } else { | |
5257 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
5258 res = JNI_ERR; | |
5259 return res; | |
5260 } | |
5261 } | |
5262 | |
5263 | |
5264 static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) { | |
5265 JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args; | |
5266 | |
5267 // Check below commented out from JDK1.2fcs as well | |
5268 /* | |
5269 if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) { | |
5270 return JNI_EVERSION; | |
5271 } | |
5272 */ | |
5273 | |
5274 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
5275 if (t != NULL) { | |
5276 // If the thread has been attached this operation is a no-op | |
5277 *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment(); | |
5278 return JNI_OK; | |
5279 } | |
5280 | |
5281 // Create a thread and mark it as attaching so it will be skipped by the | |
5282 // ThreadsListEnumerator - see CR 6404306 | |
5283 JavaThread* thread = new JavaThread(true); | |
5284 | |
5285 // Set correct safepoint info. The thread is going to call into Java when | |
5286 // initializing the Java level thread object. Hence, the correct state must | |
5287 // be set in order for the Safepoint code to deal with it correctly. | |
5288 thread->set_thread_state(_thread_in_vm); | |
5289 // Must do this before initialize_thread_local_storage | |
5290 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
|
5291 |
0 | 5292 thread->initialize_thread_local_storage(); |
5293 | |
5294 if (!os::create_attached_thread(thread)) { | |
5295 delete thread; | |
5296 return JNI_ERR; | |
5297 } | |
1290
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
5298 // Enable stack overflow checks |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
5299 thread->create_stack_guard_pages(); |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1142
diff
changeset
|
5300 |
0 | 5301 thread->initialize_tlab(); |
5302 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
5303 thread->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
5304 |
0 | 5305 // Crucial that we do not have a safepoint check for this thread, since it has |
5306 // not been added to the Thread list yet. | |
5307 { Threads_lock->lock_without_safepoint_check(); | |
5308 // This must be inside this lock in order to get FullGCALot to work properly, i.e., to | |
5309 // avoid this thread trying to do a GC before it is added to the thread-list | |
5310 thread->set_active_handles(JNIHandleBlock::allocate_block()); | |
5311 Threads::add(thread, daemon); | |
5312 Threads_lock->unlock(); | |
5313 } | |
5314 // Create thread group and name info from attach arguments | |
5315 oop group = NULL; | |
5316 char* thread_name = NULL; | |
5317 if (args != NULL && Threads::is_supported_jni_version(args->version)) { | |
5318 group = JNIHandles::resolve(args->group); | |
5319 thread_name = args->name; // may be NULL | |
5320 } | |
5321 if (group == NULL) group = Universe::main_thread_group(); | |
5322 | |
5323 // Create Java level thread object and attach it to this thread | |
5324 bool attach_failed = false; | |
5325 { | |
5326 EXCEPTION_MARK; | |
5327 HandleMark hm(THREAD); | |
5328 Handle thread_group(THREAD, group); | |
5329 thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD); | |
5330 if (HAS_PENDING_EXCEPTION) { | |
5331 CLEAR_PENDING_EXCEPTION; | |
5332 // cleanup outside the handle mark. | |
5333 attach_failed = true; | |
5334 } | |
5335 } | |
5336 | |
5337 if (attach_failed) { | |
5338 // Added missing cleanup | |
5339 thread->cleanup_failed_attach_current_thread(); | |
5340 return JNI_ERR; | |
5341 } | |
5342 | |
5343 // mark the thread as no longer attaching | |
5344 // this uses a fence to push the change through so we don't have | |
5345 // to regrab the threads_lock | |
4006 | 5346 thread->set_done_attaching_via_jni(); |
0 | 5347 |
5348 // Set java thread status. | |
5349 java_lang_Thread::set_thread_status(thread->threadObj(), | |
5350 java_lang_Thread::RUNNABLE); | |
5351 | |
5352 // Notify the debugger | |
5353 if (JvmtiExport::should_post_thread_life()) { | |
5354 JvmtiExport::post_thread_start(thread); | |
5355 } | |
5356 | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5357 EVENT_BEGIN(TraceEventThreadStart, event); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5358 EVENT_COMMIT(event, |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5359 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(thread->threadObj()))); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5360 |
0 | 5361 *(JNIEnv**)penv = thread->jni_environment(); |
5362 | |
5363 // Now leaving the VM, so change thread_state. This is normally automatically taken care | |
5364 // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by | |
5365 // using ThreadStateTransition::transition, we do a callback to the safepoint code if | |
5366 // needed. | |
5367 | |
5368 ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); | |
5369 | |
5370 // Perform any platform dependent FPU setup | |
5371 os::setup_fpu(); | |
5372 | |
5373 return JNI_OK; | |
5374 } | |
5375 | |
5376 | |
5377 jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) { | |
4006 | 5378 #ifndef USDT2 |
0 | 5379 DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args); |
4006 | 5380 #else /* USDT2 */ |
5381 HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY( | |
5382 vm, penv, _args); | |
5383 #endif /* USDT2 */ | |
0 | 5384 if (!vm_created) { |
4006 | 5385 #ifndef USDT2 |
0 | 5386 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR); |
4006 | 5387 #else /* USDT2 */ |
5388 HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( | |
5389 (uint32_t) JNI_ERR); | |
5390 #endif /* USDT2 */ | |
0 | 5391 return JNI_ERR; |
5392 } | |
5393 | |
5394 JNIWrapper("AttachCurrentThread"); | |
5395 jint ret = attach_current_thread(vm, penv, _args, false); | |
4006 | 5396 #ifndef USDT2 |
0 | 5397 DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret); |
4006 | 5398 #else /* USDT2 */ |
5399 HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( | |
5400 ret); | |
5401 #endif /* USDT2 */ | |
0 | 5402 return ret; |
5403 } | |
5404 | |
5405 | |
5406 jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { | |
4006 | 5407 #ifndef USDT2 |
0 | 5408 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm); |
4006 | 5409 #else /* USDT2 */ |
5410 HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY( | |
5411 vm); | |
5412 #endif /* USDT2 */ | |
0 | 5413 VM_Exit::block_if_vm_exited(); |
5414 | |
5415 JNIWrapper("DetachCurrentThread"); | |
5416 | |
5417 // If the thread has been deattacted the operations is a no-op | |
5418 if (ThreadLocalStorage::thread() == NULL) { | |
4006 | 5419 #ifndef USDT2 |
0 | 5420 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
4006 | 5421 #else /* USDT2 */ |
5422 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( | |
5423 JNI_OK); | |
5424 #endif /* USDT2 */ | |
0 | 5425 return JNI_OK; |
5426 } | |
5427 | |
5428 JavaThread* thread = JavaThread::current(); | |
5429 if (thread->has_last_Java_frame()) { | |
4006 | 5430 #ifndef USDT2 |
0 | 5431 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR); |
4006 | 5432 #else /* USDT2 */ |
5433 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( | |
5434 (uint32_t) JNI_ERR); | |
5435 #endif /* USDT2 */ | |
0 | 5436 // Can't detach a thread that's running java, that can't work. |
5437 return JNI_ERR; | |
5438 } | |
5439 | |
5440 // Safepoint support. Have to do call-back to safepoint code, if in the | |
5441 // middel of a safepoint operation | |
5442 ThreadStateTransition::transition_from_native(thread, _thread_in_vm); | |
5443 | |
5444 // XXX: Note that JavaThread::exit() call below removes the guards on the | |
5445 // stack pages set up via enable_stack_{red,yellow}_zone() calls | |
5446 // above in jni_AttachCurrentThread. Unfortunately, while the setting | |
5447 // of the guards is visible in jni_AttachCurrentThread above, | |
5448 // the removal of the guards is buried below in JavaThread::exit() | |
5449 // here. The abstraction should be more symmetrically either exposed | |
5450 // or hidden (e.g. it could probably be hidden in the same | |
5451 // (platform-dependent) methods where we do alternate stack | |
5452 // maintenance work?) | |
5453 thread->exit(false, JavaThread::jni_detach); | |
5454 delete thread; | |
5455 | |
4006 | 5456 #ifndef USDT2 |
0 | 5457 DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
4006 | 5458 #else /* USDT2 */ |
5459 HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( | |
5460 JNI_OK); | |
5461 #endif /* USDT2 */ | |
0 | 5462 return JNI_OK; |
5463 } | |
5464 | |
4006 | 5465 #ifndef USDT2 |
0 | 5466 DT_RETURN_MARK_DECL(GetEnv, jint); |
4006 | 5467 #else /* USDT2 */ |
5468 DT_RETURN_MARK_DECL(GetEnv, jint | |
5469 , HOTSPOT_JNI_GETENV_RETURN(_ret_ref)); | |
5470 #endif /* USDT2 */ | |
0 | 5471 |
5472 jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) { | |
4006 | 5473 #ifndef USDT2 |
0 | 5474 DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version); |
4006 | 5475 #else /* USDT2 */ |
5476 HOTSPOT_JNI_GETENV_ENTRY( | |
5477 vm, penv, version); | |
5478 #endif /* USDT2 */ | |
0 | 5479 jint ret = JNI_ERR; |
5480 DT_RETURN_MARK(GetEnv, jint, (const jint&)ret); | |
5481 | |
5482 if (!vm_created) { | |
5483 *penv = NULL; | |
5484 ret = JNI_EDETACHED; | |
5485 return ret; | |
5486 } | |
5487 | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4708
diff
changeset
|
5488 if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) { |
0 | 5489 return ret; |
5490 } | |
5491 | |
5492 #ifndef JVMPI_VERSION_1 | |
5493 // need these in order to be polite about older agents | |
5494 #define JVMPI_VERSION_1 ((jint)0x10000001) | |
5495 #define JVMPI_VERSION_1_1 ((jint)0x10000002) | |
5496 #define JVMPI_VERSION_1_2 ((jint)0x10000003) | |
5497 #endif // !JVMPI_VERSION_1 | |
5498 | |
5499 Thread* thread = ThreadLocalStorage::thread(); | |
5500 if (thread != NULL && thread->is_Java_thread()) { | |
5501 if (Threads::is_supported_jni_version_including_1_1(version)) { | |
5502 *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment(); | |
5503 ret = JNI_OK; | |
5504 return ret; | |
5505 | |
5506 } else if (version == JVMPI_VERSION_1 || | |
5507 version == JVMPI_VERSION_1_1 || | |
5508 version == JVMPI_VERSION_1_2) { | |
5509 tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported."); | |
5510 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
5511 ret = JNI_EVERSION; | |
5512 return ret; | |
5513 } else if (JvmtiExport::is_jvmdi_version(version)) { | |
5514 tty->print_cr("FATAL ERROR: JVMDI is no longer supported."); | |
5515 tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); | |
5516 ret = JNI_EVERSION; | |
5517 return ret; | |
5518 } else { | |
5519 *penv = NULL; | |
5520 ret = JNI_EVERSION; | |
5521 return ret; | |
5522 } | |
5523 } else { | |
5524 *penv = NULL; | |
5525 ret = JNI_EDETACHED; | |
5526 return ret; | |
5527 } | |
5528 } | |
5529 | |
5530 | |
5531 jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) { | |
4006 | 5532 #ifndef USDT2 |
0 | 5533 DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args); |
4006 | 5534 #else /* USDT2 */ |
5535 HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY( | |
5536 vm, penv, _args); | |
5537 #endif /* USDT2 */ | |
0 | 5538 if (!vm_created) { |
4006 | 5539 #ifndef USDT2 |
0 | 5540 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR); |
4006 | 5541 #else /* USDT2 */ |
5542 HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( | |
5543 (uint32_t) JNI_ERR); | |
5544 #endif /* USDT2 */ | |
0 | 5545 return JNI_ERR; |
5546 } | |
5547 | |
5548 JNIWrapper("AttachCurrentThreadAsDaemon"); | |
5549 jint ret = attach_current_thread(vm, penv, _args, true); | |
4006 | 5550 #ifndef USDT2 |
0 | 5551 DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret); |
4006 | 5552 #else /* USDT2 */ |
5553 HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( | |
5554 ret); | |
5555 #endif /* USDT2 */ | |
0 | 5556 return ret; |
5557 } | |
5558 | |
5559 | |
5560 } // End extern "C" | |
5561 | |
5562 const struct JNIInvokeInterface_ jni_InvokeInterface = { | |
5563 NULL, | |
5564 NULL, | |
5565 NULL, | |
5566 | |
5567 jni_DestroyJavaVM, | |
5568 jni_AttachCurrentThread, | |
5569 jni_DetachCurrentThread, | |
5570 jni_GetEnv, | |
5571 jni_AttachCurrentThreadAsDaemon | |
5572 }; |