unsafe.cpp revision 3863
1472N/A * or visit www.oracle.com if you need additional information or have any
0N/A#include "precompiled.hpp"
0N/A#include "classfile/vmSymbols.hpp"
0N/A#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
0N/A#include "memory/allocation.inline.hpp"
0N/A#include "runtime/globals.hpp"
0N/A#include "runtime/interfaceSupport.hpp"
518N/A#include "runtime/reflection.hpp"
518N/A#include "runtime/synchronizer.hpp"
0N/A#include "services/threadService.hpp"
0N/A#include "utilities/dtrace.hpp"
0N/A#define MAX_OBJECT_SIZE \
return field_offset;
return byte_offset;
return slot;
return key;
#ifdef ASSERT
if (p != NULL) {
return field_offset;
return byte_offset;
volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset));
OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), x);
oop v; \
if (UseCompressedOops) { \
volatile oop v; \
if (UseCompressedOops) { \
#ifndef SERIALGC
if (UseG1GC) {
bool needs_barrier = false;
needs_barrier = true;
if (needs_barrier) {
return ret;
UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h))
if (UseCompressedOops) {
if (x != NULL) {
if (x != NULL) {
#ifndef SERIALGC
if (UseG1GC) {
bool needs_barrier = false;
needs_barrier = true;
if (needs_barrier) {
return ret;
UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h))
if (UseCompressedOops) {
UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset))
UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h))
// Catch VolatileCallSite.target stores (via
// CallSite.setTargetVolatile) and check call site dependencies.
if ((offset == java_lang_invoke_CallSite::target_offset_in_bytes()) && p->is_a(SystemDictionary::CallSite_klass())) {
if (UseCompressedOops) {
return value;
UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x))
*addr = x;
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) \
UNSAFE_ENTRY(void, Unsafe_Set##Boolean##140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jboolean x)) \
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \
UNSAFE_ENTRY(void, Unsafe_Set##Boolean(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \
UNSAFE_ENTRY(jboolean, Unsafe_Get##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) \
UNSAFE_ENTRY(void, Unsafe_Set##Boolean##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jboolean x)) \
UNSAFE_ENTRY(void, Unsafe_SetOrderedInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint x))
UNSAFE_ENTRY(void, Unsafe_SetOrderedObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h))
if (UseCompressedOops) {
UNSAFE_ENTRY(void, Unsafe_SetOrderedLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x))
*addr = x;
t->set_doing_unsafe_access(true); \
t->set_doing_unsafe_access(false); \
t->set_doing_unsafe_access(true); \
*(volatile native_type*)p = x; \
t->set_doing_unsafe_access(false); \
t->set_doing_unsafe_access(true);
jlong x;
x = *(volatile jlong*)p;
t->set_doing_unsafe_access(false);
t->set_doing_unsafe_access(true);
*(volatile jlong*)p = x;
t->set_doing_unsafe_access(false);
return addr_to_java(*(void**)p);
*(void**)p = addr_from_java(x);
if (sz == 0) {
if (x == NULL) {
return addr_to_java(x);
if (sz == 0) {
if (x == NULL) {
return addr_to_java(x);
if (p == NULL) {
UNSAFE_ENTRY(void, Unsafe_SetMemory(JNIEnv *env, jobject unsafe, jlong addr, jlong size, jbyte value))
UNSAFE_ENTRY(void, Unsafe_SetMemory2(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value))
UNSAFE_ENTRY(void, Unsafe_CopyMemory(JNIEnv *env, jobject unsafe, jlong srcAddr, jlong dstAddr, jlong size))
if (size == 0) {
UNSAFE_ENTRY(void, Unsafe_CopyMemory2(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size))
if (size == 0) {
if (must_be_static >= 0) {
if (k != NULL) {
assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok");
static jclass Unsafe_DefineClass(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) {
// Code lifted from JDK 1.3 ClassLoader.c
char *utfName;
if (UsePerfData) {
if (length < 0) {
if (body == 0) {
goto free_body;
goto free_body;
return result;
UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length))
UNSAFE_ENTRY(jclass, Unsafe_DefineClass1(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd))
// The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
static oop
TRAPS) {
if (UsePerfData) {
if (!p->is_objArray())
KlassHandle host_klass(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(host_class)));
if (p != NULL) {
UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh))
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h))
if (UseCompressedOops) {
if (success)
return success;
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x))
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x))
return success;
#ifndef USDT2
#ifndef USDT2
if (lp != 0) {
if (p != NULL) {
#ifndef USDT2
(uintptr_t) p);
p->unpark();
switch(ret) {
return ret;
// contain the necessarily updated Unsafe.java.
env->RegisterNatives(unsafecls, prefetch_methods, sizeof(prefetch_methods)/sizeof(JNINativeMethod));
env->RegisterNatives(unsafecls, memcopy_methods_15, sizeof(memcopy_methods_15)/sizeof(JNINativeMethod));
if (EnableInvokeDynamic) {