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