145 assert_is_aligned(v, Metaspace::commit_alignment()); 146 147 size_t old_capacity_until_GC = _capacity_until_GC; 148 size_t new_value = old_capacity_until_GC + v; 149 150 if (new_value < old_capacity_until_GC) { 151 // The addition wrapped around, set new_value to aligned max value. 152 new_value = align_down(max_uintx, Metaspace::commit_alignment()); 153 } 154 155 if (new_value > MaxMetaspaceSize) { 156 if (can_retry != NULL) { 157 *can_retry = false; 158 } 159 return false; 160 } 161 162 if (can_retry != NULL) { 163 *can_retry = true; 164 } 165 size_t prev_value = Atomic::cmpxchg(new_value, &_capacity_until_GC, old_capacity_until_GC); 166 167 if (old_capacity_until_GC != prev_value) { 168 return false; 169 } 170 171 if (new_cap_until_GC != NULL) { 172 *new_cap_until_GC = new_value; 173 } 174 if (old_cap_until_GC != NULL) { 175 *old_cap_until_GC = old_capacity_until_GC; 176 } 177 return true; 178 } 179 180 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) { 181 assert_is_aligned(v, Metaspace::commit_alignment()); 182 183 return Atomic::sub(v, &_capacity_until_GC); 184 } 185 186 void MetaspaceGC::initialize() { 187 // Set the high-water mark to MaxMetapaceSize during VM initializaton since 188 // we can't do a GC during initialization. 189 _capacity_until_GC = MaxMetaspaceSize; 190 } 191 192 void MetaspaceGC::post_initialize() { 193 // Reset the high-water mark once the VM initialization is done. 194 _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize); 195 } 196 197 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { 198 // Check if the compressed class space is full. 199 if (is_class && Metaspace::using_class_space()) { 200 size_t class_committed = MetaspaceUtils::committed_bytes(Metaspace::ClassType); 201 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { 202 log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)", 203 (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord)); 377 378 size_t MetaspaceUtils::free_in_vs_bytes() { 379 return free_in_vs_bytes(Metaspace::ClassType) + free_in_vs_bytes(Metaspace::NonClassType); 380 } 381 382 static void inc_stat_nonatomically(size_t* pstat, size_t words) { 383 assert_lock_strong(MetaspaceExpand_lock); 384 (*pstat) += words; 385 } 386 387 static void dec_stat_nonatomically(size_t* pstat, size_t words) { 388 assert_lock_strong(MetaspaceExpand_lock); 389 const size_t size_now = *pstat; 390 assert(size_now >= words, "About to decrement counter below zero " 391 "(current value: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ".", 392 size_now, words); 393 *pstat = size_now - words; 394 } 395 396 static void inc_stat_atomically(volatile size_t* pstat, size_t words) { 397 Atomic::add(words, pstat); 398 } 399 400 static void dec_stat_atomically(volatile size_t* pstat, size_t words) { 401 const size_t size_now = *pstat; 402 assert(size_now >= words, "About to decrement counter below zero " 403 "(current value: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ".", 404 size_now, words); 405 Atomic::sub(words, pstat); 406 } 407 408 void MetaspaceUtils::dec_capacity(Metaspace::MetadataType mdtype, size_t words) { 409 dec_stat_nonatomically(&_capacity_words[mdtype], words); 410 } 411 void MetaspaceUtils::inc_capacity(Metaspace::MetadataType mdtype, size_t words) { 412 inc_stat_nonatomically(&_capacity_words[mdtype], words); 413 } 414 void MetaspaceUtils::dec_used(Metaspace::MetadataType mdtype, size_t words) { 415 dec_stat_atomically(&_used_words[mdtype], words); 416 } 417 void MetaspaceUtils::inc_used(Metaspace::MetadataType mdtype, size_t words) { 418 inc_stat_atomically(&_used_words[mdtype], words); 419 } 420 void MetaspaceUtils::dec_overhead(Metaspace::MetadataType mdtype, size_t words) { 421 dec_stat_nonatomically(&_overhead_words[mdtype], words); 422 } 423 void MetaspaceUtils::inc_overhead(Metaspace::MetadataType mdtype, size_t words) { 424 inc_stat_nonatomically(&_overhead_words[mdtype], words); 425 } | 145 assert_is_aligned(v, Metaspace::commit_alignment()); 146 147 size_t old_capacity_until_GC = _capacity_until_GC; 148 size_t new_value = old_capacity_until_GC + v; 149 150 if (new_value < old_capacity_until_GC) { 151 // The addition wrapped around, set new_value to aligned max value. 152 new_value = align_down(max_uintx, Metaspace::commit_alignment()); 153 } 154 155 if (new_value > MaxMetaspaceSize) { 156 if (can_retry != NULL) { 157 *can_retry = false; 158 } 159 return false; 160 } 161 162 if (can_retry != NULL) { 163 *can_retry = true; 164 } 165 size_t prev_value = Atomic::cmpxchg(&_capacity_until_GC, old_capacity_until_GC, new_value); 166 167 if (old_capacity_until_GC != prev_value) { 168 return false; 169 } 170 171 if (new_cap_until_GC != NULL) { 172 *new_cap_until_GC = new_value; 173 } 174 if (old_cap_until_GC != NULL) { 175 *old_cap_until_GC = old_capacity_until_GC; 176 } 177 return true; 178 } 179 180 size_t MetaspaceGC::dec_capacity_until_GC(size_t v) { 181 assert_is_aligned(v, Metaspace::commit_alignment()); 182 183 return Atomic::sub(&_capacity_until_GC, v); 184 } 185 186 void MetaspaceGC::initialize() { 187 // Set the high-water mark to MaxMetapaceSize during VM initializaton since 188 // we can't do a GC during initialization. 189 _capacity_until_GC = MaxMetaspaceSize; 190 } 191 192 void MetaspaceGC::post_initialize() { 193 // Reset the high-water mark once the VM initialization is done. 194 _capacity_until_GC = MAX2(MetaspaceUtils::committed_bytes(), MetaspaceSize); 195 } 196 197 bool MetaspaceGC::can_expand(size_t word_size, bool is_class) { 198 // Check if the compressed class space is full. 199 if (is_class && Metaspace::using_class_space()) { 200 size_t class_committed = MetaspaceUtils::committed_bytes(Metaspace::ClassType); 201 if (class_committed + word_size * BytesPerWord > CompressedClassSpaceSize) { 202 log_trace(gc, metaspace, freelist)("Cannot expand %s metaspace by " SIZE_FORMAT " words (CompressedClassSpaceSize = " SIZE_FORMAT " words)", 203 (is_class ? "class" : "non-class"), word_size, CompressedClassSpaceSize / sizeof(MetaWord)); 377 378 size_t MetaspaceUtils::free_in_vs_bytes() { 379 return free_in_vs_bytes(Metaspace::ClassType) + free_in_vs_bytes(Metaspace::NonClassType); 380 } 381 382 static void inc_stat_nonatomically(size_t* pstat, size_t words) { 383 assert_lock_strong(MetaspaceExpand_lock); 384 (*pstat) += words; 385 } 386 387 static void dec_stat_nonatomically(size_t* pstat, size_t words) { 388 assert_lock_strong(MetaspaceExpand_lock); 389 const size_t size_now = *pstat; 390 assert(size_now >= words, "About to decrement counter below zero " 391 "(current value: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ".", 392 size_now, words); 393 *pstat = size_now - words; 394 } 395 396 static void inc_stat_atomically(volatile size_t* pstat, size_t words) { 397 Atomic::add(pstat, words); 398 } 399 400 static void dec_stat_atomically(volatile size_t* pstat, size_t words) { 401 const size_t size_now = *pstat; 402 assert(size_now >= words, "About to decrement counter below zero " 403 "(current value: " SIZE_FORMAT ", decrement value: " SIZE_FORMAT ".", 404 size_now, words); 405 Atomic::sub(pstat, words); 406 } 407 408 void MetaspaceUtils::dec_capacity(Metaspace::MetadataType mdtype, size_t words) { 409 dec_stat_nonatomically(&_capacity_words[mdtype], words); 410 } 411 void MetaspaceUtils::inc_capacity(Metaspace::MetadataType mdtype, size_t words) { 412 inc_stat_nonatomically(&_capacity_words[mdtype], words); 413 } 414 void MetaspaceUtils::dec_used(Metaspace::MetadataType mdtype, size_t words) { 415 dec_stat_atomically(&_used_words[mdtype], words); 416 } 417 void MetaspaceUtils::inc_used(Metaspace::MetadataType mdtype, size_t words) { 418 inc_stat_atomically(&_used_words[mdtype], words); 419 } 420 void MetaspaceUtils::dec_overhead(Metaspace::MetadataType mdtype, size_t words) { 421 dec_stat_nonatomically(&_overhead_words[mdtype], words); 422 } 423 void MetaspaceUtils::inc_overhead(Metaspace::MetadataType mdtype, size_t words) { 424 inc_stat_nonatomically(&_overhead_words[mdtype], words); 425 } |