Skip to content
Permalink
Browse files
8272723: Don't use Access API to access primitive fields
Reviewed-by: stefank, eosterlund
  • Loading branch information
rkennke committed Oct 11, 2021
1 parent 49f8ce6 commit 3edee1e1feed564397ac47a32c0394d7798bac17
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 194 deletions.
@@ -4220,8 +4220,8 @@ void java_lang_invoke_MethodHandleNatives_CallSiteContext::serialize_offsets(Ser

DependencyContext java_lang_invoke_MethodHandleNatives_CallSiteContext::vmdependencies(oop call_site) {
assert(java_lang_invoke_MethodHandleNatives_CallSiteContext::is_instance(call_site), "");
nmethodBucket* volatile* vmdeps_addr = (nmethodBucket* volatile*)call_site->field_addr(_vmdependencies_offset);
volatile uint64_t* last_cleanup_addr = (volatile uint64_t*)call_site->field_addr(_last_cleanup_offset);
nmethodBucket* volatile* vmdeps_addr = call_site->field_addr<nmethodBucket* volatile>(_vmdependencies_offset);
volatile uint64_t* last_cleanup_addr = call_site->field_addr<volatile uint64_t>(_last_cleanup_offset);
DependencyContext dep_ctx(vmdeps_addr, last_cleanup_addr);
return dep_ctx;
}
@@ -4279,19 +4279,19 @@ int java_lang_ClassLoader::_parent_offset;
ClassLoaderData* java_lang_ClassLoader::loader_data_acquire(oop loader) {
assert(loader != NULL, "loader must not be NULL");
assert(oopDesc::is_oop(loader), "loader must be oop");
return HeapAccess<MO_ACQUIRE>::load_at(loader, _loader_data_offset);
return Atomic::load_acquire(loader->field_addr<ClassLoaderData*>(_loader_data_offset));
}

ClassLoaderData* java_lang_ClassLoader::loader_data(oop loader) {
assert(loader != NULL, "loader must not be NULL");
assert(oopDesc::is_oop(loader), "loader must be oop");
return HeapAccess<>::load_at(loader, _loader_data_offset);
return *loader->field_addr<ClassLoaderData*>(_loader_data_offset);
}

void java_lang_ClassLoader::release_set_loader_data(oop loader, ClassLoaderData* new_data) {
assert(loader != NULL, "loader must not be NULL");
assert(oopDesc::is_oop(loader), "loader must be oop");
HeapAccess<MO_RELEASE>::store_at(loader, _loader_data_offset, new_data);
Atomic::release_store(loader->field_addr<ClassLoaderData*>(_loader_data_offset), new_data);
}

#define CLASSLOADER_FIELDS_DO(macro) \
@@ -77,7 +77,7 @@ bool java_lang_String::is_latin1(oop java_string) {
uint8_t* java_lang_String::flags_addr(oop java_string) {
assert(_initialized, "Must be initialized");
assert(is_instance(java_string), "Must be java string");
return java_string->obj_field_addr<uint8_t>(_flags_offset);
return java_string->field_addr<uint8_t>(_flags_offset);
}

bool java_lang_String::is_flag_set(oop java_string, uint8_t flag_mask) {
@@ -146,7 +146,7 @@ void java_lang_ref_Reference::clear_referent(oop ref) {
}

HeapWord* java_lang_ref_Reference::referent_addr_raw(oop ref) {
return ref->obj_field_addr<HeapWord>(_referent_offset);
return ref->field_addr<HeapWord>(_referent_offset);
}

oop java_lang_ref_Reference::next(oop ref) {
@@ -162,7 +162,7 @@ void java_lang_ref_Reference::set_next_raw(oop ref, oop value) {
}

HeapWord* java_lang_ref_Reference::next_addr_raw(oop ref) {
return ref->obj_field_addr<HeapWord>(_next_offset);
return ref->field_addr<HeapWord>(_next_offset);
}

oop java_lang_ref_Reference::discovered(oop ref) {
@@ -178,7 +178,7 @@ void java_lang_ref_Reference::set_discovered_raw(oop ref, oop value) {
}

HeapWord* java_lang_ref_Reference::discovered_addr_raw(oop ref) {
return ref->obj_field_addr<HeapWord>(_discovered_offset);
return ref->field_addr<HeapWord>(_discovered_offset);
}

bool java_lang_ref_Reference::is_final(oop ref) {
@@ -231,13 +231,13 @@ void HotSpotJVMCI::compute_offsets(TRAPS) {
assert(className::klass() != NULL && className::klass()->is_linked(), "Class not yet linked: " #className); \
InstanceKlass* ik = className::klass(); \
oop base = ik->static_field_base_raw(); \
return HeapAccess<>::load_at(base, className::_##name##_offset); \
return *base->field_addr<jtypename>(className::_##name##_offset); \
} \
void HotSpotJVMCI::className::set_##name(JVMCIEnv* env, jtypename x) { \
assert(className::klass() != NULL && className::klass()->is_linked(), "Class not yet linked: " #className); \
InstanceKlass* ik = className::klass(); \
oop base = ik->static_field_base_raw(); \
HeapAccess<>::store_at(base, _##name##_offset, x); \
*base->field_addr<jtypename>(className::_##name##_offset) = x; \
}

#define STATIC_INT_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jint)
@@ -84,7 +84,7 @@ inline void InstanceKlass::release_set_methods_jmethod_ids(jmethodID* jmeths) {

template <typename T, class OopClosureType>
ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop obj, OopClosureType* closure) {
T* p = (T*)obj->obj_field_addr<T>(map->offset());
T* p = obj->field_addr<T>(map->offset());
T* const end = p + map->count();

for (; p < end; ++p) {
@@ -94,7 +94,7 @@ ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map(OopMapBlock* map, oop o

template <typename T, class OopClosureType>
ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_reverse(OopMapBlock* map, oop obj, OopClosureType* closure) {
T* const start = (T*)obj->obj_field_addr<T>(map->offset());
T* const start = obj->field_addr<T>(map->offset());
T* p = start + map->count();

while (start < p) {
@@ -105,7 +105,7 @@ ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_reverse(OopMapBlock* ma

template <typename T, class OopClosureType>
ALWAYSINLINE void InstanceKlass::oop_oop_iterate_oop_map_bounded(OopMapBlock* map, oop obj, OopClosureType* closure, MemRegion mr) {
T* p = (T*)obj->obj_field_addr<T>(map->offset());
T* p = obj->field_addr<T>(map->offset());
T* end = p + map->count();

T* const l = (T*)mr.start();
@@ -179,41 +179,41 @@ void oopDesc::obj_field_put_raw(int offset, oop value) { RawAcces
void oopDesc::release_obj_field_put(int offset, oop value) { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
void oopDesc::obj_field_put_volatile(int offset, oop value) { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }

address oopDesc::address_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
address oopDesc::address_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
address oopDesc::address_field(int offset) const { return *field_addr<address>(offset); }
address oopDesc::address_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<address>(offset)); }

void oopDesc::address_field_put(int offset, address value) { HeapAccess<>::store_at(as_oop(), offset, value); }
void oopDesc::release_address_field_put(int offset, address value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
void oopDesc::address_field_put(int offset, address value) { *field_addr<address>(offset) = value; }
void oopDesc::release_address_field_put(int offset, address value) { Atomic::release_store(field_addr<address>(offset), value); }

Metadata* oopDesc::metadata_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
void oopDesc::metadata_field_put(int offset, Metadata* value) { HeapAccess<>::store_at(as_oop(), offset, value); }
Metadata* oopDesc::metadata_field(int offset) const { return *field_addr<Metadata*>(offset); }
void oopDesc::metadata_field_put(int offset, Metadata* value) { *field_addr<Metadata*>(offset) = value; }

Metadata* oopDesc::metadata_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_metadata_field_put(int offset, Metadata* value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
Metadata* oopDesc::metadata_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<Metadata*>(offset)); }
void oopDesc::release_metadata_field_put(int offset, Metadata* value) { Atomic::release_store(field_addr<Metadata*>(offset), value); }

jbyte oopDesc::byte_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_byte_field_put(int offset, jbyte value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jbyte oopDesc::byte_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jbyte>(offset)); }
void oopDesc::release_byte_field_put(int offset, jbyte value) { Atomic::release_store(field_addr<jbyte>(offset), value); }

jchar oopDesc::char_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_char_field_put(int offset, jchar value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jchar oopDesc::char_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jchar>(offset)); }
void oopDesc::release_char_field_put(int offset, jchar value) { Atomic::release_store(field_addr<jchar>(offset), value); }

jboolean oopDesc::bool_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_bool_field_put(int offset, jboolean value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, jboolean(value & 1)); }
jboolean oopDesc::bool_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jboolean>(offset)); }
void oopDesc::release_bool_field_put(int offset, jboolean value) { Atomic::release_store(field_addr<jboolean>(offset), jboolean(value & 1)); }

jint oopDesc::int_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_int_field_put(int offset, jint value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jint oopDesc::int_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jint>(offset)); }
void oopDesc::release_int_field_put(int offset, jint value) { Atomic::release_store(field_addr<jint>(offset), value); }

jshort oopDesc::short_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_short_field_put(int offset, jshort value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jshort oopDesc::short_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jshort>(offset)); }
void oopDesc::release_short_field_put(int offset, jshort value) { Atomic::release_store(field_addr<jshort>(offset), value); }

jlong oopDesc::long_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_long_field_put(int offset, jlong value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jlong oopDesc::long_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jlong>(offset)); }
void oopDesc::release_long_field_put(int offset, jlong value) { Atomic::release_store(field_addr<jlong>(offset), value); }

jfloat oopDesc::float_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_float_field_put(int offset, jfloat value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jfloat oopDesc::float_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jfloat>(offset)); }
void oopDesc::release_float_field_put(int offset, jfloat value) { Atomic::release_store(field_addr<jfloat>(offset), value); }

jdouble oopDesc::double_field_acquire(int offset) const { return HeapAccess<MO_ACQUIRE>::load_at(as_oop(), offset); }
void oopDesc::release_double_field_put(int offset, jdouble value) { HeapAccess<MO_RELEASE>::store_at(as_oop(), offset, value); }
jdouble oopDesc::double_field_acquire(int offset) const { return Atomic::load_acquire(field_addr<jdouble>(offset)); }
void oopDesc::release_double_field_put(int offset, jdouble value) { Atomic::release_store(field_addr<jdouble>(offset), value); }

#ifdef ASSERT
void oopDesc::verify_forwardee(oop forwardee) {
@@ -124,11 +124,8 @@ class oopDesc {
inline oop as_oop() const { return const_cast<oopDesc*>(this); }

public:
// field addresses in oop
inline void* field_addr(int offset) const;

// Need this as public for garbage collection.
template <class T> inline T* obj_field_addr(int offset) const;
template<typename T>
inline T* field_addr(int offset) const;

template <typename T> inline size_t field_offset(T* p) const;

@@ -208,10 +208,8 @@ bool oopDesc::is_array() const { return klass()->is_array_klass(); }
bool oopDesc::is_objArray() const { return klass()->is_objArray_klass(); }
bool oopDesc::is_typeArray() const { return klass()->is_typeArray_klass(); }

void* oopDesc::field_addr(int offset) const { return reinterpret_cast<void*>(cast_from_oop<intptr_t>(as_oop()) + offset); }

template <class T>
T* oopDesc::obj_field_addr(int offset) const { return (T*) field_addr(offset); }
template<typename T>
T* oopDesc::field_addr(int offset) const { return reinterpret_cast<T*>(cast_from_oop<intptr_t>(as_oop()) + offset); }

template <typename T>
size_t oopDesc::field_offset(T* p) const { return pointer_delta((void*)p, (void*)this, 1); }
@@ -222,30 +220,30 @@ inline oop oopDesc::obj_field(int offset) const { return Hea

inline void oopDesc::obj_field_put(int offset, oop value) { HeapAccess<>::oop_store_at(as_oop(), offset, value); }

inline jbyte oopDesc::byte_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::byte_field_put(int offset, jbyte value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jbyte oopDesc::byte_field(int offset) const { return *field_addr<jbyte>(offset); }
inline void oopDesc::byte_field_put(int offset, jbyte value) { *field_addr<jbyte>(offset) = value; }

inline jchar oopDesc::char_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::char_field_put(int offset, jchar value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jchar oopDesc::char_field(int offset) const { return *field_addr<jchar>(offset); }
inline void oopDesc::char_field_put(int offset, jchar value) { *field_addr<jchar>(offset) = value; }

inline jboolean oopDesc::bool_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::bool_field_put(int offset, jboolean value) { HeapAccess<>::store_at(as_oop(), offset, jboolean(value & 1)); }
inline jboolean oopDesc::bool_field_volatile(int offset) const { return HeapAccess<MO_SEQ_CST>::load_at(as_oop(), offset); }
inline void oopDesc::bool_field_put_volatile(int offset, jboolean value) { HeapAccess<MO_SEQ_CST>::store_at(as_oop(), offset, jboolean(value & 1)); }
inline jshort oopDesc::short_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::short_field_put(int offset, jshort value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jboolean oopDesc::bool_field(int offset) const { return *field_addr<jboolean>(offset); }
inline void oopDesc::bool_field_put(int offset, jboolean value) { *field_addr<jboolean>(offset) = jboolean(value & 1); }
inline jboolean oopDesc::bool_field_volatile(int offset) const { return RawAccess<MO_SEQ_CST>::load(field_addr<jboolean>(offset)); }
inline void oopDesc::bool_field_put_volatile(int offset, jboolean value) { RawAccess<MO_SEQ_CST>::store(field_addr<jboolean>(offset), jboolean(value & 1)); }
inline jshort oopDesc::short_field(int offset) const { return *field_addr<jshort>(offset); }
inline void oopDesc::short_field_put(int offset, jshort value) { *field_addr<jshort>(offset) = value; }

inline jint oopDesc::int_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::int_field_put(int offset, jint value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jint oopDesc::int_field(int offset) const { return *field_addr<jint>(offset); }
inline void oopDesc::int_field_put(int offset, jint value) { *field_addr<jint>(offset) = value; }

inline jlong oopDesc::long_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::long_field_put(int offset, jlong value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jlong oopDesc::long_field(int offset) const { return *field_addr<jlong>(offset); }
inline void oopDesc::long_field_put(int offset, jlong value) { *field_addr<jlong>(offset) = value; }

inline jfloat oopDesc::float_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::float_field_put(int offset, jfloat value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jfloat oopDesc::float_field(int offset) const { return *field_addr<jfloat>(offset); }
inline void oopDesc::float_field_put(int offset, jfloat value) { *field_addr<jfloat>(offset) = value; }

inline jdouble oopDesc::double_field(int offset) const { return HeapAccess<>::load_at(as_oop(), offset); }
inline void oopDesc::double_field_put(int offset, jdouble value) { HeapAccess<>::store_at(as_oop(), offset, value); }
inline jdouble oopDesc::double_field(int offset) const { return *field_addr<jdouble>(offset); }
inline void oopDesc::double_field_put(int offset, jdouble value) { *field_addr<jdouble>(offset) = value; }

bool oopDesc::is_locked() const {
return mark().is_locked();

1 comment on commit 3edee1e

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 3edee1e Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.