8247740: Inline derived CollectedHeap access for G1 and ParallelGC

Added shared helper in CollectedHeap, and inlined for G1 and ParallelGC

Reviewed-by: stefank, pliden
This commit is contained in:
Kim Barrett 2020-06-23 05:58:52 -04:00
parent e3eb38f4d2
commit f8596b57f3
9 changed files with 28 additions and 34 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -101,10 +101,7 @@ size_t EpsilonHeap::unsafe_max_tlab_alloc(Thread* thr) const {
} }
EpsilonHeap* EpsilonHeap::heap() { EpsilonHeap* EpsilonHeap::heap() {
CollectedHeap* heap = Universe::heap(); return named_heap<EpsilonHeap>(CollectedHeap::Epsilon);
assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
assert(heap->kind() == CollectedHeap::Epsilon, "Not an Epsilon heap");
return (EpsilonHeap*)heap;
} }
HeapWord* EpsilonHeap::allocate_work(size_t size) { HeapWord* EpsilonHeap::allocate_work(size_t size) {

View File

@ -2668,13 +2668,6 @@ void G1CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
gc_tracer->report_metaspace_summary(when, metaspace_summary); gc_tracer->report_metaspace_summary(when, metaspace_summary);
} }
G1CollectedHeap* G1CollectedHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to G1CollectedHeap::heap()");
assert(heap->kind() == CollectedHeap::G1, "Invalid name");
return (G1CollectedHeap*)heap;
}
void G1CollectedHeap::gc_prologue(bool full) { void G1CollectedHeap::gc_prologue(bool full) {
assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer"); assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");

View File

@ -1293,7 +1293,9 @@ public:
// Convenience function to be used in situations where the heap type can be // Convenience function to be used in situations where the heap type can be
// asserted to be this type. // asserted to be this type.
static G1CollectedHeap* heap(); static G1CollectedHeap* heap() {
return named_heap<G1CollectedHeap>(CollectedHeap::G1);
}
void set_region_short_lived_locked(HeapRegion* hr); void set_region_short_lived_locked(HeapRegion* hr);
// add appropriate methods for any other surv rate groups // add appropriate methods for any other surv rate groups

View File

@ -689,13 +689,6 @@ void ParallelScavengeHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_trac
gc_tracer->report_metaspace_summary(when, metaspace_summary); gc_tracer->report_metaspace_summary(when, metaspace_summary);
} }
ParallelScavengeHeap* ParallelScavengeHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to ParallelScavengeHeap::heap()");
assert(heap->kind() == CollectedHeap::Parallel, "Invalid name");
return (ParallelScavengeHeap*)heap;
}
CardTableBarrierSet* ParallelScavengeHeap::barrier_set() { CardTableBarrierSet* ParallelScavengeHeap::barrier_set() {
return barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set()); return barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());
} }

View File

@ -126,7 +126,9 @@ class ParallelScavengeHeap : public CollectedHeap {
static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; } static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
static ParallelScavengeHeap* heap(); static ParallelScavengeHeap* heap() {
return named_heap<ParallelScavengeHeap>(CollectedHeap::Parallel);
}
CardTableBarrierSet* barrier_set(); CardTableBarrierSet* barrier_set();
PSCardTable* card_table(); PSCardTable* card_table();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,10 +31,7 @@
#include "services/memoryManager.hpp" #include "services/memoryManager.hpp"
SerialHeap* SerialHeap::heap() { SerialHeap* SerialHeap::heap() {
CollectedHeap* heap = Universe::heap(); return named_heap<SerialHeap>(CollectedHeap::Serial);
assert(heap != NULL, "Uninitialized access to SerialHeap::heap()");
assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
return static_cast<SerialHeap*>(heap);
} }
SerialHeap::SerialHeap() : SerialHeap::SerialHeap() :

View File

@ -29,6 +29,7 @@
#include "gc/shared/gcWhen.hpp" #include "gc/shared/gcWhen.hpp"
#include "gc/shared/verifyOption.hpp" #include "gc/shared/verifyOption.hpp"
#include "memory/allocation.hpp" #include "memory/allocation.hpp"
#include "memory/universe.hpp"
#include "runtime/handles.hpp" #include "runtime/handles.hpp"
#include "runtime/perfData.hpp" #include "runtime/perfData.hpp"
#include "runtime/safepoint.hpp" #include "runtime/safepoint.hpp"
@ -177,6 +178,20 @@ class CollectedHeap : public CHeapObj<mtInternal> {
Shenandoah Shenandoah
}; };
protected:
// Get a pointer to the derived heap object. Used to implement
// derived class heap() functions rather than being called directly.
template<typename T>
static T* named_heap(Name kind) {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized heap");
assert(kind == heap->kind(), "Heap kind %u should be %u",
static_cast<uint>(heap->kind()), static_cast<uint>(kind));
return static_cast<T*>(heap);
}
public:
static inline size_t filler_array_max_size() { static inline size_t filler_array_max_size() {
return _filler_array_max_size; return _filler_array_max_size;
} }

View File

@ -1199,10 +1199,8 @@ void GenCollectedHeap::save_marks() {
} }
GenCollectedHeap* GenCollectedHeap::heap() { GenCollectedHeap* GenCollectedHeap::heap() {
CollectedHeap* heap = Universe::heap(); // SerialHeap is the only subtype of GenCollectedHeap.
assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()"); return named_heap<GenCollectedHeap>(CollectedHeap::Serial);
assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
return (GenCollectedHeap*) heap;
} }
#if INCLUDE_SERIALGC #if INCLUDE_SERIALGC

View File

@ -41,10 +41,7 @@
#include "utilities/align.hpp" #include "utilities/align.hpp"
ZCollectedHeap* ZCollectedHeap::heap() { ZCollectedHeap* ZCollectedHeap::heap() {
CollectedHeap* heap = Universe::heap(); return named_heap<ZCollectedHeap>(CollectedHeap::Z);
assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()");
assert(heap->kind() == CollectedHeap::Z, "Invalid name");
return (ZCollectedHeap*)heap;
} }
ZCollectedHeap::ZCollectedHeap() : ZCollectedHeap::ZCollectedHeap() :