comparison src/share/vm/memory/metaspace.hpp @ 12838:85c1ca43713f

8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces Reviewed-by: brutisso, jmasa, coleenp
author stefank
date Mon, 07 Oct 2013 15:51:08 +0200
parents bc918fd1e584
children bdfbb1fb19ca
comparison
equal deleted inserted replaced
12837:82af7d7a0128 12838:85c1ca43713f
85 friend class VM_CollectForMetadataAllocation; 85 friend class VM_CollectForMetadataAllocation;
86 friend class MetaspaceGC; 86 friend class MetaspaceGC;
87 friend class MetaspaceAux; 87 friend class MetaspaceAux;
88 88
89 public: 89 public:
90 enum MetadataType {ClassType = 0, 90 enum MetadataType {
91 NonClassType = ClassType + 1, 91 ClassType,
92 MetadataTypeCount = ClassType + 2 92 NonClassType,
93 MetadataTypeCount
93 }; 94 };
94 enum MetaspaceType { 95 enum MetaspaceType {
95 StandardMetaspaceType, 96 StandardMetaspaceType,
96 BootMetaspaceType, 97 BootMetaspaceType,
97 ROMetaspaceType, 98 ROMetaspaceType,
101 }; 102 };
102 103
103 private: 104 private:
104 void initialize(Mutex* lock, MetaspaceType type); 105 void initialize(Mutex* lock, MetaspaceType type);
105 106
107 // Get the first chunk for a Metaspace. Used for
108 // special cases such as the boot class loader, reflection
109 // class loader and anonymous class loader.
106 Metachunk* get_initialization_chunk(MetadataType mdtype, 110 Metachunk* get_initialization_chunk(MetadataType mdtype,
107 size_t chunk_word_size, 111 size_t chunk_word_size,
108 size_t chunk_bunch); 112 size_t chunk_bunch);
109 113
110 // Align up the word size to the allocation word size 114 // Align up the word size to the allocation word size
120 _class_metaspace_size = metaspace_size; 124 _class_metaspace_size = metaspace_size;
121 } 125 }
122 126
123 static size_t _first_chunk_word_size; 127 static size_t _first_chunk_word_size;
124 static size_t _first_class_chunk_word_size; 128 static size_t _first_class_chunk_word_size;
129
130 static size_t _commit_alignment;
131 static size_t _reserve_alignment;
125 132
126 SpaceManager* _vsm; 133 SpaceManager* _vsm;
127 SpaceManager* vsm() const { return _vsm; } 134 SpaceManager* vsm() const { return _vsm; }
128 135
129 SpaceManager* _class_vsm; 136 SpaceManager* _class_vsm;
189 public: 196 public:
190 197
191 Metaspace(Mutex* lock, MetaspaceType type); 198 Metaspace(Mutex* lock, MetaspaceType type);
192 ~Metaspace(); 199 ~Metaspace();
193 200
194 // Initialize globals for Metaspace 201 static void ergo_initialize();
195 static void global_initialize(); 202 static void global_initialize();
196 203
197 static size_t first_chunk_word_size() { return _first_chunk_word_size; } 204 static size_t first_chunk_word_size() { return _first_chunk_word_size; }
198 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } 205 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; }
206
207 static size_t reserve_alignment() { return _reserve_alignment; }
208 static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
209 static size_t commit_alignment() { return _commit_alignment; }
210 static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; }
199 211
200 char* bottom() const; 212 char* bottom() const;
201 size_t used_words_slow(MetadataType mdtype) const; 213 size_t used_words_slow(MetadataType mdtype) const;
202 size_t free_words_slow(MetadataType mdtype) const; 214 size_t free_words_slow(MetadataType mdtype) const;
203 size_t capacity_words_slow(MetadataType mdtype) const; 215 size_t capacity_words_slow(MetadataType mdtype) const;
216 void dump(outputStream* const out) const; 228 void dump(outputStream* const out) const;
217 229
218 // Free empty virtualspaces 230 // Free empty virtualspaces
219 static void purge(MetadataType mdtype); 231 static void purge(MetadataType mdtype);
220 static void purge(); 232 static void purge();
233
234 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
235 MetadataType mdtype, TRAPS);
221 236
222 void print_on(outputStream* st) const; 237 void print_on(outputStream* st) const;
223 // Debugging support 238 // Debugging support
224 void verify(); 239 void verify();
225 240
350 // This class implements a policy for inducing GC's to recover 365 // This class implements a policy for inducing GC's to recover
351 // Metaspaces. 366 // Metaspaces.
352 367
353 class MetaspaceGC : AllStatic { 368 class MetaspaceGC : AllStatic {
354 369
355 // The current high-water-mark for inducing a GC. When 370 // The current high-water-mark for inducing a GC.
356 // the capacity of all space in the virtual lists reaches this value, 371 // When committed memory of all metaspaces reaches this value,
357 // a GC is induced and the value is increased. This should be changed 372 // a GC is induced and the value is increased. Size is in bytes.
358 // to the space actually used for allocations to avoid affects of 373 static volatile intptr_t _capacity_until_GC;
359 // fragmentation losses to partially used chunks. Size is in words.
360 static size_t _capacity_until_GC;
361
362 // After a GC is done any allocation that fails should try to expand
363 // the capacity of the Metaspaces. This flag is set during attempts
364 // to allocate in the VMGCOperation that does the GC.
365 static bool _expand_after_GC;
366 374
367 // For a CMS collection, signal that a concurrent collection should 375 // For a CMS collection, signal that a concurrent collection should
368 // be started. 376 // be started.
369 static bool _should_concurrent_collect; 377 static bool _should_concurrent_collect;
370 378
371 static uint _shrink_factor; 379 static uint _shrink_factor;
372 380
373 static void set_capacity_until_GC(size_t v) { _capacity_until_GC = v; }
374
375 static size_t shrink_factor() { return _shrink_factor; } 381 static size_t shrink_factor() { return _shrink_factor; }
376 void set_shrink_factor(uint v) { _shrink_factor = v; } 382 void set_shrink_factor(uint v) { _shrink_factor = v; }
377 383
378 public: 384 public:
379 385
380 static size_t capacity_until_GC() { return _capacity_until_GC; } 386 static void initialize() { _capacity_until_GC = MetaspaceSize; }
381 static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; } 387
382 static void dec_capacity_until_GC(size_t v) { 388 static size_t capacity_until_GC();
383 _capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0; 389 static size_t inc_capacity_until_GC(size_t v);
384 } 390 static size_t dec_capacity_until_GC(size_t v);
385 static bool expand_after_GC() { return _expand_after_GC; }
386 static void set_expand_after_GC(bool v) { _expand_after_GC = v; }
387 391
388 static bool should_concurrent_collect() { return _should_concurrent_collect; } 392 static bool should_concurrent_collect() { return _should_concurrent_collect; }
389 static void set_should_concurrent_collect(bool v) { 393 static void set_should_concurrent_collect(bool v) {
390 _should_concurrent_collect = v; 394 _should_concurrent_collect = v;
391 } 395 }
392 396
393 // The amount to increase the high-water-mark (_capacity_until_GC) 397 // The amount to increase the high-water-mark (_capacity_until_GC)
394 static size_t delta_capacity_until_GC(size_t word_size); 398 static size_t delta_capacity_until_GC(size_t bytes);
395 399
396 // It is expected that this will be called when the current capacity 400 // Tells if we have can expand metaspace without hitting set limits.
397 // has been used and a GC should be considered. 401 static bool can_expand(size_t words, bool is_class);
398 static bool should_expand(VirtualSpaceList* vsl, size_t word_size); 402
403 // Returns amount that we can expand without hitting a GC,
404 // measured in words.
405 static size_t allowed_expansion();
399 406
400 // Calculate the new high-water mark at which to induce 407 // Calculate the new high-water mark at which to induce
401 // a GC. 408 // a GC.
402 static void compute_new_size(); 409 static void compute_new_size();
403 }; 410 };