author | dcubed |
Wed, 22 Nov 2017 17:54:50 -0800 | |
changeset 48105 | 8d15b1369c7a |
parent 47998 | fb0275c320a0 |
child 48169 | 9289fcb41aae |
permissions | -rw-r--r-- |
1 | 1 |
/* |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, 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" |
7397 | 29 |
#include "classfile/vmSymbols.hpp" |
30 |
#include "memory/allocation.inline.hpp" |
|
37248 | 31 |
#include "memory/resourceArea.hpp" |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
32 |
#include "oops/access.inline.hpp" |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
33 |
#include "oops/fieldStreams.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
34 |
#include "oops/objArrayOop.inline.hpp" |
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28621
diff
changeset
|
35 |
#include "oops/oop.inline.hpp" |
36551 | 36 |
#include "prims/unsafe.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
40385
diff
changeset
|
37 |
#include "runtime/atomic.hpp" |
7397 | 38 |
#include "runtime/globals.hpp" |
39 |
#include "runtime/interfaceSupport.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24322
diff
changeset
|
40 |
#include "runtime/orderAccess.inline.hpp" |
7397 | 41 |
#include "runtime/reflection.hpp" |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
42 |
#include "runtime/thread.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
43 |
#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
|
44 |
#include "runtime/vm_version.hpp" |
7397 | 45 |
#include "services/threadService.hpp" |
18025 | 46 |
#include "trace/tracing.hpp" |
46625 | 47 |
#include "utilities/align.hpp" |
7397 | 48 |
#include "utilities/copy.hpp" |
49 |
#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
|
50 |
#include "utilities/macros.hpp" |
7397 | 51 |
|
36551 | 52 |
/** |
53 |
* Implementation of the jdk.internal.misc.Unsafe class |
|
1 | 54 |
*/ |
55 |
||
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
3262
diff
changeset
|
56 |
|
1 | 57 |
#define MAX_OBJECT_SIZE \ |
58 |
( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \ |
|
59 |
+ ((julong)max_jint * sizeof(double)) ) |
|
60 |
||
61 |
||
62 |
#define UNSAFE_ENTRY(result_type, header) \ |
|
36551 | 63 |
JVM_ENTRY(static result_type, header) |
1 | 64 |
|
36551 | 65 |
#define UNSAFE_LEAF(result_type, header) \ |
66 |
JVM_LEAF(static result_type, header) |
|
1 | 67 |
|
68 |
#define UNSAFE_END JVM_END |
|
69 |
||
70 |
||
36551 | 71 |
static inline void* addr_from_java(jlong addr) { |
1 | 72 |
// This assert fails in a variety of ways on 32-bit systems. |
73 |
// It is impossible to predict whether native code that converts |
|
74 |
// pointers to longs will sign-extend or zero-extend the addresses. |
|
75 |
//assert(addr == (uintptr_t)addr, "must not be odd high bits"); |
|
76 |
return (void*)(uintptr_t)addr; |
|
77 |
} |
|
78 |
||
36551 | 79 |
static inline jlong addr_to_java(void* p) { |
1 | 80 |
assert(p == (void*)(uintptr_t)p, "must not be odd high bits"); |
81 |
return (uintptr_t)p; |
|
82 |
} |
|
83 |
||
84 |
||
85 |
// Note: The VM's obj_field and related accessors use byte-scaled |
|
86 |
// ("unscaled") offsets, just as the unsafe methods do. |
|
87 |
||
88 |
// However, the method Unsafe.fieldOffset explicitly declines to |
|
89 |
// guarantee this. The field offset values manipulated by the Java user |
|
90 |
// through the Unsafe API are opaque cookies that just happen to be byte |
|
91 |
// offsets. We represent this state of affairs by passing the cookies |
|
92 |
// through conversion functions when going between the VM and the Unsafe API. |
|
93 |
// The conversion functions just happen to be no-ops at present. |
|
94 |
||
36551 | 95 |
static inline jlong field_offset_to_byte_offset(jlong field_offset) { |
1 | 96 |
return field_offset; |
97 |
} |
|
98 |
||
36551 | 99 |
static inline jlong field_offset_from_byte_offset(jlong byte_offset) { |
1 | 100 |
return byte_offset; |
101 |
} |
|
102 |
||
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
103 |
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
|
104 |
#ifdef ASSERT |
36551 | 105 |
jlong byte_offset = field_offset_to_byte_offset(field_offset); |
1 | 106 |
|
107 |
if (p != NULL) { |
|
108 |
assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset"); |
|
109 |
if (byte_offset == (jint)byte_offset) { |
|
110 |
void* ptr_plus_disp = (address)p + byte_offset; |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
111 |
assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp, |
1 | 112 |
"raw [ptr+disp] must be consistent with oop::field_base"); |
113 |
} |
|
14127
16ba0a8dfde2
8001071: Add simple range check into VM implemenation of Unsafe access methods
kvn
parents:
13952
diff
changeset
|
114 |
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
|
115 |
assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, (int64_t)byte_offset, (int64_t)p_size); |
1 | 116 |
} |
117 |
#endif |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
118 |
} |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
119 |
|
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
120 |
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
|
121 |
assert_field_offset_sane(p, field_offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
122 |
jlong byte_offset = field_offset_to_byte_offset(field_offset); |
36551 | 123 |
|
124 |
if (sizeof(char*) == sizeof(jint)) { // (this constant folds!) |
|
1 | 125 |
return (address)p + (jint) byte_offset; |
36551 | 126 |
} else { |
1 | 127 |
return (address)p + byte_offset; |
36551 | 128 |
} |
1 | 129 |
} |
130 |
||
131 |
// Externally callable versions: |
|
132 |
// (Use these in compiler intrinsics which emulate unsafe primitives.) |
|
133 |
jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) { |
|
134 |
return field_offset; |
|
135 |
} |
|
136 |
jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) { |
|
137 |
return byte_offset; |
|
138 |
} |
|
139 |
||
140 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
141 |
///// 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
|
142 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
143 |
/** |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
144 |
* Helper class for accessing memory. |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
145 |
* |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
146 |
* Normalizes values and wraps accesses in |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
147 |
* JavaThread::doing_unsafe_access() if needed. |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
148 |
*/ |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
149 |
class MemoryAccess : StackObj { |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
150 |
JavaThread* _thread; |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
151 |
oop _obj; |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
152 |
ptrdiff_t _offset; |
1 | 153 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
154 |
// Resolves and returns the address of the memory access |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
155 |
void* addr() { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
156 |
return index_oop_from_field_offset_long(_obj, _offset); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
157 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
158 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
159 |
template <typename T> |
41052 | 160 |
T normalize_for_write(T x) { |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
161 |
return x; |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
162 |
} |
37480 | 163 |
|
41052 | 164 |
jboolean normalize_for_write(jboolean x) { |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
165 |
return x & 1; |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
166 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
167 |
|
41052 | 168 |
template <typename T> |
169 |
T normalize_for_read(T x) { |
|
170 |
return x; |
|
171 |
} |
|
172 |
||
173 |
jboolean normalize_for_read(jboolean x) { |
|
174 |
return x != 0; |
|
175 |
} |
|
176 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
177 |
/** |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
178 |
* Helper class to wrap memory accesses in JavaThread::doing_unsafe_access() |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
179 |
*/ |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
180 |
class GuardUnsafeAccess { |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
181 |
JavaThread* _thread; |
1 | 182 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
183 |
public: |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
184 |
GuardUnsafeAccess(JavaThread* thread) : _thread(thread) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
185 |
// native/off-heap access which may raise SIGBUS if accessing |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
186 |
// memory mapped file data in a region of the file which has |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
187 |
// been truncated and is now invalid |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
188 |
_thread->set_doing_unsafe_access(true); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
189 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
190 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
191 |
~GuardUnsafeAccess() { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
192 |
_thread->set_doing_unsafe_access(false); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
193 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
194 |
}; |
1 | 195 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
196 |
public: |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
197 |
MemoryAccess(JavaThread* thread, jobject obj, jlong offset) |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
198 |
: _thread(thread), _obj(JNIHandles::resolve(obj)), _offset((ptrdiff_t)offset) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
199 |
assert_field_offset_sane(_obj, offset); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
200 |
} |
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 |
template <typename T> |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
203 |
T get() { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
204 |
if (oopDesc::is_null(_obj)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
205 |
GuardUnsafeAccess guard(_thread); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
206 |
T ret = RawAccess<>::load((T*)addr()); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
207 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
208 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
209 |
T ret = HeapAccess<>::load_at(_obj, _offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
210 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
211 |
} |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
212 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
213 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
214 |
template <typename T> |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
215 |
void put(T x) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
216 |
if (oopDesc::is_null(_obj)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
217 |
GuardUnsafeAccess guard(_thread); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
218 |
RawAccess<>::store((T*)addr(), normalize_for_write(x)); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
219 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
220 |
HeapAccess<>::store_at(_obj, _offset, normalize_for_write(x)); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
221 |
} |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
222 |
} |
1 | 223 |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
224 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
225 |
template <typename T> |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
226 |
T get_volatile() { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
227 |
if (oopDesc::is_null(_obj)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
228 |
GuardUnsafeAccess guard(_thread); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
229 |
volatile T ret = RawAccess<MO_SEQ_CST>::load((volatile T*)addr()); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
230 |
return normalize_for_read(ret); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
231 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
232 |
T ret = HeapAccess<MO_SEQ_CST>::load_at(_obj, _offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
233 |
return normalize_for_read(ret); |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
234 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
235 |
} |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
236 |
|
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
237 |
template <typename T> |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
238 |
void put_volatile(T x) { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
239 |
if (oopDesc::is_null(_obj)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
240 |
GuardUnsafeAccess guard(_thread); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
241 |
RawAccess<MO_SEQ_CST>::store((volatile T*)addr(), normalize_for_write(x)); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
242 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
243 |
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
|
244 |
} |
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
245 |
} |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
246 |
}; |
41181
2ce2f1c582ca
8165489: Missing G1 barrier in Unsafe_GetObjectVolatile
mdoerr
parents:
41066
diff
changeset
|
247 |
|
25057 | 248 |
// These functions allow a null base pointer with an arbitrary address. |
1 | 249 |
// But if the base pointer is non-null, the offset should make some sense. |
250 |
// That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
|
36551 | 251 |
UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
30288
476c276de939
8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents:
30209
diff
changeset
|
252 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
253 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
254 |
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
|
255 |
return JNIHandles::make_local(env, v); |
36551 | 256 |
} UNSAFE_END |
257 |
||
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
258 |
UNSAFE_ENTRY(void, Unsafe_PutObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
1 | 259 |
oop x = JNIHandles::resolve(x_h); |
260 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
261 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
262 |
HeapAccess<ON_UNKNOWN_OOP_REF>::oop_store_at(p, offset, x); |
36551 | 263 |
} UNSAFE_END |
1 | 264 |
|
36551 | 265 |
UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { |
13293
c2b4f191c489
7087357: JSR 292: remove obsolete code after 7085860
twisti
parents:
10967
diff
changeset
|
266 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
267 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
268 |
oop v = HeapAccess<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>::oop_load_at(p, offset); |
1 | 269 |
return JNIHandles::make_local(env, v); |
36551 | 270 |
} UNSAFE_END |
1 | 271 |
|
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
272 |
UNSAFE_ENTRY(void, Unsafe_PutObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) { |
1 | 273 |
oop x = JNIHandles::resolve(x_h); |
274 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
275 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
276 |
HeapAccess<MO_SEQ_CST | ON_UNKNOWN_OOP_REF>::oop_store_at(p, offset, x); |
36551 | 277 |
} UNSAFE_END |
278 |
||
279 |
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
|
280 |
oop v = *(oop*) (address) addr; |
36551 | 281 |
return JNIHandles::make_local(env, v); |
282 |
} UNSAFE_END |
|
283 |
||
284 |
UNSAFE_LEAF(jboolean, Unsafe_isBigEndian0(JNIEnv *env, jobject unsafe)) { |
|
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
285 |
#ifdef VM_LITTLE_ENDIAN |
36551 | 286 |
return false; |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
287 |
#else |
36551 | 288 |
return true; |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
289 |
#endif |
36551 | 290 |
} UNSAFE_END |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
291 |
|
36551 | 292 |
UNSAFE_LEAF(jint, Unsafe_unalignedAccess0(JNIEnv *env, jobject unsafe)) { |
293 |
return UseUnalignedAccesses; |
|
294 |
} UNSAFE_END |
|
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
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)) { \ |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
299 |
return MemoryAccess(thread, obj, offset).get<java_type>(); \ |
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)) { \ |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
303 |
MemoryAccess(thread, obj, offset).put<java_type>(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)) { \ |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
322 |
return MemoryAccess(thread, obj, offset).get_volatile<java_type>(); \ |
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)) { \ |
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
326 |
MemoryAccess(thread, obj, offset).put_volatile<java_type>(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); |
13195 | 365 |
void* x = os::malloc(sz, mtInternal); |
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 |
|
375 |
void* x = os::realloc(p, sz, mtInternal); |
|
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); |
|
36551 | 403 |
|
1 | 404 |
Copy::conjoint_memory_atomic(src, dst, sz); |
36551 | 405 |
} UNSAFE_END |
1 | 406 |
|
36086 | 407 |
// This function is a leaf since if the source and destination are both in native memory |
408 |
// the copy may potentially be very large, and we don't want to disable GC if we can avoid it. |
|
409 |
// If either source or destination (or both) are on the heap, the function will enter VM using |
|
410 |
// JVM_ENTRY_FROM_LEAF |
|
36551 | 411 |
UNSAFE_LEAF(void, Unsafe_CopySwapMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) { |
36086 | 412 |
size_t sz = (size_t)size; |
413 |
size_t esz = (size_t)elemSize; |
|
414 |
||
415 |
if (srcObj == NULL && dstObj == NULL) { |
|
416 |
// Both src & dst are in native memory |
|
417 |
address src = (address)srcOffset; |
|
418 |
address dst = (address)dstOffset; |
|
419 |
||
420 |
Copy::conjoint_swap(src, dst, sz, esz); |
|
421 |
} else { |
|
422 |
// At least one of src/dst are on heap, transition to VM to access raw pointers |
|
423 |
||
424 |
JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory0) { |
|
425 |
oop srcp = JNIHandles::resolve(srcObj); |
|
426 |
oop dstp = JNIHandles::resolve(dstObj); |
|
427 |
||
428 |
address src = (address)index_oop_from_field_offset_long(srcp, srcOffset); |
|
429 |
address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset); |
|
430 |
||
431 |
Copy::conjoint_swap(src, dst, sz, esz); |
|
432 |
} JVM_END |
|
433 |
} |
|
36551 | 434 |
} UNSAFE_END |
1 | 435 |
|
436 |
////// Random queries |
|
437 |
||
36551 | 438 |
UNSAFE_LEAF(jint, Unsafe_AddressSize0(JNIEnv *env, jobject unsafe)) { |
1 | 439 |
return sizeof(void*); |
36551 | 440 |
} UNSAFE_END |
1 | 441 |
|
36551 | 442 |
UNSAFE_LEAF(jint, Unsafe_PageSize()) { |
1 | 443 |
return os::vm_page_size(); |
36551 | 444 |
} UNSAFE_END |
1 | 445 |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
446 |
static jlong find_field_offset(jclass clazz, jstring name, TRAPS) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
447 |
assert(clazz != NULL, "clazz must not be NULL"); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
448 |
assert(name != NULL, "name must not be NULL"); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
449 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
450 |
ResourceMark rm(THREAD); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
451 |
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
|
452 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
453 |
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
|
454 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
455 |
jint offset = -1; |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
456 |
for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
457 |
Symbol *name = fs.name(); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
458 |
if (name->equals(utf_name)) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
459 |
offset = fs.offset(); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
460 |
break; |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
461 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
462 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
463 |
if (offset < 0) { |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
464 |
THROW_0(vmSymbols::java_lang_InternalError()); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
465 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
466 |
return field_offset_from_byte_offset(offset); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
467 |
} |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
468 |
|
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
469 |
static jlong find_field_offset(jobject field, int must_be_static, TRAPS) { |
36551 | 470 |
assert(field != NULL, "field must not be NULL"); |
1 | 471 |
|
472 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
473 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
36551 | 474 |
Klass* k = java_lang_Class::as_Klass(mirror); |
1 | 475 |
int slot = java_lang_reflect_Field::slot(reflected); |
476 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
477 |
||
478 |
if (must_be_static >= 0) { |
|
479 |
int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0); |
|
480 |
if (must_be_static != really_is_static) { |
|
481 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
482 |
} |
|
483 |
} |
|
484 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
485 |
int offset = InstanceKlass::cast(k)->field_offset(slot); |
1 | 486 |
return field_offset_from_byte_offset(offset); |
487 |
} |
|
488 |
||
36551 | 489 |
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 490 |
return find_field_offset(field, 0, THREAD); |
36551 | 491 |
} UNSAFE_END |
1 | 492 |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
493 |
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
|
494 |
return find_field_offset(c, name, THREAD); |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
495 |
} UNSAFE_END |
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
496 |
|
36551 | 497 |
UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) { |
1 | 498 |
return find_field_offset(field, 1, THREAD); |
36551 | 499 |
} UNSAFE_END |
1 | 500 |
|
36551 | 501 |
UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBase0(JNIEnv *env, jobject unsafe, jobject field)) { |
502 |
assert(field != NULL, "field must not be NULL"); |
|
503 |
||
1 | 504 |
// Note: In this VM implementation, a field address is always a short |
505 |
// offset from the base of a a klass metaobject. Thus, the full dynamic |
|
506 |
// range of the return type is never used. However, some implementations |
|
507 |
// might put the static field inside an array shared by many classes, |
|
508 |
// or even at a fixed address, in which case the address could be quite |
|
509 |
// large. In that last case, this function would return NULL, since |
|
510 |
// the address would operate alone, without any base pointer. |
|
511 |
||
512 |
oop reflected = JNIHandles::resolve_non_null(field); |
|
513 |
oop mirror = java_lang_reflect_Field::clazz(reflected); |
|
514 |
int modifiers = java_lang_reflect_Field::modifiers(reflected); |
|
515 |
||
516 |
if ((modifiers & JVM_ACC_STATIC) == 0) { |
|
517 |
THROW_0(vmSymbols::java_lang_IllegalArgumentException()); |
|
518 |
} |
|
519 |
||
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8490
diff
changeset
|
520 |
return JNIHandles::make_local(env, mirror); |
36551 | 521 |
} UNSAFE_END |
1 | 522 |
|
36551 | 523 |
UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
524 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
525 |
||
1 | 526 |
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
|
527 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
528 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
14488 | 529 |
if (klass != NULL && klass->should_be_initialized()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
530 |
InstanceKlass* k = InstanceKlass::cast(klass); |
1 | 531 |
k->initialize(CHECK); |
532 |
} |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
533 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
534 |
UNSAFE_END |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
535 |
|
36551 | 536 |
UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) { |
537 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
538 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
539 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
540 |
Klass* klass = java_lang_Class::as_Klass(mirror); |
36551 | 541 |
|
14488 | 542 |
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
|
543 |
return true; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
544 |
} |
36551 | 545 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
546 |
return false; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13295
diff
changeset
|
547 |
} |
1 | 548 |
UNSAFE_END |
549 |
||
36551 | 550 |
static void getBaseAndScale(int& base, int& scale, jclass clazz, TRAPS) { |
551 |
assert(clazz != NULL, "clazz must not be NULL"); |
|
552 |
||
553 |
oop mirror = JNIHandles::resolve_non_null(clazz); |
|
554 |
Klass* k = java_lang_Class::as_Klass(mirror); |
|
555 |
||
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
556 |
if (k == NULL || !k->is_array_klass()) { |
1 | 557 |
THROW(vmSymbols::java_lang_InvalidClassException()); |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
558 |
} else if (k->is_objArray_klass()) { |
1 | 559 |
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
|
560 |
scale = heapOopSize; |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33589
diff
changeset
|
561 |
} else if (k->is_typeArray_klass()) { |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13728
diff
changeset
|
562 |
TypeArrayKlass* tak = TypeArrayKlass::cast(k); |
1 | 563 |
base = tak->array_header_in_bytes(); |
564 |
assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok"); |
|
565 |
scale = (1 << tak->log2_element_size()); |
|
566 |
} else { |
|
567 |
ShouldNotReachHere(); |
|
568 |
} |
|
569 |
} |
|
570 |
||
36551 | 571 |
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
|
572 |
int base = 0, scale = 0; |
36551 | 573 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
574 |
||
1 | 575 |
return field_offset_from_byte_offset(base); |
36551 | 576 |
} UNSAFE_END |
1 | 577 |
|
578 |
||
36551 | 579 |
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
|
580 |
int base = 0, scale = 0; |
36551 | 581 |
getBaseAndScale(base, scale, clazz, CHECK_0); |
582 |
||
1 | 583 |
// This VM packs both fields and array elements down to the byte. |
584 |
// But watch out: If this changes, so that array references for |
|
585 |
// a given primitive type (say, T_BOOLEAN) use different memory units |
|
586 |
// than fields, this method MUST return zero for such arrays. |
|
587 |
// For example, the VM used to store sub-word sized fields in full |
|
588 |
// words in the object layout, so that accessors like getByte(Object,int) |
|
589 |
// did not really do what one might expect for arrays. Therefore, |
|
590 |
// this function used to report a zero scale factor, so that the user |
|
591 |
// would know not to attempt to access sub-word array elements. |
|
592 |
// // Code for unpacked fields: |
|
593 |
// if (scale < wordSize) return 0; |
|
594 |
||
595 |
// The following allows for a pretty general fieldOffset cookie scheme, |
|
596 |
// but requires it to be linear in byte offset. |
|
597 |
return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); |
|
36551 | 598 |
} UNSAFE_END |
1 | 599 |
|
600 |
||
601 |
static inline void throw_new(JNIEnv *env, const char *ename) { |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
602 |
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
|
603 |
if (env->ExceptionCheck()) { |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
604 |
env->ExceptionClear(); |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
605 |
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
|
606 |
return; |
86644d9539c2
8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents:
20282
diff
changeset
|
607 |
} |
36551 | 608 |
|
609 |
env->ThrowNew(cls, NULL); |
|
1 | 610 |
} |
611 |
||
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
612 |
static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { |
36551 | 613 |
// Code lifted from JDK 1.3 ClassLoader.c |
614 |
||
615 |
jbyte *body; |
|
616 |
char *utfName = NULL; |
|
617 |
jclass result = 0; |
|
618 |
char buf[128]; |
|
1 | 619 |
|
36551 | 620 |
assert(data != NULL, "Class bytes must not be NULL"); |
621 |
assert(length >= 0, "length must not be negative: %d", length); |
|
1 | 622 |
|
36551 | 623 |
if (UsePerfData) { |
624 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
|
625 |
} |
|
1 | 626 |
|
36551 | 627 |
body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal); |
628 |
if (body == NULL) { |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
629 |
throw_new(env, "java/lang/OutOfMemoryError"); |
36551 | 630 |
return 0; |
631 |
} |
|
632 |
||
633 |
env->GetByteArrayRegion(data, offset, length, body); |
|
634 |
if (env->ExceptionOccurred()) { |
|
635 |
goto free_body; |
|
636 |
} |
|
1 | 637 |
|
36551 | 638 |
if (name != NULL) { |
639 |
uint len = env->GetStringUTFLength(name); |
|
640 |
int unicode_len = env->GetStringLength(name); |
|
1 | 641 |
|
36551 | 642 |
if (len >= sizeof(buf)) { |
643 |
utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
|
644 |
if (utfName == NULL) { |
|
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
645 |
throw_new(env, "java/lang/OutOfMemoryError"); |
36551 | 646 |
goto free_body; |
647 |
} |
|
648 |
} else { |
|
649 |
utfName = buf; |
|
1 | 650 |
} |
651 |
||
36551 | 652 |
env->GetStringUTFRegion(name, 0, unicode_len, utfName); |
1 | 653 |
|
36551 | 654 |
for (uint i = 0; i < len; i++) { |
655 |
if (utfName[i] == '.') utfName[i] = '/'; |
|
1 | 656 |
} |
36551 | 657 |
} |
1 | 658 |
|
36551 | 659 |
result = JVM_DefineClass(env, utfName, loader, body, length, pd); |
1 | 660 |
|
36551 | 661 |
if (utfName && utfName != buf) { |
662 |
FREE_C_HEAP_ARRAY(char, utfName); |
|
663 |
} |
|
1 | 664 |
|
665 |
free_body: |
|
36551 | 666 |
FREE_C_HEAP_ARRAY(jbyte, body); |
667 |
return result; |
|
1 | 668 |
} |
669 |
||
670 |
||
36551 | 671 |
UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) { |
672 |
ThreadToNativeFromVM ttnfv(thread); |
|
673 |
||
674 |
return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd); |
|
675 |
} UNSAFE_END |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
676 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
677 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
678 |
// 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
|
679 |
// - 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
|
680 |
// 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
|
681 |
// - 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
|
682 |
// - 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
|
683 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
684 |
// 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
|
685 |
// 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
|
686 |
// 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
|
687 |
// 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
|
688 |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
689 |
// 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
|
690 |
// 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
|
691 |
// package. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
692 |
// |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
693 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
694 |
// 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
|
695 |
// 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
|
696 |
// 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
|
697 |
// 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
|
698 |
// 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
|
699 |
// 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
|
700 |
// restrictions. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
701 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
702 |
// 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
|
703 |
// 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
|
704 |
// 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
|
705 |
// access one of its anonymous classes. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
706 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
707 |
// 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
|
708 |
// 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
|
709 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
710 |
// 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
|
711 |
// 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
|
712 |
// 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
|
713 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
714 |
// 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
|
715 |
// 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
|
716 |
// 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
|
717 |
// 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
|
718 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
719 |
// 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
|
720 |
// 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
|
721 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
722 |
// 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
|
723 |
// 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
|
724 |
// 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
|
725 |
// 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
|
726 |
// 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
|
727 |
// 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
|
728 |
// 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
|
729 |
// 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
|
730 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
731 |
static InstanceKlass* |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
732 |
Unsafe_DefineAnonymousClass_impl(JNIEnv *env, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
733 |
jclass host_class, jbyteArray data, jobjectArray cp_patches_jh, |
36551 | 734 |
u1** temp_alloc, |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
735 |
TRAPS) { |
36551 | 736 |
assert(host_class != NULL, "host_class must not be NULL"); |
737 |
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
|
738 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
739 |
if (UsePerfData) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
740 |
ClassLoader::unsafe_defineClassCallCounter()->inc(); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
741 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
742 |
|
36551 | 743 |
jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length(); |
744 |
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
|
745 |
|
36551 | 746 |
int class_bytes_length = (int) length; |
747 |
||
748 |
u1* class_bytes = NEW_C_HEAP_ARRAY(u1, length, mtInternal); |
|
749 |
if (class_bytes == NULL) { |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
750 |
THROW_0(vmSymbols::java_lang_OutOfMemoryError()); |
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 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
753 |
// caller responsible to free it: |
36551 | 754 |
*temp_alloc = class_bytes; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
755 |
|
36551 | 756 |
jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0); |
757 |
Copy::conjoint_jbytes(array_base, class_bytes, length); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
758 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
759 |
objArrayHandle cp_patches_h; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
760 |
if (cp_patches_jh != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
761 |
oop p = JNIHandles::resolve_non_null(cp_patches_jh); |
36551 | 762 |
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
|
763 |
cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
764 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
765 |
|
34666 | 766 |
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
|
767 |
|
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
768 |
// 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
|
769 |
while (host_klass != NULL && host_klass->is_instance_klass() && |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
770 |
InstanceKlass::cast(host_klass)->is_anonymous()) { |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
771 |
host_klass = InstanceKlass::cast(host_klass)->host_klass(); |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
772 |
} |
a7011a835634
8030221: Checking for anonymous class should check for NULL as well as potential nesting
hseigel
parents:
39260
diff
changeset
|
773 |
|
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
|
774 |
// 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
|
775 |
if (host_klass == NULL) { |
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
776 |
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
|
777 |
} |
34666 | 778 |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
779 |
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
|
780 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
781 |
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
|
782 |
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
|
783 |
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
|
784 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
785 |
GrowableArray<Handle>* cp_patches = NULL; |
36551 | 786 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
787 |
if (cp_patches_h.not_null()) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
788 |
int alen = cp_patches_h->length(); |
36551 | 789 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
790 |
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
|
791 |
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
|
792 |
if (p != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
793 |
Handle patch(THREAD, p); |
36551 | 794 |
|
795 |
if (cp_patches == NULL) { |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
796 |
cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle()); |
36551 | 797 |
} |
798 |
||
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
799 |
cp_patches->at_put(i, patch); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
800 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
801 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
802 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
803 |
|
36551 | 804 |
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
|
805 |
|
36551 | 806 |
Symbol* no_class_name = NULL; |
807 |
Klass* anonk = SystemDictionary::parse_stream(no_class_name, |
|
808 |
host_loader, |
|
809 |
host_domain, |
|
810 |
&st, |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40918
diff
changeset
|
811 |
InstanceKlass::cast(host_klass), |
36551 | 812 |
cp_patches, |
813 |
CHECK_NULL); |
|
814 |
if (anonk == NULL) { |
|
815 |
return NULL; |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
816 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
817 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
818 |
return InstanceKlass::cast(anonk); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
819 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
820 |
|
36551 | 821 |
UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) { |
822 |
ResourceMark rm(THREAD); |
|
823 |
||
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
824 |
jobject res_jh = NULL; |
36551 | 825 |
u1* temp_alloc = NULL; |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
826 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
827 |
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
|
828 |
if (anon_klass != NULL) { |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
829 |
res_jh = JNIHandles::make_local(env, anon_klass->java_mirror()); |
36551 | 830 |
} |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
831 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
832 |
// try/finally clause: |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
833 |
if (temp_alloc != NULL) { |
36551 | 834 |
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
|
835 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
836 |
|
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
837 |
// 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
|
838 |
// 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
|
839 |
// it alive afterwards. |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
41181
diff
changeset
|
840 |
if (anon_klass != NULL) { |
38014
8731fa11f766
8152949: Jigsaw crash when Klass in _fixup_module_field_list is unloaded
lfoltan
parents:
37267
diff
changeset
|
841 |
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
|
842 |
} |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
843 |
|
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
844 |
// let caller initialize it as needed... |
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
845 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
846 |
return (jclass) res_jh; |
36551 | 847 |
} UNSAFE_END |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
848 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
1388
diff
changeset
|
849 |
|
1 | 850 |
|
36551 | 851 |
UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) { |
852 |
ThreadToNativeFromVM ttnfv(thread); |
|
853 |
env->Throw(thr); |
|
854 |
} UNSAFE_END |
|
1 | 855 |
|
856 |
// JSR166 ------------------------------------------------------------------ |
|
857 |
||
36551 | 858 |
UNSAFE_ENTRY(jobject, Unsafe_CompareAndExchangeObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) { |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
859 |
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
|
860 |
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
|
861 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
862 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
863 |
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
|
864 |
return JNIHandles::make_local(env, res); |
36551 | 865 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
866 |
|
36551 | 867 |
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
|
868 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
869 |
if (oopDesc::is_null(p)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
870 |
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
|
871 |
return RawAccess<>::atomic_cmpxchg(x, addr, e); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
872 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
873 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
874 |
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
|
875 |
} |
36551 | 876 |
} UNSAFE_END |
877 |
||
878 |
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
|
879 |
oop p = JNIHandles::resolve(obj); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
880 |
if (oopDesc::is_null(p)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
881 |
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
|
882 |
return RawAccess<>::atomic_cmpxchg(x, addr, e); |
36551 | 883 |
} else { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
884 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
885 |
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
|
886 |
} |
36551 | 887 |
} UNSAFE_END |
36316
7a83de7aabca
8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents:
36086
diff
changeset
|
888 |
|
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
889 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) { |
1 | 890 |
oop x = JNIHandles::resolve(x_h); |
891 |
oop e = JNIHandles::resolve(e_h); |
|
892 |
oop p = JNIHandles::resolve(obj); |
|
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
893 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
894 |
oop ret = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
895 |
return ret == e; |
36551 | 896 |
} UNSAFE_END |
897 |
||
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
898 |
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSetInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) { |
1 | 899 |
oop p = JNIHandles::resolve(obj); |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
900 |
if (oopDesc::is_null(p)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
901 |
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
|
902 |
return RawAccess<>::atomic_cmpxchg(x, addr, e) == e; |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
903 |
} else { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
904 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
905 |
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
|
906 |
} |
36551 | 907 |
} UNSAFE_END |
1 | 908 |
|
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
909 |
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
|
910 |
oop p = JNIHandles::resolve(obj); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
911 |
if (oopDesc::is_null(p)) { |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
912 |
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
|
913 |
return RawAccess<>::atomic_cmpxchg(x, addr, e) == e; |
36551 | 914 |
} else { |
47998
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
915 |
assert_field_offset_sane(p, offset); |
fb0275c320a0
8189871: Refactor GC barriers to use declarative semantics
eosterlund
parents:
47765
diff
changeset
|
916 |
return HeapAccess<>::atomic_cmpxchg_at(x, p, (ptrdiff_t)offset, e) == e; |
1 | 917 |
} |
36551 | 918 |
} UNSAFE_END |
1 | 919 |
|
36551 | 920 |
UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) { |
18025 | 921 |
EventThreadPark event; |
22796 | 922 |
HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time); |
923 |
||
1 | 924 |
JavaThreadParkedState jtps(thread, time != 0); |
925 |
thread->parker()->park(isAbsolute != 0, time); |
|
22796 | 926 |
|
927 |
HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker()); |
|
36551 | 928 |
|
18025 | 929 |
if (event.should_commit()) { |
930 |
oop obj = thread->current_park_blocker(); |
|
40664
1ec65b303bb7
8164523: Clean up metadata for event based tracing
egahlin
parents:
40655
diff
changeset
|
931 |
event.set_parkedClass((obj != NULL) ? obj->klass() : NULL); |
18025 | 932 |
event.set_timeout(time); |
20282
7f9cbdf89af2
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
18025
diff
changeset
|
933 |
event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0); |
18025 | 934 |
event.commit(); |
935 |
} |
|
36551 | 936 |
} UNSAFE_END |
1 | 937 |
|
36551 | 938 |
UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) { |
1 | 939 |
Parker* p = NULL; |
36551 | 940 |
|
1 | 941 |
if (jthread != NULL) { |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
942 |
ThreadsListHandle tlh; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
943 |
JavaThread* thr = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
944 |
oop java_thread = NULL; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
945 |
(void) tlh.cv_internal_thread_to_JavaThread(jthread, &thr, &java_thread); |
1 | 946 |
if (java_thread != NULL) { |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
947 |
// This is a valid oop. |
1 | 948 |
jlong lp = java_lang_Thread::park_event(java_thread); |
949 |
if (lp != 0) { |
|
950 |
// This cast is OK even though the jlong might have been read |
|
951 |
// non-atomically on 32bit systems, since there, one word will |
|
952 |
// always be zero anyway and the value set is always the same |
|
953 |
p = (Parker*)addr_from_java(lp); |
|
954 |
} else { |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
955 |
// Not cached in the java.lang.Thread oop yet (could be an |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
956 |
// older version of library). |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
957 |
if (thr != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
958 |
// The JavaThread is alive. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
959 |
p = thr->parker(); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
960 |
if (p != NULL) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
961 |
// Cache the Parker in the java.lang.Thread oop for next time. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
962 |
java_lang_Thread::set_park_event(java_thread, addr_to_java(p)); |
1 | 963 |
} |
964 |
} |
|
965 |
} |
|
966 |
} |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
47998
diff
changeset
|
967 |
} // ThreadsListHandle is destroyed here. |
36551 | 968 |
|
1 | 969 |
if (p != NULL) { |
22796 | 970 |
HOTSPOT_THREAD_UNPARK((uintptr_t) p); |
1 | 971 |
p->unpark(); |
972 |
} |
|
36551 | 973 |
} UNSAFE_END |
1 | 974 |
|
36551 | 975 |
UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) { |
1 | 976 |
const int max_nelem = 3; |
977 |
double la[max_nelem]; |
|
978 |
jint ret; |
|
979 |
||
980 |
typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg)); |
|
981 |
assert(a->is_typeArray(), "must be type array"); |
|
982 |
||
36551 | 983 |
ret = os::loadavg(la, nelem); |
984 |
if (ret == -1) { |
|
1 | 985 |
return -1; |
986 |
} |
|
987 |
||
988 |
// if successful, ret is the number of samples actually retrieved. |
|
989 |
assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value"); |
|
990 |
switch(ret) { |
|
991 |
case 3: a->double_at_put(2, (jdouble)la[2]); // fall through |
|
992 |
case 2: a->double_at_put(1, (jdouble)la[1]); // fall through |
|
993 |
case 1: a->double_at_put(0, (jdouble)la[0]); break; |
|
994 |
} |
|
36551 | 995 |
|
1 | 996 |
return ret; |
36551 | 997 |
} UNSAFE_END |
1 | 998 |
|
999 |
||
1000 |
/// JVM_RegisterUnsafeMethods |
|
1001 |
||
1002 |
#define ADR "J" |
|
1003 |
||
1004 |
#define LANG "Ljava/lang/" |
|
1005 |
||
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1006 |
#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
|
1007 |
#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
|
1008 |
#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
|
1009 |
#define THR LANG "Throwable;" |
1 | 1010 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1011 |
#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
|
1012 |
#define DAC_Args CLS "[B[" OBJ |
1 | 1013 |
|
1014 |
#define CC (char*) /*cast a literal from (const char*)*/ |
|
1015 |
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) |
|
1016 |
||
36551 | 1017 |
#define DECLARE_GETPUTOOP(Type, Desc) \ |
1018 |
{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
|
1019 |
{CC "put" #Type, CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Put##Type)}, \ |
36551 | 1020 |
{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
|
1021 |
{CC "put" #Type "Volatile", CC "(" OBJ "J" #Desc ")V", FN_PTR(Unsafe_Put##Type##Volatile)} |
1 | 1022 |
|
1023 |
||
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1024 |
static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = { |
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1025 |
{CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)}, |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
1026 |
{CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_PutObject)}, |
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1027 |
{CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)}, |
38211
fe30fdab0f62
8150921: Update Unsafe getters/setters to use double-register variants
mikael
parents:
38060
diff
changeset
|
1028 |
{CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_PutObjectVolatile)}, |
1 | 1029 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1030 |
{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
|
1031 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1032 |
DECLARE_GETPUTOOP(Boolean, Z), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1033 |
DECLARE_GETPUTOOP(Byte, B), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1034 |
DECLARE_GETPUTOOP(Short, S), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1035 |
DECLARE_GETPUTOOP(Char, C), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1036 |
DECLARE_GETPUTOOP(Int, I), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1037 |
DECLARE_GETPUTOOP(Long, J), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1038 |
DECLARE_GETPUTOOP(Float, F), |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1039 |
DECLARE_GETPUTOOP(Double, D), |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1040 |
|
36551 | 1041 |
{CC "allocateMemory0", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory0)}, |
1042 |
{CC "reallocateMemory0", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory0)}, |
|
1043 |
{CC "freeMemory0", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory0)}, |
|
1 | 1044 |
|
36551 | 1045 |
{CC "objectFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset0)}, |
46568
4a430bd81cc6
8182487: Add Unsafe.objectFieldOffset(Class, String)
redestad
parents:
46458
diff
changeset
|
1046 |
{CC "objectFieldOffset1", CC "(" CLS LANG "String;)J", FN_PTR(Unsafe_ObjectFieldOffset1)}, |
36551 | 1047 |
{CC "staticFieldOffset0", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset0)}, |
1048 |
{CC "staticFieldBase0", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBase0)}, |
|
1049 |
{CC "ensureClassInitialized0", CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized0)}, |
|
1050 |
{CC "arrayBaseOffset0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset0)}, |
|
1051 |
{CC "arrayIndexScale0", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale0)}, |
|
1052 |
{CC "addressSize0", CC "()I", FN_PTR(Unsafe_AddressSize0)}, |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1053 |
{CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)}, |
1 | 1054 |
|
36551 | 1055 |
{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
|
1056 |
{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
|
1057 |
{CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)}, |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1058 |
{CC "compareAndSetObject",CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSetObject)}, |
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1059 |
{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
|
1060 |
{CC "compareAndSetLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSetLong)}, |
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1061 |
{CC "compareAndExchangeObject", CC "(" OBJ "J" OBJ "" OBJ ")" OBJ, FN_PTR(Unsafe_CompareAndExchangeObject)}, |
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
41181
diff
changeset
|
1062 |
{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
|
1063 |
{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
|
1064 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1065 |
{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
|
1066 |
{CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)}, |
1 | 1067 |
|
36551 | 1068 |
{CC "getLoadAverage0", CC "([DI)I", FN_PTR(Unsafe_GetLoadAverage0)}, |
1 | 1069 |
|
36551 | 1070 |
{CC "copyMemory0", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory0)}, |
36086 | 1071 |
{CC "copySwapMemory0", CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory0)}, |
36551 | 1072 |
{CC "setMemory0", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory0)}, |
1 | 1073 |
|
36551 | 1074 |
{CC "defineAnonymousClass0", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass0)}, |
1 | 1075 |
|
36551 | 1076 |
{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
|
1077 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1078 |
{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
|
1079 |
{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
|
1080 |
{CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)}, |
30209
8ea30dc99369
8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents:
29083
diff
changeset
|
1081 |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1082 |
{CC "isBigEndian0", CC "()Z", FN_PTR(Unsafe_isBigEndian0)}, |
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
1083 |
{CC "unalignedAccess0", CC "()Z", FN_PTR(Unsafe_unalignedAccess0)} |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1084 |
}; |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1085 |
|
1 | 1086 |
#undef CC |
1087 |
#undef FN_PTR |
|
1088 |
||
1089 |
#undef ADR |
|
1090 |
#undef LANG |
|
1091 |
#undef OBJ |
|
1092 |
#undef CLS |
|
1093 |
#undef FLD |
|
1094 |
#undef THR |
|
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1095 |
#undef DC_Args |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1096 |
#undef DAC_Args |
1 | 1097 |
|
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28621
diff
changeset
|
1098 |
#undef DECLARE_GETPUTOOP |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1099 |
|
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15482
diff
changeset
|
1100 |
|
36551 | 1101 |
// This function is exported, used by NativeLookup. |
1 | 1102 |
// The Unsafe_xxx functions above are called only from the interpreter. |
1103 |
// The optimizer looks at names and signatures to recognize |
|
1104 |
// individual functions. |
|
1105 |
||
36551 | 1106 |
JVM_ENTRY(void, JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass)) { |
1107 |
ThreadToNativeFromVM ttnfv(thread); |
|
35103
d19354bcbfa6
8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents:
33612
diff
changeset
|
1108 |
|
36551 | 1109 |
int ok = env->RegisterNatives(unsafeclass, jdk_internal_misc_Unsafe_methods, sizeof(jdk_internal_misc_Unsafe_methods)/sizeof(JNINativeMethod)); |
1110 |
guarantee(ok == 0, "register jdk.internal.misc.Unsafe natives"); |
|
1111 |
} JVM_END |