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