# HG changeset patch # User ehelin # Date 1440052945 -7200 # Node ID b84c2d16ba53e996b8040bcf2d5814dba0f68795 # Parent 4fd9c17bc240ed500965a4e992fc0d85c87dae61 8133821: Refactor initialization of the heap and the collector policy Reviewed-by: pliden, tschatzl diff -r 4fd9c17bc240 -r b84c2d16ba53 hotspot/src/share/vm/memory/universe.cpp --- a/hotspot/src/share/vm/memory/universe.cpp Wed Aug 19 11:11:06 2015 -0700 +++ b/hotspot/src/share/vm/memory/universe.cpp Thu Aug 20 08:42:25 2015 +0200 @@ -694,13 +694,29 @@ 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::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 -r 4fd9c17bc240 -r b84c2d16ba53 hotspot/src/share/vm/memory/universe.hpp --- a/hotspot/src/share/vm/memory/universe.hpp Wed Aug 19 11:11:06 2015 -0700 +++ b/hotspot/src/share/vm/memory/universe.hpp Thu Aug 20 08:42:25 2015 +0200 @@ -214,7 +214,9 @@ 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 -r 4fd9c17bc240 -r b84c2d16ba53 hotspot/src/share/vm/memory/universe.inline.hpp --- a/hotspot/src/share/vm/memory/universe.inline.hpp Wed Aug 19 11:11:06 2015 -0700 +++ b/hotspot/src/share/vm/memory/universe.inline.hpp Thu Aug 20 08:42:25 2015 +0200 @@ -49,4 +49,11 @@ _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 -r 4fd9c17bc240 -r b84c2d16ba53 hotspot/src/share/vm/memory/universe_ext.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hotspot/src/share/vm/memory/universe_ext.cpp Thu Aug 20 08:42:25 2015 +0200 @@ -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; +}