1.1 --- a/src/share/vm/memory/metaspace.hpp Wed Oct 09 10:57:01 2013 +0200 1.2 +++ b/src/share/vm/memory/metaspace.hpp Mon Oct 07 15:51:08 2013 +0200 1.3 @@ -87,9 +87,10 @@ 1.4 friend class MetaspaceAux; 1.5 1.6 public: 1.7 - enum MetadataType {ClassType = 0, 1.8 - NonClassType = ClassType + 1, 1.9 - MetadataTypeCount = ClassType + 2 1.10 + enum MetadataType { 1.11 + ClassType, 1.12 + NonClassType, 1.13 + MetadataTypeCount 1.14 }; 1.15 enum MetaspaceType { 1.16 StandardMetaspaceType, 1.17 @@ -103,6 +104,9 @@ 1.18 private: 1.19 void initialize(Mutex* lock, MetaspaceType type); 1.20 1.21 + // Get the first chunk for a Metaspace. Used for 1.22 + // special cases such as the boot class loader, reflection 1.23 + // class loader and anonymous class loader. 1.24 Metachunk* get_initialization_chunk(MetadataType mdtype, 1.25 size_t chunk_word_size, 1.26 size_t chunk_bunch); 1.27 @@ -123,6 +127,9 @@ 1.28 static size_t _first_chunk_word_size; 1.29 static size_t _first_class_chunk_word_size; 1.30 1.31 + static size_t _commit_alignment; 1.32 + static size_t _reserve_alignment; 1.33 + 1.34 SpaceManager* _vsm; 1.35 SpaceManager* vsm() const { return _vsm; } 1.36 1.37 @@ -191,12 +198,17 @@ 1.38 Metaspace(Mutex* lock, MetaspaceType type); 1.39 ~Metaspace(); 1.40 1.41 - // Initialize globals for Metaspace 1.42 + static void ergo_initialize(); 1.43 static void global_initialize(); 1.44 1.45 static size_t first_chunk_word_size() { return _first_chunk_word_size; } 1.46 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; } 1.47 1.48 + static size_t reserve_alignment() { return _reserve_alignment; } 1.49 + static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; } 1.50 + static size_t commit_alignment() { return _commit_alignment; } 1.51 + static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; } 1.52 + 1.53 char* bottom() const; 1.54 size_t used_words_slow(MetadataType mdtype) const; 1.55 size_t free_words_slow(MetadataType mdtype) const; 1.56 @@ -219,6 +231,9 @@ 1.57 static void purge(MetadataType mdtype); 1.58 static void purge(); 1.59 1.60 + static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, 1.61 + MetadataType mdtype, TRAPS); 1.62 + 1.63 void print_on(outputStream* st) const; 1.64 // Debugging support 1.65 void verify(); 1.66 @@ -352,17 +367,10 @@ 1.67 1.68 class MetaspaceGC : AllStatic { 1.69 1.70 - // The current high-water-mark for inducing a GC. When 1.71 - // the capacity of all space in the virtual lists reaches this value, 1.72 - // a GC is induced and the value is increased. This should be changed 1.73 - // to the space actually used for allocations to avoid affects of 1.74 - // fragmentation losses to partially used chunks. Size is in words. 1.75 - static size_t _capacity_until_GC; 1.76 - 1.77 - // After a GC is done any allocation that fails should try to expand 1.78 - // the capacity of the Metaspaces. This flag is set during attempts 1.79 - // to allocate in the VMGCOperation that does the GC. 1.80 - static bool _expand_after_GC; 1.81 + // The current high-water-mark for inducing a GC. 1.82 + // When committed memory of all metaspaces reaches this value, 1.83 + // a GC is induced and the value is increased. Size is in bytes. 1.84 + static volatile intptr_t _capacity_until_GC; 1.85 1.86 // For a CMS collection, signal that a concurrent collection should 1.87 // be started. 1.88 @@ -370,20 +378,16 @@ 1.89 1.90 static uint _shrink_factor; 1.91 1.92 - static void set_capacity_until_GC(size_t v) { _capacity_until_GC = v; } 1.93 - 1.94 static size_t shrink_factor() { return _shrink_factor; } 1.95 void set_shrink_factor(uint v) { _shrink_factor = v; } 1.96 1.97 public: 1.98 1.99 - static size_t capacity_until_GC() { return _capacity_until_GC; } 1.100 - static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; } 1.101 - static void dec_capacity_until_GC(size_t v) { 1.102 - _capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0; 1.103 - } 1.104 - static bool expand_after_GC() { return _expand_after_GC; } 1.105 - static void set_expand_after_GC(bool v) { _expand_after_GC = v; } 1.106 + static void initialize() { _capacity_until_GC = MetaspaceSize; } 1.107 + 1.108 + static size_t capacity_until_GC(); 1.109 + static size_t inc_capacity_until_GC(size_t v); 1.110 + static size_t dec_capacity_until_GC(size_t v); 1.111 1.112 static bool should_concurrent_collect() { return _should_concurrent_collect; } 1.113 static void set_should_concurrent_collect(bool v) { 1.114 @@ -391,11 +395,14 @@ 1.115 } 1.116 1.117 // The amount to increase the high-water-mark (_capacity_until_GC) 1.118 - static size_t delta_capacity_until_GC(size_t word_size); 1.119 + static size_t delta_capacity_until_GC(size_t bytes); 1.120 1.121 - // It is expected that this will be called when the current capacity 1.122 - // has been used and a GC should be considered. 1.123 - static bool should_expand(VirtualSpaceList* vsl, size_t word_size); 1.124 + // Tells if we have can expand metaspace without hitting set limits. 1.125 + static bool can_expand(size_t words, bool is_class); 1.126 + 1.127 + // Returns amount that we can expand without hitting a GC, 1.128 + // measured in words. 1.129 + static size_t allowed_expansion(); 1.130 1.131 // Calculate the new high-water mark at which to induce 1.132 // a GC.