< prev index next >

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

Print this page

 77 class MetaspaceArena : public CHeapObj<mtClass> {
 78 
 79   // Reference to an outside lock to use for synchronizing access to this arena.
 80   //  This lock is normally owned by the CLD which owns the ClassLoaderMetaspace which
 81   //  owns this arena.
 82   // Todo: This should be changed. Either the CLD should synchronize access to the
 83   //       CLMS and its arenas itself, or the arena should have an own lock. The latter
 84   //       would allow for more fine granular locking since it would allow access to
 85   //       both class- and non-class arena in the CLMS independently.
 86   Mutex* const _lock;
 87 
 88   // Reference to the chunk manager to allocate chunks from.
 89   ChunkManager* const _chunk_manager;
 90 
 91   // Reference to the growth policy to use.
 92   const ArenaGrowthPolicy* const _growth_policy;
 93 
 94   // List of chunks. Head of the list is the current chunk.
 95   MetachunkList _chunks;
 96 



 97   // Structure to take care of leftover/deallocated space in used chunks.
 98   // Owned by the Arena. Gets allocated on demand only.
 99   FreeBlocks* _fbl;
100 
101   Metachunk* current_chunk()              { return _chunks.first(); }
102   const Metachunk* current_chunk() const  { return _chunks.first(); }
103 
104   // Reference to an outside counter to keep track of used space.
105   SizeAtomicCounter* const _total_used_words_counter;
106 
107   // A name for purely debugging/logging purposes.
108   const char* const _name;
109 
110 #ifdef ASSERT
111   // Allocation guards: When active, arena allocations are interleaved with
112   //  fence allocations. An overwritten fence indicates a buffer overrun in either
113   //  the preceding or the following user block. All fences are linked together;
114   //  validating the fences just means walking that linked list.
115   // Note that for the Arena, fence blocks are just another form of user blocks.
116   class Fence {

147 
148   // Attempt to enlarge the current chunk to make it large enough to hold at least
149   //  requested_word_size additional words.
150   //
151   // On success, true is returned, false otherwise.
152   bool attempt_enlarge_current_chunk(size_t requested_word_size);
153 
154   // Prematurely returns a metaspace allocation to the _block_freelists
155   // because it is not needed anymore (requires CLD lock to be active).
156   void deallocate_locked(MetaWord* p, size_t word_size);
157 
158   // Returns true if the area indicated by pointer and size have actually been allocated
159   // from this arena.
160   DEBUG_ONLY(bool is_valid_area(MetaWord* p, size_t word_size) const;)
161 
162   // Allocate from the arena proper, once dictionary allocations and fencing are sorted out.
163   MetaWord* allocate_inner(size_t word_size);
164 
165 public:
166 
167   MetaspaceArena(ChunkManager* chunk_manager, const ArenaGrowthPolicy* growth_policy,
168                  Mutex* lock, SizeAtomicCounter* total_used_words_counter,
169                  const char* name);
170 
171   ~MetaspaceArena();
172 
173   // Allocate memory from Metaspace.
174   // 1) Attempt to allocate from the dictionary of deallocated blocks.
175   // 2) Attempt to allocate from the current chunk.
176   // 3) Attempt to enlarge the current chunk in place if it is too small.
177   // 4) Attempt to get a new chunk and allocate from that chunk.
178   // At any point, if we hit a commit limit, we return NULL.
179   MetaWord* allocate(size_t word_size);
180 
181   // Prematurely returns a metaspace allocation to the _block_freelists because it is not
182   // needed anymore.
183   void deallocate(MetaWord* p, size_t word_size);
184 
185   // Update statistics. This walks all in-use chunks.
186   void add_to_statistics(ArenaStats* out) const;
187 

 77 class MetaspaceArena : public CHeapObj<mtClass> {
 78 
 79   // Reference to an outside lock to use for synchronizing access to this arena.
 80   //  This lock is normally owned by the CLD which owns the ClassLoaderMetaspace which
 81   //  owns this arena.
 82   // Todo: This should be changed. Either the CLD should synchronize access to the
 83   //       CLMS and its arenas itself, or the arena should have an own lock. The latter
 84   //       would allow for more fine granular locking since it would allow access to
 85   //       both class- and non-class arena in the CLMS independently.
 86   Mutex* const _lock;
 87 
 88   // Reference to the chunk manager to allocate chunks from.
 89   ChunkManager* const _chunk_manager;
 90 
 91   // Reference to the growth policy to use.
 92   const ArenaGrowthPolicy* const _growth_policy;
 93 
 94   // List of chunks. Head of the list is the current chunk.
 95   MetachunkList _chunks;
 96 
 97   // Alignment alignment, in words.
 98   const int _alignment_words;
 99 
100   // Structure to take care of leftover/deallocated space in used chunks.
101   // Owned by the Arena. Gets allocated on demand only.
102   FreeBlocks* _fbl;
103 
104   Metachunk* current_chunk()              { return _chunks.first(); }
105   const Metachunk* current_chunk() const  { return _chunks.first(); }
106 
107   // Reference to an outside counter to keep track of used space.
108   SizeAtomicCounter* const _total_used_words_counter;
109 
110   // A name for purely debugging/logging purposes.
111   const char* const _name;
112 
113 #ifdef ASSERT
114   // Allocation guards: When active, arena allocations are interleaved with
115   //  fence allocations. An overwritten fence indicates a buffer overrun in either
116   //  the preceding or the following user block. All fences are linked together;
117   //  validating the fences just means walking that linked list.
118   // Note that for the Arena, fence blocks are just another form of user blocks.
119   class Fence {

150 
151   // Attempt to enlarge the current chunk to make it large enough to hold at least
152   //  requested_word_size additional words.
153   //
154   // On success, true is returned, false otherwise.
155   bool attempt_enlarge_current_chunk(size_t requested_word_size);
156 
157   // Prematurely returns a metaspace allocation to the _block_freelists
158   // because it is not needed anymore (requires CLD lock to be active).
159   void deallocate_locked(MetaWord* p, size_t word_size);
160 
161   // Returns true if the area indicated by pointer and size have actually been allocated
162   // from this arena.
163   DEBUG_ONLY(bool is_valid_area(MetaWord* p, size_t word_size) const;)
164 
165   // Allocate from the arena proper, once dictionary allocations and fencing are sorted out.
166   MetaWord* allocate_inner(size_t word_size);
167 
168 public:
169 
170   MetaspaceArena(ChunkManager* chunk_manager, const ArenaGrowthPolicy* growth_policy, int alignment_words,
171                  Mutex* lock, SizeAtomicCounter* total_used_words_counter,
172                  const char* name);
173 
174   ~MetaspaceArena();
175 
176   // Allocate memory from Metaspace.
177   // 1) Attempt to allocate from the dictionary of deallocated blocks.
178   // 2) Attempt to allocate from the current chunk.
179   // 3) Attempt to enlarge the current chunk in place if it is too small.
180   // 4) Attempt to get a new chunk and allocate from that chunk.
181   // At any point, if we hit a commit limit, we return NULL.
182   MetaWord* allocate(size_t word_size);
183 
184   // Prematurely returns a metaspace allocation to the _block_freelists because it is not
185   // needed anymore.
186   void deallocate(MetaWord* p, size_t word_size);
187 
188   // Update statistics. This walks all in-use chunks.
189   void add_to_statistics(ArenaStats* out) const;
190 
< prev index next >