1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP 26 #define SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP 27 28 #include "memory/allocation.hpp" 29 #include "memory/metaspace/metaspaceCommon.hpp" 30 #include "memory/metaspace/spaceManager.hpp" 31 32 namespace metaspace { 33 34 35 class ClassLoaderMetaspace : public CHeapObj<mtClass> { 36 37 // The CLD lock. 38 Mutex* const _lock; 39 40 const Metaspace::MetaspaceType _space_type; 41 42 metaspace::SpaceManager* _non_class_space_manager; 43 metaspace::SpaceManager* _class_space_manager; 44 45 Mutex* lock() const { return _lock; } 46 metaspace::SpaceManager* non_class_space_manager() const { return _non_class_space_manager; } 47 metaspace::SpaceManager* class_space_manager() const { return _class_space_manager; } 48 49 metaspace::SpaceManager* get_space_manager(bool is_class) { 50 return is_class ? class_space_manager() : non_class_space_manager(); 51 } 52 53 public: 54 55 ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type); 56 57 ~ClassLoaderMetaspace(); 58 59 // Allocate word_size words from Metaspace. 60 MetaWord* allocate(size_t word_size, bool is_class); 61 62 // Attempt to expand the GC threshold to be good for at least another word_size words 63 // and allocate. Returns NULL if failure. Used during Metaspace GC. 64 MetaWord* expand_GC_threshold_and_allocate(size_t word_size, bool is_class); 65 66 // Prematurely returns a metaspace allocation to the _block_freelists 67 // because it is not needed anymore. 68 void deallocate(MetaWord* ptr, size_t word_size, bool is_class); 69 70 71 DEBUG_ONLY(void verify(bool slow) const;) 72 73 }; 74 75 } // namespace metaspace 76 77 #endif // SHARE_MEMORY_METASPACE_CHUNKMANAGER_HPP