8189389: Move heap creation into GC interface
authorrkennke
Thu, 16 Nov 2017 12:53:29 +0100
changeset 47913 cde4a65ba47d
parent 47912 7397b5b2d3b2
child 47914 564882d918d4
8189389: Move heap creation into GC interface Reviewed-by: pliden, eosterlund
src/hotspot/share/gc/cms/cmsArguments.cpp
src/hotspot/share/gc/cms/cmsArguments.hpp
src/hotspot/share/gc/g1/g1Arguments.cpp
src/hotspot/share/gc/g1/g1Arguments.hpp
src/hotspot/share/gc/parallel/parallelArguments.cpp
src/hotspot/share/gc/parallel/parallelArguments.hpp
src/hotspot/share/gc/serial/serialArguments.cpp
src/hotspot/share/gc/serial/serialArguments.hpp
src/hotspot/share/gc/shared/gcArguments.hpp
src/hotspot/share/gc/shared/gcArguments.inline.hpp
src/hotspot/share/memory/universe.cpp
src/hotspot/share/memory/universe.hpp
src/hotspot/share/memory/universe.inline.hpp
--- a/src/hotspot/share/gc/cms/cmsArguments.cpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/cms/cmsArguments.cpp	Thu Nov 16 12:53:29 2017 +0100
@@ -24,7 +24,10 @@
 
 #include "precompiled.hpp"
 #include "gc/cms/cmsArguments.hpp"
+#include "gc/cms/cmsCollectorPolicy.hpp"
+#include "gc/cms/cmsHeap.hpp"
 #include "gc/cms/compactibleFreeListSpace.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
 #include "gc/shared/genCollectedHeap.hpp"
 #include "runtime/arguments.hpp"
 #include "runtime/globals.hpp"
@@ -192,3 +195,7 @@
     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
   }
 }
+
+CollectedHeap* CMSArguments::create_heap() {
+  return create_heap_with_policy<CMSHeap, ConcurrentMarkSweepPolicy>();
+}
--- a/src/hotspot/share/gc/cms/cmsArguments.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/cms/cmsArguments.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -27,6 +27,8 @@
 
 #include "gc/shared/gcArguments.hpp"
 
+class CollectedHeap;
+
 class CMSArguments : public GCArguments {
 private:
   void disable_adaptive_size_policy(const char* collector_name);
@@ -34,6 +36,7 @@
 public:
   virtual void initialize_flags();
   virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
 };
 
 #endif // SHARE_GC_CMS_CMSARGUMENTS_HPP
--- a/src/hotspot/share/gc/g1/g1Arguments.cpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/g1/g1Arguments.cpp	Thu Nov 16 12:53:29 2017 +0100
@@ -24,7 +24,10 @@
 
 #include "precompiled.hpp"
 #include "gc/g1/g1Arguments.hpp"
+#include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1CollectorPolicy.hpp"
 #include "gc/g1/heapRegion.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
 #include "runtime/globals.hpp"
 #include "runtime/globals_extension.hpp"
 #include "runtime/vm_version.hpp"
@@ -90,3 +93,7 @@
 
   log_trace(gc)("MarkStackSize: %uk  MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
 }
+
+CollectedHeap* G1Arguments::create_heap() {
+  return create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
+}
--- a/src/hotspot/share/gc/g1/g1Arguments.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/g1/g1Arguments.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -27,10 +27,13 @@
 
 #include "gc/shared/gcArguments.hpp"
 
+class CollectedHeap;
+
 class G1Arguments : public GCArguments {
 public:
   virtual void initialize_flags();
   virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
 };
 
 #endif // SHARE_GC_G1_G1ARGUMENTS_HPP
--- a/src/hotspot/share/gc/parallel/parallelArguments.cpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/parallel/parallelArguments.cpp	Thu Nov 16 12:53:29 2017 +0100
@@ -24,7 +24,10 @@
 
 #include "precompiled.hpp"
 #include "gc/parallel/parallelArguments.hpp"
+#include "gc/parallel/parallelScavengeHeap.hpp"
+#include "gc/shared/adaptiveSizePolicy.hpp"
 #include "gc/shared/collectorPolicy.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
 #include "runtime/globals.hpp"
 #include "runtime/globals_extension.hpp"
 #include "runtime/java.hpp"
@@ -87,3 +90,7 @@
     }
   }
 }
+
+CollectedHeap* ParallelArguments::create_heap() {
+  return create_heap_with_policy<ParallelScavengeHeap, GenerationSizer>();
+}
--- a/src/hotspot/share/gc/parallel/parallelArguments.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/parallel/parallelArguments.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -27,10 +27,13 @@
 
 #include "gc/shared/gcArguments.hpp"
 
+class CollectedHeap;
+
 class ParallelArguments : public GCArguments {
 public:
   virtual void initialize_flags();
   virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
 };
 
 #endif // SHARE_GC_CMS_PARALLELARGUMENTS_HPP
--- a/src/hotspot/share/gc/serial/serialArguments.cpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/serial/serialArguments.cpp	Thu Nov 16 12:53:29 2017 +0100
@@ -24,8 +24,15 @@
 
 #include "precompiled.hpp"
 #include "gc/serial/serialArguments.hpp"
+#include "gc/serial/serialHeap.hpp"
+#include "gc/shared/collectorPolicy.hpp"
+#include "gc/shared/gcArguments.inline.hpp"
 #include "gc/shared/genCollectedHeap.hpp"
 
 size_t SerialArguments::conservative_max_heap_alignment() {
   return GenCollectedHeap::conservative_max_heap_alignment();
 }
