author | amurillo |
Fri, 22 Apr 2016 01:04:00 -0700 | |
changeset 38060 | 954c9575f653 |
parent 38014 | 8731fa11f766 |
parent 37480 | 291ee208fb72 |
child 38211 | fe30fdab0f62 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
36086 | 2 |
* Copyright (c) 2000, 2016, 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" |
34666 | 26 |
#include "classfile/classFileStream.hpp" |
7397 | 27 |
#include "classfile/vmSymbols.hpp" |
28 |
#include "memory/allocation.inline.hpp" |
|
37248 | 29 |
#include "memory/resourceArea.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
30 |
#include "oops/objArrayOop.inline.hpp" |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
31 |
#include "oops/oop.inline.hpp" |
7397 | 32 |
#include "prims/jni.h" |
33 |
#include "prims/jvm.h" |
|
36551 | 34 |
#include "prims/unsafe.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
25057
diff
changeset
|
35 |
#include "runtime/atomic.inline.hpp" |
7397 | 36 |
#include "runtime/globals.hpp" |
37 |
#include "runtime/interfaceSupport.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24322
diff
changeset
|
38 |
#include "runtime/orderAccess.inline.hpp" |
7397 | 39 |
#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
|
40 |
#include "runtime/vm_version.hpp" |
7397 | 41 |
#include "services/threadService.hpp" |
18025 | 42 |
#include "trace/tracing.hpp" |
7397 | 43 |
#include "utilities/copy.hpp" |
44 |
#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
|
45 |
#include "utilities/macros.hpp" |
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
46 |
#if INCLUDE_ALL_GCS |
30764 | 47 |
#include "gc/g1/g1SATBCardTableModRefBS.hpp" |
27684
e0391b2bf625
8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents:
25715
diff
changeset
|
48 |
#endif // INCLUDE_ALL_GCS |
7397 | 49 |
|
36551 | 50 |
/** |
51 |
* Implementation of the jdk.internal.misc.Unsafe class |
|
1 | 52 |
*/ |
53 |
||
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
3262
diff
changeset
|
54 |
|
1 | 55 |
#define MAX_OBJECT_SIZE \ |
56 |
( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ |
|
57 |
+ ((julong)max_jint * sizeof(double)) ) |
|
58 |
||
59 |
||
60 |
#define UNSAFE_ENTRY(result_type, header) \ |
|
36551 | 61 |
JVM_ENTRY(static result_type, header) |
1 | 62 |
|
36551 | 63 |
#define UNSAFE_LEAF(result_type, header) \ |
64 |
JVM_LEAF(static result_type, header) |
|
1 | 65 |
|
66 |
#define UNSAFE_END JVM_END |
|
67 |
||
68 |
||
36551 | 69 |
static inline void* addr_from_java(jlong addr) { |
1 | 70 |
// This assert fails in a variety of ways on 32-bit systems. |
71 |
// It is impossible to predict whether native code that converts |
|
72 |
// pointers to longs will sign-extend or zero-extend the addresses. |
|
73 |
//assert(addr == (uintptr_t)addr, "must not be odd high bits"); |
|
74 |
return (void*)(uintptr_t)addr; |
|
75 |
} |
|
76 |
||
36551 | 77 |
static inline jlong addr_to_java(void* p) { |
1 | 78 |
assert(p == (void*)(uintptr_t)p, "must not be odd high bits"); |
79 |
return (uintptr_t)p; |
|
80 |
} |
|
81 |
||
82 |
||
83 |
// Note: The VM's obj_field and related accessors use byte-scaled |
|
84 |
// ("unscaled") offsets, just as the unsafe methods do. |
|
85 |
||
86 |
// However, the method Unsafe.fieldOffset explicitly declines to |
|
87 |
// guarantee this. The field offset values manipulated by the Java user |
|
88 |
// through the Unsafe API are opaque cookies that just happen to be byte |
|
89 |
// offsets. We represent this state of affairs by passing the cookies |
|
90 |
// through conversion functions when going between the VM and the Unsafe API. |
|
91 |
// The conversion functions just happen to be no-ops at present. |
|
92 |
||
36551 | 93 |
static inline jlong field_offset_to_byte_offset(jlong field_offset) { |
1 | 94 |
return field_offset; |
95 |
} |
|
96 |
||
36551 | 97 |
static inline jlong field_offset_from_byte_offset(jlong byte_offset) { |
1 | 98 |
return byte_offset; |
99 |
} |
|
100 |
||
36551 | 101 |
static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { |
102 |
jlong byte_offset = field_offset_to_byte_offset(field_offset); |
|
1 | 103 |
|
104 |
#ifdef ASSERT |
|
105 |
if (p != NULL) { |
|
106 |
assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); |
|
107 |
if (byte_offset == (jint)byte_offset) { |
|
108 |
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
|
109 |
assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp, |
1 | 110 |
"raw [ptr+disp] must be consistent with oop::field_base"); |
111 |
} |
|
14127
16ba0a8dfde2
8001071: Add simple range check into VM implemenation of Unsafe access methods
kvn
parents:
13952
diff
changeset
|
112 |
jlong p_size = HeapWordSize * (jlong)(p->size()); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
31592
diff
changeset
|
113 |
assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, byte_offset, p_size); |
1 | 114 |
} |
115 |
#endif |
|
36551 | 116 |
|
117 |
if (sizeof(char*) == sizeof(jint)) { // (this constant folds!) |
|
1 | 118 |
return (address)p + (jint) byte_offset; |
36551 | 119 |
} else { |
1 | 120 |
return (address)p + byte_offset; |
36551 | 121 |
} |
1 | 122 |
} |
123 |
||
124 |
// Externally callable versions: |
|
125 |
// (Use these in compiler intrinsics which emulate unsafe primitives.) |
|
126 |
jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) { |
|
127 |
return field_offset; |
|
128 |
} |
|
129 |
jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) { |
|
130 |
return byte_offset; |
|
131 |
} |
|
132 |
||
133 |
||
134 |
///// Data in the Java heap. |
|
135 |
||
37480 | 136 |
#define truncate_jboolean(x) ((x) & 1) |
137 |
#define truncate_jbyte(x) (x) |
|
138 |
#define truncate_jshort(x) (x) |
|
139 |
#define truncate_jchar(x) (x) |
|
140 |
#define truncate_jint(x) (x) |
|
141 |
#define truncate_jlong(x) (x) |
|
142 |
#define truncate_jfloat(x) (x) |
|
143 |
#define truncate_jdouble(x) (x) |
|
144 |
||
1 | 145 |
#define GET_FIELD(obj, offset, type_name, v) \ |
146 |
oop p = JNIHandles::resolve(obj); \ |
|
147 |
type_name v = *(type_name*)index_oop_from_field_offset_long(p, offset) |
|
148 |
||
149 |
#define SET_FIELD(obj, offset, type_name, x) \ |
|
150 |
oop p = JNIHandles::resolve(obj); \ |
|
37480 | 151 |
*(type_name*)index_oop_from_field_offset_long(p, offset) = truncate_##type_name(x) |
1 | 152 |
|
153 |
#define GET_FIELD_VOLATILE(obj, offset, type_name, v) \ |
|
154 |
oop p = JNIHandles::resolve(obj); \ |
|
22868
7f6eb436873b
8029101: PPC64 (part 211): ordering of Independent Reads of Independent Writes
goetz
parents:
20282
diff
changeset
|
155 |
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
|
156 |
OrderAccess::fence(); \ |
7f6eb436873b
8029101: PPC64 (part 211): ordering of Independent Reads of Independent Writes
goetz
parents:
20282
diff
changeset
|
157 |
} \ |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
158 |
volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset)); |
1 | 159 |
|
160 |
#define SET_FIELD_VOLATILE(obj, offset, type_name, x) \ |
|
161 |
oop p = JNIHandles::resolve(obj); \ |
|
37480 | 162 |
OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), truncate_##type_name(x)); |
1 | 163 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
164 |
|
1 | 165 |
// Get/SetObject must be special-cased, since it works with handles. |
166 |
||
25057 | 167 |
// These functions allow a null base pointer with an arbitrary address. |
1 | 168 |
// But if the base pointer is non-null, the offset should make some sense. |
169 |
// That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
|
36551 | 170 |
UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
171 |
oop p = JNIHandles::resolve(obj); |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
172 |
oop v; |
36551 | 173 |
|
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
174 |
if (UseCompressedOops) { |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
175 |
narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset); |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
176 |
v = oopDesc::decode_heap_oop(n); |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
177 |
} else { |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
178 |
v = *(oop*)index_oop_from_field_offset_long(p, offset); |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
179 |
} |
36551 | 180 |
|
9176
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
181 |
jobject ret = JNIHandles::make_local(env, v); |
36551 | 182 |
|
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14832
diff
changeset
|
183 |
#if INCLUDE_ALL_GCS |
9176
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
184 |
// 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
|
185 |
// 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
|
186 |
// referent with the SATB barrier. |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
187 |
if (UseG1GC) { |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
188 |
bool needs_barrier = false; |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
189 |
|
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
190 |
if (ret != NULL) { |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
191 |
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
|
192 |
oop o = JNIHandles::resolve(obj); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
193 |
Klass* k = o->klass(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
194 |
if (InstanceKlass::cast(k)->reference_type() != REF_NONE) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
195 |
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
|
196 |
needs_barrier = true; |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
197 |
} |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
198 |
} |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
199 |
} |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
200 |
|
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
201 |
if (needs_barrier) { |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
202 |
oop referent = JNIHandles::resolve(ret); |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
203 |
G1SATBCardTableModRefBS::enqueue(referent); |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
204 |
} |
42d9d1010f38
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
8725
diff
changeset
|
205 |
} |
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14832
diff
changeset
|
206 |
#endif // INCLUDE_ALL_GCS |
1 | 207 |
|
36551 | 208 |
return ret; |
209 |
} UNSAFE_END |
|
210 |
||
211 |
UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
|
1 | 212 |
oop x = JNIHandles::resolve(x_h); |
213 |
oop p = JNIHandles::resolve(obj); |
|
36551 | 214 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
215 |
if (UseCompressedOops) { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
216 |
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
|
217 |
} else { |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
218 |
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
|
219 |
} |
36551 | 220 |
} UNSAFE_END |
1 | 221 |
|
36551 | 222 |
UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
223 |
oop p = JNIHandles::resolve(obj); |
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
224 |
void* addr = index_oop_from_field_offset_long(p, offset); |
36551 | 225 |
|
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
226 |
volatile oop v; |
36551 | 227 |
|
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
228 |
if (UseCompressedOops) { |
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
229 |
volatile narrowOop n = *(volatile narrowOop*) addr; |
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
230 |
(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
|
231 |
} else { |
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
232 |
(void)const_cast<oop&>(v = *(volatile oop*) addr); |
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
233 |
} |
36551 | 234 |
|
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
235 |
OrderAccess::acquire(); |
1 | 236 |
return JNIHandles::make_local(env, v); |
36551 | 237 |
} UNSAFE_END |
1 | 238 |
|
36551 | 239 |
UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
1 | 240 |
oop x = JNIHandles::resolve(x_h); |
241 |
oop p = JNIHandles::resolve(obj); |
|
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
242 |
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
|
243 |
OrderAccess::release(); |
36551 | 244 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
245 |
if (UseCompressedOops) { |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
246 |
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
|
247 |
} else { |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
248 |
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
|
249 |
} |
1 | 250 |
|
36551 | 251 |
OrderAccess::fence(); |
252 |
} UNSAFE_END |
|
253 |
||
254 |
UNSAFE_ENTRY(jobject, Unsafe_GetUncompressedObject(JNIEnv *env, jobject unsafe, jlong addr)) { |
|
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
255 |
oop v = *(oop*) (address) addr; |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
256 |
|
36551 | 257 |
return JNIHandles::make_local(env, v); |
258 |
} UNSAFE_END |
|
259 |
||
260 |
UNSAFE_ENTRY(jclass, Unsafe_GetJavaMirror(JNIEnv *env, jobject unsafe, jlong metaspace_klass)) { |
|
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
261 |
Klass* klass = (Klass*) (address) metaspace_klass; |
36551 | 262 |
|
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
263 |
return (jclass) JNIHandles::make_local(klass->java_mirror()); |
36551 | 264 |
} UNSAFE_END |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
265 |
|
36551 | 266 |
UNSAFE_ENTRY(jlong, Unsafe_GetKlassPointer(JNIEnv *env, jobject unsafe, jobject obj)) { |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
267 |
oop o = JNIHandles::resolve(obj); |
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
268 |
jlong klass = (jlong) (address) o->klass(); |
36551 | 269 |
|
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
270 |
return klass; |
36551 | 271 |
} UNSAFE_END |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
272 |
|
17316 | 273 |
#ifndef SUPPORTS_NATIVE_CX8 |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
274 |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
275 |
// 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
|
276 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
277 |
// 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
|
278 |
// 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
|
279 |
// 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
|
280 |
// 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
|
281 |
// 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
|
282 |
// 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
|
283 |
// 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
|
284 |
// 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
|
285 |
// 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
|
286 |
// 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
|
287 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
288 |
// 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
|
289 |
// 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
|
290 |
// 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
|
291 |
// 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
|
292 |
// 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
|
293 |
// lock-free path. |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
294 |
// |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
295 |
// 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
|
296 |
// 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
|
297 |
// 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
|
298 |
// 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
|
299 |
// 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
|
300 |
// been moved by the GC |
1 | 301 |
|
36551 | 302 |
UNSAFE_ENTRY(jlong, Unsafe_GetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
303 |
if (VM_Version::supports_cx8()) { |
|
304 |
GET_FIELD_VOLATILE(obj, offset, jlong, v); |
|
305 |
return v; |
|
306 |
} else { |
|
307 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
308 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
309 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
|
310 |
jlong value = Atomic::load(addr); |
|
311 |
return value; |
|
1 | 312 |
} |
36551 | 313 |
} UNSAFE_END |
1 | 314 |
|
36551 | 315 |
UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) { |
316 |
if (VM_Version::supports_cx8()) { |
|
317 |
SET_FIELD_VOLATILE(obj, offset, jlong, x); |
|
318 |
} else { |
|
319 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
|
320 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
|
321 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
|
322 |
Atomic::store(x, addr); |
|
1 | 323 |
} |
36551 | 324 |
} UNSAFE_END |
1 | 325 |
|
17316 | 326 |
#endif // not SUPPORTS_NATIVE_CX8 |
1 | 327 |
|
36551 | 328 |
UNSAFE_LEAF(jboolean, Unsafe_isBigEndian0(JNIEnv *env, jobject unsafe)) { |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
329 |
#ifdef VM_LITTLE_ENDIAN |
36551 | 330 |
return false; |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
331 |
#else |
36551 | 332 |
return true; |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
333 |
#endif |
36551 | 334 |
} UNSAFE_END |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
335 |
|
36551 | 336 |
UNSAFE_LEAF(jint, Unsafe_unalignedAccess0(JNIEnv *env, jobject unsafe)) { |
337 |
return UseUnalignedAccesses; |
|
338 |
} UNSAFE_END |
|
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
339 |
|
36551 | 340 |
#define DEFINE_GETSETOOP(java_type, Type) \ |
1 | 341 |
\ |
36551 | 342 |
UNSAFE_ENTRY(java_type, Unsafe_Get##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \ |
343 |
GET_FIELD(obj, offset, java_type, v); \ |
|
1 | 344 |
return v; \ |
36551 | 345 |
} UNSAFE_END \ |
1 | 346 |
\ |
36551 | 347 |
UNSAFE_ENTRY(void, Unsafe_Set##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \ |
348 |
SET_FIELD(obj, offset, java_type, x); \ |
|
349 |
} UNSAFE_END \ |
|
1 | 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 |
|
36551 | 364 |
#define DEFINE_GETSETOOP_VOLATILE(java_type, Type) \ |
1 | 365 |
\ |
36551 | 366 |
UNSAFE_ENTRY(java_type, Unsafe_Get##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \ |
367 |
GET_FIELD_VOLATILE(obj, offset, java_type, v); \ |
|
1 | 368 |
return v; \ |
36551 | 369 |
} UNSAFE_END \ |
1 | 370 |
\ |
36551 | 371 |
UNSAFE_ENTRY(void, Unsafe_Set##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \ |
372 |
SET_FIELD_VOLATILE(obj, offset, java_type, x); \ |
|
373 |
} UNSAFE_END \ |
|
1 | 374 |
\ |
375 |
// END DEFINE_GETSETOOP_VOLATILE. |
|
376 |
||
377 |
DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) |
|
378 |
DEFINE_GETSETOOP_VOLATILE(jbyte, Byte) |
|
379 |
DEFINE_GETSETOOP_VOLATILE(jshort, Short); |
|
380 |
DEFINE_GETSETOOP_VOLATILE(jchar, Char); |
|
381 |
DEFINE_GETSETOOP_VOLATILE(jint, Int); |
|
382 |
DEFINE_GETSETOOP_VOLATILE(jfloat, Float); |
|
383 |
DEFINE_GETSETOOP_VOLATILE(jdouble, Double); |
|
384 |
||
17316 | 385 |
#ifdef SUPPORTS_NATIVE_CX8 |
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
386 |
DEFINE_GETSETOOP_VOLATILE(jlong, Long); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
387 |
#endif |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
388 |
|
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
389 |
#undef DEFINE_GETSETOOP_VOLATILE |
1 | 390 |
|
36551 | 391 |
UNSAFE_LEAF(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe)) { |
14832 | 392 |
OrderAccess::acquire(); |
36551 | 393 |
} UNSAFE_END |
14832 | 394 |
|
36551 | 395 |
UNSAFE_LEAF(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) { |
14832 | 396 |
OrderAccess::release(); |
36551 | 397 |
} UNSAFE_END |
14832 | 398 |
|
36551 | 399 |
UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) { |
14832 | 400 |
OrderAccess::fence(); |
36551 | 401 |
} UNSAFE_END |
14832 | 402 |
|
1 | 403 |
////// Data in the C heap. |
404 |
||
405 |
// Note: These do not throw NullPointerException for bad pointers. |
|
406 |
// They just crash. Only a oop base pointer can generate a NullPointerException. |
|
407 |
// |
|
408 |
#define DEFINE_GETSETNATIVE(java_type, Type, native_type) \ |
|
409 |
\ |
|
36551 | 410 |
UNSAFE_ENTRY(java_type, Unsafe_GetNative##Type(JNIEnv *env, jobject unsafe, jlong addr)) { \ |
1 | 411 |
void* p = addr_from_java(addr); \ |
412 |
JavaThread* t = JavaThread::current(); \ |
|
413 |
t->set_doing_unsafe_access(true); \ |
|
414 |
java_type x = *(volatile native_type*)p; \ |
|
415 |
t->set_doing_unsafe_access(false); \ |
|
416 |
return x; \ |
|
36551 | 417 |
} UNSAFE_END \ |
1 | 418 |
\ |
36551 | 419 |
UNSAFE_ENTRY(void, Unsafe_SetNative##Type(JNIEnv *env, jobject unsafe, jlong addr, java_type x)) { \ |
1 | 420 |
JavaThread* t = JavaThread::current(); \ |
421 |
t->set_doing_unsafe_access(true); \ |
|
422 |
void* p = addr_from_java(addr); \ |
|
423 |
*(volatile native_type*)p = x; \ |
|
424 |
t->set_doing_unsafe_access(false); \ |
|
36551 | 425 |
} UNSAFE_END \ |
1 | 426 |
\ |
427 |
// END DEFINE_GETSETNATIVE. |
|
428 |
||
429 |
DEFINE_GETSETNATIVE(jbyte, Byte, signed char) |
|
430 |
DEFINE_GETSETNATIVE(jshort, Short, signed short); |
|
431 |
DEFINE_GETSETNATIVE(jchar, Char, unsigned short); |
|
432 |
DEFINE_GETSETNATIVE(jint, Int, jint); |
|
433 |
// no long -- handled specially |
|
434 |
DEFINE_GETSETNATIVE(jfloat, Float, float); |
|
435 |
DEFINE_GETSETNATIVE(jdouble, Double, double); |
|
436 |
||
437 |
#undef DEFINE_GETSETNATIVE |
|
438 |
||
36551 | 439 |
UNSAFE_ENTRY(jlong, Unsafe_GetNativeLong(JNIEnv *env, jobject unsafe, jlong addr)) { |
1 | 440 |
JavaThread* t = JavaThread::current(); |
441 |
// We do it this way to avoid problems with access to heap using 64 |
|
442 |
// bit loads, as jlong in heap could be not 64-bit aligned, and on |
|
443 |
// some CPUs (SPARC) it leads to SIGBUS. |
|
444 |
t->set_doing_unsafe_access(true); |
|
445 |
void* p = addr_from_java(addr); |
|
446 |
jlong x; |
|
36551 | 447 |
|
448 |
if (is_ptr_aligned(p, sizeof(jlong)) == 0) { |
|
1 | 449 |
// jlong is aligned, do a volatile access |
450 |
x = *(volatile jlong*)p; |
|
451 |
} else { |
|
452 |
jlong_accessor acc; |
|
453 |
acc.words[0] = ((volatile jint*)p)[0]; |
|
454 |
acc.words[1] = ((volatile jint*)p)[1]; |
|
455 |
x = acc.long_value; |
|
456 |
} |
|
36551 | 457 |
|
1 | 458 |
t->set_doing_unsafe_access(false); |
36551 | 459 |
|
1 | 460 |
return x; |
36551 | 461 |
} UNSAFE_END |
1 | 462 |
|
36551 | 463 |
UNSAFE_ENTRY(void, Unsafe_SetNativeLong(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) { |
1 | 464 |
JavaThread* t = JavaThread::current(); |
465 |
// see comment for Unsafe_GetNativeLong |
|
466 |
t->set_doing_unsafe_access(true); |
|
467 |
void* p = addr_from_java(addr); |
|
36551 | 468 |
|
469 |
if (is_ptr_aligned(p, sizeof(jlong))) { |
|
1 | 470 |
// jlong is aligned, do a volatile access |
471 |
*(volatile jlong*)p = x; |
|
472 |
} else { |
|
473 |
jlong_accessor acc; |
|
474 |
acc.long_value = x; |
|
475 |
((volatile jint*)p)[0] = acc.words[0]; |
|
476 |
((volatile jint*)p)[1] = acc.words[1]; |
|
477 |
} |
|
36551 | 478 |
|
1 | 479 |
t->set_doing_unsafe_access(false); |
36551 | 480 |
} UNSAFE_END |
1 | 481 |
|
482 |
||
36551 | 483 |
UNSAFE_LEAF(jlong, Unsafe_GetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr)) { |
1 | 484 |
void* p = addr_from_java(addr); |
36551 | 485 |
|
1 | 486 |
return addr_to_java(*(void**)p); |
36551 | 487 |
} UNSAFE_END |
1 | 488 |
|
36551 | 489 |
UNSAFE_LEAF(void, Unsafe_SetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) { |
1 | 490 |
void* p = addr_from_java(addr); |
491 |
*(void**)p = addr_from_java(x); |
|
36551 | 492 |
} UNSAFE_END |
1 | 493 |
|
494 |
||
495 |
////// Allocation requests |
|
496 |
||
36551 | 497 |
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) { |
498 |
ThreadToNativeFromVM ttnfv(thread); |
|
499 |
return env->AllocObject(cls); |
|
500 |
} UNSAFE_END |
|
1 | 501 |
|
36551 | 502 |
UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) { |
1 | 503 |
size_t sz = (size_t)size; |
36551 | 504 |
|
1 | 505 |
sz = round_to(sz, HeapWordSize); |
13195 | 506 |
void* x = os::malloc(sz, mtInternal); |
36551 | 507 |
|
1 | 508 |
return addr_to_java(x); |
36551 | 509 |
} UNSAFE_END |
1 | 510 |
|
36551 | 511 |
UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) { |
1 | 512 |
void* p = addr_from_java(addr); |
513 |
size_t sz = (size_t)size; |
|
514 |
sz = round_to(sz, HeapWordSize); |
|
36551 | 515 |
|
516 |
void* x = os::realloc(p, sz, mtInternal); |
|
517 |
||
1 | 518 |
return addr_to_java(x); |
36551 | 519 |
} UNSAFE_END |
1 | 520 |
|
36551 | 521 |
UNSAFE_ENTRY(void, Unsafe_FreeMemory0(JNIEnv *env, jobject unsafe, jlong addr)) { |
1 | 522 |
void* p = addr_from_java(addr); |
36551 | 523 |
|
1 | 524 |
os::free(p); |
36551 | 525 |
} UNSAFE_END |
1 | 526 |
|
36551 | 527 |
UNSAFE_ENTRY(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) { |
1 | 528 |
size_t sz = (size_t)size; |
36551 | 529 |
|
1 | 530 |
oop base = JNIHandles::resolve(obj); |
531 |
void* p = index_oop_from_field_offset_long(base, offset); |
|
36551 | 532 |
|
1 | 533 |
Copy::fill_to_memory_atomic(p, sz, value); |
36551 | 534 |
} UNSAFE_END |
1 | 535 |
|
36551 | 536 |
UNSAFE_ENTRY(void, Unsafe_CopyMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) { |
1 | 537 |
size_t sz = (size_t)size; |
36551 | 538 |
|
1 | 539 |
oop srcp = JNIHandles::resolve(srcObj); |
540 |
oop dstp = JNIHandles::resolve(dstObj); |
|
36551 | 541 |
|
1 | 542 |
void* src = index_oop_from_field_offset_long(srcp, srcOffset); |
543 |
void* dst = index_oop_from_field_offset_long(dstp, dstOffset); |
|
36551 | 544 |
|
1 | 545 |
Copy::conjoint_memory_atomic(src, dst, sz); |
36551 | 546 |
} UNSAFE_END |
1 | 547 |
|
36086 | 548 |
// This function is a leaf since if the source and destination are both in native memory |
549 |
// the copy may potentially be very large, and we don't want to disable GC if we can avoid it. |
|
550 |
// If either source or destination (or both) are on the heap, the function will enter VM using |
|
551 |
// JVM_ENTRY_FROM_LEAF |
|
36551 | 552 |
UNSAFE_LEAF(void, Unsafe_CopySwapMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) { |
36086 | 553 |
size_t sz = (size_t)size; |
554 |
size_t esz = (size_t)elemSize; |
|
555 |
||
556 |
if (srcObj == NULL && dstObj == NULL) { |
|
557 |
// Both src & dst are in native memory |
|
558 |
address src = (address)srcOffset; |
|
559 |
address dst = (address)dstOffset; |
|
560 |
||
561 |
Copy::conjoint_swap(src, dst, sz, esz); |
|
562 |
} else { |
|
563 |
// At least one of src/dst are on heap, transition to VM to access raw pointers |
|
564 |
||
565 |
JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory0) { |
|
566 |
oop srcp = JNIHandles::resolve(srcObj); |
|
567 |
oop dstp = JNIHandles::resolve(dstObj); |
|
568 |
||
569 |
address src = (address)index_oop_from_field_offset_long(srcp, srcOffset); |
|
570 |
address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset); |
|
571 |
||
572 |
Copy::conjoint_swap(src, dst, sz, esz); |
|
573 |
} JVM_END |
|
574 |
} |
|
36551 | 575 |
} UNSAFE_END |
1 | 576 |
|
577 |
////// Random queries |
|
578 |
||
36551 | 579 |
UNSAFE_LEAF(jint, Unsafe_AddressSize0(JNIEnv *env, jobject unsafe)) { |
1 | 580 |
return sizeof(void*); |
36551 | 581 |
} UNSAFE_END |
1 | 582 |
|
36551 | 583 |
UNSAFE_LEAF(jint, Unsafe_PageSize()) { |
1 | 584 |
return os::vm_page_size(); |
36551 | 585 |
} UNSAFE_END |
1 | 586 |
|
36551 | 587 |
static jint find_field_offset(jobject field, int must_be_static, TRAPS) { |
588 |
assert(field != NULL, "field must not be NULL"); |
|
1 | 589 |
|
590 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
591 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
36551 | 592 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 593 |
int slot = java_lang_reflect_Field::slot(reflected); |
594 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
595 |
||
596 |
if (must_be_static >= 0) { |
|
597 |
int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); |
|
598 |
if (must_be_static != really_is_static) { |
|
599 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
600 |
} |
|
601 |
} |
|
602 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
603 |
int offset = InstanceKlass::cast(k)->field_offset(slot); |
1 | 604 |
return field_offset_from_byte_offset(offset); |
605 |
} |
|
606 |
||
36551 | 607 |
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 608 |
return find_field_offset(field, 0, THREAD); |
36551 | 609 |
} UNSAFE_END |
1 | 610 |
|
36551 | 611 |
UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 612 |
return find_field_offset(field, 1, THREAD); |
36551 | 613 |
} UNSAFE_END |
1 | 614 |
|
36551 | 615 |
UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBase0(JNIEnv *env, jobject unsafe, jobject field)) { |
616 |
assert(field != NULL, "field must not be NULL"); |
|
617 |
||
1 | 618 |
// Note: In this VM implementation, a field address is always a short |
619 |
// offset from the base of a a klass metaobject. Thus, the full dynamic |
|
620 |
// range of the return type is never used. However, some implementations |
|
621 |
// might put the static field inside an array shared by many classes, |
|
622 |
// or even at a fixed address, in which case the address could be quite |
|
623 |
// large. In that last case, this function would return NULL, since |
|
624 |
// the address would operate alone, without any base pointer. |
|
625 |
||
626 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
627 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
628 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
629 |
||
630 |
if ((modifiers & JVM_ACC_STATIC) == 0) { |
|
631 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
632 |
} |
|
633 |
||
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8490
diff
changeset
|
634 |
return JNIHandles::make_local(env, mirror); |
36551 | 635 |
} UNSAFE_END |
1 | 636 |
|
36551 | 637 |
UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
638 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
639 |
||
1 | 640 |
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
|
641 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
642 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
14488 | 643 |
if (klass != NULL && klass->should_be_initialized()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
644 |
InstanceKlass* k = InstanceKlass::cast(klass); |
1 | 645 |
k->initialize(CHECK); |
646 |
} |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
647 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
648 |
UNSAFE_END |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
649 |
|
36551 | 650 |
UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
651 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
652 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
653 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
654 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
36551 | 655 |
|
14488 | 656 |
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
|
657 |
return true; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
658 |
} |
36551 | 659 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
660 |
return false; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
661 |
} |
1 | 662 |
UNSAFE_END |
663 |
||
36551 | 664 |
static void getBaseAndScale(int& base, int& scale, jclass clazz, TRAPS) { |
665 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
666 |
||
667 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
|
668 |
Klass* k = java_lang_Class::as_Klass(mirror); |
|
669 |
||
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
670 |
if (k == NULL || !k->is_array_klass()) { |
1 | 671 |
THROW(vmSymbols::java_lang_InvalidClassException()); |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
672 |
} else if (k->is_objArray_klass()) { |
1 | 673 |
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
|
674 |
scale = heapOopSize; |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
675 |
} else if (k->is_typeArray_klass()) { |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
676 |
TypeArrayKlass* tak = TypeArrayKlass::cast(k); |
1 | 677 |
base = tak->array_header_in_bytes(); |
678 |
assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); |
|
679 |
scale = (1 << tak->log2_element_size()); |
|
680 |
} else { |
|
681 |
ShouldNotReachHere(); |
|
682 |
} |
|
683 |
} |
|
684 |
||
36551 | 685 |
UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset0(JNIEnv *env, jobject unsafe, jclass clazz)) { |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33148
diff
changeset
|
686 |
int base = 0, scale = 0; |
36551 | 687 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
688 |
||
1 | 689 |
return field_offset_from_byte_offset(base); |
36551 | 690 |
} UNSAFE_END |
1 | 691 |
|
692 |
||
36551 | 693 |
UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale0(JNIEnv *env, jobject unsafe, jclass clazz)) { |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33148
diff
changeset
|
694 |
int base = 0, scale = 0; |
36551 | 695 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
696 |
||
1 | 697 |
// This VM packs both fields and array elements down to the byte. |
698 |
// But watch out: If this changes, so that array references for |
|
699 |
// a given primitive type (say, T_BOOLEAN) use different memory units |
|
700 |
// than fields, this method MUST return zero for such arrays. |
|
701 |
// For example, the VM used to store sub-word sized fields in full |
|
702 |
// words in the object layout, so that accessors like getByte(Object,int) |
|
703 |
// did not really do what one might expect for arrays. Therefore, |
|
704 |
// this function used to report a zero scale factor, so that the user |
|
705 |
// would know not to attempt to access sub-word array elements. |
|
706 |
// // Code for unpacked fields: |
|
707 |
// if (scale < wordSize) return 0; |
|
708 |
||
709 |
// The following allows for a pretty general fieldOffset cookie scheme, |
|
710 |
// but requires it to be linear in byte offset. |
|
711 |
return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); |
|
36551 | 712 |
} UNSAFE_END |
1 | 713 |
|
714 |
||
715 |
static inline void throw_new(JNIEnv *env, const char *ename) { |
|
716 |
char buf[100]; |
|
36551 | 717 |
|
27471 | 718 |
jio_snprintf(buf, 100, "%s%s", "java/lang/", ename); |
36551 | 719 |
|
1 | 720 |
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
|
721 |
if (env->ExceptionCheck()) { |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
722 |
env->ExceptionClear(); |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
723 |
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
|
724 |
return; |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
725 |
} |
36551 | 726 |
|
727 |
env->ThrowNew(cls, NULL); |
|
1 | 728 |
} |
729 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
730 |
static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { |
36551 | 731 |
// Code lifted from JDK 1.3 ClassLoader.c |
732 |
||
733 |
jbyte *body; |
|
734 |
char *utfName = NULL; |
|
735 |
jclass result = 0; |
|
736 |
char buf[128]; |
|
1 | 737 |
|
36551 | 738 |
assert(data != NULL, "Class bytes must not be NULL"); |
739 |
assert(length >= 0, "length must not be negative: %d", length); |
|
1 | 740 |
|
36551 | 741 |
if (UsePerfData) { |
742 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
|
743 |
} |
|
1 | 744 |
|
36551 | 745 |
body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal); |
746 |
if (body == NULL) { |
|
747 |
throw_new(env, "OutOfMemoryError"); |
|
748 |
return 0; |
|
749 |
} |
|
750 |
||
751 |
env->GetByteArrayRegion(data, offset, length, body); |
|
752 |
if (env->ExceptionOccurred()) { |
|
753 |
goto free_body; |
|
754 |
} |
|
1 | 755 |
|
36551 | 756 |
if (name != NULL) { |
757 |
uint len = env->GetStringUTFLength(name); |
|
758 |
int unicode_len = env->GetStringLength(name); |
|
1 | 759 |
|
36551 | 760 |
if (len >= sizeof(buf)) { |
761 |
utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
|
762 |
if (utfName == NULL) { |
|
1 | 763 |
throw_new(env, "OutOfMemoryError"); |
36551 | 764 |
goto free_body; |
765 |
} |
|
766 |
} else { |
|
767 |
utfName = buf; |
|
1 | 768 |
} |
769 |
||
36551 | 770 |
env->GetStringUTFRegion(name, 0, unicode_len, utfName); |
1 | 771 |
|
36551 | 772 |
for (uint i = 0; i < len; i++) { |
773 |
if (utfName[i] == '.') utfName[i] = '/'; |
|
1 | 774 |
} |
36551 | 775 |
} |
1 | 776 |
|
36551 | 777 |
result = JVM_DefineClass(env, utfName, loader, body, length, pd); |
1 | 778 |
|
36551 | 779 |
if (utfName && utfName != buf) { |
780 |
FREE_C_HEAP_ARRAY(char, utfName); |
|
781 |
} |
|
1 | 782 |
|
783 |
free_body: |
|
36551 | 784 |
FREE_C_HEAP_ARRAY(jbyte, body); |
785 |
return result; |
|
1 | 786 |
} |
787 |
||
788 |
||
36551 | 789 |
UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) { |
790 |
ThreadToNativeFromVM ttnfv(thread); |
|
791 |
||
792 |
return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd); |
|
793 |
} UNSAFE_END |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
794 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
795 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
796 |
// 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
|
797 |
// - 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
|
798 |
// - 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
|
799 |
// - 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
|
800 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
801 |
// 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
|
802 |
// 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
|
803 |
// 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
|
804 |
// 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
|
805 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
806 |
// 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
|
807 |
// 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
|
808 |
// 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
|
809 |
// 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
|
810 |
// 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
|
811 |
// 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
|
812 |
// 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
|
813 |
// restrictions. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
814 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
815 |
// 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
|
816 |
// 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
|
817 |
// 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
|
818 |
// access one of its anonymous classes. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
819 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
820 |
// 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
|
821 |
// 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
|
822 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
823 |
// 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
|
824 |
// 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
|
825 |
// 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
|
826 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
827 |
// 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
|
828 |
// 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
|
829 |
// 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
|
830 |
// 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
|
831 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
832 |
// 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
|
833 |
// 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
|
834 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
835 |
// 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
|
836 |
// 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
|
837 |
// 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
|
838 |
// 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
|
839 |
// 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
|
840 |
// 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
|
841 |
// 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
|
842 |
// 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
|
843 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
844 |
static instanceKlassHandle |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
845 |
Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
846 |
jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, |
36551 | 847 |
u1** temp_alloc, |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
848 |
TRAPS) { |
36551 | 849 |
assert(host_class != NULL, "host_class must not be NULL"); |
850 |
assert(data != NULL, "data must not be NULL"); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
851 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
852 |
if (UsePerfData) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
853 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
854 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
855 |
|
36551 | 856 |
jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); |
857 |
assert(length >= 0, "class_bytes_length must not be negative: %d", length); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
858 |
|
36551 | 859 |
int class_bytes_length = (int) length; |
860 |
||
861 |
u1* class_bytes = NEW_C_HEAP_ARRAY(u1, length, mtInternal); |
|
862 |
if (class_bytes == NULL) { |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
863 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
864 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
865 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
866 |
// caller responsible to free it: |
36551 | 867 |
*temp_alloc = class_bytes; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
868 |
|
36551 | 869 |
jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0); |
870 |
Copy::conjoint_jbytes(array_base, class_bytes, length); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
871 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
872 |
objArrayHandle cp_patches_h; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
873 |
if (cp_patches_jh != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
874 |
oop p = JNIHandles::resolve_non_null(cp_patches_jh); |
36551 | 875 |
assert(p->is_objArray(), "cp_patches must be an object[]"); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
876 |
cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
877 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
878 |
|
34666 | 879 |
const Klass* host_klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class)); |
37184
23e0d47c1f3e
8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents:
36551
diff
changeset
|
880 |
// Primitive types have NULL Klass* fields in their java.lang.Class instances. |
23e0d47c1f3e
8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents:
36551
diff
changeset
|
881 |
if (host_klass == NULL) { |
23e0d47c1f3e
8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents:
36551
diff
changeset
|
882 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
23e0d47c1f3e
8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents:
36551
diff
changeset
|
883 |
} |
34666 | 884 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
885 |
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
|
886 |
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
|
887 |
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
|
888 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
889 |
GrowableArray<Handle>* cp_patches = NULL; |
36551 | 890 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
891 |
if (cp_patches_h.not_null()) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
892 |
int alen = cp_patches_h->length(); |
36551 | 893 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
894 |
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
|
895 |
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
|
896 |
if (p != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
897 |
Handle patch(THREAD, p); |
36551 | 898 |
|
899 |
if (cp_patches == NULL) { |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
900 |
cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle()); |
36551 | 901 |
} |
902 |
||
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
903 |
cp_patches->at_put(i, patch); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
904 |
} |
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 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
907 |
|
36551 | 908 |
ClassFileStream st(class_bytes, class_bytes_length, host_source, ClassFileStream::verify); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
909 |
|
36551 | 910 |
Symbol* no_class_name = NULL; |
911 |
Klass* anonk = SystemDictionary::parse_stream(no_class_name, |
|
912 |
host_loader, |
|
913 |
host_domain, |
|
914 |
&st, |
|
915 |
host_klass, |
|
916 |
cp_patches, |
|
917 |
CHECK_NULL); |
|
918 |
if (anonk == NULL) { |
|
919 |
return NULL; |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
920 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
921 |
|
36551 | 922 |
return instanceKlassHandle(THREAD, anonk); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
923 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
924 |
|
36551 | 925 |
UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) { |
926 |
ResourceMark rm(THREAD); |
|
927 |
||
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
928 |
instanceKlassHandle anon_klass; |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
929 |
jobject res_jh = NULL; |
36551 | 930 |
u1* temp_alloc = NULL; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
931 |
|
36551 | 932 |
anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD); |
933 |
if (anon_klass() != NULL) { |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
934 |
res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); |
36551 | 935 |
} |
1550
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 |
// try/finally clause: |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
938 |
if (temp_alloc != NULL) { |
36551 | 939 |
FREE_C_HEAP_ARRAY(u1, temp_alloc); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
940 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
941 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
942 |
// 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
|
943 |
// 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
|
944 |
// it alive afterwards. |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
945 |
if (anon_klass() != NULL) { |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37267
diff
changeset
|
946 |
anon_klass->class_loader_data()->dec_keep_alive(); |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
947 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
948 |
|
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
949 |
// let caller initialize it as needed... |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
950 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
951 |
return (jclass) res_jh; |
36551 | 952 |
} UNSAFE_END |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
953 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
954 |
|
1 | 955 |
|
36551 | 956 |
UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) { |
957 |
ThreadToNativeFromVM ttnfv(thread); |
|
958 |
env->Throw(thr); |
|
959 |
} UNSAFE_END |
|
1 | 960 |
|
961 |
// JSR166 ------------------------------------------------------------------ |
|
962 |
||
36551 | 963 |
UNSAFE_ENTRY(jobject, Unsafe_CompareAndExchangeObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
964 |
oop x = JNIHandles::resolve(x_h); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
965 |
oop e = JNIHandles::resolve(e_h); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
966 |
oop p = JNIHandles::resolve(obj); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
967 |
HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
968 |
oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true); |
36551 | 969 |
if (res == e) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
970 |
update_barrier_set((void*)addr, x); |
36551 | 971 |
} |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
972 |
return JNIHandles::make_local(env, res); |
36551 | 973 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
974 |
|
36551 | 975 |
UNSAFE_ENTRY(jint, Unsafe_CompareAndExchangeInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
976 |
oop p = JNIHandles::resolve(obj); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
977 |
jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
978 |
|
36551 | 979 |
return (jint)(Atomic::cmpxchg(x, addr, e)); |
980 |
} UNSAFE_END |
|
981 |
||
982 |
UNSAFE_ENTRY(jlong, Unsafe_CompareAndExchangeLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) { |
|
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
983 |
Handle p (THREAD, JNIHandles::resolve(obj)); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
984 |
jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset)); |
36551 | 985 |
|
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
986 |
#ifdef SUPPORTS_NATIVE_CX8 |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
987 |
return (jlong)(Atomic::cmpxchg(x, addr, e)); |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
988 |
#else |
36551 | 989 |
if (VM_Version::supports_cx8()) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
990 |
return (jlong)(Atomic::cmpxchg(x, addr, e)); |
36551 | 991 |
} else { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
992 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
36551 | 993 |
|
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
994 |
jlong val = Atomic::load(addr); |
36551 | 995 |
if (val == e) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
996 |
Atomic::store(x, addr); |
36551 | 997 |
} |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
998 |
return val; |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
999 |
} |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1000 |
#endif |
36551 | 1001 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1002 |
|
36551 | 1003 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) { |
1 | 1004 |
oop x = JNIHandles::resolve(x_h); |
1005 |
oop e = JNIHandles::resolve(e_h); |
|
1006 |
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
|
1007 |
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
|
1008 |
oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true); |
36551 | 1009 |
if (res != e) { |
1010 |
return false; |
|
1011 |
} |
|
1 | 1012 |
|
36551 | 1013 |
update_barrier_set((void*)addr, x); |
1014 |
||
1015 |
return true; |
|
1016 |
} UNSAFE_END |
|
1017 |
||
1018 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) { |
|
1 | 1019 |
oop p = JNIHandles::resolve(obj); |
1020 |
jint* addr = (jint *) index_oop_from_field_offset_long(p, offset); |
|
36551 | 1021 |
|
1 | 1022 |
return (jint)(Atomic::cmpxchg(x, addr, e)) == e; |
36551 | 1023 |
} UNSAFE_END |
1 | 1024 |
|
36551 | 1025 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) { |
1026 |
Handle p(THREAD, JNIHandles::resolve(obj)); |
|
1027 |
jlong* addr = (jlong*)index_oop_from_field_offset_long(p(), offset); |
|
1028 |
||
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1029 |
#ifdef SUPPORTS_NATIVE_CX8 |
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1030 |
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
|
1031 |
#else |
36551 | 1032 |
if (VM_Version::supports_cx8()) { |
1 | 1033 |
return (jlong)(Atomic::cmpxchg(x, addr, e)) == e; |
36551 | 1034 |
} else { |
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1035 |
MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag); |
36551 | 1036 |
|
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1037 |
jlong val = Atomic::load(addr); |
36551 | 1038 |
if (val != e) { |
1039 |
return false; |
|
1040 |
} |
|
1041 |
||
1042 |
Atomic::store(x, addr); |
|
1043 |
return true; |
|
1 | 1044 |
} |
27874
e9b44eb1613f
8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents:
27471
diff
changeset
|
1045 |
#endif |
36551 | 1046 |
} UNSAFE_END |
1 | 1047 |
|
36551 | 1048 |
UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) { |
18025 | 1049 |
EventThreadPark event; |
22796 | 1050 |
HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time); |
1051 |
||
1 | 1052 |
JavaThreadParkedState jtps(thread, time != 0); |
1053 |
thread->parker()->park(isAbsolute != 0, time); |
|
22796 | 1054 |
|
1055 |
HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); |
|
36551 | 1056 |
|
18025 | 1057 |
if (event.should_commit()) { |
1058 |
oop obj = thread->current_park_blocker(); |
|
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
1059 |
event.set_klass((obj != NULL) ? obj->klass() : NULL); |
18025 | 1060 |
event.set_timeout(time); |
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
1061 |
event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0); |
18025 | 1062 |
event.commit(); |
1063 |
} |
|
36551 | 1064 |
} UNSAFE_END |
1 | 1065 |
|
36551 | 1066 |
UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { |
1 | 1067 |
Parker* p = NULL; |
36551 | 1068 |
|
1 | 1069 |
if (jthread != NULL) { |
1070 |
oop java_thread = JNIHandles::resolve_non_null(jthread); |
|
1071 |
if (java_thread != NULL) { |
|
1072 |
jlong lp = java_lang_Thread::park_event(java_thread); |
|
1073 |
if (lp != 0) { |
|
1074 |
// This cast is OK even though the jlong might have been read |
|
1075 |
// non-atomically on 32bit systems, since there, one word will |
|
1076 |
// always be zero anyway and the value set is always the same |
|
1077 |
p = (Parker*)addr_from_java(lp); |
|
1078 |
} else { |
|
1079 |
// Grab lock if apparently null or using older version of library |
|
1080 |
MutexLocker mu(Threads_lock); |
|
1081 |
java_thread = JNIHandles::resolve_non_null(jthread); |
|
36551 | 1082 |
|
1 | 1083 |
if (java_thread != NULL) { |
1084 |
JavaThread* thr = java_lang_Thread::thread(java_thread); |
|
1085 |
if (thr != NULL) { |
|
1086 |
p = thr->parker(); |
|
1087 |
if (p != NULL) { // Bind to Java thread for next time. |
|
1088 |
java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
|
1089 |
} |
|
1090 |
} |
|
1091 |
} |
|
1092 |
} |
|
1093 |
} |
|
1094 |
} |
|
36551 | 1095 |
|
1 | 1096 |
if (p != NULL) { |
22796 | 1097 |
HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
1 | 1098 |
p->unpark(); |
1099 |
} |
|
36551 | 1100 |
} UNSAFE_END |
1 | 1101 |
|
36551 | 1102 |
UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) { |
1 | 1103 |
const int max_nelem = 3; |
1104 |
double la[max_nelem]; |
|
1105 |
jint ret; |
|
1106 |
||
1107 |
typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); |
|
1108 |
assert(a->is_typeArray(), "must be type array"); |
|
1109 |
||
36551 | 1110 |
ret = os::loadavg(la, nelem); |
1111 |
if (ret == -1) { |
|
1 | 1112 |
return -1; |
1113 |
} |
|
1114 |
||
1115 |
// if successful, ret is the number of samples actually retrieved. |
|
1116 |
assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); |
|
1117 |
switch(ret) { |
|
1118 |
case 3: a->double_at_put(2, (jdouble)la[2]); // fall through |
|
1119 |
case 2: a->double_at_put(1, (jdouble)la[1]); // fall through |
|
1120 |
case 1: a->double_at_put(0, (jdouble)la[0]); break; |
|
1121 |
} |
|
36551 | 1122 |
|
1 | 1123 |
return ret; |
36551 | 1124 |
} UNSAFE_END |
1 | 1125 |
|
1126 |
||
1127 |
/// JVM_RegisterUnsafeMethods |
|
1128 |
||
1129 |
#define ADR "J" |
|
1130 |
||
1131 |
#define LANG "Ljava/lang/" |
|
1132 |
||
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1133 |
#define OBJ LANG "Object;" |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1134 |
#define CLS LANG "Class;" |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1135 |
#define FLD LANG "reflect/Field;" |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1136 |
#define THR LANG "Throwable;" |
1 | 1137 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1138 |
#define DC_Args LANG "String;[BII" LANG "ClassLoader;" "Ljava/security/ProtectionDomain;" |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1139 |
#define DAC_Args CLS "[B[" OBJ |
1 | 1140 |
|
1141 |
#define CC (char*) /*cast a literal from (const char*)*/ |
|
1142 |
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
|
1143 |
||
36551 | 1144 |
#define DECLARE_GETPUTOOP(Type, Desc) \ |
1145 |
{CC "get" #Type, CC "(" OBJ "J)" #Desc, FN_PTR(Unsafe_Get##Type)}, \ |
|
1146 |
{CC "put" #Type, CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Set##Type)}, \ |
|
1147 |
{CC "get" #Type "Volatile", CC "(" OBJ "J)" #Desc, FN_PTR(Unsafe_Get##Type##Volatile)}, \ |
|
1148 |
{CC "put" #Type "Volatile", CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Set##Type##Volatile)} |
|
1 | 1149 |
|
1150 |
||
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1151 |
#define DECLARE_GETPUTNATIVE(Byte, B) \ |
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1152 |
{CC "get" #Byte, CC "(" ADR ")" #B, FN_PTR(Unsafe_GetNative##Byte)}, \ |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1153 |
{CC "put" #Byte, CC "(" ADR#B ")V", FN_PTR(Unsafe_SetNative##Byte)} |
1 | 1154 |
|
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1155 |
static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = { |
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1156 |
{CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1157 |
{CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1158 |
{CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1159 |
{CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObjectVolatile)}, |
1 | 1160 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1161 |
{CC "getUncompressedObject", CC "(" ADR ")" OBJ, FN_PTR(Unsafe_GetUncompressedObject)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1162 |
{CC "getJavaMirror", CC "(" ADR ")" CLS, FN_PTR(Unsafe_GetJavaMirror)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1163 |
{CC "getKlassPointer", CC "(" OBJ ")" ADR, FN_PTR(Unsafe_GetKlassPointer)}, |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
1164 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1165 |
DECLARE_GETPUTOOP(Boolean, Z), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1166 |
DECLARE_GETPUTOOP(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1167 |
DECLARE_GETPUTOOP(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1168 |
DECLARE_GETPUTOOP(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1169 |
DECLARE_GETPUTOOP(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1170 |
DECLARE_GETPUTOOP(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1171 |
DECLARE_GETPUTOOP(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1172 |
DECLARE_GETPUTOOP(Double, D), |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1173 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1174 |
DECLARE_GETPUTNATIVE(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1175 |
DECLARE_GETPUTNATIVE(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1176 |
DECLARE_GETPUTNATIVE(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1177 |
DECLARE_GETPUTNATIVE(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1178 |
DECLARE_GETPUTNATIVE(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1179 |
DECLARE_GETPUTNATIVE(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1180 |
DECLARE_GETPUTNATIVE(Double, D), |
1 | 1181 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1182 |
{CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1183 |
{CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)}, |
1 | 1184 |
|
36551 | 1185 |
{CC "allocateMemory0", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory0)}, |
1186 |
{CC "reallocateMemory0", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory0)}, |
|
1187 |
{CC "freeMemory0", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory0)}, |
|
1 | 1188 |
|
36551 | 1189 |
{CC "objectFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset0)}, |
1190 |
{CC "staticFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset0)}, |
|
1191 |
{CC "staticFieldBase0", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBase0)}, |
|
1192 |
{CC "ensureClassInitialized0", CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized0)}, |
|
1193 |
{CC "arrayBaseOffset0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset0)}, |
|
1194 |
{CC "arrayIndexScale0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale0)}, |
|
1195 |
{CC "addressSize0", CC "()I", FN_PTR(Unsafe_AddressSize0)}, |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1196 |
{CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
1 | 1197 |
|
36551 | 1198 |
{CC "defineClass0", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass0)}, |
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1199 |
{CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1200 |
{CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1201 |
{CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1202 |
{CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1203 |
{CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)}, |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1204 |
{CC "compareAndExchangeObjectVolatile", CC "(" OBJ "J" OBJ "" OBJ ")" OBJ, FN_PTR(Unsafe_CompareAndExchangeObject)}, |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1205 |
{CC "compareAndExchangeIntVolatile", CC "(" OBJ "J""I""I"")I", FN_PTR(Unsafe_CompareAndExchangeInt)}, |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1206 |
{CC "compareAndExchangeLongVolatile", CC "(" OBJ "J""J""J"")J", FN_PTR(Unsafe_CompareAndExchangeLong)}, |
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1207 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1208 |
{CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1209 |
{CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)}, |
1 | 1210 |
|
36551 | 1211 |
{CC "getLoadAverage0", CC "([DI)I", FN_PTR(Unsafe_GetLoadAverage0)}, |
1 | 1212 |
|
36551 | 1213 |
{CC "copyMemory0", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory0)}, |
36086 | 1214 |
{CC "copySwapMemory0", CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory0)}, |
36551 | 1215 |
{CC "setMemory0", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory0)}, |
1 | 1216 |
|
36551 | 1217 |
{CC "defineAnonymousClass0", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass0)}, |
1 | 1218 |
|
36551 | 1219 |
{CC "shouldBeInitialized0", CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized0)}, |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
1220 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1221 |
{CC "loadFence", CC "()V", FN_PTR(Unsafe_LoadFence)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1222 |
{CC "storeFence", CC "()V", FN_PTR(Unsafe_StoreFence)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1223 |
{CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)}, |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
1224 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1225 |
{CC "isBigEndian0", CC "()Z", FN_PTR(Unsafe_isBigEndian0)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1226 |
{CC "unalignedAccess0", CC "()Z", FN_PTR(Unsafe_unalignedAccess0)} |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1227 |
}; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1228 |
|
1 | 1229 |
#undef CC |
1230 |
#undef FN_PTR |
|
1231 |
||
1232 |
#undef ADR |
|
1233 |
#undef LANG |
|
1234 |
#undef OBJ |
|
1235 |
#undef CLS |
|
1236 |
#undef FLD |
|
1237 |
#undef THR |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1238 |
#undef DC_Args |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1239 |
#undef DAC_Args |
1 | 1240 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1241 |
#undef DECLARE_GETPUTOOP |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1242 |
#undef DECLARE_GETPUTNATIVE |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1243 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1244 |
|
36551 | 1245 |
// This function is exported, used by NativeLookup. |
1 | 1246 |
// The Unsafe_xxx functions above are called only from the interpreter. |
1247 |
// The optimizer looks at names and signatures to recognize |
|
1248 |
// individual functions. |
|
1249 |
||
36551 | 1250 |
JVM_ENTRY(void, JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass)) { |
1251 |
ThreadToNativeFromVM ttnfv(thread); |
|
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1252 |
|
36551 | 1253 |
int ok = env->RegisterNatives(unsafeclass, jdk_internal_misc_Unsafe_methods, sizeof(jdk_internal_misc_Unsafe_methods)/sizeof(JNINativeMethod)); |
1254 |
guarantee(ok == 0, "register jdk.internal.misc.Unsafe natives"); |
|
1255 |
} JVM_END |