1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2020 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 28 #include "memory/metaspace/msChunkManager.hpp" 29 #include "memory/metaspace/msCommitLimiter.hpp" 30 #include "memory/metaspace/msContext.hpp" 31 #include "memory/metaspace/msVirtualSpaceList.hpp" 32 #include "utilities/debug.hpp" 33 #include "utilities/globalDefinitions.hpp" 34 #include "utilities/ostream.hpp" 35 36 namespace metaspace { 37 38 MetaspaceContext* MetaspaceContext::_class_space_context = NULL; 39 MetaspaceContext* MetaspaceContext::_nonclass_space_context = NULL; 40 41 // Destroys the context: deletes chunkmanager and virtualspacelist. 42 // If this is a non-expandable context over an existing space, that space remains 43 // untouched, otherwise all memory is unmapped. 44 // Note: the standard metaspace contexts (non-class context and class context) are 45 // never deleted. This code only exists for the sake of tests and for future reuse 46 // of metaspace contexts in different scenarios. 47 MetaspaceContext::~MetaspaceContext() { 48 delete _cm; 49 delete _vslist; 50 } 51 52 // Create a new, empty, expandable metaspace context. 53 MetaspaceContext* MetaspaceContext::create_expandable_context(const char* name, CommitLimiter* commit_limiter) { 54 VirtualSpaceList* vsl = new VirtualSpaceList(name, commit_limiter); 55 ChunkManager* cm = new ChunkManager(name, vsl); 56 return new MetaspaceContext(name, vsl, cm); 57 } 58 59 // Create a new, empty, non-expandable metaspace context atop of an externally provided space. 60 MetaspaceContext* MetaspaceContext::create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter) { 61 VirtualSpaceList* vsl = new VirtualSpaceList(name, rs, commit_limiter); 62 ChunkManager* cm = new ChunkManager(name, vsl); 63 return new MetaspaceContext(name, vsl, cm); 64 } 65 66 void MetaspaceContext::initialize_class_space_context(ReservedSpace rs) { 67 _class_space_context = create_nonexpandable_context("class-space", rs, CommitLimiter::globalLimiter()); 68 } 69 70 void MetaspaceContext::initialize_nonclass_space_context() { 71 _nonclass_space_context = create_expandable_context("non-class-space", CommitLimiter::globalLimiter()); 72 } 73 74 void MetaspaceContext::print_on(outputStream* st) const { 75 _vslist->print_on(st); 76 _cm->print_on(st); 77 } 78 79 #ifdef ASSERT 80 void MetaspaceContext::verify() const { 81 _vslist->verify(); 82 _cm->verify(); 83 } 84 #endif // ASSERT 85 86 } // namespace metaspace 87