Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
8241743: Shenandoah: refactor and inline ShenandoahHeap::heap()
Browse files Browse the repository at this point in the history
Reviewed-by: rkennke
  • Loading branch information
shipilev committed Mar 27, 2020
1 parent 7056b96 commit 0861f3f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
Expand Up @@ -27,7 +27,7 @@
#include "gc/shared/satbMarkQueue.hpp" #include "gc/shared/satbMarkQueue.hpp"
#include "gc/shenandoah/shenandoahBarrierSet.hpp" #include "gc/shenandoah/shenandoahBarrierSet.hpp"
#include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp" #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp" #include "gc/shenandoah/shenandoahHeap.inline.hpp"
#include "gc/shenandoah/shenandoahHeapRegion.hpp" #include "gc/shenandoah/shenandoahHeapRegion.hpp"
#include "gc/shenandoah/shenandoahRuntime.hpp" #include "gc/shenandoah/shenandoahRuntime.hpp"
#include "gc/shenandoah/shenandoahThreadLocalData.hpp" #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
Expand Down
14 changes: 7 additions & 7 deletions src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp
Expand Up @@ -169,7 +169,7 @@ void ShenandoahAsserts::print_failure(SafeLevel level, oop obj, void* interior_l
} }


void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) { void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) {
ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();


if (!heap->is_in(obj)) { if (!heap->is_in(obj)) {
print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap failed", print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap failed",
Expand All @@ -179,7 +179,7 @@ void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *
} }


void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) { void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();


// Step 1. Check that obj is correct. // Step 1. Check that obj is correct.
// After this step, it is safe to call heap_region_containing(). // After this step, it is safe to call heap_region_containing().
Expand Down Expand Up @@ -247,7 +247,7 @@ void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char*
void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) { void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
assert_correct(interior_loc, obj, file, line); assert_correct(interior_loc, obj, file, line);


ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();
ShenandoahHeapRegion* r = heap->heap_region_containing(obj); ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
if (!r->is_active()) { if (!r->is_active()) {
print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed", print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
Expand Down Expand Up @@ -300,7 +300,7 @@ void ShenandoahAsserts::assert_not_forwarded(void* interior_loc, oop obj, const
void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *file, int line) { void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *file, int line) {
assert_correct(interior_loc, obj, file, line); assert_correct(interior_loc, obj, file, line);


ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();
if (!heap->marking_context()->is_marked(obj)) { if (!heap->marking_context()->is_marked(obj)) {
print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked failed", print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked failed",
"Object should be marked", "Object should be marked",
Expand All @@ -311,7 +311,7 @@ void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *f
void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) { void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) {
assert_correct(interior_loc, obj, file, line); assert_correct(interior_loc, obj, file, line);


ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();
if (!heap->in_collection_set(obj)) { if (!heap->in_collection_set(obj)) {
print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_in_cset failed", print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_in_cset failed",
"Object should be in collection set", "Object should be in collection set",
Expand All @@ -322,7 +322,7 @@ void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char*
void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line) { void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line) {
assert_correct(interior_loc, obj, file, line); assert_correct(interior_loc, obj, file, line);


ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();
if (heap->in_collection_set(obj)) { if (heap->in_collection_set(obj)) {
print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_in_cset failed", print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_in_cset failed",
"Object should not be in collection set", "Object should not be in collection set",
Expand All @@ -331,7 +331,7 @@ void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const ch
} }


void ShenandoahAsserts::assert_not_in_cset_loc(void* interior_loc, const char* file, int line) { void ShenandoahAsserts::assert_not_in_cset_loc(void* interior_loc, const char* file, int line) {
ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();
if (heap->in_collection_set_loc(interior_loc)) { if (heap->in_collection_set_loc(interior_loc)) {
print_failure(_safe_unknown, NULL, interior_loc, NULL, "Shenandoah assert_not_in_cset_loc failed", print_failure(_safe_unknown, NULL, interior_loc, NULL, "Shenandoah assert_not_in_cset_loc failed",
"Interior location should not be in collection set", "Interior location should not be in collection set",
Expand Down
16 changes: 4 additions & 12 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp
Expand Up @@ -82,6 +82,8 @@
#include "services/mallocTracker.hpp" #include "services/mallocTracker.hpp"
#include "utilities/powerOfTwo.hpp" #include "utilities/powerOfTwo.hpp"


ShenandoahHeap* ShenandoahHeap::_heap = NULL;

#ifdef ASSERT #ifdef ASSERT
template <class T> template <class T>
void ShenandoahAssertToSpaceClosure::do_oop_work(T* p) { void ShenandoahAssertToSpaceClosure::do_oop_work(T* p) {
Expand Down Expand Up @@ -461,6 +463,8 @@ ShenandoahHeap::ShenandoahHeap(ShenandoahCollectorPolicy* policy) :
_liveness_cache(NULL), _liveness_cache(NULL),
_collection_set(NULL) _collection_set(NULL)
{ {
_heap = this;

log_info(gc, init)("GC threads: " UINT32_FORMAT " parallel, " UINT32_FORMAT " concurrent", ParallelGCThreads, ConcGCThreads); log_info(gc, init)("GC threads: " UINT32_FORMAT " parallel, " UINT32_FORMAT " concurrent", ParallelGCThreads, ConcGCThreads);
log_info(gc, init)("Reference processing: %s", ParallelRefProcEnabled ? "parallel" : "serial"); log_info(gc, init)("Reference processing: %s", ParallelRefProcEnabled ? "parallel" : "serial");


Expand Down Expand Up @@ -777,18 +781,6 @@ HeapWord* ShenandoahHeap::allocate_new_gclab(size_t min_size,
return res; return res;
} }


ShenandoahHeap* ShenandoahHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Unitialized access to ShenandoahHeap::heap()");
assert(heap->kind() == CollectedHeap::Shenandoah, "not a shenandoah heap");
return (ShenandoahHeap*) heap;
}

ShenandoahHeap* ShenandoahHeap::heap_no_check() {
CollectedHeap* heap = Universe::heap();
return (ShenandoahHeap*) heap;
}

HeapWord* ShenandoahHeap::allocate_memory(ShenandoahAllocRequest& req) { HeapWord* ShenandoahHeap::allocate_memory(ShenandoahAllocRequest& req) {
intptr_t pacer_epoch = 0; intptr_t pacer_epoch = 0;
bool in_new_region = false; bool in_new_region = false;
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp
Expand Up @@ -132,9 +132,11 @@ class ShenandoahHeap : public CollectedHeap {


// ---------- Initialization, termination, identification, printing routines // ---------- Initialization, termination, identification, printing routines
// //
private:
static ShenandoahHeap* _heap;

public: public:
static ShenandoahHeap* heap(); static ShenandoahHeap* heap();
static ShenandoahHeap* heap_no_check();


const char* name() const { return "Shenandoah"; } const char* name() const { return "Shenandoah"; }
ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; } ShenandoahHeap::Name kind() const { return CollectedHeap::Shenandoah; }
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp
Expand Up @@ -48,6 +48,10 @@
#include "utilities/copy.hpp" #include "utilities/copy.hpp"
#include "utilities/globalDefinitions.hpp" #include "utilities/globalDefinitions.hpp"


inline ShenandoahHeap* ShenandoahHeap::heap() {
assert(_heap != NULL, "Heap is not initialized yet");
return _heap;
}


inline ShenandoahHeapRegion* ShenandoahRegionIterator::next() { inline ShenandoahHeapRegion* ShenandoahRegionIterator::next() {
size_t new_index = Atomic::add(&_index, (size_t) 1); size_t new_index = Atomic::add(&_index, (size_t) 1);
Expand Down
Expand Up @@ -27,7 +27,7 @@
#include "gc/shared/generationCounters.hpp" #include "gc/shared/generationCounters.hpp"
#include "gc/shared/hSpaceCounters.hpp" #include "gc/shared/hSpaceCounters.hpp"
#include "gc/shenandoah/shenandoahMonitoringSupport.hpp" #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp" #include "gc/shenandoah/shenandoahHeap.inline.hpp"
#include "gc/shenandoah/shenandoahHeapRegionCounters.hpp" #include "gc/shenandoah/shenandoahHeapRegionCounters.hpp"
#include "memory/metaspaceCounters.hpp" #include "memory/metaspaceCounters.hpp"
#include "services/memoryService.hpp" #include "services/memoryService.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahVerifier.cpp
Expand Up @@ -982,7 +982,7 @@ class ShenandoahVerifyInToSpaceClosure : public OopClosure {
T o = RawAccess<>::oop_load(p); T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) { if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o); oop obj = CompressedOops::decode_not_null(o);
ShenandoahHeap* heap = ShenandoahHeap::heap_no_check(); ShenandoahHeap* heap = ShenandoahHeap::heap();


if (!heap->marking_context()->is_marked(obj)) { if (!heap->marking_context()->is_marked(obj)) {
ShenandoahAsserts::print_failure(ShenandoahAsserts::_safe_all, obj, p, NULL, ShenandoahAsserts::print_failure(ShenandoahAsserts::_safe_all, obj, p, NULL,
Expand Down

0 comments on commit 0861f3f

Please sign in to comment.