1.1 --- a/src/share/vm/memory/metaspace.cpp Wed Sep 11 18:47:54 2013 +0200 1.2 +++ b/src/share/vm/memory/metaspace.cpp Thu Sep 12 10:15:30 2013 +0200 1.3 @@ -177,8 +177,8 @@ 1.4 void return_chunks(ChunkIndex index, Metachunk* chunks); 1.5 1.6 // Total of the space in the free chunks list 1.7 - size_t free_chunks_total(); 1.8 - size_t free_chunks_total_in_bytes(); 1.9 + size_t free_chunks_total_words(); 1.10 + size_t free_chunks_total_bytes(); 1.11 1.12 // Number of chunks in the free chunks list 1.13 size_t free_chunks_count(); 1.14 @@ -1080,12 +1080,12 @@ 1.15 // Sum used region [bottom, top) in each virtualspace 1.16 allocated_by_vs += vsl->used_words_in_vs(); 1.17 } 1.18 - assert(allocated_by_vs >= chunk_manager()->free_chunks_total(), 1.19 + assert(allocated_by_vs >= chunk_manager()->free_chunks_total_words(), 1.20 err_msg("Total in free chunks " SIZE_FORMAT 1.21 " greater than total from virtual_spaces " SIZE_FORMAT, 1.22 - allocated_by_vs, chunk_manager()->free_chunks_total())); 1.23 + allocated_by_vs, chunk_manager()->free_chunks_total_words())); 1.24 size_t used = 1.25 - allocated_by_vs - chunk_manager()->free_chunks_total(); 1.26 + allocated_by_vs - chunk_manager()->free_chunks_total_words(); 1.27 return used; 1.28 } 1.29 1.30 @@ -1526,7 +1526,7 @@ 1.31 sm->sum_count_in_chunks_in_use()); 1.32 dummy_chunk->print_on(gclog_or_tty); 1.33 gclog_or_tty->print_cr(" Free chunks total %d count %d", 1.34 - vsl->chunk_manager()->free_chunks_total(), 1.35 + vsl->chunk_manager()->free_chunks_total_words(), 1.36 vsl->chunk_manager()->free_chunks_count()); 1.37 } 1.38 } 1.39 @@ -1583,12 +1583,12 @@ 1.40 1.41 // ChunkManager methods 1.42 1.43 -size_t ChunkManager::free_chunks_total() { 1.44 +size_t ChunkManager::free_chunks_total_words() { 1.45 return _free_chunks_total; 1.46 } 1.47 1.48 -size_t ChunkManager::free_chunks_total_in_bytes() { 1.49 - return free_chunks_total() * BytesPerWord; 1.50 +size_t ChunkManager::free_chunks_total_bytes() { 1.51 + return free_chunks_total_words() * BytesPerWord; 1.52 } 1.53 1.54 size_t ChunkManager::free_chunks_count() { 1.55 @@ -2567,13 +2567,13 @@ 1.56 return used * BytesPerWord; 1.57 } 1.58 1.59 -size_t MetaspaceAux::free_in_bytes(Metaspace::MetadataType mdtype) { 1.60 +size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) { 1.61 size_t free = 0; 1.62 ClassLoaderDataGraphMetaspaceIterator iter; 1.63 while (iter.repeat()) { 1.64 Metaspace* msp = iter.get_next(); 1.65 if (msp != NULL) { 1.66 - free += msp->free_words(mdtype); 1.67 + free += msp->free_words_slow(mdtype); 1.68 } 1.69 } 1.70 return free * BytesPerWord; 1.71 @@ -2596,34 +2596,51 @@ 1.72 return capacity * BytesPerWord; 1.73 } 1.74 1.75 -size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) { 1.76 +size_t MetaspaceAux::capacity_bytes_slow() { 1.77 +#ifdef PRODUCT 1.78 + // Use allocated_capacity_bytes() in PRODUCT instead of this function. 1.79 + guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT"); 1.80 +#endif 1.81 + size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType); 1.82 + size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType); 1.83 + assert(allocated_capacity_bytes() == class_capacity + non_class_capacity, 1.84 + err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT 1.85 + " class_capacity + non_class_capacity " SIZE_FORMAT 1.86 + " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT, 1.87 + allocated_capacity_bytes(), class_capacity + non_class_capacity, 1.88 + class_capacity, non_class_capacity)); 1.89 + 1.90 + return class_capacity + non_class_capacity; 1.91 +} 1.92 + 1.93 +size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) { 1.94 VirtualSpaceList* list = Metaspace::get_space_list(mdtype); 1.95 - return list == NULL ? 0 : list->virtual_space_total(); 1.96 + return list == NULL ? 0 : list->virtual_space_total() * BytesPerWord; 1.97 } 1.98 1.99 -size_t MetaspaceAux::min_chunk_size() { return Metaspace::first_chunk_word_size(); } 1.100 - 1.101 -size_t MetaspaceAux::free_chunks_total(Metaspace::MetadataType mdtype) { 1.102 +size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); } 1.103 + 1.104 +size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) { 1.105 VirtualSpaceList* list = Metaspace::get_space_list(mdtype); 1.106 if (list == NULL) { 1.107 return 0; 1.108 } 1.109 ChunkManager* chunk = list->chunk_manager(); 1.110 chunk->slow_verify(); 1.111 - return chunk->free_chunks_total(); 1.112 + return chunk->free_chunks_total_words(); 1.113 } 1.114 1.115 -size_t MetaspaceAux::free_chunks_total_in_bytes(Metaspace::MetadataType mdtype) { 1.116 - return free_chunks_total(mdtype) * BytesPerWord; 1.117 +size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) { 1.118 + return free_chunks_total_words(mdtype) * BytesPerWord; 1.119 } 1.120 1.121 -size_t MetaspaceAux::free_chunks_total() { 1.122 - return free_chunks_total(Metaspace::ClassType) + 1.123 - free_chunks_total(Metaspace::NonClassType); 1.124 +size_t MetaspaceAux::free_chunks_total_words() { 1.125 + return free_chunks_total_words(Metaspace::ClassType) + 1.126 + free_chunks_total_words(Metaspace::NonClassType); 1.127 } 1.128 1.129 -size_t MetaspaceAux::free_chunks_total_in_bytes() { 1.130 - return free_chunks_total() * BytesPerWord; 1.131 +size_t MetaspaceAux::free_chunks_total_bytes() { 1.132 + return free_chunks_total_words() * BytesPerWord; 1.133 } 1.134 1.135 void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) { 1.136 @@ -2634,14 +2651,14 @@ 1.137 "(" SIZE_FORMAT ")", 1.138 prev_metadata_used, 1.139 allocated_used_bytes(), 1.140 - reserved_in_bytes()); 1.141 + reserved_bytes()); 1.142 } else { 1.143 gclog_or_tty->print(" " SIZE_FORMAT "K" 1.144 "->" SIZE_FORMAT "K" 1.145 "(" SIZE_FORMAT "K)", 1.146 - prev_metadata_used / K, 1.147 - allocated_used_bytes() / K, 1.148 - reserved_in_bytes()/ K); 1.149 + prev_metadata_used/K, 1.150 + allocated_used_bytes()/K, 1.151 + reserved_bytes()/K); 1.152 } 1.153 1.154 gclog_or_tty->print("]"); 1.155 @@ -2654,14 +2671,14 @@ 1.156 out->print_cr(" Metaspace total " 1.157 SIZE_FORMAT "K, used " SIZE_FORMAT "K," 1.158 " reserved " SIZE_FORMAT "K", 1.159 - allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K); 1.160 + allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_bytes()/K); 1.161 1.162 out->print_cr(" data space " 1.163 SIZE_FORMAT "K, used " SIZE_FORMAT "K," 1.164 " reserved " SIZE_FORMAT "K", 1.165 allocated_capacity_bytes(nct)/K, 1.166 allocated_used_bytes(nct)/K, 1.167 - reserved_in_bytes(nct)/K); 1.168 + reserved_bytes(nct)/K); 1.169 if (Metaspace::using_class_space()) { 1.170 Metaspace::MetadataType ct = Metaspace::ClassType; 1.171 out->print_cr(" class space " 1.172 @@ -2669,17 +2686,17 @@ 1.173 " reserved " SIZE_FORMAT "K", 1.174 allocated_capacity_bytes(ct)/K, 1.175 allocated_used_bytes(ct)/K, 1.176 - reserved_in_bytes(ct)/K); 1.177 + reserved_bytes(ct)/K); 1.178 } 1.179 } 1.180 1.181 // Print information for class space and data space separately. 1.182 // This is almost the same as above. 1.183 void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) { 1.184 - size_t free_chunks_capacity_bytes = free_chunks_total_in_bytes(mdtype); 1.185 + size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype); 1.186 size_t capacity_bytes = capacity_bytes_slow(mdtype); 1.187 size_t used_bytes = used_bytes_slow(mdtype); 1.188 - size_t free_bytes = free_in_bytes(mdtype); 1.189 + size_t free_bytes = free_bytes_slow(mdtype); 1.190 size_t used_and_free = used_bytes + free_bytes + 1.191 free_chunks_capacity_bytes; 1.192 out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT 1.193 @@ -3132,7 +3149,7 @@ 1.194 } 1.195 } 1.196 1.197 -size_t Metaspace::free_words(MetadataType mdtype) const { 1.198 +size_t Metaspace::free_words_slow(MetadataType mdtype) const { 1.199 if (mdtype == ClassType) { 1.200 return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0; 1.201 } else {