From 6ad40faac5fabd12bf0770764276a740cc3a2dbc Mon Sep 17 00:00:00 2001 From: Erik Helin Date: Thu, 20 Aug 2015 08:42:25 +0200 Subject: [PATCH] 8133821: Refactor initialization of the heap and the collector policy Reviewed-by: pliden, tschatzl --- hotspot/src/share/vm/memory/universe.cpp | 51 ++++++++++--------- hotspot/src/share/vm/memory/universe.hpp | 4 +- .../src/share/vm/memory/universe.inline.hpp | 7 +++ hotspot/src/share/vm/memory/universe_ext.cpp | 30 +++++++++++ 4 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 hotspot/src/share/vm/memory/universe_ext.cpp diff --git a/hotspot/src/share/vm/memory/universe.cpp b/hotspot/src/share/vm/memory/universe.cpp index 57fe41ab3aa..3a8359c4bb2 100644 --- a/hotspot/src/share/vm/memory/universe.cpp +++ b/hotspot/src/share/vm/memory/universe.cpp @@ -694,13 +694,29 @@ jint universe_init() { return JNI_OK; } -template -jint Universe::create_heap() { +CollectedHeap* Universe::create_heap() { assert(_collectedHeap == NULL, "Heap already created"); - Policy* policy = new Policy(); - policy->initialize_all(); - _collectedHeap = new Heap(policy); - return _collectedHeap->initialize(); +#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; } // Choose the heap base address and oop encoding mode @@ -714,27 +730,12 @@ jint Universe::create_heap() { jint Universe::initialize_heap() { jint status = JNI_ERR; -#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) { - status = Universe::create_heap(); - } else if (UseG1GC) { - status = Universe::create_heap(); - } else if (UseConcMarkSweepGC) { - status = Universe::create_heap(); -#endif - } else if (UseSerialGC) { - status = Universe::create_heap(); - } else { - ShouldNotReachHere(); + _collectedHeap = create_heap_ext(); + if (_collectedHeap == NULL) { + _collectedHeap = create_heap(); } + status = _collectedHeap->initialize(); if (status != JNI_OK) { return status; } diff --git a/hotspot/src/share/vm/memory/universe.hpp b/hotspot/src/share/vm/memory/universe.hpp index d79f1947c7f..56c2fca89e6 100644 --- a/hotspot/src/share/vm/memory/universe.hpp +++ b/hotspot/src/share/vm/memory/universe.hpp @@ -214,7 +214,9 @@ class Universe: AllStatic { static size_t _heap_capacity_at_last_gc; static size_t _heap_used_at_last_gc; - template static jint create_heap(); + template static CollectedHeap* create_heap_with_policy(); + static CollectedHeap* create_heap(); + static CollectedHeap* create_heap_ext(); static jint initialize_heap(); static void initialize_basic_type_mirrors(TRAPS); static void fixup_mirrors(TRAPS); diff --git a/hotspot/src/share/vm/memory/universe.inline.hpp b/hotspot/src/share/vm/memory/universe.inline.hpp index 3d0047c12ac..b770680d239 100644 --- a/hotspot/src/share/vm/memory/universe.inline.hpp +++ b/hotspot/src/share/vm/memory/universe.inline.hpp @@ -49,4 +49,11 @@ inline void Universe::set_allocation_context_notification_obj(oop obj) { _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 diff --git a/hotspot/src/share/vm/memory/universe_ext.cpp b/hotspot/src/share/vm/memory/universe_ext.cpp new file mode 100644 index 00000000000..5ed36b7fd80 --- /dev/null +++ b/hotspot/src/share/vm/memory/universe_ext.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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 "memory/universe.hpp" + +CollectedHeap* Universe::create_heap_ext() { + return NULL; +}