8183542: Factor out serial GC specific code from GenCollectedHeap into its own subclass
authorrkennke
Wed, 25 Oct 2017 10:05:17 +0200
changeset 47819 ee36a8e36561
parent 47818 2f6ab27efb60
child 47820 1bc021ddeae0
8183542: Factor out serial GC specific code from GenCollectedHeap into its own subclass Reviewed-by: kbarrett, jgeorge
src/hotspot/share/gc/cms/cmsHeap.hpp
src/hotspot/share/gc/serial/serialHeap.cpp
src/hotspot/share/gc/serial/serialHeap.hpp
src/hotspot/share/gc/shared/collectedHeap.hpp
src/hotspot/share/gc/shared/genCollectedHeap.cpp
src/hotspot/share/gc/shared/genCollectedHeap.hpp
src/hotspot/share/memory/universe.cpp
src/hotspot/share/runtime/vmStructs.cpp
src/hotspot/share/services/memoryService.cpp
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/SerialHeap.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java
--- a/src/hotspot/share/gc/cms/cmsHeap.hpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/gc/cms/cmsHeap.hpp	Wed Oct 25 10:05:17 2017 +0200
@@ -39,14 +39,16 @@
 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 @@
   // 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;
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/serial/serialHeap.cpp	Wed Oct 25 10:05:17 2017 +0200
@@ -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");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/serial/serialHeap.hpp	Wed Oct 25 10:05:17 2017 +0200
@@ -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
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Wed Oct 25 10:05:17 2017 +0200
@@ -81,9 +81,10 @@
 //
 // CollectedHeap
 //   GenCollectedHeap
+//     SerialHeap
+//     CMSHeap
 //   G1CollectedHeap
 //   ParallelScavengeHeap
-//   CMSHeap
 //
 class CollectedHeap : public CHeapObj<mtInternal> {
   friend class VMStructs;
@@ -193,7 +194,7 @@
 
  public:
   enum Name {
-    GenCollectedHeap,
+    SerialHeap,
     ParallelScavengeHeap,
     G1CollectedHeap,
     CMSHeap
--- a/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.cpp	Wed Oct 25 10:05:17 2017 +0200
@@ -153,13 +153,6 @@
   _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 @@
 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;
 }
--- a/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/gc/shared/genCollectedHeap.hpp	Wed Oct 25 10:05:17 2017 +0200
@@ -83,6 +83,12 @@
                           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 @@
   // we absolutely __must__ clear soft refs?
   bool must_clear_all_soft_refs();
 
+  GenCollectedHeap(GenCollectorPolicy *policy);
+
+  virtual void check_gen_kinds() = 0;
+
 public:
-  GenCollectedHeap(GenCollectorPolicy *policy);
 
   // 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 @@
   // 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 @@
     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
--- a/src/hotspot/share/memory/universe.cpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/memory/universe.cpp	Wed Oct 25 10:05:17 2017 +0200
@@ -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 @@
     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();
--- a/src/hotspot/share/runtime/vmStructs.cpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/runtime/vmStructs.cpp	Wed Oct 25 10:05:17 2017 +0200
@@ -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 @@
   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 @@
                                                                           \
   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)                        \
                                                                           \
--- a/src/hotspot/share/services/memoryService.cpp	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/hotspot/share/services/memoryService.cpp	Wed Oct 25 10:05:17 2017 +0200
@@ -86,7 +86,7 @@
 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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/serial/SerialHeap.java	Wed Oct 25 10:05:17 2017 +0200
@@ -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;
+  }
+}
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/shared/CollectedHeapName.java	Wed Oct 25 10:05:17 2017 +0200
@@ -33,6 +33,7 @@
 
   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");
 
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java	Thu Nov 09 11:13:50 2017 -0800
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/Universe.java	Wed Oct 25 10:05:17 2017 +0200
@@ -28,6 +28,7 @@
 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 @@
     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);