Mercurial > hg > truffle
annotate src/share/vm/prims/unsafe.cpp @ 7403:807f1d348f7b
Merge
author | collins |
---|---|
date | Fri, 14 Dec 2012 11:45:55 -0800 |
parents | 90273fc0a981 |
children | 1e41b0bc58a0 |
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 |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
999 static instanceKlassHandle |
431
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 |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1076 return anon_klass; |
431
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 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1079 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
|
1080 { |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1081 instanceKlassHandle anon_klass; |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1082 jobject res_jh = NULL; |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1083 |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1084 UnsafeWrapper("Unsafe_DefineAnonymousClass"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1085 ResourceMark rm(THREAD); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1086 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1087 HeapWord* temp_alloc = NULL; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1088 |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1089 anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1090 cp_patches_jh, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1091 &temp_alloc, THREAD); |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1092 if (anon_klass() != NULL) |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1093 res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1094 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1095 // try/finally clause: |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1096 if (temp_alloc != NULL) { |
6197 | 1097 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
|
1098 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1099 |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1100 // The anonymous class loader data has been artificially been kept alive to |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1101 // this point. The mirror and any instances of this class have to keep |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1102 // it alive afterwards. |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1103 if (anon_klass() != NULL) { |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1104 anon_klass->class_loader_data()->set_keep_alive(false); |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1105 } |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1106 |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1107 // let caller initialize it as needed... |
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
1108 |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1109 return (jclass) res_jh; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1110 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1111 UNSAFE_END |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1112 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1113 |
0 | 1114 |
1115 UNSAFE_ENTRY(void, Unsafe_MonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1116 UnsafeWrapper("Unsafe_MonitorEnter"); | |
1117 { | |
1118 if (jobj == NULL) { | |
1119 THROW(vmSymbols::java_lang_NullPointerException()); | |
1120 } | |
1121 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
1122 ObjectSynchronizer::jni_enter(obj, CHECK); | |
1123 } | |
1124 UNSAFE_END | |
1125 | |
1126 | |
1127 UNSAFE_ENTRY(jboolean, Unsafe_TryMonitorEnter(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1128 UnsafeWrapper("Unsafe_TryMonitorEnter"); | |
1129 { | |
1130 if (jobj == NULL) { | |
1131 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE); | |
1132 } | |
1133 Handle obj(thread, JNIHandles::resolve_non_null(jobj)); | |
1134 bool res = ObjectSynchronizer::jni_try_enter(obj, CHECK_0); | |
1135 return (res ? JNI_TRUE : JNI_FALSE); | |
1136 } | |
1137 UNSAFE_END | |
1138 | |
1139 | |
1140 UNSAFE_ENTRY(void, Unsafe_MonitorExit(JNIEnv *env, jobject unsafe, jobject jobj)) | |
1141 UnsafeWrapper("Unsafe_MonitorExit"); | |
1142 { | |
1143 if (jobj == NULL) { | |
1144 THROW(vmSymbols::java_lang_NullPointerException()); | |
1145 } | |
1146 Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); | |
1147 ObjectSynchronizer::jni_exit(obj(), CHECK); | |
1148 } | |
1149 UNSAFE_END | |
1150 | |
1151 | |
1152 UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) | |
1153 UnsafeWrapper("Unsafe_ThrowException"); | |
1154 { | |
1155 ThreadToNativeFromVM ttnfv(thread); | |
1156 env->Throw(thr); | |
1157 } | |
1158 UNSAFE_END | |
1159 | |
1160 // JSR166 ------------------------------------------------------------------ | |
1161 | |
1162 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) | |
1163 UnsafeWrapper("Unsafe_CompareAndSwapObject"); | |
1164 oop x = JNIHandles::resolve(x_h); | |
1165 oop e = JNIHandles::resolve(e_h); | |
1166 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
|
1167 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
|
1168 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
|
1169 jboolean success = (res == e); |
0 | 1170 if (success) |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
1171 update_barrier_set((void*)addr, x); |
0 | 1172 return success; |
1173 UNSAFE_END | |
1174 | |
1175 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) | |
1176 UnsafeWrapper("Unsafe_CompareAndSwapInt"); | |
1177 oop p = JNIHandles::resolve(obj); | |
1178 jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); | |
1179 return (jint)(Atomic::cmpxchg(x, addr, e)) == e; | |
1180 UNSAFE_END | |
1181 | |
1182 UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) | |
1183 UnsafeWrapper("Unsafe_CompareAndSwapLong"); | |
1184 Handle p (THREAD, JNIHandles::resolve(obj)); | |
1185 jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); | |
1186 if (VM_Version::supports_cx8()) | |
1187 return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; | |
1188 else { | |
1189 jboolean success = false; | |
1190 ObjectLocker ol(p, THREAD); | |
1191 if (*addr == e) { *addr = x; success = true; } | |
1192 return success; | |
1193 } | |
1194 UNSAFE_END | |
1195 | |
1196 UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) | |
1197 UnsafeWrapper("Unsafe_Park"); | |
4006 | 1198 #ifndef USDT2 |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1199 HS_DTRACE_PROBE3(hotspot, thread__park__begin, thread->parker(), (int) isAbsolute, time); |
4006 | 1200 #else /* USDT2 */ |
1201 HOTSPOT_THREAD_PARK_BEGIN( | |
1202 (uintptr_t) thread->parker(), (int) isAbsolute, time); | |
1203 #endif /* USDT2 */ | |
0 | 1204 JavaThreadParkedState jtps(thread, time != 0); |
1205 thread->parker()->park(isAbsolute != 0, time); | |
4006 | 1206 #ifndef USDT2 |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1207 HS_DTRACE_PROBE1(hotspot, thread__park__end, thread->parker()); |
4006 | 1208 #else /* USDT2 */ |
1209 HOTSPOT_THREAD_PARK_END( | |
1210 (uintptr_t) thread->parker()); | |
1211 #endif /* USDT2 */ | |
0 | 1212 UNSAFE_END |
1213 | |
1214 UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) | |
1215 UnsafeWrapper("Unsafe_Unpark"); | |
1216 Parker* p = NULL; | |
1217 if (jthread != NULL) { | |
1218 oop java_thread = JNIHandles::resolve_non_null(jthread); | |
1219 if (java_thread != NULL) { | |
1220 jlong lp = java_lang_Thread::park_event(java_thread); | |
1221 if (lp != 0) { | |
1222 // This cast is OK even though the jlong might have been read | |
1223 // non-atomically on 32bit systems, since there, one word will | |
1224 // always be zero anyway and the value set is always the same | |
1225 p = (Parker*)addr_from_java(lp); | |
1226 } else { | |
1227 // Grab lock if apparently null or using older version of library | |
1228 MutexLocker mu(Threads_lock); | |
1229 java_thread = JNIHandles::resolve_non_null(jthread); | |
1230 if (java_thread != NULL) { | |
1231 JavaThread* thr = java_lang_Thread::thread(java_thread); | |
1232 if (thr != NULL) { | |
1233 p = thr->parker(); | |
1234 if (p != NULL) { // Bind to Java thread for next time. | |
1235 java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); | |
1236 } | |
1237 } | |
1238 } | |
1239 } | |
1240 } | |
1241 } | |
1242 if (p != NULL) { | |
4006 | 1243 #ifndef USDT2 |
1324
e392695de029
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
845
diff
changeset
|
1244 HS_DTRACE_PROBE1(hotspot, thread__unpark, p); |
4006 | 1245 #else /* USDT2 */ |
1246 HOTSPOT_THREAD_UNPARK( | |
1247 (uintptr_t) p); | |
1248 #endif /* USDT2 */ | |
0 | 1249 p->unpark(); |
1250 } | |
1251 UNSAFE_END | |
1252 | |
1253 UNSAFE_ENTRY(jint, Unsafe_Loadavg(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) | |
1254 UnsafeWrapper("Unsafe_Loadavg"); | |
1255 const int max_nelem = 3; | |
1256 double la[max_nelem]; | |
1257 jint ret; | |
1258 | |
1259 typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); | |
1260 assert(a->is_typeArray(), "must be type array"); | |
1261 | |
1262 if (nelem < 0 || nelem > max_nelem || a->length() < nelem) { | |
1263 ThreadToNativeFromVM ttnfv(thread); | |
1264 throw_new(env, "ArrayIndexOutOfBoundsException"); | |
1265 return -1; | |
1266 } | |
1267 | |
1268 ret = os::loadavg(la, nelem); | |
1269 if (ret == -1) return -1; | |
1270 | |
1271 // if successful, ret is the number of samples actually retrieved. | |
1272 assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); | |
1273 switch(ret) { | |
1274 case 3: a->double_at_put(2, (jdouble)la[2]); // fall through | |
1275 case 2: a->double_at_put(1, (jdouble)la[1]); // fall through | |
1276 case 1: a->double_at_put(0, (jdouble)la[0]); break; | |
1277 } | |
1278 return ret; | |
1279 UNSAFE_END | |
1280 | |
1281 UNSAFE_ENTRY(void, Unsafe_PrefetchRead(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) | |
1282 UnsafeWrapper("Unsafe_PrefetchRead"); | |
1283 oop p = JNIHandles::resolve(obj); | |
1284 void* addr = index_oop_from_field_offset_long(p, 0); | |
1285 Prefetch::read(addr, (intx)offset); | |
1286 UNSAFE_END | |
1287 | |
1288 UNSAFE_ENTRY(void, Unsafe_PrefetchWrite(JNIEnv* env, jclass ignored, jobject obj, jlong offset)) | |
1289 UnsafeWrapper("Unsafe_PrefetchWrite"); | |
1290 oop p = JNIHandles::resolve(obj); | |
1291 void* addr = index_oop_from_field_offset_long(p, 0); | |
1292 Prefetch::write(addr, (intx)offset); | |
1293 UNSAFE_END | |
1294 | |
1295 | |
1296 /// JVM_RegisterUnsafeMethods | |
1297 | |
1298 #define ADR "J" | |
1299 | |
1300 #define LANG "Ljava/lang/" | |
1301 | |
1302 #define OBJ LANG"Object;" | |
1303 #define CLS LANG"Class;" | |
1304 #define CTR LANG"reflect/Constructor;" | |
1305 #define FLD LANG"reflect/Field;" | |
1306 #define MTH LANG"reflect/Method;" | |
1307 #define THR LANG"Throwable;" | |
1308 | |
1309 #define DC0_Args LANG"String;[BII" | |
1310 #define DC1_Args DC0_Args LANG"ClassLoader;" "Ljava/security/ProtectionDomain;" | |
1311 | |
1312 #define CC (char*) /*cast a literal from (const char*)*/ | |
1313 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | |
1314 | |
1315 // define deprecated accessors for compabitility with 1.4.0 | |
1316 #define DECLARE_GETSETOOP_140(Boolean, Z) \ | |
1317 {CC"get"#Boolean, CC"("OBJ"I)"#Z, FN_PTR(Unsafe_Get##Boolean##140)}, \ | |
1318 {CC"put"#Boolean, CC"("OBJ"I"#Z")V", FN_PTR(Unsafe_Set##Boolean##140)} | |
1319 | |
1320 // Note: In 1.4.1, getObject and kin take both int and long offsets. | |
1321 #define DECLARE_GETSETOOP_141(Boolean, Z) \ | |
1322 {CC"get"#Boolean, CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean)}, \ | |
1323 {CC"put"#Boolean, CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean)} | |
1324 | |
1325 // Note: In 1.5.0, there are volatile versions too | |
1326 #define DECLARE_GETSETOOP(Boolean, Z) \ | |
1327 {CC"get"#Boolean, CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean)}, \ | |
1328 {CC"put"#Boolean, CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean)}, \ | |
1329 {CC"get"#Boolean"Volatile", CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean##Volatile)}, \ | |
1330 {CC"put"#Boolean"Volatile", CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean##Volatile)} | |
1331 | |
1332 | |
1333 #define DECLARE_GETSETNATIVE(Byte, B) \ | |
1334 {CC"get"#Byte, CC"("ADR")"#B, FN_PTR(Unsafe_GetNative##Byte)}, \ | |
1335 {CC"put"#Byte, CC"("ADR#B")V", FN_PTR(Unsafe_SetNative##Byte)} | |
1336 | |
1337 | |
1338 | |
1339 // %%% These are temporarily supported until the SDK sources | |
1340 // contain the necessarily updated Unsafe.java. | |
1341 static JNINativeMethod methods_140[] = { | |
1342 | |
1343 {CC"getObject", CC"("OBJ"I)"OBJ"", FN_PTR(Unsafe_GetObject140)}, | |
1344 {CC"putObject", CC"("OBJ"I"OBJ")V", FN_PTR(Unsafe_SetObject140)}, | |
1345 | |
1346 DECLARE_GETSETOOP_140(Boolean, Z), | |
1347 DECLARE_GETSETOOP_140(Byte, B), | |
1348 DECLARE_GETSETOOP_140(Short, S), | |
1349 DECLARE_GETSETOOP_140(Char, C), | |
1350 DECLARE_GETSETOOP_140(Int, I), | |
1351 DECLARE_GETSETOOP_140(Long, J), | |
1352 DECLARE_GETSETOOP_140(Float, F), | |
1353 DECLARE_GETSETOOP_140(Double, D), | |
1354 | |
1355 DECLARE_GETSETNATIVE(Byte, B), | |
1356 DECLARE_GETSETNATIVE(Short, S), | |
1357 DECLARE_GETSETNATIVE(Char, C), | |
1358 DECLARE_GETSETNATIVE(Int, I), | |
1359 DECLARE_GETSETNATIVE(Long, J), | |
1360 DECLARE_GETSETNATIVE(Float, F), | |
1361 DECLARE_GETSETNATIVE(Double, D), | |
1362 | |
1363 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1364 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1365 | |
1366 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1367 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1368 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1369 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1370 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1371 | |
1372 {CC"fieldOffset", CC"("FLD")I", FN_PTR(Unsafe_FieldOffset)}, //deprecated | |
1373 {CC"staticFieldBase", CC"("CLS")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromClass)}, //deprecated | |
1374 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1375 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1376 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1377 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1378 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1379 | |
1380 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1381 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1382 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1383 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1384 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1385 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)} | |
1386 }; | |
1387 | |
1388 // These are the old methods prior to the JSR 166 changes in 1.5.0 | |
1389 static JNINativeMethod methods_141[] = { | |
1390 | |
1391 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1392 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1393 | |
1394 DECLARE_GETSETOOP_141(Boolean, Z), | |
1395 DECLARE_GETSETOOP_141(Byte, B), | |
1396 DECLARE_GETSETOOP_141(Short, S), | |
1397 DECLARE_GETSETOOP_141(Char, C), | |
1398 DECLARE_GETSETOOP_141(Int, I), | |
1399 DECLARE_GETSETOOP_141(Long, J), | |
1400 DECLARE_GETSETOOP_141(Float, F), | |
1401 DECLARE_GETSETOOP_141(Double, D), | |
1402 | |
1403 DECLARE_GETSETNATIVE(Byte, B), | |
1404 DECLARE_GETSETNATIVE(Short, S), | |
1405 DECLARE_GETSETNATIVE(Char, C), | |
1406 DECLARE_GETSETNATIVE(Int, I), | |
1407 DECLARE_GETSETNATIVE(Long, J), | |
1408 DECLARE_GETSETNATIVE(Float, F), | |
1409 DECLARE_GETSETNATIVE(Double, D), | |
1410 | |
1411 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1412 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1413 | |
1414 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1415 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1416 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1417 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1418 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1419 | |
1420 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1421 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1422 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1423 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1424 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1425 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1426 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1427 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1428 | |
1429 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1430 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1431 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1432 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1433 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1434 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)} | |
1435 | |
1436 }; | |
1437 | |
1438 // These are the old methods prior to the JSR 166 changes in 1.6.0 | |
1439 static JNINativeMethod methods_15[] = { | |
1440 | |
1441 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1442 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1443 {CC"getObjectVolatile",CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObjectVolatile)}, | |
1444 {CC"putObjectVolatile",CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObjectVolatile)}, | |
1445 | |
1446 | |
1447 DECLARE_GETSETOOP(Boolean, Z), | |
1448 DECLARE_GETSETOOP(Byte, B), | |
1449 DECLARE_GETSETOOP(Short, S), | |
1450 DECLARE_GETSETOOP(Char, C), | |
1451 DECLARE_GETSETOOP(Int, I), | |
1452 DECLARE_GETSETOOP(Long, J), | |
1453 DECLARE_GETSETOOP(Float, F), | |
1454 DECLARE_GETSETOOP(Double, D), | |
1455 | |
1456 DECLARE_GETSETNATIVE(Byte, B), | |
1457 DECLARE_GETSETNATIVE(Short, S), | |
1458 DECLARE_GETSETNATIVE(Char, C), | |
1459 DECLARE_GETSETNATIVE(Int, I), | |
1460 DECLARE_GETSETNATIVE(Long, J), | |
1461 DECLARE_GETSETNATIVE(Float, F), | |
1462 DECLARE_GETSETNATIVE(Double, D), | |
1463 | |
1464 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1465 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1466 | |
1467 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1468 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1469 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1470 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1471 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1472 | |
1473 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1474 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1475 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1476 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1477 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1478 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1479 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1480 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1481 | |
1482 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1483 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1484 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1485 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1486 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1487 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)}, | |
1488 {CC"compareAndSwapObject", CC"("OBJ"J"OBJ""OBJ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, | |
1489 {CC"compareAndSwapInt", CC"("OBJ"J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, | |
1490 {CC"compareAndSwapLong", CC"("OBJ"J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, | |
1491 {CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)}, | |
1492 {CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)} | |
1493 | |
1494 }; | |
1495 | |
1496 // These are the correct methods, moving forward: | |
1497 static JNINativeMethod methods[] = { | |
1498 | |
1499 {CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, | |
1500 {CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, | |
1501 {CC"getObjectVolatile",CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObjectVolatile)}, | |
1502 {CC"putObjectVolatile",CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObjectVolatile)}, | |
1503 | |
1504 | |
1505 DECLARE_GETSETOOP(Boolean, Z), | |
1506 DECLARE_GETSETOOP(Byte, B), | |
1507 DECLARE_GETSETOOP(Short, S), | |
1508 DECLARE_GETSETOOP(Char, C), | |
1509 DECLARE_GETSETOOP(Int, I), | |
1510 DECLARE_GETSETOOP(Long, J), | |
1511 DECLARE_GETSETOOP(Float, F), | |
1512 DECLARE_GETSETOOP(Double, D), | |
1513 | |
1514 DECLARE_GETSETNATIVE(Byte, B), | |
1515 DECLARE_GETSETNATIVE(Short, S), | |
1516 DECLARE_GETSETNATIVE(Char, C), | |
1517 DECLARE_GETSETNATIVE(Int, I), | |
1518 DECLARE_GETSETNATIVE(Long, J), | |
1519 DECLARE_GETSETNATIVE(Float, F), | |
1520 DECLARE_GETSETNATIVE(Double, D), | |
1521 | |
1522 {CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, | |
1523 {CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, | |
1524 | |
1525 {CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, | |
1526 {CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, | |
1527 // {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1528 // {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)}, | |
1529 {CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, | |
1530 | |
1531 {CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, | |
1532 {CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, | |
1533 {CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, | |
1534 {CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, | |
1535 {CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, | |
1536 {CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, | |
1537 {CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, | |
1538 {CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, | |
1539 | |
1540 {CC"defineClass", CC"("DC0_Args")"CLS, FN_PTR(Unsafe_DefineClass0)}, | |
1541 {CC"defineClass", CC"("DC1_Args")"CLS, FN_PTR(Unsafe_DefineClass1)}, | |
1542 {CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, | |
1543 {CC"monitorEnter", CC"("OBJ")V", FN_PTR(Unsafe_MonitorEnter)}, | |
1544 {CC"monitorExit", CC"("OBJ")V", FN_PTR(Unsafe_MonitorExit)}, | |
1545 {CC"tryMonitorEnter", CC"("OBJ")Z", FN_PTR(Unsafe_TryMonitorEnter)}, | |
1546 {CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)}, | |
1547 {CC"compareAndSwapObject", CC"("OBJ"J"OBJ""OBJ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, | |
1548 {CC"compareAndSwapInt", CC"("OBJ"J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, | |
1549 {CC"compareAndSwapLong", CC"("OBJ"J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, | |
1550 {CC"putOrderedObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetOrderedObject)}, | |
1551 {CC"putOrderedInt", CC"("OBJ"JI)V", FN_PTR(Unsafe_SetOrderedInt)}, | |
1552 {CC"putOrderedLong", CC"("OBJ"JJ)V", FN_PTR(Unsafe_SetOrderedLong)}, | |
1553 {CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)}, | |
1554 {CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)} | |
1555 | |
1556 // {CC"getLoadAverage", CC"([DI)I", FN_PTR(Unsafe_Loadavg)}, | |
1557 | |
1558 // {CC"prefetchRead", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1559 // {CC"prefetchWrite", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1560 // {CC"prefetchReadStatic", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1561 // {CC"prefetchWriteStatic",CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1562 | |
1563 }; | |
1564 | |
1565 JNINativeMethod loadavg_method[] = { | |
1566 {CC"getLoadAverage", CC"([DI)I", FN_PTR(Unsafe_Loadavg)} | |
1567 }; | |
1568 | |
1569 JNINativeMethod prefetch_methods[] = { | |
1570 {CC"prefetchRead", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1571 {CC"prefetchWrite", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)}, | |
1572 {CC"prefetchReadStatic", CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchRead)}, | |
1573 {CC"prefetchWriteStatic",CC"("OBJ"J)V", FN_PTR(Unsafe_PrefetchWrite)} | |
1574 }; | |
1575 | |
1576 JNINativeMethod memcopy_methods[] = { | |
1577 {CC"copyMemory", CC"("OBJ"J"OBJ"JJ)V", FN_PTR(Unsafe_CopyMemory2)}, | |
1578 {CC"setMemory", CC"("OBJ"JJB)V", FN_PTR(Unsafe_SetMemory2)} | |
1579 }; | |
1580 | |
1581 JNINativeMethod memcopy_methods_15[] = { | |
1582 {CC"setMemory", CC"("ADR"JB)V", FN_PTR(Unsafe_SetMemory)}, | |
1583 {CC"copyMemory", CC"("ADR ADR"J)V", FN_PTR(Unsafe_CopyMemory)} | |
1584 }; | |
1585 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1586 JNINativeMethod anonk_methods[] = { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1587 {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
|
1588 }; |
0 | 1589 |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1590 JNINativeMethod lform_methods[] = { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1591 {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
|
1592 }; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1593 |
0 | 1594 #undef CC |
1595 #undef FN_PTR | |
1596 | |
1597 #undef ADR | |
1598 #undef LANG | |
1599 #undef OBJ | |
1600 #undef CLS | |
1601 #undef CTR | |
1602 #undef FLD | |
1603 #undef MTH | |
1604 #undef THR | |
1605 #undef DC0_Args | |
1606 #undef DC1_Args | |
1607 | |
1608 #undef DECLARE_GETSETOOP | |
1609 #undef DECLARE_GETSETNATIVE | |
1610 | |
1611 | |
1612 // This one function is exported, used by NativeLookup. | |
1613 // The Unsafe_xxx functions above are called only from the interpreter. | |
1614 // The optimizer looks at names and signatures to recognize | |
1615 // individual functions. | |
1616 | |
1617 JVM_ENTRY(void, JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls)) | |
1618 UnsafeWrapper("JVM_RegisterUnsafeMethods"); | |
1619 { | |
1620 ThreadToNativeFromVM ttnfv(thread); | |
1621 { | |
1622 env->RegisterNatives(unsafecls, loadavg_method, sizeof(loadavg_method)/sizeof(JNINativeMethod)); | |
1623 if (env->ExceptionOccurred()) { | |
1624 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1625 tty->print_cr("Warning: SDK 1.6 Unsafe.loadavg not found."); | |
1626 } | |
1627 env->ExceptionClear(); | |
1628 } | |
1629 } | |
1630 { | |
1631 env->RegisterNatives(unsafecls, prefetch_methods, sizeof(prefetch_methods)/sizeof(JNINativeMethod)); | |
1632 if (env->ExceptionOccurred()) { | |
1633 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1634 tty->print_cr("Warning: SDK 1.6 Unsafe.prefetchRead/Write not found."); | |
1635 } | |
1636 env->ExceptionClear(); | |
1637 } | |
1638 } | |
1639 { | |
1640 env->RegisterNatives(unsafecls, memcopy_methods, sizeof(memcopy_methods)/sizeof(JNINativeMethod)); | |
1641 if (env->ExceptionOccurred()) { | |
1642 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1643 tty->print_cr("Warning: SDK 1.7 Unsafe.copyMemory not found."); | |
1644 } | |
1645 env->ExceptionClear(); | |
1646 env->RegisterNatives(unsafecls, memcopy_methods_15, sizeof(memcopy_methods_15)/sizeof(JNINativeMethod)); | |
1647 if (env->ExceptionOccurred()) { | |
1648 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1649 tty->print_cr("Warning: SDK 1.5 Unsafe.copyMemory not found."); | |
1650 } | |
1651 env->ExceptionClear(); | |
1652 } | |
1653 } | |
1654 } | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
1655 if (EnableInvokeDynamic) { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1656 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
|
1657 if (env->ExceptionOccurred()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1658 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1659 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
|
1660 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1661 env->ExceptionClear(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1662 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
356
diff
changeset
|
1663 } |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1664 if (EnableInvokeDynamic) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1665 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
|
1666 if (env->ExceptionOccurred()) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1667 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1668 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
|
1669 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1670 env->ExceptionClear(); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1671 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6226
diff
changeset
|
1672 } |
0 | 1673 int status = env->RegisterNatives(unsafecls, methods, sizeof(methods)/sizeof(JNINativeMethod)); |
1674 if (env->ExceptionOccurred()) { | |
1675 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1676 tty->print_cr("Warning: SDK 1.6 version of Unsafe not found."); | |
1677 } | |
1678 env->ExceptionClear(); | |
1679 // %%% For now, be backward compatible with an older class: | |
1680 status = env->RegisterNatives(unsafecls, methods_15, sizeof(methods_15)/sizeof(JNINativeMethod)); | |
1681 } | |
1682 if (env->ExceptionOccurred()) { | |
1683 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1684 tty->print_cr("Warning: SDK 1.5 version of Unsafe not found."); | |
1685 } | |
1686 env->ExceptionClear(); | |
1687 // %%% For now, be backward compatible with an older class: | |
1688 status = env->RegisterNatives(unsafecls, methods_141, sizeof(methods_141)/sizeof(JNINativeMethod)); | |
1689 } | |
1690 if (env->ExceptionOccurred()) { | |
1691 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1692 tty->print_cr("Warning: SDK 1.4.1 version of Unsafe not found."); | |
1693 } | |
1694 env->ExceptionClear(); | |
1695 // %%% For now, be backward compatible with an older class: | |
1696 status = env->RegisterNatives(unsafecls, methods_140, sizeof(methods_140)/sizeof(JNINativeMethod)); | |
1697 } | |
1698 guarantee(status == 0, "register unsafe natives"); | |
1699 } | |
1700 JVM_END |