27 #include "classfile/vmSymbols.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "oops/objArrayOop.inline.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "prims/jni.h"
33 #include "prims/jvm.h"
34 #include "prims/unsafe.hpp"
35 #include "runtime/atomic.inline.hpp"
36 #include "runtime/globals.hpp"
37 #include "runtime/interfaceSupport.hpp"
38 #include "runtime/orderAccess.inline.hpp"
39 #include "runtime/reflection.hpp"
40 #include "runtime/vm_version.hpp"
41 #include "services/threadService.hpp"
42 #include "trace/tracing.hpp"
43 #include "utilities/copy.hpp"
44 #include "utilities/dtrace.hpp"
45 #include "utilities/macros.hpp"
46 #if INCLUDE_ALL_GCS
47 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
48 #endif // INCLUDE_ALL_GCS
49
50 /**
51 * Implementation of the jdk.internal.misc.Unsafe class
52 */
53
54
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) \
61 JVM_ENTRY(static result_type, header)
62
63 #define UNSAFE_LEAF(result_type, header) \
64 JVM_LEAF(static result_type, header)
65
66 #define UNSAFE_END JVM_END
67
174 #if INCLUDE_ALL_GCS
175 // We could be accessing the referent field in a reference
176 // object. If G1 is enabled then we need to register non-null
177 // referent with the SATB barrier.
178 if (UseG1GC) {
179 bool needs_barrier = false;
180
181 if (ret != NULL) {
182 if (offset == java_lang_ref_Reference::referent_offset && obj != NULL) {
183 oop o = JNIHandles::resolve(obj);
184 Klass* k = o->klass();
185 if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
186 assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
187 needs_barrier = true;
188 }
189 }
190 }
191
192 if (needs_barrier) {
193 oop referent = JNIHandles::resolve(ret);
194 G1SATBCardTableModRefBS::enqueue(referent);
195 }
196 }
197 #endif // INCLUDE_ALL_GCS
198
199 return ret;
200 } UNSAFE_END
201
202 UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) {
203 oop x = JNIHandles::resolve(x_h);
204 oop p = JNIHandles::resolve(obj);
205
206 if (UseCompressedOops) {
207 oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x);
208 } else {
209 oop_store((oop*)index_oop_from_field_offset_long(p, offset), x);
210 }
211 } UNSAFE_END
212
213 UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) {
214 oop p = JNIHandles::resolve(obj);
|
27 #include "classfile/vmSymbols.hpp"
28 #include "memory/allocation.inline.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "oops/objArrayOop.inline.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "prims/jni.h"
33 #include "prims/jvm.h"
34 #include "prims/unsafe.hpp"
35 #include "runtime/atomic.inline.hpp"
36 #include "runtime/globals.hpp"
37 #include "runtime/interfaceSupport.hpp"
38 #include "runtime/orderAccess.inline.hpp"
39 #include "runtime/reflection.hpp"
40 #include "runtime/vm_version.hpp"
41 #include "services/threadService.hpp"
42 #include "trace/tracing.hpp"
43 #include "utilities/copy.hpp"
44 #include "utilities/dtrace.hpp"
45 #include "utilities/macros.hpp"
46 #if INCLUDE_ALL_GCS
47 #include "gc/shared/satbMarkQueue.hpp"
48 #endif // INCLUDE_ALL_GCS
49
50 /**
51 * Implementation of the jdk.internal.misc.Unsafe class
52 */
53
54
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) \
61 JVM_ENTRY(static result_type, header)
62
63 #define UNSAFE_LEAF(result_type, header) \
64 JVM_LEAF(static result_type, header)
65
66 #define UNSAFE_END JVM_END
67
174 #if INCLUDE_ALL_GCS
175 // We could be accessing the referent field in a reference
176 // object. If G1 is enabled then we need to register non-null
177 // referent with the SATB barrier.
178 if (UseG1GC) {
179 bool needs_barrier = false;
180
181 if (ret != NULL) {
182 if (offset == java_lang_ref_Reference::referent_offset && obj != NULL) {
183 oop o = JNIHandles::resolve(obj);
184 Klass* k = o->klass();
185 if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
186 assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
187 needs_barrier = true;
188 }
189 }
190 }
191
192 if (needs_barrier) {
193 oop referent = JNIHandles::resolve(ret);
194 SATBMarkQueue::enqueue(referent);
195 }
196 }
197 #endif // INCLUDE_ALL_GCS
198
199 return ret;
200 } UNSAFE_END
201
202 UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) {
203 oop x = JNIHandles::resolve(x_h);
204 oop p = JNIHandles::resolve(obj);
205
206 if (UseCompressedOops) {
207 oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x);
208 } else {
209 oop_store((oop*)index_oop_from_field_offset_long(p, offset), x);
210 }
211 } UNSAFE_END
212
213 UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) {
214 oop p = JNIHandles::resolve(obj);
|