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