Mercurial > hg > graal-compiler
annotate src/share/vm/prims/unsafe.cpp @ 2182:9569fdf936ff
Made merge compile.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Wed, 16 Feb 2011 14:21:52 +0100 |
parents | 3582bf76420e |
children | d411927672ed |
rev | line source |
---|---|
0 | 1 /* |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1324
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1324
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1324
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/vmSymbols.hpp" | |
27 #include "memory/allocation.inline.hpp" | |
28 #include "prims/jni.h" | |
29 #include "prims/jvm.h" | |
30 #include "runtime/globals.hpp" | |
31 #include "runtime/interfaceSupport.hpp" | |
32 #include "runtime/reflection.hpp" | |
33 #include "runtime/reflectionCompat.hpp" | |
34 #include "runtime/synchronizer.hpp" | |
35 #include "services/threadService.hpp" | |
36 #include "utilities/copy.hpp" | |
37 #include "utilities/dtrace.hpp" | |
38 | |
0 | 39 /* |
40 * Implementation of class sun.misc.Unsafe | |
41 */ | |
42 | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
43 HS_DTRACE_PROBE_DECL3(hotspot, thread__park__begin, uintptr_t, int, long long); |
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
44 HS_DTRACE_PROBE_DECL1(hotspot, thread__park__end, uintptr_t); |
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
45 HS_DTRACE_PROBE_DECL1(hotspot, thread__unpark, uintptr_t); |
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
46 |
0 | 47 #define MAX_OBJECT_SIZE \ |
48 ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ | |
49 + ((julong)max_jint * sizeof(double)) ) | |
50 | |
51 | |
52 #define UNSAFE_ENTRY(result_type, header) \ | |
53 JVM_ENTRY(result_type, header) | |
54 | |
55 // Can't use UNSAFE_LEAF because it has the signature of a straight | |
56 // call into the runtime (just like JVM_LEAF, funny that) but it's | |
57 // called like a Java Native and thus the wrapper built for it passes | |
58 // arguments like a JNI call. It expects those arguments to be popped | |
59 // from the stack on Intel like all good JNI args are, and adjusts the | |
60 // stack according. Since the JVM_LEAF call expects no extra | |
61 // arguments the stack isn't popped in the C code, is pushed by the | |
62 // wrapper and we get sick. | |
63 //#define UNSAFE_LEAF(result_type, header) \ | |
64 // JVM_LEAF(result_type, header) | |
65 | |
66 #define UNSAFE_END JVM_END | |
67 | |
68 #define UnsafeWrapper(arg) /*nothing, for the present*/ | |
69 | |
70 | |
71 inline void* addr_from_java(jlong addr) { | |
72 // This assert fails in a variety of ways on 32-bit systems. | |
73 // It is impossible to predict whether native code that converts | |
74 // pointers to longs will sign-extend or zero-extend the addresses. | |
75 //assert(addr == (uintptr_t)addr, "must not be odd high bits"); | |
76 return (void*)(uintptr_t)addr; | |
77 } | |
78 | |
79 inline jlong addr_to_java(void* p) { | |
80 assert(p == (void*)(uintptr_t)p, "must not be odd high bits"); | |
81 return (uintptr_t)p; | |
82 } | |
83 | |
84 | |
85 // Note: The VM's obj_field and related accessors use byte-scaled | |
86 // ("unscaled") offsets, just as the unsafe methods do. | |
87 | |
88 // However, the method Unsafe.fieldOffset explicitly declines to | |
89 // guarantee this. The field offset values manipulated by the Java user | |
90 // through the Unsafe API are opaque cookies that just happen to be byte | |
91 // offsets. We represent this state of affairs by passing the cookies | |
92 // through conversion functions when going between the VM and the Unsafe API. | |
93 // The conversion functions just happen to be no-ops at present. | |
94 | |
95 inline jlong field_offset_to_byte_offset(jlong field_offset) { | |
96 return field_offset; | |
97 } | |
98 | |
99 inline jlong field_offset_from_byte_offset(jlong byte_offset) { | |
100 return byte_offset; | |
101 } | |
102 | |
103 inline jint invocation_key_from_method_slot(jint slot) { | |
104 return slot; | |
105 } | |
106 | |
107 inline jint invocation_key_to_method_slot(jint key) { | |
108 return key; | |
109 } | |
110 | |
111 inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { | |
112 jlong byte_offset = field_offset_to_byte_offset(field_offset); | |
113 #ifdef ASSERT | |
114 if (p != NULL) { | |
115 assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); | |
116 if (byte_offset == (jint)byte_offset) { | |
117 void* ptr_plus_disp = (address)p + byte_offset; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
118 assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp, |
0 | 119 "raw [ptr+disp] must be consistent with oop::field_base"); |
120 } | |
121 } | |
122 #endif | |
123 if (sizeof(char*) == sizeof(jint)) // (this constant folds!) | |
124 return (address)p + (jint) byte_offset; | |
125 else | |
126 return (address)p + byte_offset; | |
127 } | |
128 | |
129 // Externally callable versions: | |
130 // (Use these in compiler intrinsics which emulate unsafe primitives.) | |
131 jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) { | |
132 return field_offset; | |
133 } | |
134 jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) { | |
135 return byte_offset; | |
136 } | |
137 jint Unsafe_invocation_key_from_method_slot(jint slot) { | |
138 return invocation_key_from_method_slot(slot); | |
139 } | |
140 jint Unsafe_invocation_key_to_method_slot(jint key) { | |
141 return invocation_key_to_method_slot(key); | |
142 } | |
143 | |
144 | |
145 ///// Data in the Java heap. | |
146 | |
147 #define GET_FIELD(obj, offset, type_name, v) \ | |
148 oop p = JNIHandles::resolve(obj); \ | |
149 type_name v = *(type_name*)index_oop_from_field_offset_long(p, offset) | |
150 | |
151 #define SET_FIELD(obj, offset, type_name, x) \ | |
152 oop p = JNIHandles::resolve(obj); \ | |
153 *(type_name*)index_oop_from_field_offset_long(p, offset) = x | |
154 | |
155 #define GET_FIELD_VOLATILE(obj, offset, type_name, v) \ | |
156 oop p = JNIHandles::resolve(obj); \ | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
157 volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset)); |
0 | 158 |
159 #define SET_FIELD_VOLATILE(obj, offset, type_name, x) \ | |
160 oop p = JNIHandles::resolve(obj); \ | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
161 OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), x); |
0 | 162 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
163 // Macros for oops that check UseCompressedOops |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
164 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
165 #define GET_OOP_FIELD(obj, offset, v) \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
166 oop p = JNIHandles::resolve(obj); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
167 oop v; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
168 if (UseCompressedOops) { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
169 narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
170 v = oopDesc::decode_heap_oop(n); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
171 } else { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
172 v = *(oop*)index_oop_from_field_offset_long(p, offset); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
173 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
174 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
175 #define GET_OOP_FIELD_VOLATILE(obj, offset, v) \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
176 oop p = JNIHandles::resolve(obj); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
177 volatile oop v; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
178 if (UseCompressedOops) { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
179 volatile narrowOop n = *(volatile narrowOop*)index_oop_from_field_offset_long(p, offset); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
180 v = oopDesc::decode_heap_oop(n); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
181 } else { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
182 v = *(volatile oop*)index_oop_from_field_offset_long(p, offset); \ |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
183 } \ |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
184 OrderAccess::acquire(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
185 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
186 |
0 | 187 // Get/SetObject must be special-cased, since it works with handles. |
188 | |
189 // The xxx140 variants for backward compatibility do not allow a full-width offset. | |
190 UNSAFE_ENTRY(jobject, Unsafe_GetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) | |
191 UnsafeWrapper("Unsafe_GetObject"); | |
192 if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
193 GET_OOP_FIELD(obj, offset, v) |
0 | 194 return JNIHandles::make_local(env, v); |
195 UNSAFE_END | |
196 | |
197 UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h)) | |
198 UnsafeWrapper("Unsafe_SetObject"); | |
199 if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); | |
200 oop x = JNIHandles::resolve(x_h); | |
201 //SET_FIELD(obj, offset, oop, x); | |
202 oop p = JNIHandles::resolve(obj); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
203 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
204 if (x != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
205 // If there is a heap base pointer, we are obliged to emit a store barrier. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
206 oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
207 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
208 narrowOop n = oopDesc::encode_heap_oop_not_null(x); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
209 *(narrowOop*)index_oop_from_field_offset_long(p, offset) = n; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
210 } |
0 | 211 } else { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
212 if (x != NULL) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
213 // If there is a heap base pointer, we are obliged to emit a store barrier. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
214 oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
215 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
216 *(oop*)index_oop_from_field_offset_long(p, offset) = x; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
217 } |
0 | 218 } |
219 UNSAFE_END | |
220 | |
221 // The normal variants allow a null base pointer with an arbitrary address. | |
222 // But if the base pointer is non-null, the offset should make some sense. | |
223 // That is, it should be in the range [0, MAX_OBJECT_SIZE]. | |
224 UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) | |
225 UnsafeWrapper("Unsafe_GetObject"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
226 GET_OOP_FIELD(obj, offset, v) |
0 | 227 return JNIHandles::make_local(env, v); |
228 UNSAFE_END | |
229 | |
230 UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) | |
231 UnsafeWrapper("Unsafe_SetObject"); | |
232 oop x = JNIHandles::resolve(x_h); | |
233 oop p = JNIHandles::resolve(obj); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
234 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
235 oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
236 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
237 oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
238 } |
0 | 239 UNSAFE_END |
240 | |
241 UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) | |
242 UnsafeWrapper("Unsafe_GetObjectVolatile"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
243 GET_OOP_FIELD_VOLATILE(obj, offset, v) |
0 | 244 return JNIHandles::make_local(env, v); |
245 UNSAFE_END | |
246 | |
247 UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) | |
248 UnsafeWrapper("Unsafe_SetObjectVolatile"); | |
249 oop x = JNIHandles::resolve(x_h); | |
250 oop p = JNIHandles::resolve(obj); | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
251 void* addr = index_oop_from_field_offset_long(p, offset); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
252 OrderAccess::release(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
253 if (UseCompressedOops) { |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
254 oop_store((narrowOop*)addr, x); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
255 } else { |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
256 oop_store((oop*)addr, x); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
257 } |
0 | 258 OrderAccess::fence(); |
259 UNSAFE_END | |
260 | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
261 #if defined(SPARC) || defined(X86) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
262 // Sparc and X86 have atomic jlong (8 bytes) instructions |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
263 |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
264 #else |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
265 // Keep old code for platforms which may not have atomic jlong (8 bytes) instructions |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
266 |
0 | 267 // Volatile long versions must use locks if !VM_Version::supports_cx8(). |
268 // support_cx8 is a surrogate for 'supports atomic long memory ops'. | |
269 | |
270 UNSAFE_ENTRY(jlong, Unsafe_GetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) | |
271 UnsafeWrapper("Unsafe_GetLongVolatile"); | |
272 { | |
273 if (VM_Version::supports_cx8()) { | |
274 GET_FIELD_VOLATILE(obj, offset, jlong, v); | |
275 return v; | |
276 } | |
277 else { | |
278 Handle p (THREAD, JNIHandles::resolve(obj)); | |
279 jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); | |
280 ObjectLocker ol(p, THREAD); | |
281 jlong value = *addr; | |
282 return value; | |
283 } | |
284 } | |
285 UNSAFE_END | |
286 | |
287 UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) | |
288 UnsafeWrapper("Unsafe_SetLongVolatile"); | |
289 { | |
290 if (VM_Version::supports_cx8()) { | |
291 SET_FIELD_VOLATILE(obj, offset, jlong, x); | |
292 } | |
293 else { | |
294 Handle p (THREAD, JNIHandles::resolve(obj)); | |
295 jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); | |
296 ObjectLocker ol(p, THREAD); | |
297 *addr = x; | |
298 } | |
299 } | |
300 UNSAFE_END | |
301 | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
302 #endif // not SPARC and not X86 |
0 | 303 |
304 #define DEFINE_GETSETOOP(jboolean, Boolean) \ | |
305 \ | |
306 UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) \ | |
307 UnsafeWrapper("Unsafe_Get"#Boolean); \ | |
308 if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); \ | |
309 GET_FIELD(obj, offset, jboolean, v); \ | |
310 return v; \ | |
311 UNSAFE_END \ | |
312 \ | |
313 UNSAFE_ENTRY(void, Unsafe_Set##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jboolean x)) \ | |
314 UnsafeWrapper("Unsafe_Set"#Boolean); \ | |
315 if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); \ | |
316 SET_FIELD(obj, offset, jboolean, x); \ | |
317 UNSAFE_END \ | |
318 \ | |
319 UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ | |
320 UnsafeWrapper("Unsafe_Get"#Boolean); \ | |
321 GET_FIELD(obj, offset, jboolean, v); \ | |
322 return v; \ | |
323 UNSAFE_END \ | |
324 \ | |
325 UNSAFE_ENTRY(void, Unsafe_Set##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ | |
326 UnsafeWrapper("Unsafe_Set"#Boolean); \ | |
327 SET_FIELD(obj, offset, jboolean, x); \ | |
328 UNSAFE_END \ | |
329 \ | |
330 // END DEFINE_GETSETOOP. | |
331 | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
332 DEFINE_GETSETOOP(jboolean, Boolean) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
333 DEFINE_GETSETOOP(jbyte, Byte) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
334 DEFINE_GETSETOOP(jshort, Short); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
335 DEFINE_GETSETOOP(jchar, Char); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
336 DEFINE_GETSETOOP(jint, Int); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
337 DEFINE_GETSETOOP(jlong, Long); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
338 DEFINE_GETSETOOP(jfloat, Float); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
339 DEFINE_GETSETOOP(jdouble, Double); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
340 |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
341 #undef DEFINE_GETSETOOP |
0 | 342 |
343 #define DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) \ | |
344 \ | |
345 UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ | |
346 UnsafeWrapper("Unsafe_Get"#Boolean); \ | |
347 GET_FIELD_VOLATILE(obj, offset, jboolean, v); \ | |
348 return v; \ | |
349 UNSAFE_END \ | |
350 \ | |
351 UNSAFE_ENTRY(void, Unsafe_Set##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ | |
352 UnsafeWrapper("Unsafe_Set"#Boolean); \ | |
353 SET_FIELD_VOLATILE(obj, offset, jboolean, x); \ | |
354 UNSAFE_END \ | |
355 \ | |
356 // END DEFINE_GETSETOOP_VOLATILE. | |
357 | |
358 DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) | |
359 DEFINE_GETSETOOP_VOLATILE(jbyte, Byte) | |
360 DEFINE_GETSETOOP_VOLATILE(jshort, Short); | |
361 DEFINE_GETSETOOP_VOLATILE(jchar, Char); | |
362 DEFINE_GETSETOOP_VOLATILE(jint, Int); | |
363 DEFINE_GETSETOOP_VOLATILE(jfloat, Float); | |
364 DEFINE_GETSETOOP_VOLATILE(jdouble, Double); | |
365 | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
366 #if defined(SPARC) || defined(X86) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
367 // Sparc and X86 have atomic jlong (8 bytes) instructions |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
368 DEFINE_GETSETOOP_VOLATILE(jlong, Long); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
369 #endif |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
370 |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
371 #undef DEFINE_GETSETOOP_VOLATILE |
0 | 372 |
373 // The non-intrinsified versions of setOrdered just use setVolatile | |
374 | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
375 UNSAFE_ENTRY(void, Unsafe_SetOrderedInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint x)) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
376 UnsafeWrapper("Unsafe_SetOrderedInt"); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
377 SET_FIELD_VOLATILE(obj, offset, jint, x); |
0 | 378 UNSAFE_END |
379 | |
380 UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) | |
381 UnsafeWrapper("Unsafe_SetOrderedObject"); | |
382 oop x = JNIHandles::resolve(x_h); | |
383 oop p = JNIHandles::resolve(obj); | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
384 void* addr = index_oop_from_field_offset_long(p, offset); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
385 OrderAccess::release(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
386 if (UseCompressedOops) { |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
387 oop_store((narrowOop*)addr, x); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
388 } else { |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
389 oop_store((oop*)addr, x); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
390 } |
0 | 391 OrderAccess::fence(); |
392 UNSAFE_END | |
393 | |
394 UNSAFE_ENTRY(void, Unsafe_SetOrderedLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) | |
395 UnsafeWrapper("Unsafe_SetOrderedLong"); | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
396 #if defined(SPARC) || defined(X86) |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
397 // Sparc and X86 have atomic jlong (8 bytes) instructions |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
398 SET_FIELD_VOLATILE(obj, offset, jlong, x); |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
399 #else |
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
400 // Keep old code for platforms which may not have atomic long (8 bytes) instructions |
0 | 401 { |
402 if (VM_Version::supports_cx8()) { | |
403 SET_FIELD_VOLATILE(obj, offset, jlong, x); | |
404 } | |
405 else { | |
406 Handle p (THREAD, JNIHandles::resolve(obj)); | |
407 jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); | |
408 ObjectLocker ol(p, THREAD); | |
409 *addr = x; | |
410 } | |
411 } | |
2114
4fc084dac61e
7009756: volatile variables could be broken throw reflection API
kvn
parents:
1972
diff
changeset
|
412 #endif |
0 | 413 UNSAFE_END |
414 | |
415 ////// Data in the C heap. | |
416 | |
417 // Note: These do not throw NullPointerException for bad pointers. | |
418 // They just crash. Only a oop base pointer can generate a NullPointerException. | |
419 // | |
420 #define DEFINE_GETSETNATIVE(java_type, Type, native_type) \ | |
421 \ | |
422 UNSAFE_ENTRY(java_type, Unsafe_GetNative##Type(JNIEnv *env, jobject unsafe, jlong addr)) \ | |
423 UnsafeWrapper("Unsafe_GetNative"#Type); \ | |
424 void* p = addr_from_java(addr); \ | |
425 JavaThread* t = JavaThread::current(); \ | |
426 t->set_doing_unsafe_access(true); \ | |
427 java_type x = *(volatile native_type*)p; \ | |
428 t->set_doing_unsafe_access(false); \ | |
429 return x; \ | |
430 UNSAFE_END \ | |
431 \ | |
432 UNSAFE_ENTRY(void, Unsafe_SetNative##Type(JNIEnv *env, jobject unsafe, jlong addr, java_type x)) \ | |
433 UnsafeWrapper("Unsafe_SetNative"#Type); \ | |
434 JavaThread* t = JavaThread::current(); \ | |
435 t->set_doing_unsafe_access(true); \ | |
436 void* p = addr_from_java(addr); \ | |
437 *(volatile native_type*)p = x; \ | |
438 t->set_doing_unsafe_access(false); \ | |
439 UNSAFE_END \ | |
440 \ | |
441 // END DEFINE_GETSETNATIVE. | |
442 | |
443 DEFINE_GETSETNATIVE(jbyte, Byte, signed char) | |
444 DEFINE_GETSETNATIVE(jshort, Short, signed short); | |
445 DEFINE_GETSETNATIVE(jchar, Char, unsigned short); | |
446 DEFINE_GETSETNATIVE(jint, Int, jint); | |
447 // no long -- handled specially | |
448 DEFINE_GETSETNATIVE(jfloat, Float, float); | |
449 DEFINE_GETSETNATIVE(jdouble, Double, double); | |
450 | |
451 #undef DEFINE_GETSETNATIVE | |
452 | |
453 UNSAFE_ENTRY(jlong, Unsafe_GetNativeLong(JNIEnv *env, jobject unsafe, jlong addr)) | |
454 UnsafeWrapper("Unsafe_GetNativeLong"); | |
455 JavaThread* t = JavaThread::current(); | |
456 // We do it this way to avoid problems with access to heap using 64 | |
457 // bit loads, as jlong in heap could be not 64-bit aligned, and on | |
458 // some CPUs (SPARC) it leads to SIGBUS. | |
459 t->set_doing_unsafe_access(true); | |
460 void* p = addr_from_java(addr); | |
461 jlong x; | |
462 if (((intptr_t)p & 7) == 0) { | |
463 // jlong is aligned, do a volatile access | |
464 x = *(volatile jlong*)p; | |
465 } else { | |
466 jlong_accessor acc; | |
467 acc.words[0] = ((volatile jint*)p)[0]; | |
468 acc.words[1] = ((volatile jint*)p)[1]; | |
469 x = acc.long_value; | |
470 } | |
471 t->set_doing_unsafe_access(false); | |
472 return x; | |
473 UNSAFE_END | |
474 | |
475 UNSAFE_ENTRY(void, Unsafe_SetNativeLong(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) | |
476 UnsafeWrapper("Unsafe_SetNativeLong"); | |
477 JavaThread* t = JavaThread::current(); | |
478 // see comment for Unsafe_GetNativeLong | |
479 t->set_doing_unsafe_access(true); | |
480 void* p = addr_from_java(addr); | |
481 if (((intptr_t)p & 7) == 0) { | |
482 // jlong is aligned, do a volatile access | |
483 *(volatile jlong*)p = x; | |
484 } else { | |
485 jlong_accessor acc; | |
486 acc.long_value = x; | |
487 ((volatile jint*)p)[0] = acc.words[0]; | |
488 ((volatile jint*)p)[1] = acc.words[1]; | |
489 } | |
490 t->set_doing_unsafe_access(false); | |
491 UNSAFE_END | |
492 | |
493 | |
494 UNSAFE_ENTRY(jlong, Unsafe_GetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr)) | |
495 UnsafeWrapper("Unsafe_GetNativeAddress"); | |
496 void* p = addr_from_java(addr); | |
497 return addr_to_java(*(void**)p); | |
498 UNSAFE_END | |
499 | |
500 UNSAFE_ENTRY(void, Unsafe_SetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) | |
501 UnsafeWrapper("Unsafe_SetNativeAddress"); | |
502 void* p = addr_from_java(addr); | |
503 *(void**)p = addr_from_java(x); | |
504 UNSAFE_END | |
505 | |
506 | |
507 ////// Allocation requests | |
508 | |
509 UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) | |
510 UnsafeWrapper("Unsafe_AllocateInstance"); | |
511 { | |
512 ThreadToNativeFromVM ttnfv(thread); | |
513 return env->AllocObject(cls); | |
514 } | |
515 UNSAFE_END | |
516 | |
517 UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory(JNIEnv *env, jobject unsafe, jlong size)) | |
518 UnsafeWrapper("Unsafe_AllocateMemory"); | |
519 size_t sz = (size_t)size; | |
520 if (sz != (julong)size || size < 0) { | |
521 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); | |
522 } | |
523 if (sz == 0) { | |
524 return 0; | |
525 } | |
526 sz = round_to(sz, HeapWordSize); | |
527 void* x = os::malloc(sz); | |
528 if (x == NULL) { | |
529 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); | |
530 } | |
531 //Copy::fill_to_words((HeapWord*)x, sz / HeapWordSize); | |
532 return addr_to_java(x); | |
533 UNSAFE_END | |
534 | |
535 UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) | |
536 UnsafeWrapper("Unsafe_ReallocateMemory"); | |
537 void* p = addr_from_java(addr); | |
538 size_t sz = (size_t)size; | |
539 if (sz != (julong)size || size < 0) { | |
540 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); | |
541 } | |
542 if (sz == 0) { | |
543 os::free(p); | |
544 return 0; | |
545 } | |
546 sz = round_to(sz, HeapWordSize); | |
547 void* x = (p == NULL) ? os::malloc(sz) : os::realloc(p, sz); | |
548 if (x == NULL) { | |
549 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); | |
550 } | |
551 return addr_to_java(x); | |
552 UNSAFE_END | |
553 | |
554 UNSAFE_ENTRY(void, Unsafe_FreeMemory(JNIEnv *env, jobject unsafe, jlong addr)) | |
555 UnsafeWrapper("Unsafe_FreeMemory"); | |
556 void* p = addr_from_java(addr); | |
557 if (p == NULL) { | |
558 return; | |
559 } | |
560 os::free(p); | |
561 UNSAFE_END | |
562 | |
563 UNSAFE_ENTRY(void, Unsafe_SetMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size, jbyte value)) | |
564 UnsafeWrapper("Unsafe_SetMemory"); | |
565 size_t sz = (size_t)size; | |
566 if (sz != (julong)size || size < 0) { | |
567 THROW(vmSymbols::java_lang_IllegalArgumentException()); | |
568 } | |
569 char* p = (char*) addr_from_java(addr); | |
570 Copy::fill_to_memory_atomic(p, sz, value); | |
571 UNSAFE_END | |
572 | |
573 UNSAFE_ENTRY(void, Unsafe_SetMemory2(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) | |
574 UnsafeWrapper("Unsafe_SetMemory"); | |
575 size_t sz = (size_t)size; | |
576 if (sz != (julong)size || size < 0) { | |
577 THROW(vmSymbols::java_lang_IllegalArgumentException()); | |
578 } | |
579 oop base = JNIHandles::resolve(obj); | |
580 void* p = index_oop_from_field_offset_long(base, offset); | |
581 Copy::fill_to_memory_atomic(p, sz, value); | |
582 UNSAFE_END | |
583 | |
584 UNSAFE_ENTRY(void, Unsafe_CopyMemory(JNIEnv *env, jobject unsafe, jlong srcAddr, jlong dstAddr, jlong size)) | |
585 UnsafeWrapper("Unsafe_CopyMemory"); | |
586 if (size == 0) { | |
587 return; | |
588 } | |
589 size_t sz = (size_t)size; | |
590 if (sz != (julong)size || size < 0) { | |
591 THROW(vmSymbols::java_lang_IllegalArgumentException()); | |
592 } | |
593 void* src = addr_from_java(srcAddr); | |
594 void* dst = addr_from_java(dstAddr); | |
595 Copy::conjoint_memory_atomic(src, dst, sz); | |
596 UNSAFE_END | |
597 | |
598 UNSAFE_ENTRY(void, Unsafe_CopyMemory2(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) | |
599 UnsafeWrapper("Unsafe_CopyMemory"); | |
600 if (size == 0) { | |
601 return; | |
602 } | |
603 size_t sz = (size_t)size; | |
604 if (sz != (julong)size || size < 0) { | |
605 THROW(vmSymbols::java_lang_IllegalArgumentException()); | |
606 } | |
607 oop srcp = JNIHandles::resolve(srcObj); | |
608 oop dstp = JNIHandles::resolve(dstObj); | |
609 if (dstp != NULL && !dstp->is_typeArray()) { | |
610 // NYI: This works only for non-oop arrays at present. | |
611 // Generalizing it would be reasonable, but requires card marking. | |
612 // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad. | |
613 THROW(vmSymbols::java_lang_IllegalArgumentException()); | |
614 } | |
615 void* src = index_oop_from_field_offset_long(srcp, srcOffset); | |
616 void* dst = index_oop_from_field_offset_long(dstp, dstOffset); | |
617 Copy::conjoint_memory_atomic(src, dst, sz); | |
618 UNSAFE_END | |
619 | |
620 | |
621 ////// Random queries | |
622 | |
623 // See comment at file start about UNSAFE_LEAF | |
624 //UNSAFE_LEAF(jint, Unsafe_AddressSize()) | |
625 UNSAFE_ENTRY(jint, Unsafe_AddressSize(JNIEnv *env, jobject unsafe)) | |
626 UnsafeWrapper("Unsafe_AddressSize"); | |
627 return sizeof(void*); | |
628 UNSAFE_END | |
629 | |
630 // See comment at file start about UNSAFE_LEAF | |
631 //UNSAFE_LEAF(jint, Unsafe_PageSize()) | |
632 UNSAFE_ENTRY(jint, Unsafe_PageSize(JNIEnv *env, jobject unsafe)) | |
633 UnsafeWrapper("Unsafe_PageSize"); | |
634 return os::vm_page_size(); | |
635 UNSAFE_END | |
636 | |
637 jint find_field_offset(jobject field, int must_be_static, TRAPS) { | |
638 if (field == NULL) { | |
639 THROW_0(vmSymbols::java_lang_NullPointerException()); | |
640 } | |
641 | |
642 oop reflected = JNIHandles::resolve_non_null(field); | |
643 oop mirror = java_lang_reflect_Field::clazz(reflected); | |
644 klassOop k = java_lang_Class::as_klassOop(mirror); | |
645 int slot = java_lang_reflect_Field::slot(reflected); | |
646 int modifiers = java_lang_reflect_Field::modifiers(reflected); | |
647 | |
648 if (must_be_static >= 0) { | |
649 int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); | |
650 if (must_be_static != really_is_static) { | |
651 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); | |
652 } | |
653 } | |
654 | |
655 int offset = instanceKlass::cast(k)->offset_from_fields(slot); | |
656 return field_offset_from_byte_offset(offset); | |
657 } | |
658 | |
659 UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) | |
660 UnsafeWrapper("Unsafe_ObjectFieldOffset"); | |
661 return find_field_offset(field, 0, THREAD); | |
662 UNSAFE_END | |
663 | |
664 UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) | |
665 UnsafeWrapper("Unsafe_StaticFieldOffset"); | |
666 return find_field_offset(field, 1, THREAD); | |
667 UNSAFE_END | |
668 | |
669 UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBaseFromField(JNIEnv *env, jobject unsafe, jobject field)) | |
670 UnsafeWrapper("Unsafe_StaticFieldBase"); | |
671 // Note: In this VM implementation, a field address is always a short | |
672 // offset from the base of a a klass metaobject. Thus, the full dynamic | |
673 // range of the return type is never used. However, some implementations | |
674 // might put the static field inside an array shared by many classes, | |
675 // or even at a fixed address, in which case the address could be quite | |
676 // large. In that last case, this function would return NULL, since | |
677 // the address would operate alone, without any base pointer. | |
678 | |
679 if (field == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); | |
680 | |
681 oop reflected = JNIHandles::resolve_non_null(field); | |
682 oop mirror = java_lang_reflect_Field::clazz(reflected); | |
683 int modifiers = java_lang_reflect_Field::modifiers(reflected); | |
684 | |
685 if ((modifiers & JVM_ACC_STATIC) == 0) { | |
686 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); | |
687 } | |
688 | |
689 return JNIHandles::make_local(env, java_lang_Class::as_klassOop(mirror)); | |
690 UNSAFE_END | |
691 | |
692 //@deprecated | |
693 UNSAFE_ENTRY(jint, Unsafe_FieldOffset(JNIEnv *env, jobject unsafe, jobject field)) | |
694 UnsafeWrapper("Unsafe_FieldOffset"); | |
695 // tries (but fails) to be polymorphic between static and non-static: | |
696 jlong offset = find_field_offset(field, -1, THREAD); | |
697 guarantee(offset == (jint)offset, "offset fits in 32 bits"); | |
698 return (jint)offset; | |
699 UNSAFE_END | |
700 | |
701 //@deprecated | |
702 UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBaseFromClass(JNIEnv *env, jobject unsafe, jobject clazz)) | |
703 UnsafeWrapper("Unsafe_StaticFieldBase"); | |
704 if (clazz == NULL) { | |
705 THROW_0(vmSymbols::java_lang_NullPointerException()); | |
706 } | |
707 return JNIHandles::make_local(env, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz))); | |
708 UNSAFE_END | |
709 | |
710 UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized(JNIEnv *env, jobject unsafe, jobject clazz)) | |
711 UnsafeWrapper("Unsafe_EnsureClassInitialized"); | |
712 if (clazz == NULL) { | |
713 THROW(vmSymbols::java_lang_NullPointerException()); | |
714 } | |
715 oop mirror = JNIHandles::resolve_non_null(clazz); | |
716 instanceKlass* k = instanceKlass::cast(java_lang_Class::as_klassOop(mirror)); | |
717 if (k != NULL) { | |
718 k->initialize(CHECK); | |
719 } | |
720 UNSAFE_END | |
721 | |
722 static void getBaseAndScale(int& base, int& scale, jclass acls, TRAPS) { | |
723 if (acls == NULL) { | |
724 THROW(vmSymbols::java_lang_NullPointerException()); | |
725 } | |
726 oop mirror = JNIHandles::resolve_non_null(acls); | |
727 klassOop k = java_lang_Class::as_klassOop(mirror); | |
728 if (k == NULL || !k->klass_part()->oop_is_array()) { | |
729 THROW(vmSymbols::java_lang_InvalidClassException()); | |
730 } else if (k->klass_part()->oop_is_objArray()) { | |
731 base = arrayOopDesc::base_offset_in_bytes(T_OBJECT); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
732 scale = heapOopSize; |
0 | 733 } else if (k->klass_part()->oop_is_typeArray()) { |
734 typeArrayKlass* tak = typeArrayKlass::cast(k); | |
735 base = tak->array_header_in_bytes(); | |
736 assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); | |
737 scale = (1 << tak->log2_element_size()); | |
738 } else { | |
739 ShouldNotReachHere(); | |
740 } | |
741 } | |
742 | |
743 UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset(JNIEnv *env, jobject unsafe, jclass acls)) | |
744 UnsafeWrapper("Unsafe_ArrayBaseOffset"); | |
745 int base, scale; | |
746 getBaseAndScale(base, scale, acls, CHECK_0); | |
747 return field_offset_from_byte_offset(base); | |
748 UNSAFE_END | |
749 | |
750 | |
751 UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale(JNIEnv *env, jobject unsafe, jclass acls)) | |
752 UnsafeWrapper("Unsafe_ArrayIndexScale"); | |
753 int base, scale; | |
754 getBaseAndScale(base, scale, acls, CHECK_0); | |
755 // This VM packs both fields and array elements down to the byte. | |
756 // But watch out: If this changes, so that array references for | |
757 // a given primitive type (say, T_BOOLEAN) use different memory units | |
758 // than fields, this method MUST return zero for such arrays. | |
759 // For example, the VM used to store sub-word sized fields in full | |
760 // words in the object layout, so that accessors like getByte(Object,int) | |
761 // did not really do what one might expect for arrays. Therefore, | |
762 // this function used to report a zero scale factor, so that the user | |
763 // would know not to attempt to access sub-word array elements. | |
764 // // Code for unpacked fields: | |
765 // if (scale < wordSize) return 0; | |
766 | |
767 // The following allows for a pretty general fieldOffset cookie scheme, | |
768 // but requires it to be linear in byte offset. | |
769 return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); | |
770 UNSAFE_END | |
771 | |
772 | |
773 static inline void throw_new(JNIEnv *env, const char *ename) { | |
774 char buf[100]; | |
775 strcpy(buf, "java/lang/"); | |
776 strcat(buf, ename); | |
777 jclass cls = env->FindClass(buf); | |
778 char* msg = NULL; | |
779 env->ThrowNew(cls, msg); | |
780 } | |
781 | |
782 static jclass Unsafe_DefineClass(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { | |
783 { | |
784 // Code lifted from JDK 1.3 ClassLoader.c | |
785 | |
786 jbyte *body; | |
787 char *utfName; | |
788 jclass result = 0; | |
789 char buf[128]; | |
790 | |
791 if (UsePerfData) { | |
792 ClassLoader::unsafe_defineClassCallCounter()->inc(); | |
793 } | |
794 | |
795 if (data == NULL) { | |
796 throw_new(env, "NullPointerException"); | |
797 return 0; | |
798 } | |
799 | |
800 /* Work around 4153825. malloc crashes on Solaris when passed a | |
801 * negative size. | |
802 */ | |
803 if (length < 0) { | |
804 throw_new(env, "ArrayIndexOutOfBoundsException"); | |
805 return 0; | |
806 } | |
807 | |
808 body = NEW_C_HEAP_ARRAY(jbyte, length); | |
809 | |
810 if (body == 0) { | |
811 throw_new(env, "OutOfMemoryError"); | |
812 return 0; | |
813 } | |
814 | |
815 env->GetByteArrayRegion(data, offset, length, body); | |
816 | |
817 if (env->ExceptionOccurred()) | |
818 goto free_body; | |
819 | |
820 if (name != NULL) { | |
821 uint len = env->GetStringUTFLength(name); | |
822 int unicode_len = env->GetStringLength(name); | |
823 if (len >= sizeof(buf)) { | |
824 utfName = NEW_C_HEAP_ARRAY(char, len + 1); | |
825 if (utfName == NULL) { | |
826 throw_new(env, "OutOfMemoryError"); | |
827 goto free_body; | |
828 } | |
829 } else { | |
830 utfName = buf; | |
831 } | |
832 env->GetStringUTFRegion(name, 0, unicode_len, utfName); | |
833 //VerifyFixClassname(utfName); | |
834 for (uint i = 0; i < len; i++) { | |
835 if (utfName[i] == '.') utfName[i] = '/'; | |
836 } | |
837 } else { | |
838 utfName = NULL; | |
839 } | |
840 | |
841 result = JVM_DefineClass(env, utfName, loader, body, length, pd); | |
842 | |
843 if (utfName && utfName != buf) | |
844 FREE_C_HEAP_ARRAY(char, utfName); | |
845 | |
846 free_body: | |
847 FREE_C_HEAP_ARRAY(jbyte, body); | |
848 return result; | |
849 } | |
850 } | |
851 | |
852 | |
853 UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length)) | |
854 UnsafeWrapper("Unsafe_DefineClass"); | |
855 { | |
856 ThreadToNativeFromVM ttnfv(thread); | |
857 | |
858 int depthFromDefineClass0 = 1; | |
859 jclass caller = JVM_GetCallerClass(env, depthFromDefineClass0); | |
860 jobject loader = (caller == NULL) ? NULL : JVM_GetClassLoader(env, caller); | |
861 jobject pd = (caller == NULL) ? NULL : JVM_GetProtectionDomain(env, caller); | |
862 | |
863 return Unsafe_DefineClass(env, name, data, offset, length, loader, pd); | |
864 } | |
865 UNSAFE_END | |
866 | |
867 | |
868 UNSAFE_ENTRY(jclass, Unsafe_DefineClass1(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) | |
869 UnsafeWrapper("Unsafe_DefineClass"); | |
870 { | |
871 ThreadToNativeFromVM ttnfv(thread); | |
872 | |
873 return Unsafe_DefineClass(env, name, data, offset, length, loader, pd); | |
874 } | |
875 UNSAFE_END | |
876 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
877 #define DAC_Args CLS"[B["OBJ |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
878 // define a class but do not make it known to the class loader or system dictionary |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
879 // - host_class: supplies context for linkage, access control, protection domain, and class loader |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
880 // - data: bytes of a class file, a raw memory address (length gives the number of bytes) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
881 // - cp_patches: where non-null entries exist, they replace corresponding CP entries in data |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
882 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
883 // When you load an anonymous class U, it works as if you changed its name just before loading, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
884 // to a name that you will never use again. Since the name is lost, no other class can directly |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
885 // link to any member of U. Just after U is loaded, the only way to use it is reflectively, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
886 // through java.lang.Class methods like Class.newInstance. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
887 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
888 // Access checks for linkage sites within U continue to follow the same rules as for named classes. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
889 // The package of an anonymous class is given by the package qualifier on the name under which it was loaded. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
890 // An anonymous class also has special privileges to access any member of its host class. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
891 // This is the main reason why this loading operation is unsafe. The purpose of this is to |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
892 // allow language implementations to simulate "open classes"; a host class in effect gets |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
893 // new code when an anonymous class is loaded alongside it. A less convenient but more |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
894 // standard way to do this is with reflection, which can also be set to ignore access |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
895 // restrictions. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
896 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
897 // Access into an anonymous class is possible only through reflection. Therefore, there |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
898 // are no special access rules for calling into an anonymous class. The relaxed access |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
899 // rule for the host class is applied in the opposite direction: A host class reflectively |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
900 // access one of its anonymous classes. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
901 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
902 // If you load the same bytecodes twice, you get two different classes. You can reload |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
903 // the same bytecodes with or without varying CP patches. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
904 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
905 // By using the CP patching array, you can have a new anonymous class U2 refer to an older one U1. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
906 // The bytecodes for U2 should refer to U1 by a symbolic name (doesn't matter what the name is). |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
907 // The CONSTANT_Class entry for that name can be patched to refer directly to U1. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
908 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
909 // This allows, for example, U2 to use U1 as a superclass or super-interface, or as |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
910 // an outer class (so that U2 is an anonymous inner class of anonymous U1). |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
911 // It is not possible for a named class, or an older anonymous class, to refer by |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
912 // name (via its CP) to a newer anonymous class. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
913 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
914 // CP patching may also be used to modify (i.e., hack) the names of methods, classes, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
915 // or type descriptors used in the loaded anonymous class. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
916 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
917 // Finally, CP patching may be used to introduce "live" objects into the constant pool, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
918 // instead of "dead" strings. A compiled statement like println((Object)"hello") can |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
919 // be changed to println(greeting), where greeting is an arbitrary object created before |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
920 // the anonymous class is loaded. This is useful in dynamic languages, in which |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
921 // various kinds of metaobjects must be introduced as constants into bytecode. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
922 // Note the cast (Object), which tells the verifier to expect an arbitrary object, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
923 // not just a literal string. For such ldc instructions, the verifier uses the |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
924 // type Object instead of String, if the loaded constant is not in fact a String. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
925 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
926 static oop |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
927 Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
928 jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
929 HeapWord* *temp_alloc, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
930 TRAPS) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
931 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
932 if (UsePerfData) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
933 ClassLoader::unsafe_defineClassCallCounter()->inc(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
934 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
935 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
936 if (data == NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
937 THROW_0(vmSymbols::java_lang_NullPointerException()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
938 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
939 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
940 jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
941 jint word_length = (length + sizeof(HeapWord)-1) / sizeof(HeapWord); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
942 HeapWord* body = NEW_C_HEAP_ARRAY(HeapWord, word_length); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
943 if (body == NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
944 THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
945 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
946 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
947 // caller responsible to free it: |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
948 (*temp_alloc) = body; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
949 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
950 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
951 jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
952 Copy::conjoint_words((HeapWord*) array_base, body, word_length); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
953 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
954 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
955 u1* class_bytes = (u1*) body; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
956 int class_bytes_length = (int) length; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
957 if (class_bytes_length < 0) class_bytes_length = 0; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
958 if (class_bytes == NULL |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
959 || host_class == NULL |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
960 || length != class_bytes_length) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
961 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
962 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
963 objArrayHandle cp_patches_h; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
964 if (cp_patches_jh != NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
965 oop p = JNIHandles::resolve_non_null(cp_patches_jh); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
966 if (!p->is_objArray()) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
967 THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
968 cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
969 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
970 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
971 KlassHandle host_klass(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(host_class))); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
972 const char* host_source = host_klass->external_name(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
973 Handle host_loader(THREAD, host_klass->class_loader()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
974 Handle host_domain(THREAD, host_klass->protection_domain()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
975 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
976 GrowableArray<Handle>* cp_patches = NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
977 if (cp_patches_h.not_null()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
978 int alen = cp_patches_h->length(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
979 for (int i = alen-1; i >= 0; i--) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
980 oop p = cp_patches_h->obj_at(i); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
981 if (p != NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
982 Handle patch(THREAD, p); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
983 if (cp_patches == NULL) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
984 cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
985 cp_patches->at_put(i, patch); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
986 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
987 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
988 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
989 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
990 ClassFileStream st(class_bytes, class_bytes_length, (char*) host_source); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
991 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
992 instanceKlassHandle anon_klass; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
993 { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2114
diff
changeset
|
994 Symbol* no_class_name = NULL; |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
995 klassOop anonk = SystemDictionary::parse_stream(no_class_name, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
996 host_loader, host_domain, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
997 &st, host_klass, cp_patches, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
998 CHECK_NULL); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
999 if (anonk == NULL) return NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1000 anon_klass = instanceKlassHandle(THREAD, anonk); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1001 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1002 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1003 // let caller initialize it as needed... |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1004 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1005 return anon_klass->java_mirror(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1006 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1007 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1008 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1009 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1010 UnsafeWrapper("Unsafe_DefineAnonymousClass"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1011 ResourceMark rm(THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1012 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1013 HeapWord* temp_alloc = NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1014 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1015 jobject res_jh = NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1016 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1017 { oop res_oop = Unsafe_DefineAnonymousClass_impl(env, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1018 host_class, data, cp_patches_jh, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1019 &temp_alloc, THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1020 if (res_oop != NULL) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1021 res_jh = JNIHandles::make_local(env, res_oop); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1022 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1023 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1024 // try/finally clause: |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1025 if (temp_alloc != NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1026 FREE_C_HEAP_ARRAY(HeapWord, temp_alloc); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1027 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1028 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1029 return (jclass) res_jh; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1030 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1031 UNSAFE_END |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1032 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1033 |
0 | 1034 |
1035 UNSAFE_ENTRY(void, Unsafe_MonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1036 UnsafeWrapper("Unsafe_MonitorEnter"); | |
1037 { | |
1038 if (jobj == NULL) { | |
1039 THROW(vmSymbols::java_lang_NullPointerException()); | |
1040 } | |
1041 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
1042 ObjectSynchronizer::jni_enter(obj, CHECK); | |
1043 } | |
1044 UNSAFE_END | |
1045 | |
1046 | |
1047 UNSAFE_ENTRY(jboolean, Unsafe_TryMonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1048 UnsafeWrapper("Unsafe_TryMonitorEnter"); | |
1049 { | |
1050 if (jobj == NULL) { | |
1051 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1052 } | |
1053 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
1054 bool res = ObjectSynchronizer::jni_try_enter(obj, CHECK_0); | |
1055 return (res ? JNI_TRUE : JNI_FALSE); | |
1056 } | |
1057 UNSAFE_END | |
1058 | |
1059 | |
1060 UNSAFE_ENTRY(void, Unsafe_MonitorExit(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1061 UnsafeWrapper("Unsafe_MonitorExit"); | |
1062 { | |
1063 if (jobj == NULL) { | |
1064 THROW(vmSymbols::java_lang_NullPointerException()); | |
1065 } | |
1066 Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); | |
1067 ObjectSynchronizer::jni_exit(obj(), CHECK); | |
1068 } | |
1069 UNSAFE_END | |
1070 | |
1071 | |
1072 UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) | |
1073 UnsafeWrapper("Unsafe_ThrowException"); | |
1074 { | |
1075 ThreadToNativeFromVM ttnfv(thread); | |
1076 env->Throw(thr); | |
1077 } | |
1078 UNSAFE_END | |
1079 | |
1080 // JSR166 ------------------------------------------------------------------ | |
1081 | |
1082 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) | |
1083 UnsafeWrapper("Unsafe_CompareAndSwapObject"); | |
1084 oop x = JNIHandles::resolve(x_h); | |
1085 oop e = JNIHandles::resolve(e_h); | |
1086 oop p = JNIHandles::resolve(obj); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1087 HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
431
diff
changeset
|
1088 if (UseCompressedOops) { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
431
diff
changeset
|
1089 update_barrier_set_pre((narrowOop*)addr, e); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
431
diff
changeset
|
1090 } else { |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
431
diff
changeset
|
1091 update_barrier_set_pre((oop*)addr, e); |
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
431
diff
changeset
|
1092 } |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1093 oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1094 jboolean success = (res == e); |
0 | 1095 if (success) |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1096 update_barrier_set((void*)addr, x); |
0 | 1097 return success; |
1098 UNSAFE_END | |
1099 | |
1100 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) | |
1101 UnsafeWrapper("Unsafe_CompareAndSwapInt"); | |
1102 oop p = JNIHandles::resolve(obj); | |
1103 jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); | |
1104 return (jint)(Atomic::cmpxchg(x, addr, e)) == e; | |
1105 UNSAFE_END | |
1106 | |
1107 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) | |
1108 UnsafeWrapper("Unsafe_CompareAndSwapLong"); | |
1109 Handle p (THREAD, JNIHandles::resolve(obj)); | |
1110 jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); | |
1111 if (VM_Version::supports_cx8()) | |
1112 return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; | |
1113 else { | |
1114 jboolean success = false; | |
1115 ObjectLocker ol(p, THREAD); | |
1116 if (*addr == e) { *addr = x; success = true; } | |
1117 return success; | |
1118 } | |
1119 UNSAFE_END | |
1120 | |
1121 UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) | |
1122 UnsafeWrapper("Unsafe_Park"); | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1123 HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time); |
0 | 1124 JavaThreadParkedState jtps(thread, time != 0); |
1125 thread->parker()->park(isAbsolute != 0, time); | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1126 HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker()); |
0 | 1127 UNSAFE_END |
1128 | |
1129 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) | |
1130 UnsafeWrapper("Unsafe_Unpark"); | |
1131 Parker* p = NULL; | |
1132 if (jthread != NULL) { | |
1133 oop java_thread = JNIHandles::resolve_non_null(jthread); | |
1134 if (java_thread != NULL) { | |
1135 jlong lp = java_lang_Thread::park_event(java_thread); | |
1136 if (lp != 0) { | |
1137 // This cast is OK even though the jlong might have been read | |
1138 // non-atomically on 32bit systems, since there, one word will | |
1139 // always be zero anyway and the value set is always the same | |
1140 p = (Parker*)addr_from_java(lp); | |
1141 } else { | |
1142 // Grab lock if apparently null or using older version of library | |
1143 MutexLocker mu(Threads_lock); | |
1144 java_thread = JNIHandles::resolve_non_null(jthread); | |
1145 if (java_thread != NULL) { | |
1146 JavaThread* thr = java_lang_Thread::thread(java_thread); | |
1147 if (thr != NULL) { | |
1148 p = thr->parker(); | |
1149 if (p != NULL) { // Bind to Java thread for next time. | |
1150 java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); | |
1151 } | |
1152 } | |
1153 } | |
1154 } | |
1155 } | |
1156 } | |
1157 if (p != NULL) { | |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1158 HS_DTRACE_PROBE1(hotspot, thread__unpark, p); |
0 | 1159 p->unpark(); |
1160 } | |
1161 UNSAFE_END | |
1162 | |
1163 UNSAFE_ENTRY(jint, Unsafe_Loadavg(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) | |
1164 UnsafeWrapper("Unsafe_Loadavg"); | |
1165 const int max_nelem = 3; | |
1166 double la[max_nelem]; | |
1167 jint ret; | |
1168 | |
1169 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); | |
1170 assert(a->is_typeArray(), "must be type array"); | |
1171 | |
1172 if (nelem < 0 || nelem > max_nelem || a->length() < nelem) { | |
1173 ThreadToNativeFromVM ttnfv(thread); | |
1174 throw_new(env, "ArrayIndexOutOfBoundsException"); | |
1175 return -1; | |
1176 } | |
1177 | |
1178 ret = os::loadavg(la, nelem); | |
1179 if (ret == -1) return -1; | |
1180 | |
1181 // if successful, ret is the number of samples actually retrieved. | |
1182 assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); | |
1183 switch(ret) { | |
1184 case 3: a->double_at_put(2, (jdouble)la[2]); // fall through | |
1185 case 2: a->double_at_put(1, (jdouble)la[1]); // fall through | |
1186 case 1: a->double_at_put(0, (jdouble)la[0]); break; | |
1187 } | |
1188 return ret; | |
1189 UNSAFE_END | |
1190 | |
1191 UNSAFE_ENTRY(void, Unsafe_PrefetchRead(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) | |
1192 UnsafeWrapper("Unsafe_PrefetchRead"); | |
1193 oop p = JNIHandles::resolve(obj); | |
1194 void* addr = index_oop_from_field_offset_long(p, 0); | |
1195 Prefetch::read(addr, (intx)offset); | |
1196 UNSAFE_END | |
1197 | |
1198 UNSAFE_ENTRY(void, Unsafe_PrefetchWrite(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) | |
1199 UnsafeWrapper("Unsafe_PrefetchWrite"); | |
1200 oop p = JNIHandles::resolve(obj); | |
1201 void* addr = index_oop_from_field_offset_long(p, 0); | |
1202 Prefetch::write(addr, (intx)offset); | |
1203 UNSAFE_END | |
1204 | |
1205 | |
1206 /// JVM_RegisterUnsafeMethods | |
1207 | |
1208 #define ADR "J" | |
1209 | |
1210 #define LANG "Ljava/lang/" | |
1211 | |
1212 #define OBJ LANG"Object;" | |
1213 #define CLS LANG"Class;" | |
1214 #define CTR LANG"reflect/Constructor;" | |
1215 #define FLD LANG"reflect/Field;" | |
1216 #define MTH LANG"reflect/Method;" | |
1217 #define THR LANG"Throwable;" | |
1218 | |
1219 #define DC0_Args LANG"String;[BII" | |
1220 #define DC1_Args DC0_Args LANG"ClassLoader;" "Ljava/security/ProtectionDomain;" | |
1221 | |
1222 #define CC (char*) /*cast a literal from (const char*)*/ | |
1223 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | |
1224 | |
1225 // define deprecated accessors for compabitility with 1.4.0 | |
1226 #define DECLARE_GETSETOOP_140(Boolean, Z) \ | |
1227 {CC"get"#Boolean, CC"("OBJ"I)"#Z, FN_PTR(Unsafe_Get##Boolean##140)}, \ | |
1228 {CC"put"#Boolean, CC"("OBJ"I"#Z")V", FN_PTR(Unsafe_Set##Boolean##140)} | |
1229 | |
1230 // Note: In 1.4.1, getObject and kin take both int and long offsets. | |
1231 #define DECLARE_GETSETOOP_141(Boolean, Z) \ | |
1232 {CC"get"#Boolean, CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean)}, \ | |
1233 {CC"put"#Boolean, CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean)} | |
1234 | |
1235 // Note: In 1.5.0, there are volatile versions too | |
1236 #define DECLARE_GETSETOOP(Boolean, Z) \ | |
1237 {CC"get"#Boolean, CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean)}, \ | |
1238 {CC"put"#Boolean, CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean)}, \ | |
1239 {CC"get"#Boolean"Volatile", CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean##Volatile)}, \ | |
1240 {CC"put"#Boolean"Volatile", CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean##Volatile)} | |
1241 | |
1242 | |
1243 #define DECLARE_GETSETNATIVE(Byte, B) \ | |
1244 {CC"get"#Byte, CC"("ADR")"#B, FN_PTR(Unsafe_GetNative##Byte)}, \ | |
1245 {CC"put"#Byte, CC"("ADR#B")V", FN_PTR(Unsafe_SetNative##Byte)} | |
1246 | |
1247 | |
1248 | |
1249 // %%% These are temporarily supported until the SDK sources | |
1250 // contain the necessarily updated Unsafe.java. | |
1251 static JNINativeMethod methods_140[] = { | |
1252 | |
1253 {CC"getObject", CC"("OBJ"I)"OBJ"", FN_PTR(Unsafe_GetObject140)}, | |
1254 {CC"putObject", CC"("OBJ"I"OBJ")V", FN_PTR(Unsafe_SetObject140)}, | |
1255 | |
1256 DECLARE_GETSETOOP_140(Boolean, Z), | |
1257 DECLARE_GETSETOOP_140(Byte, B), | |
1258 DECLARE_GETSETOOP_140(Short, S), | |
1259 DECLARE_GETSETOOP_140(Char, C), | |
1260 DECLARE_GETSETOOP_140(Int, I), | |
1261 DECLARE_GETSETOOP_140(Long, J), | |
1262 DECLARE_GETSETOOP_140(Float, F), | |
1263 DECLARE_GETSETOOP_140(Double, D), | |
1264 | |
1265 DECLARE_GETSETNATIVE(Byte, B), | |
1266 DECLARE_GETSETNATIVE(Short, S), | |
1267 DECLARE_GETSETNATIVE(Char, C), | |
1268 DECLARE_GETSETNATIVE(Int, I), | |
1269 DECLARE_GETSETNATIVE(Long, J), | |
1270 DECLARE_GETSETNATIVE(Float, F), | |
1271 DECLARE_GETSETNATIVE(Double, D), | |
1272 | |
1273 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1274 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1275 | |
1276 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1277 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1278 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1279 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1280 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1281 | |
1282 {CC"fieldOffset", CC"("FLD")I", FN_PTR(Unsafe_FieldOffset)}, //deprecated | |
1283 {CC"staticFieldBase", CC"("CLS")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromClass)}, //deprecated | |
1284 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1285 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1286 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1287 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1288 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1289 | |
1290 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1291 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1292 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1293 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1294 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1295 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)} | |
1296 }; | |
1297 | |
1298 // These are the old methods prior to the JSR 166 changes in 1.5.0 | |
1299 static JNINativeMethod methods_141[] = { | |
1300 | |
1301 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1302 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1303 | |
1304 DECLARE_GETSETOOP_141(Boolean, Z), | |
1305 DECLARE_GETSETOOP_141(Byte, B), | |
1306 DECLARE_GETSETOOP_141(Short, S), | |
1307 DECLARE_GETSETOOP_141(Char, C), | |
1308 DECLARE_GETSETOOP_141(Int, I), | |
1309 DECLARE_GETSETOOP_141(Long, J), | |
1310 DECLARE_GETSETOOP_141(Float, F), | |
1311 DECLARE_GETSETOOP_141(Double, D), | |
1312 | |
1313 DECLARE_GETSETNATIVE(Byte, B), | |
1314 DECLARE_GETSETNATIVE(Short, S), | |
1315 DECLARE_GETSETNATIVE(Char, C), | |
1316 DECLARE_GETSETNATIVE(Int, I), | |
1317 DECLARE_GETSETNATIVE(Long, J), | |
1318 DECLARE_GETSETNATIVE(Float, F), | |
1319 DECLARE_GETSETNATIVE(Double, D), | |
1320 | |
1321 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1322 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1323 | |
1324 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1325 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1326 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1327 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1328 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1329 | |
1330 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1331 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1332 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1333 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1334 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1335 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1336 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1337 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1338 | |
1339 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1340 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1341 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1342 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1343 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1344 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)} | |
1345 | |
1346 }; | |
1347 | |
1348 // These are the old methods prior to the JSR 166 changes in 1.6.0 | |
1349 static JNINativeMethod methods_15[] = { | |
1350 | |
1351 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1352 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1353 {CC"getObjectVolatile",CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObjectVolatile)}, | |
1354 {CC"putObjectVolatile",CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObjectVolatile)}, | |
1355 | |
1356 | |
1357 DECLARE_GETSETOOP(Boolean, Z), | |
1358 DECLARE_GETSETOOP(Byte, B), | |
1359 DECLARE_GETSETOOP(Short, S), | |
1360 DECLARE_GETSETOOP(Char, C), | |
1361 DECLARE_GETSETOOP(Int, I), | |
1362 DECLARE_GETSETOOP(Long, J), | |
1363 DECLARE_GETSETOOP(Float, F), | |
1364 DECLARE_GETSETOOP(Double, D), | |
1365 | |
1366 DECLARE_GETSETNATIVE(Byte, B), | |
1367 DECLARE_GETSETNATIVE(Short, S), | |
1368 DECLARE_GETSETNATIVE(Char, C), | |
1369 DECLARE_GETSETNATIVE(Int, I), | |
1370 DECLARE_GETSETNATIVE(Long, J), | |
1371 DECLARE_GETSETNATIVE(Float, F), | |
1372 DECLARE_GETSETNATIVE(Double, D), | |
1373 | |
1374 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1375 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1376 | |
1377 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1378 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1379 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1380 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1381 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1382 | |
1383 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1384 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1385 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1386 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1387 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1388 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1389 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1390 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1391 | |
1392 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1393 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1394 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1395 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1396 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1397 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)}, | |
1398 {CC"compareAndSwapObject", CC"("OBJ"J"OBJ""OBJ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, | |
1399 {CC"compareAndSwapInt", CC"("OBJ"J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, | |
1400 {CC"compareAndSwapLong", CC"("OBJ"J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, | |
1401 {CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)}, | |
1402 {CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)} | |
1403 | |
1404 }; | |
1405 | |
1406 // These are the correct methods, moving forward: | |
1407 static JNINativeMethod methods[] = { | |
1408 | |
1409 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1410 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1411 {CC"getObjectVolatile",CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObjectVolatile)}, | |
1412 {CC"putObjectVolatile",CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObjectVolatile)}, | |
1413 | |
1414 | |
1415 DECLARE_GETSETOOP(Boolean, Z), | |
1416 DECLARE_GETSETOOP(Byte, B), | |
1417 DECLARE_GETSETOOP(Short, S), | |
1418 DECLARE_GETSETOOP(Char, C), | |
1419 DECLARE_GETSETOOP(Int, I), | |
1420 DECLARE_GETSETOOP(Long, J), | |
1421 DECLARE_GETSETOOP(Float, F), | |
1422 DECLARE_GETSETOOP(Double, D), | |
1423 | |
1424 DECLARE_GETSETNATIVE(Byte, B), | |
1425 DECLARE_GETSETNATIVE(Short, S), | |
1426 DECLARE_GETSETNATIVE(Char, C), | |
1427 DECLARE_GETSETNATIVE(Int, I), | |
1428 DECLARE_GETSETNATIVE(Long, J), | |
1429 DECLARE_GETSETNATIVE(Float, F), | |
1430 DECLARE_GETSETNATIVE(Double, D), | |
1431 | |
1432 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1433 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1434 | |
1435 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1436 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1437 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1438 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1439 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1440 | |
1441 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1442 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1443 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1444 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1445 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1446 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1447 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1448 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1449 | |
1450 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1451 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1452 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1453 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1454 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1455 {CC"tryMonitorEnter", CC"("OBJ")Z", FN_PTR(Unsafe_TryMonitorEnter)}, | |
1456 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)}, | |
1457 {CC"compareAndSwapObject", CC"("OBJ"J"OBJ""OBJ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, | |
1458 {CC"compareAndSwapInt", CC"("OBJ"J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, | |
1459 {CC"compareAndSwapLong", CC"("OBJ"J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, | |
1460 {CC"putOrderedObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetOrderedObject)}, | |
1461 {CC"putOrderedInt", CC"("OBJ"JI)V", FN_PTR(Unsafe_SetOrderedInt)}, | |
1462 {CC"putOrderedLong", CC"("OBJ"JJ)V", FN_PTR(Unsafe_SetOrderedLong)}, | |
1463 {CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)}, | |
1464 {CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)} | |
1465 | |
1466 // {CC"getLoadAverage", CC"([DI)I", FN_PTR(Unsafe_Loadavg)}, | |
1467 | |
1468 // {CC"prefetchRead", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1469 // {CC"prefetchWrite", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1470 // {CC"prefetchReadStatic", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1471 // {CC"prefetchWriteStatic",CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1472 | |
1473 }; | |
1474 | |
1475 JNINativeMethod loadavg_method[] = { | |
1476 {CC"getLoadAverage", CC"([DI)I", FN_PTR(Unsafe_Loadavg)} | |
1477 }; | |
1478 | |
1479 JNINativeMethod prefetch_methods[] = { | |
1480 {CC"prefetchRead", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1481 {CC"prefetchWrite", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)}, | |
1482 {CC"prefetchReadStatic", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1483 {CC"prefetchWriteStatic",CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1484 }; | |
1485 | |
1486 JNINativeMethod memcopy_methods[] = { | |
1487 {CC"copyMemory", CC"("OBJ"J"OBJ"JJ)V", FN_PTR(Unsafe_CopyMemory2)}, | |
1488 {CC"setMemory", CC"("OBJ"JJB)V", FN_PTR(Unsafe_SetMemory2)} | |
1489 }; | |
1490 | |
1491 JNINativeMethod memcopy_methods_15[] = { | |
1492 {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1493 {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)} | |
1494 }; | |
1495 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1496 JNINativeMethod anonk_methods[] = { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1497 {CC"defineAnonymousClass", CC"("DAC_Args")"CLS, FN_PTR(Unsafe_DefineAnonymousClass)}, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1498 }; |
0 | 1499 |
1500 #undef CC | |
1501 #undef FN_PTR | |
1502 | |
1503 #undef ADR | |
1504 #undef LANG | |
1505 #undef OBJ | |
1506 #undef CLS | |
1507 #undef CTR | |
1508 #undef FLD | |
1509 #undef MTH | |
1510 #undef THR | |
1511 #undef DC0_Args | |
1512 #undef DC1_Args | |
1513 | |
1514 #undef DECLARE_GETSETOOP | |
1515 #undef DECLARE_GETSETNATIVE | |
1516 | |
1517 | |
1518 // This one function is exported, used by NativeLookup. | |
1519 // The Unsafe_xxx functions above are called only from the interpreter. | |
1520 // The optimizer looks at names and signatures to recognize | |
1521 // individual functions. | |
1522 | |
1523 JVM_ENTRY(void, JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls)) | |
1524 UnsafeWrapper("JVM_RegisterUnsafeMethods"); | |
1525 { | |
1526 ThreadToNativeFromVM ttnfv(thread); | |
1527 { | |
1528 env->RegisterNatives(unsafecls, loadavg_method, sizeof(loadavg_method)/sizeof(JNINativeMethod)); | |
1529 if (env->ExceptionOccurred()) { | |
1530 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1531 tty->print_cr("Warning: SDK 1.6 Unsafe.loadavg not found."); | |
1532 } | |
1533 env->ExceptionClear(); | |
1534 } | |
1535 } | |
1536 { | |
1537 env->RegisterNatives(unsafecls, prefetch_methods, sizeof(prefetch_methods)/sizeof(JNINativeMethod)); | |
1538 if (env->ExceptionOccurred()) { | |
1539 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1540 tty->print_cr("Warning: SDK 1.6 Unsafe.prefetchRead/Write not found."); | |
1541 } | |
1542 env->ExceptionClear(); | |
1543 } | |
1544 } | |
1545 { | |
1546 env->RegisterNatives(unsafecls, memcopy_methods, sizeof(memcopy_methods)/sizeof(JNINativeMethod)); | |
1547 if (env->ExceptionOccurred()) { | |
1548 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1549 tty->print_cr("Warning: SDK 1.7 Unsafe.copyMemory not found."); | |
1550 } | |
1551 env->ExceptionClear(); | |
1552 env->RegisterNatives(unsafecls, memcopy_methods_15, sizeof(memcopy_methods_15)/sizeof(JNINativeMethod)); | |
1553 if (env->ExceptionOccurred()) { | |
1554 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1555 tty->print_cr("Warning: SDK 1.5 Unsafe.copyMemory not found."); | |
1556 } | |
1557 env->ExceptionClear(); | |
1558 } | |
1559 } | |
1560 } | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1561 if (AnonymousClasses) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1562 env->RegisterNatives(unsafecls, anonk_methods, sizeof(anonk_methods)/sizeof(JNINativeMethod)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1563 if (env->ExceptionOccurred()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1564 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1565 tty->print_cr("Warning: SDK 1.7 Unsafe.defineClass (anonymous version) not found."); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1566 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1567 env->ExceptionClear(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1568 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1569 } |
0 | 1570 int status = env->RegisterNatives(unsafecls, methods, sizeof(methods)/sizeof(JNINativeMethod)); |
1571 if (env->ExceptionOccurred()) { | |
1572 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1573 tty->print_cr("Warning: SDK 1.6 version of Unsafe not found."); | |
1574 } | |
1575 env->ExceptionClear(); | |
1576 // %%% For now, be backward compatible with an older class: | |
1577 status = env->RegisterNatives(unsafecls, methods_15, sizeof(methods_15)/sizeof(JNINativeMethod)); | |
1578 } | |
1579 if (env->ExceptionOccurred()) { | |
1580 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1581 tty->print_cr("Warning: SDK 1.5 version of Unsafe not found."); | |
1582 } | |
1583 env->ExceptionClear(); | |
1584 // %%% For now, be backward compatible with an older class: | |
1585 status = env->RegisterNatives(unsafecls, methods_141, sizeof(methods_141)/sizeof(JNINativeMethod)); | |
1586 } | |
1587 if (env->ExceptionOccurred()) { | |
1588 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1589 tty->print_cr("Warning: SDK 1.4.1 version of Unsafe not found."); | |
1590 } | |
1591 env->ExceptionClear(); | |
1592 // %%% For now, be backward compatible with an older class: | |
1593 status = env->RegisterNatives(unsafecls, methods_140, sizeof(methods_140)/sizeof(JNINativeMethod)); | |
1594 } | |
1595 guarantee(status == 0, "register unsafe natives"); | |
1596 } | |
1597 JVM_END |