Wed, 06 Feb 2019 14:59:45 +0900
8217432: MetaspaceGC::_capacity_until_GC exceeds MaxMetaspaceSize
Reviewed-by: tschatzl, stuefe
src/share/vm/memory/metaspace.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/memory/metaspace.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/memory/metaspace.cpp Wed Feb 06 04:09:15 2019 +0000 1.2 +++ b/src/share/vm/memory/metaspace.cpp Wed Feb 06 14:59:45 2019 +0900 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -1422,7 +1422,15 @@ 1.11 return value; 1.12 } 1.13 1.14 -bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC) { 1.15 +// Try to increase the _capacity_until_GC limit counter by v bytes. 1.16 +// Returns true if it succeeded. It may fail if either another thread 1.17 +// concurrently increased the limit or the new limit would be larger 1.18 +// than MaxMetaspaceSize. 1.19 +// On success, optionally returns new and old metaspace capacity in 1.20 +// new_cap_until_GC and old_cap_until_GC respectively. 1.21 +// On error, optionally sets can_retry to indicate whether if there is 1.22 +// actually enough space remaining to satisfy the request. 1.23 +bool MetaspaceGC::inc_capacity_until_GC(size_t v, size_t* new_cap_until_GC, size_t* old_cap_until_GC, bool* can_retry) { 1.24 assert_is_size_aligned(v, Metaspace::commit_alignment()); 1.25 1.26 size_t capacity_until_GC = (size_t) _capacity_until_GC; 1.27 @@ -1433,6 +1441,17 @@ 1.28 new_value = align_size_down(max_uintx, Metaspace::commit_alignment()); 1.29 } 1.30 1.31 + if (new_value > MaxMetaspaceSize) { 1.32 + if (can_retry != NULL) { 1.33 + *can_retry = false; 1.34 + } 1.35 + return false; 1.36 + } 1.37 + 1.38 + if (can_retry != NULL) { 1.39 + *can_retry = true; 1.40 + } 1.41 + 1.42 intptr_t expected = (intptr_t) capacity_until_GC; 1.43 intptr_t actual = Atomic::cmpxchg_ptr((intptr_t) new_value, &_capacity_until_GC, expected); 1.44 1.45 @@ -1520,7 +1539,7 @@ 1.46 1.47 const double min_tmp = used_after_gc / maximum_used_percentage; 1.48 size_t minimum_desired_capacity = 1.49 - (size_t)MIN2(min_tmp, double(max_uintx)); 1.50 + (size_t)MIN2(min_tmp, double(MaxMetaspaceSize)); 1.51 // Don't shrink less than the initial generation size 1.52 minimum_desired_capacity = MAX2(minimum_desired_capacity, 1.53 MetaspaceSize); 1.54 @@ -1579,7 +1598,7 @@ 1.55 const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0; 1.56 const double minimum_used_percentage = 1.0 - maximum_free_percentage; 1.57 const double max_tmp = used_after_gc / minimum_used_percentage; 1.58 - size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); 1.59 + size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(MaxMetaspaceSize)); 1.60 maximum_desired_capacity = MAX2(maximum_desired_capacity, 1.61 MetaspaceSize); 1.62 if (PrintGCDetails && Verbose) { 1.63 @@ -3408,6 +3427,7 @@ 1.64 1.65 size_t before = 0; 1.66 size_t after = 0; 1.67 + bool can_retry = true; 1.68 MetaWord* res; 1.69 bool incremented; 1.70 1.71 @@ -3415,9 +3435,9 @@ 1.72 // the HWM, an allocation is still attempted. This is because another thread must then 1.73 // have incremented the HWM and therefore the allocation might still succeed. 1.74 do { 1.75 - incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before); 1.76 + incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before, &can_retry); 1.77 res = allocate(word_size, mdtype); 1.78 - } while (!incremented && res == NULL); 1.79 + } while (!incremented && res == NULL && can_retry); 1.80 1.81 if (incremented) { 1.82 tracer()->report_gc_threshold(before, after,
2.1 --- a/src/share/vm/memory/metaspace.hpp Wed Feb 06 04:09:15 2019 +0000 2.2 +++ b/src/share/vm/memory/metaspace.hpp Wed Feb 06 14:59:45 2019 +0900 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -416,7 +416,8 @@ 2.11 static size_t capacity_until_GC(); 2.12 static bool inc_capacity_until_GC(size_t v, 2.13 size_t* new_cap_until_GC = NULL, 2.14 - size_t* old_cap_until_GC = NULL); 2.15 + size_t* old_cap_until_GC = NULL, 2.16 + bool* can_retry = NULL); 2.17 static size_t dec_capacity_until_GC(size_t v); 2.18 2.19 static bool should_concurrent_collect() { return _should_concurrent_collect; }