# HG changeset patch # User rkennke # Date 1510833209 -3600 # Thu Nov 16 12:53:29 2017 +0100 # Node ID b84c104d2175ddc8431f3ab8c49993ee8555f196 # Parent 4c42aa431f40a51a40c50f9e6a5fbac0df0f0e5e 8189389: Move heap creation into GC interface diff --git a/src/hotspot/share/gc/cms/cmsArguments.cpp b/src/hotspot/share/gc/cms/cmsArguments.cpp --- a/src/hotspot/share/gc/cms/cmsArguments.cpp +++ b/src/hotspot/share/gc/cms/cmsArguments.cpp @@ -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(); +} diff --git a/src/hotspot/share/gc/cms/cmsArguments.hpp b/src/hotspot/share/gc/cms/cmsArguments.hpp --- a/src/hotspot/share/gc/cms/cmsArguments.hpp +++ b/src/hotspot/share/gc/cms/cmsArguments.hpp @@ -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 diff --git a/src/hotspot/share/gc/g1/g1Arguments.cpp b/src/hotspot/share/gc/g1/g1Arguments.cpp --- a/src/hotspot/share/gc/g1/g1Arguments.cpp +++ b/src/hotspot/share/gc/g1/g1Arguments.cpp @@ -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(); +} diff --git a/src/hotspot/share/gc/g1/g1Arguments.hpp b/src/hotspot/share/gc/g1/g1Arguments.hpp --- a/src/hotspot/share/gc/g1/g1Arguments.hpp +++ b/src/hotspot/share/gc/g1/g1Arguments.hpp @@ -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 diff --git a/src/hotspot/share/gc/parallel/parallelArguments.cpp b/src/hotspot/share/gc/parallel/parallelArguments.cpp --- a/src/hotspot/share/gc/parallel/parallelArguments.cpp +++ b/src/hotspot/share/gc/parallel/parallelArguments.cpp @@ -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(); +} diff --git a/src/hotspot/share/gc/parallel/parallelArguments.hpp b/src/hotspot/share/gc/parallel/parallelArguments.hpp --- a/src/hotspot/share/gc/parallel/parallelArguments.hpp +++ b/src/hotspot/share/gc/parallel/parallelArguments.hpp @@ -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 diff --git a/src/hotspot/share/gc/serial/serialArguments.cpp b/src/hotspot/share/gc/serial/serialArguments.cpp --- a/src/hotspot/share/gc/serial/serialArguments.cpp +++ b/src/hotspot/share/gc/serial/serialArguments.cpp @@ -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(); +} diff --git a/src/hotspot/share/gc/serial/serialArguments.hpp b/src/hotspot/share/gc/serial/serialArguments.hpp --- a/src/hotspot/share/gc/serial/serialArguments.hpp +++ b/src/hotspot/share/gc/serial/serialArguments.hpp @@ -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 diff --git a/src/hotspot/share/gc/shared/gcArguments.hpp b/src/hotspot/share/gc/shared/gcArguments.hpp --- a/src/hotspot/share/gc/shared/gcArguments.hpp +++ b/src/hotspot/share/gc/shared/gcArguments.hpp @@ -27,6 +27,8 @@ #include "memory/allocation.hpp" +class CollectedHeap; + class GCArguments : public CHeapObj { private: static GCArguments* _instance; @@ -35,6 +37,10 @@ static void select_gc_ergonomically(); static bool gc_selected(); +protected: + template + 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 diff --git a/src/hotspot/share/gc/shared/gcArguments.inline.hpp b/src/hotspot/share/gc/shared/gcArguments.inline.hpp new file mode 100644 --- /dev/null +++ b/src/hotspot/share/gc/shared/gcArguments.inline.hpp @@ -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 +CollectedHeap* GCArguments::create_heap_with_policy() { + Policy* policy = new Policy(); + policy->initialize_all(); + return new Heap(policy); +} diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -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(); - } else if (UseG1GC) { - return Universe::create_heap_with_policy(); - } else if (UseConcMarkSweepGC) { - return Universe::create_heap_with_policy(); -#endif - } else if (UseSerialGC) { - return Universe::create_heap_with_policy(); - } - - 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 diff --git a/src/hotspot/share/memory/universe.hpp b/src/hotspot/share/memory/universe.hpp --- a/src/hotspot/share/memory/universe.hpp +++ b/src/hotspot/share/memory/universe.hpp @@ -220,7 +220,6 @@ static size_t _heap_capacity_at_last_gc; static size_t _heap_used_at_last_gc; - template static CollectedHeap* create_heap_with_policy(); static CollectedHeap* create_heap(); static CollectedHeap* create_heap_ext(); static jint initialize_heap(); diff --git a/src/hotspot/share/memory/universe.inline.hpp b/src/hotspot/share/memory/universe.inline.hpp --- a/src/hotspot/share/memory/universe.inline.hpp +++ b/src/hotspot/share/memory/universe.inline.hpp @@ -49,11 +49,4 @@ _allocation_context_notification_obj = obj; } -template -CollectedHeap* Universe::create_heap_with_policy() { - Policy* policy = new Policy(); - policy->initialize_all(); - return new Heap(policy); -} - #endif // SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP