< prev index next >

src/hotspot/share/memory/metaspace/metaspaceContext.hpp

Print this page

 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 #ifndef SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
 27 #define SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
 28 
 29 #include "memory/allocation.hpp"

 30 #include "memory/virtualspace.hpp"
 31 #include "utilities/debug.hpp"
 32 
 33 class outputStream;
 34 
 35 namespace metaspace {
 36 
 37 class ChunkManager;
 38 class VirtualSpaceList;
 39 class CommitLimiter;
 40 
 41 // MetaspaceContext is a convenience bracket around:
 42 //
 43 // - a VirtualSpaceList managing a memory area used for Metaspace
 44 // - a ChunkManager sitting atop of that which manages chunk freelists
 45 //
 46 // In a normal VM only one or two of these contexts ever exist: one for the metaspace, and
 47 //  optionally another one for the compressed class space.
 48 //
 49 // For tests more contexts may be created, and this would also be a way to use Metaspace
 50 //  for things other than class metadata. We would have to work on the naming then.
 51 //
 52 // - (Future TODO): Context should own a lock to guard it. Currently this stuff is guarded
 53 //     by one global lock, the slightly misnamed Metaspace_expandlock, but that one
 54 //     should be split into one per context.
 55 // - (Future TODO): Context can/should have its own allocation alignment. That way we
 56 //     can have different alignment between class space and non-class metaspace. That could
 57 //     help optimize compressed class pointer encoding, see discussion for JDK-8244943).
 58 
 59 class MetaspaceContext : public CHeapObj<mtMetaspace> {
 60 
 61   const char* const _name;
 62   VirtualSpaceList* const _vslist;
 63   ChunkManager* const _cm;

 64 
 65   MetaspaceContext(const char* name, VirtualSpaceList* vslist, ChunkManager* cm) :
 66     _name(name),
 67     _vslist(vslist),
 68     _cm(cm)
 69   {}
 70 
 71   static MetaspaceContext* _nonclass_space_context;
 72   static MetaspaceContext* _class_space_context;
 73 
 74 public:
 75 
 76   // Destroys the context: deletes chunkmanager and virtualspacelist.
 77   // If this is a non-expandable context over an existing space, that space remains
 78   // untouched, otherwise all memory is unmapped.
 79   ~MetaspaceContext();
 80 
 81   VirtualSpaceList* vslist() { return _vslist; }
 82   ChunkManager* cm() { return _cm; }

 83 
 84   // Create a new, empty, expandable metaspace context.
 85   static MetaspaceContext* create_expandable_context(const char* name, CommitLimiter* commit_limiter);
 86 
 87   // Create a new, empty, non-expandable metaspace context atop of an externally provided space.
 88   static MetaspaceContext* create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter);
 89 
 90   void print_on(outputStream* st) const;
 91 
 92   DEBUG_ONLY(void verify() const;)
 93 
 94   static void initialize_class_space_context(ReservedSpace rs);
 95   static void initialize_nonclass_space_context();
 96 
 97   // Returns pointer to the global metaspace context.
 98   // If compressed class space is active, this contains the non-class-space allocations.
 99   // If compressed class space is inactive, this contains all metaspace allocations.
100   static MetaspaceContext* context_nonclass()     { return _nonclass_space_context; }
101 
102   // Returns pointer to the global class space context, if compressed class space is active,
103   // null otherwise.
104   static MetaspaceContext* context_class()        { return _class_space_context; }
105 



106 };
107 
108 } // end namespace
109 
110 #endif // SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
111 

 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 #ifndef SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
 27 #define SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
 28 
 29 #include "memory/allocation.hpp"
 30 #include "memory/metaspace/counters.hpp"
 31 #include "memory/virtualspace.hpp"
 32 #include "utilities/debug.hpp"
 33 
 34 class outputStream;
 35 
 36 namespace metaspace {
 37 
 38 class ChunkManager;
 39 class VirtualSpaceList;
 40 class CommitLimiter;
 41 
 42 // MetaspaceContext is a convenience bracket around:
 43 //
 44 // - a VirtualSpaceList managing a memory area used for Metaspace
 45 // - a ChunkManager sitting atop of that which manages chunk freelists
 46 //
 47 // In a normal VM only one or two of these contexts ever exist: one for the metaspace, and
 48 //  optionally another one for the compressed class space.
 49 //
 50 // For tests more contexts may be created, and this would also be a way to use Metaspace
 51 //  for things other than class metadata. We would have to work on the naming then.
 52 //
 53 // - (Future TODO): Context should own a lock to guard it. Currently this stuff is guarded
 54 //     by one global lock, the slightly misnamed Metaspace_expandlock, but that one
 55 //     should be split into one per context.
 56 // - (Future TODO): Context can/should have its own allocation alignment. That way we
 57 //     can have different alignment between class space and non-class metaspace. That could
 58 //     help optimize compressed class pointer encoding, see discussion for JDK-8244943).
 59 
 60 class MetaspaceContext : public CHeapObj<mtMetaspace> {
 61 
 62   const char* const _name;
 63   VirtualSpaceList* const _vslist;
 64   ChunkManager* const _cm;
 65   SizeAtomicCounter _used_words_counter;
 66 
 67   MetaspaceContext(const char* name, VirtualSpaceList* vslist, ChunkManager* cm) :
 68     _name(name),
 69     _vslist(vslist),
 70     _cm(cm)
 71   {}
 72 
 73   static MetaspaceContext* _nonclass_space_context;
 74   static MetaspaceContext* _class_space_context;
 75 
 76 public:
 77 
 78   // Destroys the context: deletes chunkmanager and virtualspacelist.
 79   // If this is a non-expandable context over an existing space, that space remains
 80   // untouched, otherwise all memory is unmapped.
 81   ~MetaspaceContext();
 82 
 83   VirtualSpaceList* vslist()                    { return _vslist; }
 84   ChunkManager* cm()                            { return _cm; }
 85   SizeAtomicCounter* used_words_counter()       { return &_used_words_counter; }
 86 
 87   // Create a new, empty, expandable metaspace context.
 88   static MetaspaceContext* create_expandable_context(const char* name, CommitLimiter* commit_limiter);
 89 
 90   // Create a new, empty, non-expandable metaspace context atop of an externally provided space.
 91   static MetaspaceContext* create_nonexpandable_context(const char* name, ReservedSpace rs, CommitLimiter* commit_limiter);
 92 
 93   void print_on(outputStream* st) const;
 94 
 95   DEBUG_ONLY(void verify() const;)
 96 
 97   static void initialize_class_space_context(ReservedSpace rs);
 98   static void initialize_nonclass_space_context();
 99 
100   // Returns pointer to the global metaspace context.
101   // If compressed class space is active, this contains the non-class-space allocations.
102   // If compressed class space is inactive, this contains all metaspace allocations.
103   static MetaspaceContext* context_nonclass()     { return _nonclass_space_context; }
104 
105   // Returns pointer to the global class space context, if compressed class space is active,
106   // null otherwise.
107   static MetaspaceContext* context_class()        { return _class_space_context; }
108 
109   size_t used_words() const;
110   size_t committed_words() const;
111   size_t reserved_words() const;
112 };
113 
114 } // end namespace
115 
116 #endif // SHARE_MEMORY_METASPACE_METASPACECONTEXT_HPP
117 
< prev index next >