Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8247740: Inline derived CollectedHeap access for G1 and ParallelGC
Added shared helper in CollectedHeap, and inlined for G1 and ParallelGC

Reviewed-by: stefank, pliden
  • Loading branch information
Kim Barrett committed Jun 23, 2020
1 parent e3eb38f commit f8596b57f36a1080f5b139944f89decee841d22d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 34 deletions.
@@ -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.
*
* 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() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
assert(heap->kind() == CollectedHeap::Epsilon, "Not an Epsilon heap");
return (EpsilonHeap*)heap;
return named_heap<EpsilonHeap>(CollectedHeap::Epsilon);
}

HeapWord* EpsilonHeap::allocate_work(size_t size) {
@@ -2668,13 +2668,6 @@ void G1CollectedHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_tracer) {
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) {
assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");

@@ -1293,7 +1293,9 @@ class G1CollectedHeap : public CollectedHeap {

// Convenience function to be used in situations where the heap type can be
// 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);
// add appropriate methods for any other surv rate groups
@@ -689,13 +689,6 @@ void ParallelScavengeHeap::trace_heap(GCWhen::Type when, const GCTracer* gc_trac
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() {
return barrier_set_cast<CardTableBarrierSet>(BarrierSet::barrier_set());
}
@@ -126,7 +126,9 @@ class ParallelScavengeHeap : public CollectedHeap {

static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }

static ParallelScavengeHeap* heap();
static ParallelScavengeHeap* heap() {
return named_heap<ParallelScavengeHeap>(CollectedHeap::Parallel);
}

CardTableBarrierSet* barrier_set();
PSCardTable* card_table();
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,10 +31,7 @@
#include "services/memoryManager.hpp"

SerialHeap* SerialHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to SerialHeap::heap()");
assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
return static_cast<SerialHeap*>(heap);
return named_heap<SerialHeap>(CollectedHeap::Serial);
}

SerialHeap::SerialHeap() :
@@ -29,6 +29,7 @@
#include "gc/shared/gcWhen.hpp"
#include "gc/shared/verifyOption.hpp"
#include "memory/allocation.hpp"
#include "memory/universe.hpp"
#include "runtime/handles.hpp"
#include "runtime/perfData.hpp"
#include "runtime/safepoint.hpp"
@@ -177,6 +178,20 @@ class CollectedHeap : public CHeapObj<mtInternal> {
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() {
return _filler_array_max_size;
}
@@ -1199,10 +1199,8 @@ void GenCollectedHeap::save_marks() {
}

GenCollectedHeap* GenCollectedHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()");
assert(heap->kind() == CollectedHeap::Serial, "Invalid name");
return (GenCollectedHeap*) heap;
// SerialHeap is the only subtype of GenCollectedHeap.
return named_heap<GenCollectedHeap>(CollectedHeap::Serial);
}

#if INCLUDE_SERIALGC
@@ -41,10 +41,7 @@
#include "utilities/align.hpp"

ZCollectedHeap* ZCollectedHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()");
assert(heap->kind() == CollectedHeap::Z, "Invalid name");
return (ZCollectedHeap*)heap;
return named_heap<ZCollectedHeap>(CollectedHeap::Z);
}

ZCollectedHeap::ZCollectedHeap() :

0 comments on commit f8596b5

Please sign in to comment.