Skip to content

Commit

Permalink
8253278: Refactor/cleanup oopDesc::*_klass_addr
Browse files Browse the repository at this point in the history
Reviewed-by: coleenp, stefank
  • Loading branch information
shipilev committed Sep 18, 2020
1 parent 73c9088 commit 11c4ea9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/hotspot/share/oops/oop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ bool oopDesc::has_klass_gap() {

void* oopDesc::load_klass_raw(oop obj) {
if (UseCompressedClassPointers) {
narrowKlass narrow_klass = *(obj->compressed_klass_addr());
narrowKlass narrow_klass = obj->_metadata._compressed_klass;
if (narrow_klass == 0) return NULL;
return (void*)CompressedKlassPointers::decode_raw(narrow_klass);
} else {
return *(void**)(obj->klass_addr());
return obj->_metadata._klass;
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/hotspot/share/oops/oop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ class oopDesc {
inline Klass* klass() const;
inline Klass* klass_or_null() const;
inline Klass* klass_or_null_acquire() const;
static inline Klass** klass_addr(HeapWord* mem);
static inline narrowKlass* compressed_klass_addr(HeapWord* mem);
inline Klass** klass_addr();
inline narrowKlass* compressed_klass_addr();

inline void set_klass(Klass* k);
static inline void release_set_klass(HeapWord* mem, Klass* klass);
static inline void release_set_klass(HeapWord* mem, Klass* k);

// For klass field compression
inline int klass_gap() const;
Expand Down
47 changes: 9 additions & 38 deletions src/hotspot/share/oops/oop.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,55 +113,26 @@ Klass* oopDesc::klass_or_null_acquire() const {
}
}

Klass** oopDesc::klass_addr(HeapWord* mem) {
// Only used internally and with CMS and will not work with
// UseCompressedOops
assert(!UseCompressedClassPointers, "only supported with uncompressed klass pointers");
ByteSize offset = byte_offset_of(oopDesc, _metadata._klass);
return (Klass**) (((char*)mem) + in_bytes(offset));
}

narrowKlass* oopDesc::compressed_klass_addr(HeapWord* mem) {
assert(UseCompressedClassPointers, "only called by compressed klass pointers");
ByteSize offset = byte_offset_of(oopDesc, _metadata._compressed_klass);
return (narrowKlass*) (((char*)mem) + in_bytes(offset));
}

Klass** oopDesc::klass_addr() {
return klass_addr((HeapWord*)this);
}

narrowKlass* oopDesc::compressed_klass_addr() {
return compressed_klass_addr((HeapWord*)this);
}

#define CHECK_SET_KLASS(k) \
do { \
assert(Universe::is_bootstrapping() || k != NULL, "NULL Klass"); \
assert(Universe::is_bootstrapping() || k->is_klass(), "not a Klass"); \
} while (0)

void oopDesc::set_klass(Klass* k) {
CHECK_SET_KLASS(k);
assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
if (UseCompressedClassPointers) {
*compressed_klass_addr() = CompressedKlassPointers::encode_not_null(k);
_metadata._compressed_klass = CompressedKlassPointers::encode_not_null(k);
} else {
*klass_addr() = k;
_metadata._klass = k;
}
}

void oopDesc::release_set_klass(HeapWord* mem, Klass* klass) {
CHECK_SET_KLASS(klass);
void oopDesc::release_set_klass(HeapWord* mem, Klass* k) {
assert(Universe::is_bootstrapping() || (k != NULL && k->is_klass()), "incorrect Klass");
char* raw_mem = ((char*)mem + klass_offset_in_bytes());
if (UseCompressedClassPointers) {
Atomic::release_store(compressed_klass_addr(mem),
CompressedKlassPointers::encode_not_null(klass));
Atomic::release_store((narrowKlass*)raw_mem,
CompressedKlassPointers::encode_not_null(k));
} else {
Atomic::release_store(klass_addr(mem), klass);
Atomic::release_store((Klass**)raw_mem, k);
}
}

#undef CHECK_SET_KLASS

int oopDesc::klass_gap() const {
return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
}
Expand Down

1 comment on commit 11c4ea9

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 11c4ea9 Sep 18, 2020

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.