author | coleenp |
Wed, 13 Nov 2019 08:23:23 -0500 | |
changeset 59056 | 15936b142f86 |
parent 58282 | 03fce7b04b42 |
child 59252 | 623722a6aeb9 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53582 | 2 |
* Copyright (c) 2000, 2019, 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" |
47659 | 26 |
#include "jni.h" |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47659
diff
changeset
|
27 |
#include "jvm.h" |
34666 | 28 |
#include "classfile/classFileStream.hpp" |
54347
235883996bc7
8221698: Remove redundant includes from popular header files
iklam
parents:
53582
diff
changeset
|
29 |
#include "classfile/classLoader.hpp" |
7397 | 30 |
#include "classfile/vmSymbols.hpp" |
50113 | 31 |
#include "jfr/jfrEvents.hpp" |
7397 | 32 |
#include "memory/allocation.inline.hpp" |
37248 | 33 |
#include "memory/resourceArea.hpp" |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
34 |
#include "oops/access.inline.hpp" |
59056
15936b142f86
8233913: Remove implicit conversion from Method* to methodHandle
coleenp
parents:
58282
diff
changeset
|
35 |
#include "oops/fieldStreams.inline.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
36 |
#include "oops/objArrayOop.inline.hpp" |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
37 |
#include "oops/oop.inline.hpp" |
49036
bc92debe57e4
8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents:
48169
diff
changeset
|
38 |
#include "oops/typeArrayOop.inline.hpp" |
36551 | 39 |
#include "prims/unsafe.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
40385
diff
changeset
|
40 |
#include "runtime/atomic.hpp" |
7397 | 41 |
#include "runtime/globals.hpp" |
53582 | 42 |
#include "runtime/handles.inline.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49192
diff
changeset
|
43 |
#include "runtime/interfaceSupport.inline.hpp" |
49192
6734eeef4283
8198474: Move JNIHandles::resolve into jniHandles.inline.hpp
kbarrett
parents:
49041
diff
changeset
|
44 |
#include "runtime/jniHandles.inline.hpp" |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50389
diff
changeset
|
45 |
#include "runtime/orderAccess.hpp" |
7397 | 46 |
#include "runtime/reflection.hpp" |
57804 | 47 |
#include "runtime/sharedRuntime.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
48 |
#include "runtime/thread.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
49 |
#include "runtime/threadSMR.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
25354
diff
changeset
|
50 |
#include "runtime/vm_version.hpp" |
7397 | 51 |
#include "services/threadService.hpp" |
46625 | 52 |
#include "utilities/align.hpp" |
7397 | 53 |
#include "utilities/copy.hpp" |
54 |
#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
|
55 |
#include "utilities/macros.hpp" |
7397 | 56 |
|
36551 | 57 |
/** |
58 |
* Implementation of the jdk.internal.misc.Unsafe class |
|
1 | 59 |
*/ |
60 |
||
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
3262
diff
changeset
|
61 |
|
1 | 62 |
#define MAX_OBJECT_SIZE \ |
63 |
( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ |
|
64 |
+ ((julong)max_jint * sizeof(double)) ) |
|
65 |
||
66 |
||
67 |
#define UNSAFE_ENTRY(result_type, header) \ |
|
36551 | 68 |
JVM_ENTRY(static result_type, header) |
1 | 69 |
|
36551 | 70 |
#define UNSAFE_LEAF(result_type, header) \ |
71 |
JVM_LEAF(static result_type, header) |
|
1 | 72 |
|
73 |
#define UNSAFE_END JVM_END |
|
74 |
||
75 |
||
36551 | 76 |
static inline void* addr_from_java(jlong addr) { |
1 | 77 |
// This assert fails in a variety of ways on 32-bit systems. |
78 |
// It is impossible to predict whether native code that converts |
|
79 |
// pointers to longs will sign-extend or zero-extend the addresses. |
|
80 |
//assert(addr == (uintptr_t)addr, "must not be odd high bits"); |
|
81 |
return (void*)(uintptr_t)addr; |
|
82 |
} |
|
83 |
||
36551 | 84 |
static inline jlong addr_to_java(void* p) { |
1 | 85 |
assert(p == (void*)(uintptr_t)p, "must not be odd high bits"); |
86 |
return (uintptr_t)p; |
|
87 |
} |
|
88 |
||
89 |
||
90 |
// Note: The VM's obj_field and related accessors use byte-scaled |
|
91 |
// ("unscaled") offsets, just as the unsafe methods do. |
|
92 |
||
93 |
// However, the method Unsafe.fieldOffset explicitly declines to |
|
94 |
// guarantee this. The field offset values manipulated by the Java user |
|
95 |
// through the Unsafe API are opaque cookies that just happen to be byte |
|
96 |
// offsets. We represent this state of affairs by passing the cookies |
|
97 |
// through conversion functions when going between the VM and the Unsafe API. |
|
98 |
// The conversion functions just happen to be no-ops at present. |
|
99 |
||
36551 | 100 |
static inline jlong field_offset_to_byte_offset(jlong field_offset) { |
1 | 101 |
return field_offset; |
102 |
} |
|
103 |
||
36551 | 104 |
static inline jlong field_offset_from_byte_offset(jlong byte_offset) { |
1 | 105 |
return byte_offset; |
106 |
} |
|
107 |
||
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
108 |
static inline void assert_field_offset_sane(oop p, jlong field_offset) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
109 |
#ifdef ASSERT |
36551 | 110 |
jlong byte_offset = field_offset_to_byte_offset(field_offset); |
1 | 111 |
|
112 |
if (p != NULL) { |
|
113 |
assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); |
|
114 |
if (byte_offset == (jint)byte_offset) { |
|
115 |
void* ptr_plus_disp = (address)p + byte_offset; |
|
49041
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
49036
diff
changeset
|
116 |
assert(p->field_addr_raw((jint)byte_offset) == ptr_plus_disp, |
44122f767467
8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents:
49036
diff
changeset
|
117 |
"raw [ptr+disp] must be consistent with oop::field_addr_raw"); |
1 | 118 |
} |
14127
16ba0a8dfde2
8001071: Add simple range check into VM implemenation of Unsafe access methods
kvn
parents:
13952
diff
changeset
|
119 |
jlong p_size = HeapWordSize * (jlong)(p->size()); |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46625
diff
changeset
|
120 |
assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, (int64_t)byte_offset, (int64_t)p_size); |
1 | 121 |
} |
122 |
#endif |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
123 |
} |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
124 |
|
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
125 |
static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
126 |
assert_field_offset_sane(p, field_offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
127 |
jlong byte_offset = field_offset_to_byte_offset(field_offset); |
36551 | 128 |
|
49661
a3fed4b041ac
8199780: SetMemory0 and CopyMemory0 in unsafe.cpp need to resolve their operands
rkennke
parents:
49658
diff
changeset
|
129 |
if (p != NULL) { |
a3fed4b041ac
8199780: SetMemory0 and CopyMemory0 in unsafe.cpp need to resolve their operands
rkennke
parents:
49658
diff
changeset
|
130 |
p = Access<>::resolve(p); |
a3fed4b041ac
8199780: SetMemory0 and CopyMemory0 in unsafe.cpp need to resolve their operands
rkennke
parents:
49658
diff
changeset
|
131 |
} |
a3fed4b041ac
8199780: SetMemory0 and CopyMemory0 in unsafe.cpp need to resolve their operands
rkennke
parents:
49658
diff
changeset
|
132 |
|
36551 | 133 |
if (sizeof(char*) == sizeof(jint)) { // (this constant folds!) |
1 | 134 |
return (address)p + (jint) byte_offset; |
36551 | 135 |
} else { |
1 | 136 |
return (address)p + byte_offset; |
36551 | 137 |
} |
1 | 138 |
} |
139 |
||
140 |
// Externally callable versions: |
|
141 |
// (Use these in compiler intrinsics which emulate unsafe primitives.) |
|
142 |
jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) { |
|
143 |
return field_offset; |
|
144 |
} |
|
145 |
jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) { |
|
146 |
return byte_offset; |
|
147 |
} |
|
148 |
||
149 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
150 |
///// Data read/writes on the Java heap and in native (off-heap) memory |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
151 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
152 |
/** |
55490
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
153 |
* Helper class to wrap memory accesses in JavaThread::doing_unsafe_access() |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
154 |
*/ |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
155 |
class GuardUnsafeAccess { |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
156 |
JavaThread* _thread; |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
157 |
|
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
158 |
public: |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
159 |
GuardUnsafeAccess(JavaThread* thread) : _thread(thread) { |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
160 |
// native/off-heap access which may raise SIGBUS if accessing |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
161 |
// memory mapped file data in a region of the file which has |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
162 |
// been truncated and is now invalid. |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
163 |
_thread->set_doing_unsafe_access(true); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
164 |
} |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
165 |
|
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
166 |
~GuardUnsafeAccess() { |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
167 |
_thread->set_doing_unsafe_access(false); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
168 |
} |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
169 |
}; |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
170 |
|
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
171 |
/** |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
172 |
* Helper class for accessing memory. |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
173 |
* |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
174 |
* Normalizes values and wraps accesses in |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
175 |
* JavaThread::doing_unsafe_access() if needed. |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
176 |
*/ |
48169 | 177 |
template <typename T> |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
178 |
class MemoryAccess : StackObj { |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
179 |
JavaThread* _thread; |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
180 |
oop _obj; |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
181 |
ptrdiff_t _offset; |
1 | 182 |
|
48169 | 183 |
// Resolves and returns the address of the memory access. |
184 |
// This raw memory access may fault, so we make sure it happens within the |
|
185 |
// guarded scope by making the access volatile at least. Since the store |
|
186 |
// of Thread::set_doing_unsafe_access() is also volatile, these accesses |
|
187 |
// can not be reordered by the compiler. Therefore, if the access triggers |
|
188 |
// a fault, we will know that Thread::doing_unsafe_access() returns true. |
|
189 |
volatile T* addr() { |
|
190 |
void* addr = index_oop_from_field_offset_long(_obj, _offset); |
|
191 |
return static_cast<volatile T*>(addr); |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
192 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
193 |
|
48169 | 194 |
template <typename U> |
195 |
U normalize_for_write(U x) { |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
196 |
return x; |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
197 |
} |
37480 | 198 |
|
41052 | 199 |
jboolean normalize_for_write(jboolean x) { |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
200 |
return x & 1; |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
201 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
202 |
|
48169 | 203 |
template <typename U> |
204 |
U normalize_for_read(U x) { |
|
41052 | 205 |
return x; |
206 |
} |
|
207 |
||
208 |
jboolean normalize_for_read(jboolean x) { |
|
209 |
return x != 0; |
|
210 |
} |
|
211 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
212 |
public: |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
213 |
MemoryAccess(JavaThread* thread, jobject obj, jlong offset) |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
214 |
: _thread(thread), _obj(JNIHandles::resolve(obj)), _offset((ptrdiff_t)offset) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
215 |
assert_field_offset_sane(_obj, offset); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
216 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
217 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
218 |
T get() { |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
219 |
if (_obj == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
220 |
GuardUnsafeAccess guard(_thread); |
48169 | 221 |
T ret = RawAccess<>::load(addr()); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
222 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
223 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
224 |
T ret = HeapAccess<>::load_at(_obj, _offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
225 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
226 |
} |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
227 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
228 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
229 |
void put(T x) { |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
230 |
if (_obj == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
231 |
GuardUnsafeAccess guard(_thread); |
48169 | 232 |
RawAccess<>::store(addr(), normalize_for_write(x)); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
233 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
234 |
HeapAccess<>::store_at(_obj, _offset, normalize_for_write(x)); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
235 |
} |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
236 |
} |
1 | 237 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
238 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
239 |
T get_volatile() { |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
240 |
if (_obj == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
241 |
GuardUnsafeAccess guard(_thread); |
48169 | 242 |
volatile T ret = RawAccess<MO_SEQ_CST>::load(addr()); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
243 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
244 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
245 |
T ret = HeapAccess<MO_SEQ_CST>::load_at(_obj, _offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
246 |
return normalize_for_read(ret); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
247 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
248 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
249 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
250 |
void put_volatile(T x) { |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
251 |
if (_obj == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
252 |
GuardUnsafeAccess guard(_thread); |
48169 | 253 |
RawAccess<MO_SEQ_CST>::store(addr(), normalize_for_write(x)); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
254 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
255 |
HeapAccess<MO_SEQ_CST>::store_at(_obj, _offset, normalize_for_write(x)); |
41181
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
256 |
} |
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
257 |
} |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
258 |
}; |
41181
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
259 |
|
25057 | 260 |
// These functions allow a null base pointer with an arbitrary address. |
1 | 261 |
// But if the base pointer is non-null, the offset should make some sense. |
262 |
// That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
263 |
UNSAFE_ENTRY(jobject, Unsafe_GetReference(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
|
264 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
265 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
266 |
oop v = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(p, offset); |
41181
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
267 |
return JNIHandles::make_local(env, v); |
36551 | 268 |
} UNSAFE_END |
269 |
||
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
270 |
UNSAFE_ENTRY(void, Unsafe_PutReference(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
1 | 271 |
oop x = JNIHandles::resolve(x_h); |
272 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
273 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
274 |
HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(p, offset, x); |
36551 | 275 |
} UNSAFE_END |
1 | 276 |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
277 |
UNSAFE_ENTRY(jobject, Unsafe_GetReferenceVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
278 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
279 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
280 |
oop v = HeapAccess<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>::oop_load_at(p, offset); |
1 | 281 |
return JNIHandles::make_local(env, v); |
36551 | 282 |
} UNSAFE_END |
1 | 283 |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
284 |
UNSAFE_ENTRY(void, Unsafe_PutReferenceVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
1 | 285 |
oop x = JNIHandles::resolve(x_h); |
286 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
287 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
288 |
HeapAccess<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>::oop_store_at(p, offset, x); |
36551 | 289 |
} UNSAFE_END |
290 |
||
291 |
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
|
292 |
oop v = *(oop*) (address) addr; |
36551 | 293 |
return JNIHandles::make_local(env, v); |
294 |
} UNSAFE_END |
|
295 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
296 |
#define DEFINE_GETSETOOP(java_type, Type) \ |
1 | 297 |
\ |
36551 | 298 |
UNSAFE_ENTRY(java_type, Unsafe_Get##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \ |
48169 | 299 |
return MemoryAccess<java_type>(thread, obj, offset).get(); \ |
36551 | 300 |
} UNSAFE_END \ |
1 | 301 |
\ |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
302 |
UNSAFE_ENTRY(void, Unsafe_Put##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \ |
48169 | 303 |
MemoryAccess<java_type>(thread, obj, offset).put(x); \ |
36551 | 304 |
} UNSAFE_END \ |
1 | 305 |
\ |
306 |
// END DEFINE_GETSETOOP. |
|
307 |
||
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
308 |
DEFINE_GETSETOOP(jboolean, Boolean) |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
309 |
DEFINE_GETSETOOP(jbyte, Byte) |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
310 |
DEFINE_GETSETOOP(jshort, Short); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
311 |
DEFINE_GETSETOOP(jchar, Char); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
312 |
DEFINE_GETSETOOP(jint, Int); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
313 |
DEFINE_GETSETOOP(jlong, Long); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
314 |
DEFINE_GETSETOOP(jfloat, Float); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
315 |
DEFINE_GETSETOOP(jdouble, Double); |
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
316 |
|
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
317 |
#undef DEFINE_GETSETOOP |
1 | 318 |
|
36551 | 319 |
#define DEFINE_GETSETOOP_VOLATILE(java_type, Type) \ |
1 | 320 |
\ |
36551 | 321 |
UNSAFE_ENTRY(java_type, Unsafe_Get##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \ |
48169 | 322 |
return MemoryAccess<java_type>(thread, obj, offset).get_volatile(); \ |
36551 | 323 |
} UNSAFE_END \ |
1 | 324 |
\ |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
325 |
UNSAFE_ENTRY(void, Unsafe_Put##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \ |
48169 | 326 |
MemoryAccess<java_type>(thread, obj, offset).put_volatile(x); \ |
36551 | 327 |
} UNSAFE_END \ |
1 | 328 |
\ |
329 |
// END DEFINE_GETSETOOP_VOLATILE. |
|
330 |
||
331 |
DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean) |
|
332 |
DEFINE_GETSETOOP_VOLATILE(jbyte, Byte) |
|
333 |
DEFINE_GETSETOOP_VOLATILE(jshort, Short); |
|
334 |
DEFINE_GETSETOOP_VOLATILE(jchar, Char); |
|
335 |
DEFINE_GETSETOOP_VOLATILE(jint, Int); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
336 |
DEFINE_GETSETOOP_VOLATILE(jlong, Long); |
1 | 337 |
DEFINE_GETSETOOP_VOLATILE(jfloat, Float); |
338 |
DEFINE_GETSETOOP_VOLATILE(jdouble, Double); |
|
339 |
||
7885
c02b05ba16a1
7009756: volatile variables could be broken throw reflection API
kvn
parents:
7397
diff
changeset
|
340 |
#undef DEFINE_GETSETOOP_VOLATILE |
1 | 341 |
|
36551 | 342 |
UNSAFE_LEAF(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe)) { |
14832 | 343 |
OrderAccess::acquire(); |
36551 | 344 |
} UNSAFE_END |
14832 | 345 |
|
36551 | 346 |
UNSAFE_LEAF(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) { |
14832 | 347 |
OrderAccess::release(); |
36551 | 348 |
} UNSAFE_END |
14832 | 349 |
|
36551 | 350 |
UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) { |
14832 | 351 |
OrderAccess::fence(); |
36551 | 352 |
} UNSAFE_END |
14832 | 353 |
|
1 | 354 |
////// Allocation requests |
355 |
||
36551 | 356 |
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) { |
357 |
ThreadToNativeFromVM ttnfv(thread); |
|
358 |
return env->AllocObject(cls); |
|
359 |
} UNSAFE_END |
|
1 | 360 |
|
36551 | 361 |
UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) { |
1 | 362 |
size_t sz = (size_t)size; |
36551 | 363 |
|
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46568
diff
changeset
|
364 |
sz = align_up(sz, HeapWordSize); |
49456
647d7631fb9d
8199752: NMT: Memory allocated by Unsafe.allocateMemory should be tagged as mtOther
zgu
parents:
49449
diff
changeset
|
365 |
void* x = os::malloc(sz, mtOther); |
36551 | 366 |
|
1 | 367 |
return addr_to_java(x); |
36551 | 368 |
} UNSAFE_END |
1 | 369 |
|
36551 | 370 |
UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) { |
1 | 371 |
void* p = addr_from_java(addr); |
372 |
size_t sz = (size_t)size; |
|
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46568
diff
changeset
|
373 |
sz = align_up(sz, HeapWordSize); |
36551 | 374 |
|
49456
647d7631fb9d
8199752: NMT: Memory allocated by Unsafe.allocateMemory should be tagged as mtOther
zgu
parents:
49449
diff
changeset
|
375 |
void* x = os::realloc(p, sz, mtOther); |
36551 | 376 |
|
1 | 377 |
return addr_to_java(x); |
36551 | 378 |
} UNSAFE_END |
1 | 379 |
|
36551 | 380 |
UNSAFE_ENTRY(void, Unsafe_FreeMemory0(JNIEnv *env, jobject unsafe, jlong addr)) { |
1 | 381 |
void* p = addr_from_java(addr); |
36551 | 382 |
|
1 | 383 |
os::free(p); |
36551 | 384 |
} UNSAFE_END |
1 | 385 |
|
36551 | 386 |
UNSAFE_ENTRY(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) { |
1 | 387 |
size_t sz = (size_t)size; |
36551 | 388 |
|
1 | 389 |
oop base = JNIHandles::resolve(obj); |
390 |
void* p = index_oop_from_field_offset_long(base, offset); |
|
36551 | 391 |
|
1 | 392 |
Copy::fill_to_memory_atomic(p, sz, value); |
36551 | 393 |
} UNSAFE_END |
1 | 394 |
|
36551 | 395 |
UNSAFE_ENTRY(void, Unsafe_CopyMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) { |
1 | 396 |
size_t sz = (size_t)size; |
36551 | 397 |
|
1 | 398 |
oop srcp = JNIHandles::resolve(srcObj); |
399 |
oop dstp = JNIHandles::resolve(dstObj); |
|
36551 | 400 |
|
1 | 401 |
void* src = index_oop_from_field_offset_long(srcp, srcOffset); |
402 |
void* dst = index_oop_from_field_offset_long(dstp, dstOffset); |
|
55490
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
403 |
{ |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
404 |
GuardUnsafeAccess guard(thread); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
405 |
if (StubRoutines::unsafe_arraycopy() != NULL) { |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
406 |
StubRoutines::UnsafeArrayCopy_stub()(src, dst, sz); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
407 |
} else { |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
408 |
Copy::conjoint_memory_atomic(src, dst, sz); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
409 |
} |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
410 |
} |
36551 | 411 |
} UNSAFE_END |
1 | 412 |
|
36086 | 413 |
// This function is a leaf since if the source and destination are both in native memory |
414 |
// the copy may potentially be very large, and we don't want to disable GC if we can avoid it. |
|
415 |
// If either source or destination (or both) are on the heap, the function will enter VM using |
|
416 |
// JVM_ENTRY_FROM_LEAF |
|
36551 | 417 |
UNSAFE_LEAF(void, Unsafe_CopySwapMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) { |
36086 | 418 |
size_t sz = (size_t)size; |
419 |
size_t esz = (size_t)elemSize; |
|
420 |
||
421 |
if (srcObj == NULL && dstObj == NULL) { |
|
422 |
// Both src & dst are in native memory |
|
423 |
address src = (address)srcOffset; |
|
424 |
address dst = (address)dstOffset; |
|
425 |
||
55490
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
426 |
{ |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
427 |
JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
428 |
GuardUnsafeAccess guard(thread); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
429 |
Copy::conjoint_swap(src, dst, sz, esz); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
430 |
} |
36086 | 431 |
} else { |
432 |
// At least one of src/dst are on heap, transition to VM to access raw pointers |
|
433 |
||
434 |
JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory0) { |
|
435 |
oop srcp = JNIHandles::resolve(srcObj); |
|
436 |
oop dstp = JNIHandles::resolve(dstObj); |
|
437 |
||
438 |
address src = (address)index_oop_from_field_offset_long(srcp, srcOffset); |
|
439 |
address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset); |
|
440 |
||
55490
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
441 |
{ |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
442 |
GuardUnsafeAccess guard(thread); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
443 |
Copy::conjoint_swap(src, dst, sz, esz); |
3f3dc00a69a5
8191278: MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
54629
diff
changeset
|
444 |
} |
36086 | 445 |
} JVM_END |
446 |
} |
|
36551 | 447 |
} UNSAFE_END |
1 | 448 |
|
57804 | 449 |
UNSAFE_LEAF (void, Unsafe_WriteBack0(JNIEnv *env, jobject unsafe, jlong line)) { |
450 |
assert(VM_Version::supports_data_cache_line_flush(), "should not get here"); |
|
451 |
#ifdef ASSERT |
|
452 |
if (TraceMemoryWriteback) { |
|
453 |
tty->print_cr("Unsafe: writeback 0x%p", addr_from_java(line)); |
|
454 |
} |
|
455 |
#endif |
|
456 |
||
457 |
assert(StubRoutines::data_cache_writeback() != NULL, "sanity"); |
|
458 |
(StubRoutines::DataCacheWriteback_stub())(addr_from_java(line)); |
|
459 |
} UNSAFE_END |
|
460 |
||
461 |
static void doWriteBackSync0(bool is_pre) |
|
462 |
{ |
|
463 |
assert(StubRoutines::data_cache_writeback_sync() != NULL, "sanity"); |
|
464 |
(StubRoutines::DataCacheWritebackSync_stub())(is_pre); |
|
465 |
} |
|
466 |
||
467 |
UNSAFE_LEAF (void, Unsafe_WriteBackPreSync0(JNIEnv *env, jobject unsafe)) { |
|
468 |
assert(VM_Version::supports_data_cache_line_flush(), "should not get here"); |
|
469 |
#ifdef ASSERT |
|
470 |
if (TraceMemoryWriteback) { |
|
471 |
tty->print_cr("Unsafe: writeback pre-sync"); |
|
472 |
} |
|
473 |
#endif |
|
474 |
||
475 |
doWriteBackSync0(true); |
|
476 |
} UNSAFE_END |
|
477 |
||
478 |
UNSAFE_LEAF (void, Unsafe_WriteBackPostSync0(JNIEnv *env, jobject unsafe)) { |
|
479 |
assert(VM_Version::supports_data_cache_line_flush(), "should not get here"); |
|
480 |
#ifdef ASSERT |
|
481 |
if (TraceMemoryWriteback) { |
|
482 |
tty->print_cr("Unsafe: writeback pre-sync"); |
|
483 |
} |
|
484 |
#endif |
|
485 |
||
486 |
doWriteBackSync0(false); |
|
487 |
} UNSAFE_END |
|
488 |
||
1 | 489 |
////// Random queries |
490 |
||
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
491 |
static jlong find_field_offset(jclass clazz, jstring name, TRAPS) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
492 |
assert(clazz != NULL, "clazz must not be NULL"); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
493 |
assert(name != NULL, "name must not be NULL"); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
494 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
495 |
ResourceMark rm(THREAD); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
496 |
char *utf_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
497 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
498 |
InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
499 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
500 |
jint offset = -1; |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
501 |
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
502 |
Symbol *name = fs.name(); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
503 |
if (name->equals(utf_name)) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
504 |
offset = fs.offset(); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
505 |
break; |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
506 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
507 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
508 |
if (offset < 0) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
509 |
THROW_0(vmSymbols::java_lang_InternalError()); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
510 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
511 |
return field_offset_from_byte_offset(offset); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
512 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
513 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
514 |
static jlong find_field_offset(jobject field, int must_be_static, TRAPS) { |
36551 | 515 |
assert(field != NULL, "field must not be NULL"); |
1 | 516 |
|
517 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
518 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
36551 | 519 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 520 |
int slot = java_lang_reflect_Field::slot(reflected); |
521 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
522 |
||
523 |
if (must_be_static >= 0) { |
|
524 |
int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); |
|
525 |
if (must_be_static != really_is_static) { |
|
526 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
527 |
} |
|
528 |
} |
|
529 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
530 |
int offset = InstanceKlass::cast(k)->field_offset(slot); |
1 | 531 |
return field_offset_from_byte_offset(offset); |
532 |
} |
|
533 |
||
36551 | 534 |
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 535 |
return find_field_offset(field, 0, THREAD); |
36551 | 536 |
} UNSAFE_END |
1 | 537 |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
538 |
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset1(JNIEnv *env, jobject unsafe, jclass c, jstring name)) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
539 |
return find_field_offset(c, name, THREAD); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
540 |
} UNSAFE_END |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
541 |
|
36551 | 542 |
UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 543 |
return find_field_offset(field, 1, THREAD); |
36551 | 544 |
} UNSAFE_END |
1 | 545 |
|
36551 | 546 |
UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBase0(JNIEnv *env, jobject unsafe, jobject field)) { |
547 |
assert(field != NULL, "field must not be NULL"); |
|
548 |
||
1 | 549 |
// Note: In this VM implementation, a field address is always a short |
550 |
// offset from the base of a a klass metaobject. Thus, the full dynamic |
|
551 |
// range of the return type is never used. However, some implementations |
|
552 |
// might put the static field inside an array shared by many classes, |
|
553 |
// or even at a fixed address, in which case the address could be quite |
|
554 |
// large. In that last case, this function would return NULL, since |
|
555 |
// the address would operate alone, without any base pointer. |
|
556 |
||
557 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
558 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
559 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
560 |
||
561 |
if ((modifiers & JVM_ACC_STATIC) == 0) { |
|
562 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
563 |
} |
|
564 |
||
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8490
diff
changeset
|
565 |
return JNIHandles::make_local(env, mirror); |
36551 | 566 |
} UNSAFE_END |
1 | 567 |
|
36551 | 568 |
UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
569 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
570 |
||
1 | 571 |
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
|
572 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
573 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
14488 | 574 |
if (klass != NULL && klass->should_be_initialized()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
575 |
InstanceKlass* k = InstanceKlass::cast(klass); |
1 | 576 |
k->initialize(CHECK); |
577 |
} |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
578 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
579 |
UNSAFE_END |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
580 |
|
36551 | 581 |
UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
582 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
583 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
584 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
585 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
36551 | 586 |
|
14488 | 587 |
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
|
588 |
return true; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
589 |
} |
36551 | 590 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
591 |
return false; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
592 |
} |
1 | 593 |
UNSAFE_END |
594 |
||
36551 | 595 |
static void getBaseAndScale(int& base, int& scale, jclass clazz, TRAPS) { |
596 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
597 |
||
598 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
|
599 |
Klass* k = java_lang_Class::as_Klass(mirror); |
|
600 |
||
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
601 |
if (k == NULL || !k->is_array_klass()) { |
1 | 602 |
THROW(vmSymbols::java_lang_InvalidClassException()); |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
603 |
} else if (k->is_objArray_klass()) { |
1 | 604 |
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
|
605 |
scale = heapOopSize; |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
606 |
} else if (k->is_typeArray_klass()) { |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
607 |
TypeArrayKlass* tak = TypeArrayKlass::cast(k); |
1 | 608 |
base = tak->array_header_in_bytes(); |
609 |
assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); |
|
610 |
scale = (1 << tak->log2_element_size()); |
|
611 |
} else { |
|
612 |
ShouldNotReachHere(); |
|
613 |
} |
|
614 |
} |
|
615 |
||
36551 | 616 |
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
|
617 |
int base = 0, scale = 0; |
36551 | 618 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
619 |
||
1 | 620 |
return field_offset_from_byte_offset(base); |
36551 | 621 |
} UNSAFE_END |
1 | 622 |
|
623 |
||
36551 | 624 |
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
|
625 |
int base = 0, scale = 0; |
36551 | 626 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
627 |
||
1 | 628 |
// This VM packs both fields and array elements down to the byte. |
629 |
// But watch out: If this changes, so that array references for |
|
630 |
// a given primitive type (say, T_BOOLEAN) use different memory units |
|
631 |
// than fields, this method MUST return zero for such arrays. |
|
632 |
// For example, the VM used to store sub-word sized fields in full |
|
633 |
// words in the object layout, so that accessors like getByte(Object,int) |
|
634 |
// did not really do what one might expect for arrays. Therefore, |
|
635 |
// this function used to report a zero scale factor, so that the user |
|
636 |
// would know not to attempt to access sub-word array elements. |
|
637 |
// // Code for unpacked fields: |
|
638 |
// if (scale < wordSize) return 0; |
|
639 |
||
640 |
// The following allows for a pretty general fieldOffset cookie scheme, |
|
641 |
// but requires it to be linear in byte offset. |
|
642 |
return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); |
|
36551 | 643 |
} UNSAFE_END |
1 | 644 |
|
645 |
||
646 |
static inline void throw_new(JNIEnv *env, const char *ename) { |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
647 |
jclass cls = env->FindClass(ename); |
22786
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
648 |
if (env->ExceptionCheck()) { |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
649 |
env->ExceptionClear(); |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
650 |
tty->print_cr("Unsafe: cannot throw %s because FindClass has failed", ename); |
22786
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
651 |
return; |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
652 |
} |
36551 | 653 |
|
654 |
env->ThrowNew(cls, NULL); |
|
1 | 655 |
} |
656 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
657 |
static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { |
36551 | 658 |
// Code lifted from JDK 1.3 ClassLoader.c |
659 |
||
660 |
jbyte *body; |
|
661 |
char *utfName = NULL; |
|
662 |
jclass result = 0; |
|
663 |
char buf[128]; |
|
1 | 664 |
|
36551 | 665 |
assert(data != NULL, "Class bytes must not be NULL"); |
666 |
assert(length >= 0, "length must not be negative: %d", length); |
|
1 | 667 |
|
36551 | 668 |
if (UsePerfData) { |
669 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
|
670 |
} |
|
1 | 671 |
|
58282
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
58177
diff
changeset
|
672 |
body = NEW_C_HEAP_ARRAY_RETURN_NULL(jbyte, length, mtInternal); |
36551 | 673 |
if (body == NULL) { |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
674 |
throw_new(env, "java/lang/OutOfMemoryError"); |
36551 | 675 |
return 0; |
676 |
} |
|
677 |
||
678 |
env->GetByteArrayRegion(data, offset, length, body); |
|
679 |
if (env->ExceptionOccurred()) { |
|
680 |
goto free_body; |
|
681 |
} |
|
1 | 682 |
|
36551 | 683 |
if (name != NULL) { |
684 |
uint len = env->GetStringUTFLength(name); |
|
685 |
int unicode_len = env->GetStringLength(name); |
|
1 | 686 |
|
36551 | 687 |
if (len >= sizeof(buf)) { |
58282
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
58177
diff
changeset
|
688 |
utfName = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len + 1, mtInternal); |
36551 | 689 |
if (utfName == NULL) { |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
690 |
throw_new(env, "java/lang/OutOfMemoryError"); |
36551 | 691 |
goto free_body; |
692 |
} |
|
693 |
} else { |
|
694 |
utfName = buf; |
|
1 | 695 |
} |
696 |
||
36551 | 697 |
env->GetStringUTFRegion(name, 0, unicode_len, utfName); |
1 | 698 |
|
36551 | 699 |
for (uint i = 0; i < len; i++) { |
700 |
if (utfName[i] == '.') utfName[i] = '/'; |
|
1 | 701 |
} |
36551 | 702 |
} |
1 | 703 |
|
36551 | 704 |
result = JVM_DefineClass(env, utfName, loader, body, length, pd); |
1 | 705 |
|
36551 | 706 |
if (utfName && utfName != buf) { |
707 |
FREE_C_HEAP_ARRAY(char, utfName); |
|
708 |
} |
|
1 | 709 |
|
710 |
free_body: |
|
36551 | 711 |
FREE_C_HEAP_ARRAY(jbyte, body); |
712 |
return result; |
|
1 | 713 |
} |
714 |
||
715 |
||
36551 | 716 |
UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) { |
717 |
ThreadToNativeFromVM ttnfv(thread); |
|
718 |
||
719 |
return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd); |
|
720 |
} UNSAFE_END |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
721 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
722 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
723 |
// 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
|
724 |
// - host_class: supplies context for linkage, access control, protection domain, and class loader |
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
725 |
// if host_class is itself anonymous then it is replaced with its host class. |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
726 |
// - 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
|
727 |
// - 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
|
728 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
729 |
// 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
|
730 |
// 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
|
731 |
// 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
|
732 |
// 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
|
733 |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
734 |
// The package of an anonymous class must either match its host's class's package or be in the |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
735 |
// unnamed package. If it is in the unnamed package then it will be put in its host class's |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
736 |
// package. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
737 |
// |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
738 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
739 |
// 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
|
740 |
// 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
|
741 |
// 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
|
742 |
// 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
|
743 |
// 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
|
744 |
// 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
|
745 |
// restrictions. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
746 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
747 |
// 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
|
748 |
// 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
|
749 |
// 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
|
750 |
// access one of its anonymous classes. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
751 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
752 |
// 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
|
753 |
// 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
|
754 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
755 |
// 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
|
756 |
// 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
|
757 |
// 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
|
758 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
759 |
// 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
|
760 |
// 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
|
761 |
// 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
|
762 |
// 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
|
763 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
764 |
// 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
|
765 |
// 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
|
766 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
767 |
// 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
|
768 |
// 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
|
769 |
// 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
|
770 |
// 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
|
771 |
// 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
|
772 |
// 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
|
773 |
// 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
|
774 |
// 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
|
775 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
776 |
static InstanceKlass* |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
777 |
Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
778 |
jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, |
36551 | 779 |
u1** temp_alloc, |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
780 |
TRAPS) { |
36551 | 781 |
assert(host_class != NULL, "host_class must not be NULL"); |
782 |
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
|
783 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
784 |
if (UsePerfData) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
785 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
786 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
787 |
|
36551 | 788 |
jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); |
789 |
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
|
790 |
|
36551 | 791 |
int class_bytes_length = (int) length; |
792 |
||
58282
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
58177
diff
changeset
|
793 |
u1* class_bytes = NEW_C_HEAP_ARRAY_RETURN_NULL(u1, length, mtInternal); |
36551 | 794 |
if (class_bytes == NULL) { |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
795 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
796 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
797 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
798 |
// caller responsible to free it: |
36551 | 799 |
*temp_alloc = class_bytes; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
800 |
|
50389
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50113
diff
changeset
|
801 |
ArrayAccess<>::arraycopy_to_native(arrayOop(JNIHandles::resolve_non_null(data)), typeArrayOopDesc::element_offset<jbyte>(0), |
7e8c0409a747
8198285: More consistent Access API for arraycopy
rkennke
parents:
50113
diff
changeset
|
802 |
reinterpret_cast<jbyte*>(class_bytes), length); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
803 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
804 |
objArrayHandle cp_patches_h; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
805 |
if (cp_patches_jh != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
806 |
oop p = JNIHandles::resolve_non_null(cp_patches_jh); |
36551 | 807 |
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
|
808 |
cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
809 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
810 |
|
34666 | 811 |
const Klass* host_klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class)); |
40385
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
812 |
|
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
813 |
// Make sure it's the real host class, not another anonymous class. |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
814 |
while (host_klass != NULL && host_klass->is_instance_klass() && |
51444
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50429
diff
changeset
|
815 |
InstanceKlass::cast(host_klass)->is_unsafe_anonymous()) { |
3e5d28e6de32
8209301: JVM rename is_anonymous, host_klass to unsafe specific terminology ahead of Unsafe.defineAnonymousClass deprecation
lfoltan
parents:
50429
diff
changeset
|
816 |
host_klass = InstanceKlass::cast(host_klass)->unsafe_anonymous_host(); |
40385
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
817 |
} |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
818 |
|
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
|
819 |
// 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
|
820 |
if (host_klass == NULL) { |
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
821 |
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Host class is null"); |
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
|
822 |
} |
34666 | 823 |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
824 |
assert(host_klass->is_instance_klass(), "Host class must be an instance class"); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
825 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
826 |
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
|
827 |
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
|
828 |
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
|
829 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
830 |
GrowableArray<Handle>* cp_patches = NULL; |
36551 | 831 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
832 |
if (cp_patches_h.not_null()) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
833 |
int alen = cp_patches_h->length(); |
36551 | 834 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
835 |
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
|
836 |
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
|
837 |
if (p != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
838 |
Handle patch(THREAD, p); |
36551 | 839 |
|
840 |
if (cp_patches == NULL) { |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
841 |
cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle()); |
36551 | 842 |
} |
843 |
||
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
844 |
cp_patches->at_put(i, patch); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
845 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
846 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
847 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
848 |
|
36551 | 849 |
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
|
850 |
|
36551 | 851 |
Symbol* no_class_name = NULL; |
852 |
Klass* anonk = SystemDictionary::parse_stream(no_class_name, |
|
853 |
host_loader, |
|
854 |
host_domain, |
|
855 |
&st, |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
856 |
InstanceKlass::cast(host_klass), |
36551 | 857 |
cp_patches, |
858 |
CHECK_NULL); |
|
859 |
if (anonk == NULL) { |
|
860 |
return NULL; |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
861 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
862 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
863 |
return InstanceKlass::cast(anonk); |
1550
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 |
|
36551 | 866 |
UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) { |
867 |
ResourceMark rm(THREAD); |
|
868 |
||
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
869 |
jobject res_jh = NULL; |
36551 | 870 |
u1* temp_alloc = NULL; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
871 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
872 |
InstanceKlass* anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
873 |
if (anon_klass != NULL) { |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
874 |
res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); |
36551 | 875 |
} |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
876 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
877 |
// try/finally clause: |
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
57804
diff
changeset
|
878 |
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
|
879 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
880 |
// 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
|
881 |
// 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
|
882 |
// it alive afterwards. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
883 |
if (anon_klass != NULL) { |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37267
diff
changeset
|
884 |
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
|
885 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
886 |
|
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
887 |
// let caller initialize it as needed... |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
888 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
889 |
return (jclass) res_jh; |
36551 | 890 |
} UNSAFE_END |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
891 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
892 |
|
1 | 893 |
|
36551 | 894 |
UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) { |
895 |
ThreadToNativeFromVM ttnfv(thread); |
|
896 |
env->Throw(thr); |
|
897 |
} UNSAFE_END |
|
1 | 898 |
|
899 |
// JSR166 ------------------------------------------------------------------ |
|
900 |
||
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
901 |
UNSAFE_ENTRY(jobject, Unsafe_CompareAndExchangeReference(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
|
902 |
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
|
903 |
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
|
904 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
905 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
906 |
oop res = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e); |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
907 |
return JNIHandles::make_local(env, res); |
36551 | 908 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
909 |
|
36551 | 910 |
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
|
911 |
oop p = JNIHandles::resolve(obj); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
912 |
if (p == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
913 |
volatile jint* addr = (volatile jint*)index_oop_from_field_offset_long(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
914 |
return RawAccess<>::atomic_cmpxchg(x, addr, e); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
915 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
916 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
917 |
return HeapAccess<>::atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
918 |
} |
36551 | 919 |
} UNSAFE_END |
920 |
||
921 |
UNSAFE_ENTRY(jlong, Unsafe_CompareAndExchangeLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) { |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
922 |
oop p = JNIHandles::resolve(obj); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
923 |
if (p == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
924 |
volatile jlong* addr = (volatile jlong*)index_oop_from_field_offset_long(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
925 |
return RawAccess<>::atomic_cmpxchg(x, addr, e); |
36551 | 926 |
} else { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
927 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
928 |
return HeapAccess<>::atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e); |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
929 |
} |
36551 | 930 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
931 |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
932 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetReference(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) { |
1 | 933 |
oop x = JNIHandles::resolve(x_h); |
934 |
oop e = JNIHandles::resolve(e_h); |
|
935 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
936 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
937 |
oop ret = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e); |
58177 | 938 |
return ret == e; |
36551 | 939 |
} UNSAFE_END |
940 |
||
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
941 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) { |
1 | 942 |
oop p = JNIHandles::resolve(obj); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
943 |
if (p == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
944 |
volatile jint* addr = (volatile jint*)index_oop_from_field_offset_long(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
945 |
return RawAccess<>::atomic_cmpxchg(x, addr, e) == e; |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
946 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
947 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
948 |
return HeapAccess<>::atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e) == e; |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
949 |
} |
36551 | 950 |
} UNSAFE_END |
1 | 951 |
|
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
952 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
953 |
oop p = JNIHandles::resolve(obj); |
49592
77fb0be7d19f
8199946: Move load/store and encode/decode out of oopDesc
stefank
parents:
49456
diff
changeset
|
954 |
if (p == NULL) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
955 |
volatile jlong* addr = (volatile jlong*)index_oop_from_field_offset_long(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
956 |
return RawAccess<>::atomic_cmpxchg(x, addr, e) == e; |
36551 | 957 |
} else { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
958 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
959 |
return HeapAccess<>::atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e) == e; |
1 | 960 |
} |
36551 | 961 |
} UNSAFE_END |
1 | 962 |
|
52981
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
963 |
static void post_thread_park_event(EventThreadPark* event, const oop obj, jlong timeout_nanos, jlong until_epoch_millis) { |
50113 | 964 |
assert(event != NULL, "invariant"); |
965 |
assert(event->should_commit(), "invariant"); |
|
966 |
event->set_parkedClass((obj != NULL) ? obj->klass() : NULL); |
|
52981
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
967 |
event->set_timeout(timeout_nanos); |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
968 |
event->set_until(until_epoch_millis); |
50113 | 969 |
event->set_address((obj != NULL) ? (u8)cast_from_oop<uintptr_t>(obj) : 0); |
970 |
event->commit(); |
|
971 |
} |
|
972 |
||
36551 | 973 |
UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) { |
50113 | 974 |
HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time); |
18025 | 975 |
EventThreadPark event; |
22796 | 976 |
|
1 | 977 |
JavaThreadParkedState jtps(thread, time != 0); |
978 |
thread->parker()->park(isAbsolute != 0, time); |
|
50113 | 979 |
if (event.should_commit()) { |
52981
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
980 |
const oop obj = thread->current_park_blocker(); |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
981 |
if (time == 0) { |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
982 |
post_thread_park_event(&event, obj, min_jlong, min_jlong); |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
983 |
} else { |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
984 |
if (isAbsolute != 0) { |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
985 |
post_thread_park_event(&event, obj, min_jlong, time); |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
986 |
} else { |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
987 |
post_thread_park_event(&event, obj, time, min_jlong); |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
988 |
} |
4eff16f47ae2
8165675: Trace event for thread park has incorrect unit for timeout
egahlin
parents:
52220
diff
changeset
|
989 |
} |
50113 | 990 |
} |
22796 | 991 |
HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); |
36551 | 992 |
} UNSAFE_END |
1 | 993 |
|
36551 | 994 |
UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { |
1 | 995 |
Parker* p = NULL; |
36551 | 996 |
|
1 | 997 |
if (jthread != NULL) { |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
998 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
999 |
JavaThread* thr = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
1000 |
oop java_thread = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
1001 |
(void) tlh.cv_internal_thread_to_JavaThread(jthread, &thr, &java_thread); |
1 | 1002 |
if (java_thread != NULL) { |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
1003 |
// This is a valid oop. |
54629
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1004 |
if (thr != NULL) { |
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1005 |
// The JavaThread is alive. |
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1006 |
p = thr->parker(); |
1 | 1007 |
} |
1008 |
} |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
1009 |
} // ThreadsListHandle is destroyed here. |
36551 | 1010 |
|
54629
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1011 |
// 'p' points to type-stable-memory if non-NULL. If the target |
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1012 |
// thread terminates before we get here the new user of this |
9ebb614d293d
8222518: Remove unnecessary caching of Parker object in java.lang.Thread
dholmes
parents:
54439
diff
changeset
|
1013 |
// Parker will get a 'spurious' unpark - which is perfectly valid. |
1 | 1014 |
if (p != NULL) { |
22796 | 1015 |
HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
1 | 1016 |
p->unpark(); |
1017 |
} |
|
36551 | 1018 |
} UNSAFE_END |
1 | 1019 |
|
36551 | 1020 |
UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) { |
1 | 1021 |
const int max_nelem = 3; |
1022 |
double la[max_nelem]; |
|
1023 |
jint ret; |
|
1024 |
||
1025 |
typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); |
|
1026 |
assert(a->is_typeArray(), "must be type array"); |
|
1027 |
||
36551 | 1028 |
ret = os::loadavg(la, nelem); |
1029 |
if (ret == -1) { |
|
1 | 1030 |
return -1; |
1031 |
} |
|
1032 |
||
1033 |
// if successful, ret is the number of samples actually retrieved. |
|
1034 |
assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); |
|
1035 |
switch(ret) { |
|
1036 |
case 3: a->double_at_put(2, (jdouble)la[2]); // fall through |
|
1037 |
case 2: a->double_at_put(1, (jdouble)la[1]); // fall through |
|
1038 |
case 1: a->double_at_put(0, (jdouble)la[0]); break; |
|
1039 |
} |
|
36551 | 1040 |
|
1 | 1041 |
return ret; |
36551 | 1042 |
} UNSAFE_END |
1 | 1043 |
|
1044 |
||
1045 |
/// JVM_RegisterUnsafeMethods |
|
1046 |
||
1047 |
#define ADR "J" |
|
1048 |
||
1049 |
#define LANG "Ljava/lang/" |
|
1050 |
||
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1051 |
#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
|
1052 |
#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
|
1053 |
#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
|
1054 |
#define THR LANG "Throwable;" |
1 | 1055 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1056 |
#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
|
1057 |
#define DAC_Args CLS "[B[" OBJ |
1 | 1058 |
|
1059 |
#define CC (char*) /*cast a literal from (const char*)*/ |
|
1060 |
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
|
1061 |
||
36551 | 1062 |
#define DECLARE_GETPUTOOP(Type, Desc) \ |
1063 |
{CC "get" #Type, CC "(" OBJ "J)" #Desc, FN_PTR(Unsafe_Get##Type)}, \ |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
1064 |
{CC "put" #Type, CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Put##Type)}, \ |
36551 | 1065 |
{CC "get" #Type "Volatile", CC "(" OBJ "J)" #Desc, FN_PTR(Unsafe_Get##Type##Volatile)}, \ |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
1066 |
{CC "put" #Type "Volatile", CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Put##Type##Volatile)} |
1 | 1067 |
|
1068 |
||
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1069 |
static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = { |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1070 |
{CC "getReference", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetReference)}, |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1071 |
{CC "putReference", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_PutReference)}, |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1072 |
{CC "getReferenceVolatile", CC "(" OBJ "J)" OBJ, FN_PTR(Unsafe_GetReferenceVolatile)}, |
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1073 |
{CC "putReferenceVolatile", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_PutReferenceVolatile)}, |
1 | 1074 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1075 |
{CC "getUncompressedObject", CC "(" ADR ")" OBJ, FN_PTR(Unsafe_GetUncompressedObject)}, |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
1076 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1077 |
DECLARE_GETPUTOOP(Boolean, Z), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1078 |
DECLARE_GETPUTOOP(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1079 |
DECLARE_GETPUTOOP(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1080 |
DECLARE_GETPUTOOP(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1081 |
DECLARE_GETPUTOOP(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1082 |
DECLARE_GETPUTOOP(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1083 |
DECLARE_GETPUTOOP(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1084 |
DECLARE_GETPUTOOP(Double, D), |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1085 |
|
36551 | 1086 |
{CC "allocateMemory0", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory0)}, |
1087 |
{CC "reallocateMemory0", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory0)}, |
|
1088 |
{CC "freeMemory0", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory0)}, |
|
1 | 1089 |
|
36551 | 1090 |
{CC "objectFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset0)}, |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
1091 |
{CC "objectFieldOffset1", CC "(" CLS LANG "String;)J", FN_PTR(Unsafe_ObjectFieldOffset1)}, |
36551 | 1092 |
{CC "staticFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset0)}, |
1093 |
{CC "staticFieldBase0", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBase0)}, |
|
1094 |
{CC "ensureClassInitialized0", CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized0)}, |
|
1095 |
{CC "arrayBaseOffset0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset0)}, |
|
1096 |
{CC "arrayIndexScale0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale0)}, |
|
1 | 1097 |
|
36551 | 1098 |
{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
|
1099 |
{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
|
1100 |
{CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1101 |
{CC "compareAndSetReference",CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSetReference)}, |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1102 |
{CC "compareAndSetInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSetInt)}, |
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1103 |
{CC "compareAndSetLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSetLong)}, |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
51444
diff
changeset
|
1104 |
{CC "compareAndExchangeReference", CC "(" OBJ "J" OBJ "" OBJ ")" OBJ, FN_PTR(Unsafe_CompareAndExchangeReference)}, |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1105 |
{CC "compareAndExchangeInt", CC "(" OBJ "J""I""I"")I", FN_PTR(Unsafe_CompareAndExchangeInt)}, |
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1106 |
{CC "compareAndExchangeLong", CC "(" OBJ "J""J""J"")J", FN_PTR(Unsafe_CompareAndExchangeLong)}, |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
1107 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1108 |
{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
|
1109 |
{CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)}, |
1 | 1110 |
|
36551 | 1111 |
{CC "getLoadAverage0", CC "([DI)I", FN_PTR(Unsafe_GetLoadAverage0)}, |
1 | 1112 |
|
36551 | 1113 |
{CC "copyMemory0", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory0)}, |
36086 | 1114 |
{CC "copySwapMemory0", CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory0)}, |
57804 | 1115 |
{CC "writeback0", CC "(" "J" ")V", FN_PTR(Unsafe_WriteBack0)}, |
1116 |
{CC "writebackPreSync0", CC "()V", FN_PTR(Unsafe_WriteBackPreSync0)}, |
|
1117 |
{CC "writebackPostSync0", CC "()V", FN_PTR(Unsafe_WriteBackPostSync0)}, |
|
36551 | 1118 |
{CC "setMemory0", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory0)}, |
1 | 1119 |
|
36551 | 1120 |
{CC "defineAnonymousClass0", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass0)}, |
1 | 1121 |
|
36551 | 1122 |
{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
|
1123 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1124 |
{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
|
1125 |
{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
|
1126 |
{CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)}, |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1127 |
}; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1128 |
|
1 | 1129 |
#undef CC |
1130 |
#undef FN_PTR |
|
1131 |
||
1132 |
#undef ADR |
|
1133 |
#undef LANG |
|
1134 |
#undef OBJ |
|
1135 |
#undef CLS |
|
1136 |
#undef FLD |
|
1137 |
#undef THR |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1138 |
#undef DC_Args |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1139 |
#undef DAC_Args |
1 | 1140 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1141 |
#undef DECLARE_GETPUTOOP |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1142 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1143 |
|
36551 | 1144 |
// This function is exported, used by NativeLookup. |
1 | 1145 |
// The Unsafe_xxx functions above are called only from the interpreter. |
1146 |
// The optimizer looks at names and signatures to recognize |
|
1147 |
// individual functions. |
|
1148 |
||
36551 | 1149 |
JVM_ENTRY(void, JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass)) { |
1150 |
ThreadToNativeFromVM ttnfv(thread); |
|
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1151 |
|
36551 | 1152 |
int ok = env->RegisterNatives(unsafeclass, jdk_internal_misc_Unsafe_methods, sizeof(jdk_internal_misc_Unsafe_methods)/sizeof(JNINativeMethod)); |
1153 |
guarantee(ok == 0, "register jdk.internal.misc.Unsafe natives"); |
|
1154 |
} JVM_END |