< prev index next >

src/hotspot/share/memory/classLoaderMetaspace.hpp

Print this page

 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 #ifndef SHARE_MEMORY_CLASSLOADERMETASPACE_HPP
 25 #define SHARE_MEMORY_CLASSLOADERMETASPACE_HPP
 26 
 27 #include "memory/allocation.hpp"
 28 #include "memory/metaspace.hpp"
 29 #include "utilities/debug.hpp"
 30 #include "utilities/globalDefinitions.hpp"
 31 
 32 class outputStream;
 33 
 34 namespace metaspace {
 35   struct ClmsStats;

 36   class MetaspaceArena;

 37 }
 38 
 39 // A ClassLoaderMetaspace manages MetaspaceArena(s) for a CLD.
 40 //
 41 // A CLD owns one MetaspaceArena if UseCompressedClassPointers is false. Otherwise
 42 // it owns two - one for the Klass* objects from the class space, one for the other
 43 // types of MetaspaceObjs from the non-class space.
 44 //
 45 // +------+       +----------------------+       +-------------------+
 46 // | CLD  | --->  | ClassLoaderMetaspace | ----> | (non class) Arena |
 47 // +------+       +----------------------+  |    +-------------------+     allocation top
 48 //                                          |       |                        v
 49 //                                          |       + chunk -- chunk ... -- chunk
 50 //                                          |
 51 //                                          |    +-------------------+
 52 //                                          +--> | (class) Arena     |
 53 //                                               +-------------------+
 54 //                                                  |
 55 //                                                  + chunk ... chunk
 56 //                                                               ^
 57 //                                                               alloc top
 58 //
 59 class ClassLoaderMetaspace : public CHeapObj<mtClass> {

 60 
 61   // A reference to an outside lock, held by the CLD.
 62   Mutex* const _lock;
 63 
 64   const Metaspace::MetaspaceType _space_type;
 65 
 66   // Arena for allocations from non-class  metaspace
 67   //  (resp. for all allocations if -XX:-UseCompressedClassPointers).
 68   metaspace::MetaspaceArena* _non_class_space_arena;
 69 
 70   // Arena for allocations from class space
 71   //  (null if -XX:-UseCompressedClassPointers).
 72   metaspace::MetaspaceArena* _class_space_arena;
 73 
 74   Mutex* lock() const                             { return _lock; }
 75   metaspace::MetaspaceArena* non_class_space_arena() const   { return _non_class_space_arena; }
 76   metaspace::MetaspaceArena* class_space_arena() const       { return _class_space_arena; }
 77 
 78 public:





 79 

 80   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type);
 81 
 82   ~ClassLoaderMetaspace();
 83 
 84   Metaspace::MetaspaceType space_type() const { return _space_type; }
 85 
 86   // Allocate word_size words from Metaspace.
 87   MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdType);
 88 
 89   // Attempt to expand the GC threshold to be good for at least another word_size words
 90   // and allocate. Returns null if failure. Used during Metaspace GC.
 91   MetaWord* expand_and_allocate(size_t word_size, Metaspace::MetadataType mdType);
 92 
 93   // Prematurely returns a metaspace allocation to the _block_freelists
 94   // because it is not needed anymore.
 95   void deallocate(MetaWord* ptr, size_t word_size, bool is_class);
 96 
 97   // Update statistics. This walks all in-use chunks.
 98   void add_to_statistics(metaspace::ClmsStats* out) const;
 99 

 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 #ifndef SHARE_MEMORY_CLASSLOADERMETASPACE_HPP
 25 #define SHARE_MEMORY_CLASSLOADERMETASPACE_HPP
 26 
 27 #include "memory/allocation.hpp"
 28 #include "memory/metaspace.hpp"
 29 #include "utilities/debug.hpp"
 30 #include "utilities/globalDefinitions.hpp"
 31 
 32 class outputStream;
 33 
 34 namespace metaspace {
 35   struct ClmsStats;
 36   class ClmsTester;
 37   class MetaspaceArena;
 38   class MetaspaceContext;
 39 }
 40 
 41 // A ClassLoaderMetaspace manages MetaspaceArena(s) for a CLD.
 42 //
 43 // A CLD owns one MetaspaceArena if UseCompressedClassPointers is false. Otherwise
 44 // it owns two - one for the Klass* objects from the class space, one for the other
 45 // types of MetaspaceObjs from the non-class space.
 46 //
 47 // +------+       +----------------------+       +-------------------+
 48 // | CLD  | --->  | ClassLoaderMetaspace | ----> | (non class) Arena |
 49 // +------+       +----------------------+  |    +-------------------+     allocation top
 50 //                                          |       |                        v
 51 //                                          |       + chunk -- chunk ... -- chunk
 52 //                                          |
 53 //                                          |    +-------------------+
 54 //                                          +--> | (class) Arena     |
 55 //                                               +-------------------+
 56 //                                                  |
 57 //                                                  + chunk ... chunk
 58 //                                                               ^
 59 //                                                               alloc top
 60 //
 61 class ClassLoaderMetaspace : public CHeapObj<mtClass> {
 62   friend class metaspace::ClmsTester; // for gtests
 63 
 64   // A reference to an outside lock, held by the CLD.
 65   Mutex* const _lock;
 66 
 67   const Metaspace::MetaspaceType _space_type;
 68 
 69   // Arena for allocations from non-class  metaspace
 70   //  (resp. for all allocations if -XX:-UseCompressedClassPointers).
 71   metaspace::MetaspaceArena* _non_class_space_arena;
 72 
 73   // Arena for allocations from class space
 74   //  (null if -XX:-UseCompressedClassPointers).
 75   metaspace::MetaspaceArena* _class_space_arena;
 76 
 77   Mutex* lock() const                             { return _lock; }
 78   metaspace::MetaspaceArena* non_class_space_arena() const   { return _non_class_space_arena; }
 79   metaspace::MetaspaceArena* class_space_arena() const       { return _class_space_arena; }
 80 
 81   bool have_class_space_arena() const { return _class_space_arena != nullptr; }
 82 
 83   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type,
 84                        metaspace::MetaspaceContext* non_class_context,
 85                        metaspace::MetaspaceContext* class_context,
 86                        size_t klass_alignment_words);
 87 
 88 public:
 89   ClassLoaderMetaspace(Mutex* lock, Metaspace::MetaspaceType space_type);
 90 
 91   ~ClassLoaderMetaspace();
 92 
 93   Metaspace::MetaspaceType space_type() const { return _space_type; }
 94 
 95   // Allocate word_size words from Metaspace.
 96   MetaWord* allocate(size_t word_size, Metaspace::MetadataType mdType);
 97 
 98   // Attempt to expand the GC threshold to be good for at least another word_size words
 99   // and allocate. Returns null if failure. Used during Metaspace GC.
100   MetaWord* expand_and_allocate(size_t word_size, Metaspace::MetadataType mdType);
101 
102   // Prematurely returns a metaspace allocation to the _block_freelists
103   // because it is not needed anymore.
104   void deallocate(MetaWord* ptr, size_t word_size, bool is_class);
105 
106   // Update statistics. This walks all in-use chunks.
107   void add_to_statistics(metaspace::ClmsStats* out) const;
108 
< prev index next >