author | psandoz |
Tue, 10 Feb 2015 14:10:43 +0100 | |
changeset 28951 | a29d2048e16a |
parent 28621 | 37cc414b6491 |
child 29083 | 5e7bce2712ac |
permissions | -rw-r--r-- |
1 | 1 |
/* |
28621
37cc414b6491
8054494: Remove sun.misc.Unsafe.monitorEnter, monitorExit and tryMonitorEnter
psandoz
parents:
27883
diff
changeset
|
2 |
* Copyright (c) 2000, 2015, 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" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
28 |
#include "prims/jni.h" |
|
29 |
#include "prims/jvm.h" |
|
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
25057
diff
changeset
|
30 |
#include "runtime/atomic.inline.hpp" |
7397 | 31 |
#include "runtime/globals.hpp" |
32 |
#include "runtime/interfaceSupport.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24322
diff
changeset
|
33 |
#include "runtime/orderAccess.inline.hpp" |
7397 | 34 |
#include "runtime/reflection.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
25354
diff
changeset
|
35 |
#include "runtime/vm_version.hpp" |
7397 | 36 |
#include "services/threadService.hpp" |
18025 | 37 |
#include "trace/tracing.hpp" |
7397 | 38 |
#include "utilities/copy.hpp" |
39 |
#include "utilities/dtrace.hpp" |
|
27684
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
40 |
#include "utilities/macros.hpp" |
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
41 |
#if INCLUDE_ALL_GCS |
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
42 |
#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
43 |
#endif // INCLUDE_ALL_GCS |
7397 | 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 |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
264 |
// VM_Version::supports_cx8() is a surrogate for 'supports atomic long memory ops'. |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
265 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
266 |
// On platforms which do not support atomic compare-and-swap of jlong (8 byte) |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
267 |
// values we have to use a lock-based scheme to enforce atomicity. This has to be |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
268 |
// applied to all Unsafe operations that set the value of a jlong field. Even so |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
269 |
// the compareAndSwapLong operation will not be atomic with respect to direct stores |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
270 |
// to the field from Java code. It is important therefore that any Java code that |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
271 |
// utilizes these Unsafe jlong operations does not perform direct stores. To permit |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
272 |
// direct loads of the field from Java code we must also use Atomic::store within the |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
273 |
// locked regions. And for good measure, in case there are direct stores, we also |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
274 |
// employ Atomic::load within those regions. Note that the field in question must be |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
275 |
// volatile and so must have atomic load/store accesses applied at the Java level. |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
276 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
277 |
// The locking scheme could utilize a range of strategies for controlling the locking |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
278 |
// granularity: from a lock per-field through to a single global lock. The latter is |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
279 |
// the simplest and is used for the current implementation. Note that the Java object |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
280 |
// that contains the field, can not, in general, be used for locking. To do so can lead |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
281 |
// to deadlocks as we may introduce locking into what appears to the Java code to be a |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
282 |
// lock-free path. |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
283 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
284 |
// As all the locked-regions are very short and themselves non-blocking we can treat |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
285 |
// them as leaf routines and elide safepoint checks (ie we don't perform any thread |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
286 |
// state transitions even when blocking for the lock). Note that if we do choose to |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
287 |
// add safepoint checks and thread state transitions, we must ensure that we calculate |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
288 |
// the address of the field _after_ we have acquired the lock, else the object may have |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
289 |
// been moved by the GC |
1 | 290 |
|
291 |
UNSAFE_ENTRY(jlong, Unsafe_GetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
|
292 |
UnsafeWrapper("Unsafe_GetLongVolatile"); |
|
293 |
{ |
|
294 |
if (VM_Version::supports_cx8()) { |
|
295 |
GET_FIELD_VOLATILE(obj, offset, jlong, v); |
|
296 |
return v; |
|
297 |
} |
|
298 |
else { |
|
299 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
300 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
301 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
302 |
jlong value = Atomic::load(addr); |
1 | 303 |
return value; |
304 |
} |
|
305 |
} |
|
306 |
UNSAFE_END |
|
307 |
||
308 |
UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) |
|
309 |
UnsafeWrapper("Unsafe_SetLongVolatile"); |
|
310 |
{ |
|
311 |
if (VM_Version::supports_cx8()) { |
|
312 |
SET_FIELD_VOLATILE(obj, offset, jlong, x); |
|
313 |
} |
|
314 |
else { |
|
315 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
316 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
317 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
318 |
Atomic::store(x, addr); |
1 | 319 |
} |
320 |
} |
|
321 |
UNSAFE_END |
|
322 |
||
17316 | 323 |
#endif // not SUPPORTS_NATIVE_CX8 |
1 | 324 |
|
325 |
#define DEFINE_GETSETOOP(jboolean, Boolean) \ |
|
326 |
\ |
|
327 |
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) \ |
|
328 |
UnsafeWrapper("Unsafe_Get"#Boolean); \ |
|
329 |
if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); \ |
|
330 |
GET_FIELD(obj, offset, jboolean, v); \ |
|
331 |
return v; \ |
|
332 |
UNSAFE_END \ |
|
333 |
\ |
|
334 |
UNSAFE_ENTRY(void, Unsafe_Set##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jboolean x)) \ |
|
335 |
UnsafeWrapper("Unsafe_Set"#Boolean); \ |
|
336 |
if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); \ |
|
337 |
SET_FIELD(obj, offset, jboolean, x); \ |
|
338 |
UNSAFE_END \ |
|
339 |
\ |
|
340 |
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ |
|
341 |
UnsafeWrapper("Unsafe_Get"#Boolean); \ |
|
342 |
GET_FIELD(obj, offset, jboolean, v); \ |
|
343 |
return v; \ |
|
344 |
UNSAFE_END \ |
|
345 |
\ |
|
346 |
UNSAFE_ENTRY(void, Unsafe_Set##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ |
|
347 |
UnsafeWrapper("Unsafe_Set"#Boolean); \ |
|
348 |
SET_FIELD(obj, offset, jboolean, x); \ |
|
349 |
UNSAFE_END \ |
|
350 |
\ |
|
351 |
// END DEFINE_GETSETOOP. |
|
352 |
||
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
353 |
DEFINE_GETSETOOP(jboolean, Boolean) |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
354 |
DEFINE_GETSETOOP(jbyte, Byte) |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
355 |
DEFINE_GETSETOOP(jshort, Short); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
356 |
DEFINE_GETSETOOP(jchar, Char); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
357 |
DEFINE_GETSETOOP(jint, Int); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
358 |
DEFINE_GETSETOOP(jlong, Long); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
359 |
DEFINE_GETSETOOP(jfloat, Float); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
360 |
DEFINE_GETSETOOP(jdouble, Double); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
361 |
|
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
362 |
#undef DEFINE_GETSETOOP |
1 | 363 |
|
364 |
#define DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) \ |
|
365 |
\ |
|
366 |
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \ |
|
367 |
UnsafeWrapper("Unsafe_Get"#Boolean); \ |
|
368 |
GET_FIELD_VOLATILE(obj, offset, jboolean, v); \ |
|
369 |
return v; \ |
|
370 |
UNSAFE_END \ |
|
371 |
\ |
|
372 |
UNSAFE_ENTRY(void, Unsafe_Set##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \ |
|
373 |
UnsafeWrapper("Unsafe_Set"#Boolean); \ |
|
374 |
SET_FIELD_VOLATILE(obj, offset, jboolean, x); \ |
|
375 |
UNSAFE_END \ |
|
376 |
\ |
|
377 |
// END DEFINE_GETSETOOP_VOLATILE. |
|
378 |
||
379 |
DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) |
|
380 |
DEFINE_GETSETOOP_VOLATILE(jbyte, Byte) |
|
381 |
DEFINE_GETSETOOP_VOLATILE(jshort, Short); |
|
382 |
DEFINE_GETSETOOP_VOLATILE(jchar, Char); |
|
383 |
DEFINE_GETSETOOP_VOLATILE(jint, Int); |
|
384 |
DEFINE_GETSETOOP_VOLATILE(jfloat, Float); |
|
385 |
DEFINE_GETSETOOP_VOLATILE(jdouble, Double); |
|
386 |
||
17316 | 387 |
#ifdef SUPPORTS_NATIVE_CX8 |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
388 |
DEFINE_GETSETOOP_VOLATILE(jlong, Long); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
389 |
#endif |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
390 |
|
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
391 |
#undef DEFINE_GETSETOOP_VOLATILE |
1 | 392 |
|
393 |
// The non-intrinsified versions of setOrdered just use setVolatile |
|
394 |
||
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
395 |
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
|
396 |
UnsafeWrapper("Unsafe_SetOrderedInt"); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
397 |
SET_FIELD_VOLATILE(obj, offset, jint, x); |
1 | 398 |
UNSAFE_END |
399 |
||
400 |
UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) |
|
401 |
UnsafeWrapper("Unsafe_SetOrderedObject"); |
|
402 |
oop x = JNIHandles::resolve(x_h); |
|
403 |
oop p = JNIHandles::resolve(obj); |
|
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
404 |
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
|
405 |
OrderAccess::release(); |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
406 |
if (UseCompressedOops) { |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
407 |
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
|
408 |
} else { |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
409 |
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
|
410 |
} |
1 | 411 |
OrderAccess::fence(); |
412 |
UNSAFE_END |
|
413 |
||
414 |
UNSAFE_ENTRY(void, Unsafe_SetOrderedLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) |
|
415 |
UnsafeWrapper("Unsafe_SetOrderedLong"); |
|
17316 | 416 |
#ifdef SUPPORTS_NATIVE_CX8 |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
417 |
SET_FIELD_VOLATILE(obj, offset, jlong, x); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
418 |
#else |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
419 |
// Keep old code for platforms which may not have atomic long (8 bytes) instructions |
1 | 420 |
{ |
421 |
if (VM_Version::supports_cx8()) { |
|
422 |
SET_FIELD_VOLATILE(obj, offset, jlong, x); |
|
423 |
} |
|
424 |
else { |
|
425 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
426 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
427 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
428 |
Atomic::store(x, addr); |
1 | 429 |
} |
430 |
} |
|
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
431 |
#endif |
1 | 432 |
UNSAFE_END |
433 |
||
14832 | 434 |
UNSAFE_ENTRY(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe)) |
435 |
UnsafeWrapper("Unsafe_LoadFence"); |
|
436 |
OrderAccess::acquire(); |
|
437 |
UNSAFE_END |
|
438 |
||
439 |
UNSAFE_ENTRY(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) |
|
440 |
UnsafeWrapper("Unsafe_StoreFence"); |
|
441 |
OrderAccess::release(); |
|
442 |
UNSAFE_END |
|
443 |
||
444 |
UNSAFE_ENTRY(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) |
|
445 |
UnsafeWrapper("Unsafe_FullFence"); |
|
446 |
OrderAccess::fence(); |
|
447 |
UNSAFE_END |
|
448 |
||
1 | 449 |
////// Data in the C heap. |
450 |
||
451 |
// Note: These do not throw NullPointerException for bad pointers. |
|
452 |
// They just crash. Only a oop base pointer can generate a NullPointerException. |
|
453 |
// |
|
454 |
#define DEFINE_GETSETNATIVE(java_type, Type, native_type) \ |
|
455 |
\ |
|
456 |
UNSAFE_ENTRY(java_type, Unsafe_GetNative##Type(JNIEnv *env, jobject unsafe, jlong addr)) \ |
|
457 |
UnsafeWrapper("Unsafe_GetNative"#Type); \ |
|
458 |
void* p = addr_from_java(addr); \ |
|
459 |
JavaThread* t = JavaThread::current(); \ |
|
460 |
t->set_doing_unsafe_access(true); \ |
|
461 |
java_type x = *(volatile native_type*)p; \ |
|
462 |
t->set_doing_unsafe_access(false); \ |
|
463 |
return x; \ |
|
464 |
UNSAFE_END \ |
|
465 |
\ |
|
466 |
UNSAFE_ENTRY(void, Unsafe_SetNative##Type(JNIEnv *env, jobject unsafe, jlong addr, java_type x)) \ |
|
467 |
UnsafeWrapper("Unsafe_SetNative"#Type); \ |
|
468 |
JavaThread* t = JavaThread::current(); \ |
|
469 |
t->set_doing_unsafe_access(true); \ |
|
470 |
void* p = addr_from_java(addr); \ |
|
471 |
*(volatile native_type*)p = x; \ |
|
472 |
t->set_doing_unsafe_access(false); \ |
|
473 |
UNSAFE_END \ |
|
474 |
\ |
|
475 |
// END DEFINE_GETSETNATIVE. |
|
476 |
||
477 |
DEFINE_GETSETNATIVE(jbyte, Byte, signed char) |
|
478 |
DEFINE_GETSETNATIVE(jshort, Short, signed short); |
|
479 |
DEFINE_GETSETNATIVE(jchar, Char, unsigned short); |
|
480 |
DEFINE_GETSETNATIVE(jint, Int, jint); |
|
481 |
// no long -- handled specially |
|
482 |
DEFINE_GETSETNATIVE(jfloat, Float, float); |
|
483 |
DEFINE_GETSETNATIVE(jdouble, Double, double); |
|
484 |
||
485 |
#undef DEFINE_GETSETNATIVE |
|
486 |
||
487 |
UNSAFE_ENTRY(jlong, Unsafe_GetNativeLong(JNIEnv *env, jobject unsafe, jlong addr)) |
|
488 |
UnsafeWrapper("Unsafe_GetNativeLong"); |
|
489 |
JavaThread* t = JavaThread::current(); |
|
490 |
// We do it this way to avoid problems with access to heap using 64 |
|
491 |
// bit loads, as jlong in heap could be not 64-bit aligned, and on |
|
492 |
// some CPUs (SPARC) it leads to SIGBUS. |
|
493 |
t->set_doing_unsafe_access(true); |
|
494 |
void* p = addr_from_java(addr); |
|
495 |
jlong x; |
|
496 |
if (((intptr_t)p & 7) == 0) { |
|
497 |
// jlong is aligned, do a volatile access |
|
498 |
x = *(volatile jlong*)p; |
|
499 |
} else { |
|
500 |
jlong_accessor acc; |
|
501 |
acc.words[0] = ((volatile jint*)p)[0]; |
|
502 |
acc.words[1] = ((volatile jint*)p)[1]; |
|
503 |
x = acc.long_value; |
|
504 |
} |
|
505 |
t->set_doing_unsafe_access(false); |
|
506 |
return x; |
|
507 |
UNSAFE_END |
|
508 |
||
509 |
UNSAFE_ENTRY(void, Unsafe_SetNativeLong(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) |
|
510 |
UnsafeWrapper("Unsafe_SetNativeLong"); |
|
511 |
JavaThread* t = JavaThread::current(); |
|
512 |
// see comment for Unsafe_GetNativeLong |
|
513 |
t->set_doing_unsafe_access(true); |
|
514 |
void* p = addr_from_java(addr); |
|
515 |
if (((intptr_t)p & 7) == 0) { |
|
516 |
// jlong is aligned, do a volatile access |
|
517 |
*(volatile jlong*)p = x; |
|
518 |
} else { |
|
519 |
jlong_accessor acc; |
|
520 |
acc.long_value = x; |
|
521 |
((volatile jint*)p)[0] = acc.words[0]; |
|
522 |
((volatile jint*)p)[1] = acc.words[1]; |
|
523 |
} |
|
524 |
t->set_doing_unsafe_access(false); |
|
525 |
UNSAFE_END |
|
526 |
||
527 |
||
528 |
UNSAFE_ENTRY(jlong, Unsafe_GetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr)) |
|
529 |
UnsafeWrapper("Unsafe_GetNativeAddress"); |
|
530 |
void* p = addr_from_java(addr); |
|
531 |
return addr_to_java(*(void**)p); |
|
532 |
UNSAFE_END |
|
533 |
||
534 |
UNSAFE_ENTRY(void, Unsafe_SetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) |
|
535 |
UnsafeWrapper("Unsafe_SetNativeAddress"); |
|
536 |
void* p = addr_from_java(addr); |
|
537 |
*(void**)p = addr_from_java(x); |
|
538 |
UNSAFE_END |
|
539 |
||
540 |
||
541 |
////// Allocation requests |
|
542 |
||
543 |
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) |
|
544 |
UnsafeWrapper("Unsafe_AllocateInstance"); |
|
545 |
{ |
|
546 |
ThreadToNativeFromVM ttnfv(thread); |
|
547 |
return env->AllocObject(cls); |
|
548 |
} |
|
549 |
UNSAFE_END |
|
550 |
||
551 |
UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory(JNIEnv *env, jobject unsafe, jlong size)) |
|
552 |
UnsafeWrapper("Unsafe_AllocateMemory"); |
|
553 |
size_t sz = (size_t)size; |
|
554 |
if (sz != (julong)size || size < 0) { |
|
555 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
556 |
} |
|
557 |
if (sz == 0) { |
|
558 |
return 0; |
|
559 |
} |
|
560 |
sz = round_to(sz, HeapWordSize); |
|
13195 | 561 |
void* x = os::malloc(sz, mtInternal); |
1 | 562 |
if (x == NULL) { |
563 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
|
564 |
} |
|
565 |
//Copy::fill_to_words((HeapWord*)x, sz / HeapWordSize); |
|
566 |
return addr_to_java(x); |
|
567 |
UNSAFE_END |
|
568 |
||
569 |
UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) |
|
570 |
UnsafeWrapper("Unsafe_ReallocateMemory"); |
|
571 |
void* p = addr_from_java(addr); |
|
572 |
size_t sz = (size_t)size; |
|
573 |
if (sz != (julong)size || size < 0) { |
|
574 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
575 |
} |
|
576 |
if (sz == 0) { |
|
577 |
os::free(p); |
|
578 |
return 0; |
|
579 |
} |
|
580 |
sz = round_to(sz, HeapWordSize); |
|
13195 | 581 |
void* x = (p == NULL) ? os::malloc(sz, mtInternal) : os::realloc(p, sz, mtInternal); |
1 | 582 |
if (x == NULL) { |
583 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
|
584 |
} |
|
585 |
return addr_to_java(x); |
|
586 |
UNSAFE_END |
|
587 |
||
588 |
UNSAFE_ENTRY(void, Unsafe_FreeMemory(JNIEnv *env, jobject unsafe, jlong addr)) |
|
589 |
UnsafeWrapper("Unsafe_FreeMemory"); |
|
590 |
void* p = addr_from_java(addr); |
|
591 |
if (p == NULL) { |
|
592 |
return; |
|
593 |
} |
|
594 |
os::free(p); |
|
595 |
UNSAFE_END |
|
596 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
597 |
UNSAFE_ENTRY(void, Unsafe_SetMemory(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) |
1 | 598 |
UnsafeWrapper("Unsafe_SetMemory"); |
599 |
size_t sz = (size_t)size; |
|
600 |
if (sz != (julong)size || size < 0) { |
|
601 |
THROW(vmSymbols::java_lang_IllegalArgumentException()); |
|
602 |
} |
|
603 |
oop base = JNIHandles::resolve(obj); |
|
604 |
void* p = index_oop_from_field_offset_long(base, offset); |
|
605 |
Copy::fill_to_memory_atomic(p, sz, value); |
|
606 |
UNSAFE_END |
|
607 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
608 |
UNSAFE_ENTRY(void, Unsafe_CopyMemory(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) |
1 | 609 |
UnsafeWrapper("Unsafe_CopyMemory"); |
610 |
if (size == 0) { |
|
611 |
return; |
|
612 |
} |
|
613 |
size_t sz = (size_t)size; |
|
614 |
if (sz != (julong)size || size < 0) { |
|
615 |
THROW(vmSymbols::java_lang_IllegalArgumentException()); |
|
616 |
} |
|
617 |
oop srcp = JNIHandles::resolve(srcObj); |
|
618 |
oop dstp = JNIHandles::resolve(dstObj); |
|
619 |
if (dstp != NULL && !dstp->is_typeArray()) { |
|
620 |
// NYI: This works only for non-oop arrays at present. |
|
621 |
// Generalizing it would be reasonable, but requires card marking. |
|
622 |
// Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad. |
|
623 |
THROW(vmSymbols::java_lang_IllegalArgumentException()); |
|
624 |
} |
|
625 |
void* src = index_oop_from_field_offset_long(srcp, srcOffset); |
|
626 |
void* dst = index_oop_from_field_offset_long(dstp, dstOffset); |
|
627 |
Copy::conjoint_memory_atomic(src, dst, sz); |
|
628 |
UNSAFE_END |
|
629 |
||
630 |
||
631 |
////// Random queries |
|
632 |
||
633 |
// See comment at file start about UNSAFE_LEAF |
|
634 |
//UNSAFE_LEAF(jint, Unsafe_AddressSize()) |
|
635 |
UNSAFE_ENTRY(jint, Unsafe_AddressSize(JNIEnv *env, jobject unsafe)) |
|
636 |
UnsafeWrapper("Unsafe_AddressSize"); |
|
637 |
return sizeof(void*); |
|
638 |
UNSAFE_END |
|
639 |
||
640 |
// See comment at file start about UNSAFE_LEAF |
|
641 |
//UNSAFE_LEAF(jint, Unsafe_PageSize()) |
|
642 |
UNSAFE_ENTRY(jint, Unsafe_PageSize(JNIEnv *env, jobject unsafe)) |
|
643 |
UnsafeWrapper("Unsafe_PageSize"); |
|
644 |
return os::vm_page_size(); |
|
645 |
UNSAFE_END |
|
646 |
||
647 |
jint find_field_offset(jobject field, int must_be_static, TRAPS) { |
|
648 |
if (field == NULL) { |
|
649 |
THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
650 |
} |
|
651 |
||
652 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
653 |
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
|
654 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 655 |
int slot = java_lang_reflect_Field::slot(reflected); |
656 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
657 |
||
658 |
if (must_be_static >= 0) { |
|
659 |
int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); |
|
660 |
if (must_be_static != really_is_static) { |
|
661 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
662 |
} |
|
663 |
} |
|
664 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
665 |
int offset = InstanceKlass::cast(k)->field_offset(slot); |
1 | 666 |
return field_offset_from_byte_offset(offset); |
667 |
} |
|
668 |
||
669 |
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) |
|
670 |
UnsafeWrapper("Unsafe_ObjectFieldOffset"); |
|
671 |
return find_field_offset(field, 0, THREAD); |
|
672 |
UNSAFE_END |
|
673 |
||
674 |
UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset(JNIEnv *env, jobject unsafe, jobject field)) |
|
675 |
UnsafeWrapper("Unsafe_StaticFieldOffset"); |
|
676 |
return find_field_offset(field, 1, THREAD); |
|
677 |
UNSAFE_END |
|
678 |
||
679 |
UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBaseFromField(JNIEnv *env, jobject unsafe, jobject field)) |
|
680 |
UnsafeWrapper("Unsafe_StaticFieldBase"); |
|
681 |
// Note: In this VM implementation, a field address is always a short |
|
682 |
// offset from the base of a a klass metaobject. Thus, the full dynamic |
|
683 |
// range of the return type is never used. However, some implementations |
|
684 |
// might put the static field inside an array shared by many classes, |
|
685 |
// or even at a fixed address, in which case the address could be quite |
|
686 |
// large. In that last case, this function would return NULL, since |
|
687 |
// the address would operate alone, without any base pointer. |
|
688 |
||
689 |
if (field == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
690 |
||
691 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
692 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
693 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
694 |
||
695 |
if ((modifiers & JVM_ACC_STATIC) == 0) { |
|
696 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
697 |
} |
|
698 |
||
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8490
diff
changeset
|
699 |
return JNIHandles::make_local(env, mirror); |
1 | 700 |
UNSAFE_END |
701 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
702 |
UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized(JNIEnv *env, jobject unsafe, jobject clazz)) { |
1 | 703 |
UnsafeWrapper("Unsafe_EnsureClassInitialized"); |
704 |
if (clazz == NULL) { |
|
705 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
706 |
} |
|
707 |
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
|
708 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
709 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
14488 | 710 |
if (klass != NULL && klass->should_be_initialized()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
711 |
InstanceKlass* k = InstanceKlass::cast(klass); |
1 | 712 |
k->initialize(CHECK); |
713 |
} |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
714 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
715 |
UNSAFE_END |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
716 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
717 |
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
|
718 |
UnsafeWrapper("Unsafe_ShouldBeInitialized"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
719 |
if (clazz == NULL) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
720 |
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
|
721 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
722 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
723 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
14488 | 724 |
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
|
725 |
return true; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
726 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
727 |
return false; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
728 |
} |
1 | 729 |
UNSAFE_END |
730 |
||
731 |
static void getBaseAndScale(int& base, int& scale, jclass acls, TRAPS) { |
|
732 |
if (acls == NULL) { |
|
733 |
THROW(vmSymbols::java_lang_NullPointerException()); |
|
734 |
} |
|
735 |
oop mirror = JNIHandles::resolve_non_null(acls); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
736 |
Klass* k = java_lang_Class::as_Klass(mirror); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
737 |
if (k == NULL || !k->oop_is_array()) { |
1 | 738 |
THROW(vmSymbols::java_lang_InvalidClassException()); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
739 |
} else if (k->oop_is_objArray()) { |
1 | 740 |
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
|
741 |
scale = heapOopSize; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
742 |
} else if (k->oop_is_typeArray()) { |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
743 |
TypeArrayKlass* tak = TypeArrayKlass::cast(k); |
1 | 744 |
base = tak->array_header_in_bytes(); |
745 |
assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); |
|
746 |
scale = (1 << tak->log2_element_size()); |
|
747 |
} else { |
|
748 |
ShouldNotReachHere(); |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset(JNIEnv *env, jobject unsafe, jclass acls)) |
|
753 |
UnsafeWrapper("Unsafe_ArrayBaseOffset"); |
|
754 |
int base, scale; |
|
755 |
getBaseAndScale(base, scale, acls, CHECK_0); |
|
756 |
return field_offset_from_byte_offset(base); |
|
757 |
UNSAFE_END |
|
758 |
||
759 |
||
760 |
UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale(JNIEnv *env, jobject unsafe, jclass acls)) |
|
761 |
UnsafeWrapper("Unsafe_ArrayIndexScale"); |
|
762 |
int base, scale; |
|
763 |
getBaseAndScale(base, scale, acls, CHECK_0); |
|
764 |
// This VM packs both fields and array elements down to the byte. |
|
765 |
// But watch out: If this changes, so that array references for |
|
766 |
// a given primitive type (say, T_BOOLEAN) use different memory units |
|
767 |
// than fields, this method MUST return zero for such arrays. |
|
768 |
// For example, the VM used to store sub-word sized fields in full |
|
769 |
// words in the object layout, so that accessors like getByte(Object,int) |
|
770 |
// did not really do what one might expect for arrays. Therefore, |
|
771 |
// this function used to report a zero scale factor, so that the user |
|
772 |
// would know not to attempt to access sub-word array elements. |
|
773 |
// // Code for unpacked fields: |
|
774 |
// if (scale < wordSize) return 0; |
|
775 |
||
776 |
// The following allows for a pretty general fieldOffset cookie scheme, |
|
777 |
// but requires it to be linear in byte offset. |
|
778 |
return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); |
|
779 |
UNSAFE_END |
|
780 |
||
781 |
||
782 |
static inline void throw_new(JNIEnv *env, const char *ename) { |
|
783 |
char buf[100]; |
|
27471 | 784 |
jio_snprintf(buf, 100, "%s%s", "java/lang/", ename); |
1 | 785 |
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
|
786 |
if (env->ExceptionCheck()) { |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
787 |
env->ExceptionClear(); |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
788 |
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
|
789 |
return; |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
790 |
} |
1 | 791 |
char* msg = NULL; |
792 |
env->ThrowNew(cls, msg); |
|
793 |
} |
|
794 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
795 |
static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { |
1 | 796 |
{ |
797 |
// Code lifted from JDK 1.3 ClassLoader.c |
|
798 |
||
799 |
jbyte *body; |
|
800 |
char *utfName; |
|
801 |
jclass result = 0; |
|
802 |
char buf[128]; |
|
803 |
||
804 |
if (UsePerfData) { |
|
805 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
|
806 |
} |
|
807 |
||
808 |
if (data == NULL) { |
|
809 |
throw_new(env, "NullPointerException"); |
|
810 |
return 0; |
|
811 |
} |
|
812 |
||
813 |
/* Work around 4153825. malloc crashes on Solaris when passed a |
|
814 |
* negative size. |
|
815 |
*/ |
|
816 |
if (length < 0) { |
|
817 |
throw_new(env, "ArrayIndexOutOfBoundsException"); |
|
818 |
return 0; |
|
819 |
} |
|
820 |
||
13195 | 821 |
body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal); |
1 | 822 |
|
823 |
if (body == 0) { |
|
824 |
throw_new(env, "OutOfMemoryError"); |
|
825 |
return 0; |
|
826 |
} |
|
827 |
||
828 |
env->GetByteArrayRegion(data, offset, length, body); |
|
829 |
||
830 |
if (env->ExceptionOccurred()) |
|
831 |
goto free_body; |
|
832 |
||
833 |
if (name != NULL) { |
|
834 |
uint len = env->GetStringUTFLength(name); |
|
835 |
int unicode_len = env->GetStringLength(name); |
|
836 |
if (len >= sizeof(buf)) { |
|
13195 | 837 |
utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
1 | 838 |
if (utfName == NULL) { |
839 |
throw_new(env, "OutOfMemoryError"); |
|
840 |
goto free_body; |
|
841 |
} |
|
842 |
} else { |
|
843 |
utfName = buf; |
|
844 |
} |
|
845 |
env->GetStringUTFRegion(name, 0, unicode_len, utfName); |
|
846 |
//VerifyFixClassname(utfName); |
|
847 |
for (uint i = 0; i < len; i++) { |
|
848 |
if (utfName[i] == '.') utfName[i] = '/'; |
|
849 |
} |
|
850 |
} else { |
|
851 |
utfName = NULL; |
|
852 |
} |
|
853 |
||
854 |
result = JVM_DefineClass(env, utfName, loader, body, length, pd); |
|
855 |
||
856 |
if (utfName && utfName != buf) |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27874
diff
changeset
|
857 |
FREE_C_HEAP_ARRAY(char, utfName); |
1 | 858 |
|
859 |
free_body: |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27874
diff
changeset
|
860 |
FREE_C_HEAP_ARRAY(jbyte, body); |
1 | 861 |
return result; |
862 |
} |
|
863 |
} |
|
864 |
||
865 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
866 |
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
|
867 |
UnsafeWrapper("Unsafe_DefineClass"); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
868 |
{ |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
869 |
ThreadToNativeFromVM ttnfv(thread); |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
870 |
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
|
871 |
} |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
872 |
UNSAFE_END |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
873 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
874 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
875 |
// 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
|
876 |
// - 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
|
877 |
// - 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
|
878 |
// - 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
|
879 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
880 |
// 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
|
881 |
// 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
|
882 |
// 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
|
883 |
// 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
|
884 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
885 |
// 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
|
886 |
// 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
|
887 |
// 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
|
888 |
// 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
|
889 |
// 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
|
890 |
// 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
|
891 |
// 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
|
892 |
// restrictions. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
893 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
894 |
// 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
|
895 |
// 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
|
896 |
// 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
|
897 |
// access one of its anonymous classes. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
898 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
899 |
// 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
|
900 |
// 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
|
901 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
902 |
// 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
|
903 |
// 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
|
904 |
// 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
|
905 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
906 |
// 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
|
907 |
// 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
|
908 |
// 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
|
909 |
// 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
|
910 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
911 |
// 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
|
912 |
// 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
|
913 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
914 |
// 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
|
915 |
// 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
|
916 |
// 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
|
917 |
// 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
|
918 |
// 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
|
919 |
// 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
|
920 |
// 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
|
921 |
// 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
|
922 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
923 |
static instanceKlassHandle |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
924 |
Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
925 |
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
|
926 |
HeapWord* *temp_alloc, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
927 |
TRAPS) { |
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 |
if (UsePerfData) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
930 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
931 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
932 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
933 |
if (data == NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
934 |
THROW_0(vmSymbols::java_lang_NullPointerException()); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
935 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
936 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
937 |
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
|
938 |
jint word_length = (length + sizeof(HeapWord)-1) / sizeof(HeapWord); |
13195 | 939 |
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
|
940 |
if (body == NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
941 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
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 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
944 |
// caller responsible to free it: |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
945 |
(*temp_alloc) = body; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
946 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
947 |
{ |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
948 |
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
|
949 |
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
|
950 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
951 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
952 |
u1* class_bytes = (u1*) body; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
953 |
int class_bytes_length = (int) length; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
954 |
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
|
955 |
if (class_bytes == NULL |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
956 |
|| host_class == NULL |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
957 |
|| length != class_bytes_length) |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
958 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
959 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
960 |
objArrayHandle cp_patches_h; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
961 |
if (cp_patches_jh != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
962 |
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
|
963 |
if (!p->is_objArray()) |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
964 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
965 |
cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
966 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
967 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
968 |
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
|
969 |
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
|
970 |
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
|
971 |
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
|
972 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
973 |
GrowableArray<Handle>* cp_patches = NULL; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
974 |
if (cp_patches_h.not_null()) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
975 |
int alen = cp_patches_h->length(); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
976 |
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
|
977 |
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
|
978 |
if (p != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
979 |
Handle patch(THREAD, p); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
980 |
if (cp_patches == NULL) |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
981 |
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
|
982 |
cp_patches->at_put(i, patch); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
983 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
984 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
985 |
} |
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 |
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
|
988 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
989 |
instanceKlassHandle anon_klass; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
990 |
{ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7885
diff
changeset
|
991 |
Symbol* no_class_name = NULL; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
992 |
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
|
993 |
host_loader, host_domain, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
994 |
&st, host_klass, cp_patches, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
995 |
CHECK_NULL); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
996 |
if (anonk == NULL) return NULL; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
997 |
anon_klass = instanceKlassHandle(THREAD, anonk); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
998 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
999 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1000 |
return anon_klass; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1001 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1002 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1003 |
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
|
1004 |
{ |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1005 |
instanceKlassHandle anon_klass; |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1006 |
jobject res_jh = NULL; |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1007 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1008 |
UnsafeWrapper("Unsafe_DefineAnonymousClass"); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1009 |
ResourceMark rm(THREAD); |
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 |
HeapWord* temp_alloc = NULL; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1012 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1013 |
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
|
1014 |
cp_patches_jh, |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1015 |
&temp_alloc, THREAD); |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1016 |
if (anon_klass() != NULL) |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1017 |
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
|
1018 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1019 |
// try/finally clause: |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1020 |
if (temp_alloc != NULL) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27874
diff
changeset
|
1021 |
FREE_C_HEAP_ARRAY(HeapWord, temp_alloc); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1022 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1023 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1024 |
// 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
|
1025 |
// 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
|
1026 |
// it alive afterwards. |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1027 |
if (anon_klass() != NULL) { |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1028 |
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
|
1029 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1030 |
|
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1031 |
// let caller initialize it as needed... |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
1032 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1033 |
return (jclass) res_jh; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1034 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1035 |
UNSAFE_END |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1036 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1037 |
|
1 | 1038 |
|
1039 |
UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) |
|
1040 |
UnsafeWrapper("Unsafe_ThrowException"); |
|
1041 |
{ |
|
1042 |
ThreadToNativeFromVM ttnfv(thread); |
|
1043 |
env->Throw(thr); |
|
1044 |
} |
|
1045 |
UNSAFE_END |
|
1046 |
||
1047 |
// JSR166 ------------------------------------------------------------------ |
|
1048 |
||
1049 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) |
|
1050 |
UnsafeWrapper("Unsafe_CompareAndSwapObject"); |
|
1051 |
oop x = JNIHandles::resolve(x_h); |
|
1052 |
oop e = JNIHandles::resolve(e_h); |
|
1053 |
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
|
1054 |
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
|
1055 |
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
|
1056 |
jboolean success = (res == e); |
1 | 1057 |
if (success) |
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
1058 |
update_barrier_set((void*)addr, x); |
1 | 1059 |
return success; |
1060 |
UNSAFE_END |
|
1061 |
||
1062 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) |
|
1063 |
UnsafeWrapper("Unsafe_CompareAndSwapInt"); |
|
1064 |
oop p = JNIHandles::resolve(obj); |
|
1065 |
jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); |
|
1066 |
return (jint)(Atomic::cmpxchg(x, addr, e)) == e; |
|
1067 |
UNSAFE_END |
|
1068 |
||
1069 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) |
|
1070 |
UnsafeWrapper("Unsafe_CompareAndSwapLong"); |
|
1071 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
1072 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1073 |
#ifdef SUPPORTS_NATIVE_CX8 |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1074 |
return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1075 |
#else |
1 | 1076 |
if (VM_Version::supports_cx8()) |
1077 |
return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; |
|
1078 |
else { |
|
1079 |
jboolean success = false; |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1080 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1081 |
jlong val = Atomic::load(addr); |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1082 |
if (val == e) { Atomic::store(x, addr); success = true; } |
1 | 1083 |
return success; |
1084 |
} |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1085 |
#endif |
1 | 1086 |
UNSAFE_END |
1087 |
||
1088 |
UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) |
|
1089 |
UnsafeWrapper("Unsafe_Park"); |
|
18025 | 1090 |
EventThreadPark event; |
22796 | 1091 |
HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time); |
1092 |
||
1 | 1093 |
JavaThreadParkedState jtps(thread, time != 0); |
1094 |
thread->parker()->park(isAbsolute != 0, time); |
|
22796 | 1095 |
|
1096 |
HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); |
|
18025 | 1097 |
if (event.should_commit()) { |
1098 |
oop obj = thread->current_park_blocker(); |
|
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
1099 |
event.set_klass((obj != NULL) ? obj->klass() : NULL); |
18025 | 1100 |
event.set_timeout(time); |
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
1101 |
event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0); |
18025 | 1102 |
event.commit(); |
1103 |
} |
|
1 | 1104 |
UNSAFE_END |
1105 |
||
1106 |
UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) |
|
1107 |
UnsafeWrapper("Unsafe_Unpark"); |
|
1108 |
Parker* p = NULL; |
|
1109 |
if (jthread != NULL) { |
|
1110 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
1111 |
if (java_thread != NULL) { |
|
1112 |
jlong lp = java_lang_Thread::park_event(java_thread); |
|
1113 |
if (lp != 0) { |
|
1114 |
// This cast is OK even though the jlong might have been read |
|
1115 |
// non-atomically on 32bit systems, since there, one word will |
|
1116 |
// always be zero anyway and the value set is always the same |
|
1117 |
p = (Parker*)addr_from_java(lp); |
|
1118 |
} else { |
|
1119 |
// Grab lock if apparently null or using older version of library |
|
1120 |
MutexLocker mu(Threads_lock); |
|
1121 |
java_thread = JNIHandles::resolve_non_null(jthread); |
|
1122 |
if (java_thread != NULL) { |
|
1123 |
JavaThread* thr = java_lang_Thread::thread(java_thread); |
|
1124 |
if (thr != NULL) { |
|
1125 |
p = thr->parker(); |
|
1126 |
if (p != NULL) { // Bind to Java thread for next time. |
|
1127 |
java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
|
1128 |
} |
|
1129 |
} |
|
1130 |
} |
|
1131 |
} |
|
1132 |
} |
|
1133 |
} |
|
1134 |
if (p != NULL) { |
|
22796 | 1135 |
HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
1 | 1136 |
p->unpark(); |
1137 |
} |
|
1138 |
UNSAFE_END |
|
1139 |
||
1140 |
UNSAFE_ENTRY(jint, Unsafe_Loadavg(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) |
|
1141 |
UnsafeWrapper("Unsafe_Loadavg"); |
|
1142 |
const int max_nelem = 3; |
|
1143 |
double la[max_nelem]; |
|
1144 |
jint ret; |
|
1145 |
||
1146 |
typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); |
|
1147 |
assert(a->is_typeArray(), "must be type array"); |
|
1148 |
||
1149 |
if (nelem < 0 || nelem > max_nelem || a->length() < nelem) { |
|
1150 |
ThreadToNativeFromVM ttnfv(thread); |
|
1151 |
throw_new(env, "ArrayIndexOutOfBoundsException"); |
|
1152 |
return -1; |
|
1153 |
} |
|
1154 |
||
1155 |
ret = os::loadavg(la, nelem); |
|
1156 |
if (ret == -1) return -1; |
|
1157 |
||
1158 |
// if successful, ret is the number of samples actually retrieved. |
|
1159 |
assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); |
|
1160 |
switch(ret) { |
|
1161 |
case 3: a->double_at_put(2, (jdouble)la[2]); // fall through |
|
1162 |
case 2: a->double_at_put(1, (jdouble)la[1]); // fall through |
|
1163 |
case 1: a->double_at_put(0, (jdouble)la[0]); break; |
|
1164 |
} |
|
1165 |
return ret; |
|
1166 |
UNSAFE_END |
|
1167 |
||
1168 |
||
1169 |
/// JVM_RegisterUnsafeMethods |
|
1170 |
||
1171 |
#define ADR "J" |
|
1172 |
||
1173 |
#define LANG "Ljava/lang/" |
|
1174 |
||
1175 |
#define OBJ LANG"Object;" |
|
1176 |
#define CLS LANG"Class;" |
|
1177 |
#define FLD LANG"reflect/Field;" |
|
1178 |
#define THR LANG"Throwable;" |
|
1179 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1180 |
#define DC_Args LANG"String;[BII" LANG"ClassLoader;" "Ljava/security/ProtectionDomain;" |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1181 |
#define DAC_Args CLS"[B["OBJ |
1 | 1182 |
|
1183 |
#define CC (char*) /*cast a literal from (const char*)*/ |
|
1184 |
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
|
1185 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1186 |
#define DECLARE_GETPUTOOP(Boolean, Z) \ |
1 | 1187 |
{CC"get"#Boolean, CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean)}, \ |
1188 |
{CC"put"#Boolean, CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean)}, \ |
|
1189 |
{CC"get"#Boolean"Volatile", CC"("OBJ"J)"#Z, FN_PTR(Unsafe_Get##Boolean##Volatile)}, \ |
|
1190 |
{CC"put"#Boolean"Volatile", CC"("OBJ"J"#Z")V", FN_PTR(Unsafe_Set##Boolean##Volatile)} |
|
1191 |
||
1192 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1193 |
#define DECLARE_GETPUTNATIVE(Byte, B) \ |
1 | 1194 |
{CC"get"#Byte, CC"("ADR")"#B, FN_PTR(Unsafe_GetNative##Byte)}, \ |
1195 |
{CC"put"#Byte, CC"("ADR#B")V", FN_PTR(Unsafe_SetNative##Byte)} |
|
1196 |
||
1197 |
||
1198 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1199 |
static JNINativeMethod methods[] = { |
1 | 1200 |
{CC"getObject", CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObject)}, |
1201 |
{CC"putObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObject)}, |
|
1202 |
{CC"getObjectVolatile",CC"("OBJ"J)"OBJ"", FN_PTR(Unsafe_GetObjectVolatile)}, |
|
1203 |
{CC"putObjectVolatile",CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetObjectVolatile)}, |
|
1204 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1205 |
DECLARE_GETPUTOOP(Boolean, Z), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1206 |
DECLARE_GETPUTOOP(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1207 |
DECLARE_GETPUTOOP(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1208 |
DECLARE_GETPUTOOP(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1209 |
DECLARE_GETPUTOOP(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1210 |
DECLARE_GETPUTOOP(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1211 |
DECLARE_GETPUTOOP(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1212 |
DECLARE_GETPUTOOP(Double, D), |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1213 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1214 |
DECLARE_GETPUTNATIVE(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1215 |
DECLARE_GETPUTNATIVE(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1216 |
DECLARE_GETPUTNATIVE(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1217 |
DECLARE_GETPUTNATIVE(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1218 |
DECLARE_GETPUTNATIVE(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1219 |
DECLARE_GETPUTNATIVE(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1220 |
DECLARE_GETPUTNATIVE(Double, D), |
1 | 1221 |
|
1222 |
{CC"getAddress", CC"("ADR")"ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
|
1223 |
{CC"putAddress", CC"("ADR""ADR")V", FN_PTR(Unsafe_SetNativeAddress)}, |
|
1224 |
||
1225 |
{CC"allocateMemory", CC"(J)"ADR, FN_PTR(Unsafe_AllocateMemory)}, |
|
1226 |
{CC"reallocateMemory", CC"("ADR"J)"ADR, FN_PTR(Unsafe_ReallocateMemory)}, |
|
1227 |
{CC"freeMemory", CC"("ADR")V", FN_PTR(Unsafe_FreeMemory)}, |
|
1228 |
||
1229 |
{CC"objectFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_ObjectFieldOffset)}, |
|
1230 |
{CC"staticFieldOffset", CC"("FLD")J", FN_PTR(Unsafe_StaticFieldOffset)}, |
|
1231 |
{CC"staticFieldBase", CC"("FLD")"OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)}, |
|
1232 |
{CC"ensureClassInitialized",CC"("CLS")V", FN_PTR(Unsafe_EnsureClassInitialized)}, |
|
1233 |
{CC"arrayBaseOffset", CC"("CLS")I", FN_PTR(Unsafe_ArrayBaseOffset)}, |
|
1234 |
{CC"arrayIndexScale", CC"("CLS")I", FN_PTR(Unsafe_ArrayIndexScale)}, |
|
1235 |
{CC"addressSize", CC"()I", FN_PTR(Unsafe_AddressSize)}, |
|
1236 |
{CC"pageSize", CC"()I", FN_PTR(Unsafe_PageSize)}, |
|
1237 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1238 |
{CC"defineClass", CC"("DC_Args")"CLS, FN_PTR(Unsafe_DefineClass)}, |
1 | 1239 |
{CC"allocateInstance", CC"("CLS")"OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
1240 |
{CC"throwException", CC"("THR")V", FN_PTR(Unsafe_ThrowException)}, |
|
1241 |
{CC"compareAndSwapObject", CC"("OBJ"J"OBJ""OBJ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, |
|
1242 |
{CC"compareAndSwapInt", CC"("OBJ"J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, |
|
1243 |
{CC"compareAndSwapLong", CC"("OBJ"J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, |
|
1244 |
{CC"putOrderedObject", CC"("OBJ"J"OBJ")V", FN_PTR(Unsafe_SetOrderedObject)}, |
|
1245 |
{CC"putOrderedInt", CC"("OBJ"JI)V", FN_PTR(Unsafe_SetOrderedInt)}, |
|
1246 |
{CC"putOrderedLong", CC"("OBJ"JJ)V", FN_PTR(Unsafe_SetOrderedLong)}, |
|
1247 |
{CC"park", CC"(ZJ)V", FN_PTR(Unsafe_Park)}, |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1248 |
{CC"unpark", CC"("OBJ")V", FN_PTR(Unsafe_Unpark)}, |
1 | 1249 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1250 |
{CC"getLoadAverage", CC"([DI)I", FN_PTR(Unsafe_Loadavg)}, |
1 | 1251 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1252 |
{CC"copyMemory", CC"("OBJ"J"OBJ"JJ)V", FN_PTR(Unsafe_CopyMemory)}, |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1253 |
{CC"setMemory", CC"("OBJ"JJB)V", FN_PTR(Unsafe_SetMemory)}, |
1 | 1254 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
1255 |
{CC"defineAnonymousClass", CC"("DAC_Args")"CLS, FN_PTR(Unsafe_DefineAnonymousClass)}, |
1 | 1256 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
1257 |
{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
|
1258 |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1259 |
{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
|
1260 |
{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
|
1261 |
{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
|
1262 |
}; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1263 |
|
1 | 1264 |
#undef CC |
1265 |
#undef FN_PTR |
|
1266 |
||
1267 |
#undef ADR |
|
1268 |
#undef LANG |
|
1269 |
#undef OBJ |
|
1270 |
#undef CLS |
|
1271 |
#undef FLD |
|
1272 |
#undef THR |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1273 |
#undef DC_Args |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1274 |
#undef DAC_Args |
1 | 1275 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1276 |
#undef DECLARE_GETPUTOOP |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1277 |
#undef DECLARE_GETPUTNATIVE |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1278 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1279 |
|
1 | 1280 |
// This one function is exported, used by NativeLookup. |
1281 |
// The Unsafe_xxx functions above are called only from the interpreter. |
|
1282 |
// The optimizer looks at names and signatures to recognize |
|
1283 |
// individual functions. |
|
1284 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1285 |
JVM_ENTRY(void, JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafeclass)) |
1 | 1286 |
UnsafeWrapper("JVM_RegisterUnsafeMethods"); |
1287 |
{ |
|
1288 |
ThreadToNativeFromVM ttnfv(thread); |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1289 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1290 |
int ok = env->RegisterNatives(unsafeclass, methods, sizeof(methods)/sizeof(JNINativeMethod)); |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1291 |
guarantee(ok == 0, "register unsafe natives"); |
1 | 1292 |
} |
1293 |
JVM_END |