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