8183542: Factor out serial GC specific code from GenCollectedHeap into its own subclass

Reviewed-by: kbarrett, jgeorge
This commit is contained in:
Roman Kennke 2017-10-25 10:05:17 +02:00
parent ac52bdcdd1
commit 04e375658c
12 changed files with 161 additions and 47 deletions

View File

@ -39,14 +39,16 @@ class ThreadClosure;
class WorkGang;
class CMSHeap : public GenCollectedHeap {
protected:
virtual void check_gen_kinds();
public:
CMSHeap(GenCollectorPolicy *policy);
// Returns JNI_OK on success
virtual jint initialize();
virtual void check_gen_kinds();
// Convenience function to be used in situations where the heap type can be
// asserted to be this type.
static CMSHeap* heap();
@ -70,10 +72,6 @@ public:
// supports. Caller does not hold the Heap_lock on entry.
void collect(GCCause::Cause cause);
bool is_in_closed_subset(const void* p) const {
return is_in_reserved(p);
}
bool card_mark_must_follow_store() const {
return true;
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2017, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "gc/serial/serialHeap.hpp"
SerialHeap::SerialHeap(GenCollectorPolicy* policy) : GenCollectedHeap(policy) {}
void SerialHeap::check_gen_kinds() {
assert(young_gen()->kind() == Generation::DefNew,
"Wrong youngest generation type");
assert(old_gen()->kind() == Generation::MarkSweepCompact,
"Wrong generation kind");
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2017, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_GC_SERIAL_SERIALHEAP_HPP
#define SHARE_VM_GC_SERIAL_SERIALHEAP_HPP
#include "gc/shared/genCollectedHeap.hpp"
class GenCollectorPolicy;
class SerialHeap : public GenCollectedHeap {
protected:
virtual void check_gen_kinds();
public:
SerialHeap(GenCollectorPolicy* policy);
virtual Name kind() const {
return CollectedHeap::SerialHeap;
}
virtual const char* name() const {
return "Serial";
}
// override
virtual bool is_in_closed_subset(const void* p) const {
return is_in(p);
}
virtual bool card_mark_must_follow_store() const {
return false;
}
};
#endif // SHARE_VM_GC_CMS_CMSHEAP_HPP

View File

@ -81,9 +81,10 @@ class GCHeapLog : public EventLogBase<GCMessage> {
//
// CollectedHeap
// GenCollectedHeap
// SerialHeap
// CMSHeap
// G1CollectedHeap
// ParallelScavengeHeap
// CMSHeap
//
class CollectedHeap : public CHeapObj<mtInternal> {
friend class VMStructs;
@ -193,7 +194,7 @@ class CollectedHeap : public CHeapObj<mtInternal> {
public:
enum Name {
GenCollectedHeap,
SerialHeap,
ParallelScavengeHeap,
G1CollectedHeap,
CMSHeap

View File

@ -153,13 +153,6 @@ void GenCollectedHeap::post_initialize() {
_gen_policy->initialize_gc_policy_counters();
}
void GenCollectedHeap::check_gen_kinds() {
assert(young_gen()->kind() == Generation::DefNew,
"Wrong youngest generation type");
assert(old_gen()->kind() == Generation::MarkSweepCompact,
"Wrong generation kind");
}
void GenCollectedHeap::ref_processing_init() {
_young_gen->ref_processor_init();
_old_gen->ref_processor_init();
@ -984,7 +977,7 @@ void GenCollectedHeap::save_marks() {
GenCollectedHeap* GenCollectedHeap::heap() {
CollectedHeap* heap = Universe::heap();
assert(heap != NULL, "Uninitialized access to GenCollectedHeap::heap()");
assert(heap->kind() == CollectedHeap::GenCollectedHeap ||
assert(heap->kind() == CollectedHeap::SerialHeap ||
heap->kind() == CollectedHeap::CMSHeap, "Not a GenCollectedHeap");
return (GenCollectedHeap*) heap;
}

View File

@ -83,6 +83,12 @@ private:
bool run_verification, bool clear_soft_refs,
bool restore_marks_for_biased_locking);
// Reserve aligned space for the heap as needed by the contained generations.
char* allocate(size_t alignment, ReservedSpace* heap_rs);
// Initialize ("weak") refs processing support
void ref_processing_init();
protected:
// The set of potentially parallel tasks in root scanning.
@ -134,31 +140,18 @@ protected:
// we absolutely __must__ clear soft refs?
bool must_clear_all_soft_refs();
public:
GenCollectedHeap(GenCollectorPolicy *policy);
virtual void check_gen_kinds() = 0;
public:
// Returns JNI_OK on success
virtual jint initialize();
// Reserve aligned space for the heap as needed by the contained generations.
char* allocate(size_t alignment, ReservedSpace* heap_rs);
// Does operations required after initialization has been done.
void post_initialize();
virtual void check_gen_kinds();
// Initialize ("weak") refs processing support
virtual void ref_processing_init();
virtual Name kind() const {
return CollectedHeap::GenCollectedHeap;
}
virtual const char* name() const {
return "Serial";
}
Generation* young_gen() const { return _young_gen; }
Generation* old_gen() const { return _old_gen; }
@ -215,11 +208,6 @@ public:
// assertion checking or verification only.
bool is_in(const void* p) const;
// override
virtual bool is_in_closed_subset(const void* p) const {
return is_in(p);
}
// Returns true if the reference is to an object in the reserved space
// for the young generation.
// Assumes the the young gen address range is less than that of the old gen.
@ -286,10 +274,6 @@ public:
return true;
}
virtual bool card_mark_must_follow_store() const {
return false;
}
// We don't need barriers for stores to objects in the
// young gen and, a fortiori, for initializing stores to
// objects therein. This applies to DefNew+Tenured and ParNew+CMS

View File

@ -32,10 +32,10 @@
#include "classfile/vmSymbols.hpp"
#include "code/codeCache.hpp"
#include "code/dependencies.hpp"
#include "gc/serial/serialHeap.hpp"
#include "gc/shared/cardTableModRefBS.hpp"
#include "gc/shared/collectedHeap.inline.hpp"
#include "gc/shared/gcLocker.inline.hpp"
#include "gc/shared/genCollectedHeap.hpp"
#include "gc/shared/generation.hpp"
#include "gc/shared/gcTraceTime.inline.hpp"
#include "gc/shared/space.hpp"
@ -762,7 +762,7 @@ CollectedHeap* Universe::create_heap() {
return Universe::create_heap_with_policy<CMSHeap, ConcurrentMarkSweepPolicy>();
#endif
} else if (UseSerialGC) {
return Universe::create_heap_with_policy<GenCollectedHeap, MarkSweepPolicy>();
return Universe::create_heap_with_policy<SerialHeap, MarkSweepPolicy>();
}
ShouldNotReachHere();

View File

@ -47,6 +47,7 @@
#include "gc/parallel/immutableSpace.hpp"
#include "gc/parallel/mutableSpace.hpp"
#include "gc/serial/defNewGeneration.hpp"
#include "gc/serial/serialHeap.hpp"
#include "gc/serial/tenuredGeneration.hpp"
#include "gc/cms/cmsHeap.hpp"
#include "gc/shared/cardTableRS.hpp"
@ -1465,6 +1466,7 @@ typedef PaddedEnd<ObjectMonitor> PaddedObjectMonitor;
declare_toplevel_type(CollectedHeap) \
declare_type(GenCollectedHeap, CollectedHeap) \
declare_type(CMSHeap, GenCollectedHeap) \
declare_type(SerialHeap, GenCollectedHeap) \
declare_toplevel_type(Generation) \
declare_type(DefNewGeneration, Generation) \
declare_type(CardGeneration, Generation) \
@ -2258,7 +2260,8 @@ typedef PaddedEnd<ObjectMonitor> PaddedObjectMonitor;
\
declare_constant(G1SATBCardTableModRefBS::g1_young_gen) \
\
declare_constant(CollectedHeap::GenCollectedHeap) \
declare_constant(CollectedHeap::SerialHeap) \
declare_constant(CollectedHeap::CMSHeap) \
declare_constant(CollectedHeap::ParallelScavengeHeap) \
declare_constant(CollectedHeap::G1CollectedHeap) \
\

View File

@ -86,7 +86,7 @@ void GcThreadCountClosure::do_thread(Thread* thread) {
void MemoryService::set_universe_heap(CollectedHeap* heap) {
CollectedHeap::Name kind = heap->kind();
switch (kind) {
case CollectedHeap::GenCollectedHeap :
case CollectedHeap::SerialHeap :
case CollectedHeap::CMSHeap : {
add_gen_collected_heap_info(GenCollectedHeap::heap());
break;

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
package sun.jvm.hotspot.gc.serial;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.gc.shared.GenCollectedHeap;
import sun.jvm.hotspot.gc.shared.CollectedHeapName;
public class SerialHeap extends GenCollectedHeap {
public SerialHeap(Address addr) {
super(addr);
}
public CollectedHeapName kind() {
return CollectedHeapName.SERIAL_HEAP;
}
}

View File

@ -33,6 +33,7 @@ public class CollectedHeapName {
public static final CollectedHeapName GEN_COLLECTED_HEAP = new CollectedHeapName("GenCollectedHeap");
public static final CollectedHeapName CMS_HEAP = new CollectedHeapName("CMSHeap");
public static final CollectedHeapName SERIAL_HEAP = new CollectedHeapName("SerialHeap");
public static final CollectedHeapName G1_COLLECTED_HEAP = new CollectedHeapName("G1CollectedHeap");
public static final CollectedHeapName PARALLEL_SCAVENGE_HEAP = new CollectedHeapName("ParallelScavengeHeap");

View File

@ -28,6 +28,7 @@ import java.io.*;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.gc.cms.CMSHeap;
import sun.jvm.hotspot.gc.serial.SerialHeap;
import sun.jvm.hotspot.gc.shared.*;
import sun.jvm.hotspot.gc.g1.G1CollectedHeap;
import sun.jvm.hotspot.gc.parallel.*;
@ -77,8 +78,8 @@ public class Universe {
collectedHeapField = type.getAddressField("_collectedHeap");
heapConstructor = new VirtualConstructor(db);
heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
heapConstructor.addMapping("CMSHeap", CMSHeap.class);
heapConstructor.addMapping("SerialHeap", SerialHeap.class);
heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
heapConstructor.addMapping("G1CollectedHeap", G1CollectedHeap.class);