+
+CollectedHeap* SerialArguments::create_heap() {
+  return create_heap_with_policy<SerialHeap, MarkSweepPolicy>();
+}
--- a/src/hotspot/share/gc/serial/serialArguments.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/serial/serialArguments.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -27,9 +27,12 @@
 
 #include "gc/shared/gcArguments.hpp"
 
+class CollectedHeap;
+
 class SerialArguments : public GCArguments {
 public:
   virtual size_t conservative_max_heap_alignment();
+  virtual CollectedHeap* create_heap();
 };
 
 #endif // SHARE_GC_SERIAL_SERIALARGUMENTS_HPP
--- a/src/hotspot/share/gc/shared/gcArguments.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/gc/shared/gcArguments.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -27,6 +27,8 @@
 
 #include "memory/allocation.hpp"
 
+class CollectedHeap;
+
 class GCArguments : public CHeapObj<mtGC> {
 private:
   static GCArguments* _instance;
@@ -35,6 +37,10 @@
   static void select_gc_ergonomically();
   static bool gc_selected();
 
+protected:
+  template <class Heap, class Policy>
+  CollectedHeap* create_heap_with_policy();
+
 public:
   static jint initialize();
   static bool is_initialized();
@@ -43,6 +49,8 @@
   virtual void initialize_flags();
 
   virtual size_t conservative_max_heap_alignment() = 0;
+
+  virtual CollectedHeap* create_heap() = 0;
 };
 
 #endif // SHARE_GC_SHARED_GCARGUMENTS_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/gc/shared/gcArguments.inline.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ *
+ */
+
+#include "gc/shared/gcArguments.hpp"
+
+class CollectedHeap;
+
+template <class Heap, class Policy>
+CollectedHeap* GCArguments::create_heap_with_policy() {
+  Policy* policy = new Policy();
+  policy->initialize_all();
+  return new Heap(policy);
+}
--- a/src/hotspot/share/memory/universe.cpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/memory/universe.cpp	Thu Nov 16 12:53:29 2017 +0100
@@ -32,9 +32,9 @@
 #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/gcArguments.hpp"
 #include "gc/shared/gcLocker.inline.hpp"
 #include "gc/shared/generation.hpp"
 #include "gc/shared/gcTraceTime.inline.hpp"
@@ -82,14 +82,6 @@
 #include "utilities/macros.hpp"
 #include "utilities/ostream.hpp"
 #include "utilities/preserveException.hpp"
-#if INCLUDE_ALL_GCS
-#include "gc/cms/cmsCollectorPolicy.hpp"
-#include "gc/cms/cmsHeap.hpp"
-#include "gc/g1/g1CollectedHeap.inline.hpp"
-#include "gc/g1/g1CollectorPolicy.hpp"
-#include "gc/parallel/parallelScavengeHeap.hpp"
-#include "gc/shared/adaptiveSizePolicy.hpp"
-#endif // INCLUDE_ALL_GCS
 #if INCLUDE_CDS
 #include "classfile/sharedClassUtil.hpp"
 #endif
@@ -746,27 +738,8 @@
 
 CollectedHeap* Universe::create_heap() {
   assert(_collectedHeap == NULL, "Heap already created");
-#if !INCLUDE_ALL_GCS
-  if (UseParallelGC) {
-    fatal("UseParallelGC not supported in this VM.");
-  } else if (UseG1GC) {
-    fatal("UseG1GC not supported in this VM.");
-  } else if (UseConcMarkSweepGC) {
-    fatal("UseConcMarkSweepGC not supported in this VM.");
-#else
-  if (UseParallelGC) {
-    return Universe::create_heap_with_policy<ParallelScavengeHeap, GenerationSizer>();
-  } else if (UseG1GC) {
-    return Universe::create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
-  } else if (UseConcMarkSweepGC) {
-    return Universe::create_heap_with_policy<CMSHeap, ConcurrentMarkSweepPolicy>();
-#endif
-  } else if (UseSerialGC) {
-    return Universe::create_heap_with_policy<SerialHeap, MarkSweepPolicy>();
-  }
-
-  ShouldNotReachHere();
-  return NULL;
+  assert(GCArguments::is_initialized(), "GC must be initialized here");
+  return GCArguments::arguments()->create_heap();
 }
 
 // Choose the heap base address and oop encoding mode
--- a/src/hotspot/share/memory/universe.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/memory/universe.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -220,7 +220,6 @@
   static size_t _heap_capacity_at_last_gc;
   static size_t _heap_used_at_last_gc;
 
-  template <class Heap, class Policy> static CollectedHeap* create_heap_with_policy();
   static CollectedHeap* create_heap();
   static CollectedHeap* create_heap_ext();
   static jint initialize_heap();
--- a/src/hotspot/share/memory/universe.inline.hpp	Thu Nov 16 17:10:21 2017 +0100
+++ b/src/hotspot/share/memory/universe.inline.hpp	Thu Nov 16 12:53:29 2017 +0100
@@ -49,11 +49,4 @@
   _allocation_context_notification_obj = obj;
 }
 
-template <class Heap, class Policy>
-CollectedHeap* Universe::create_heap_with_policy() {
-  Policy* policy = new Policy();
-  policy->initialize_all();
-  return new Heap(policy);
-}
-
 #endif // SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP