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