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/chunkManager.hpp" 29 #include "memory/metaspace/metaspaceContext.hpp" 30 #include "memory/metaspace/virtualSpaceList.hpp" 31 #include "utilities/debug.hpp" 32 #include "utilities/globalDefinitions.hpp" 33 #include "utilities/ostream.hpp" 34 35 36 namespace metaspace { 37 38 #define LOGFMT "SpcMgr @" PTR_FORMAT " (%s)" 39 #define LOGFMT_ARGS p2i(this), this->_name 40 41 42 MetaspaceContext* MetaspaceContext::_class_space_context = NULL; 43 MetaspaceContext* MetaspaceContext::_nonclass_space_context = NULL; 44 45 // Destroys the context: deletes chunkmanager and virtualspacelist. 46 // If this is a non-expandable context over an existing space, that space remains 47 // untouched, otherwise all memory is unmapped. 48 MetaspaceContext::~MetaspaceContext() { 49 delete _cm; 50 delete _vslist; 51 } 52 53 // Create a new, empty, expandable metaspace context. 54 MetaspaceContext* MetaspaceContext::create_expandable_context(const char* name, CommitLimiter* commit_limiter) { 55 VirtualSpaceList* vsl = new VirtualSpaceList(name, commit_limiter); 56 ChunkManager* cm = new ChunkManager(name, vsl); 57 return new MetaspaceContext(name, vsl, cm); 58 } 59 60 // Create a new, empty, non-expandable metaspace context atop of an externally provided space. 61 MetaspaceContext* MetaspaceContext::create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter) { 62 VirtualSpaceList* vsl = new VirtualSpaceList(name, rs, commit_limiter); 63 ChunkManager* cm = new ChunkManager(name, vsl); 64 return new MetaspaceContext(name, vsl, cm); 65 } 66 67 68 void MetaspaceContext::initialize_class_space_context(ReservedSpace rs) { 69 _class_space_context = create_nonexpandable_context("class-space", rs, CommitLimiter::globalLimiter()); 70 } 71 72 void MetaspaceContext::initialize_nonclass_space_context() { 73 _nonclass_space_context = create_expandable_context("non-class-space", CommitLimiter::globalLimiter()); 74 } 75 76 void MetaspaceContext::print_on(outputStream* st) const { 77 _vslist->print_on(st); 78 _cm->print_on(st); 79 } 80 81 #ifdef ASSERT 82 void MetaspaceContext::verify(bool slow) const { 83 _vslist->verify(slow); 84 _cm->verify(slow); 85 } 86 #endif // ASSERT 87 88 } // namespace metaspace 89