--- old/src/hotspot/share/memory/metaspace.cpp 2019-01-21 17:49:44.461947023 +0900 +++ new/src/hotspot/share/memory/metaspace.cpp 2019-01-21 17:49:44.248948912 +0900 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -143,6 +143,10 @@ new_value = align_down(max_uintx, Metaspace::commit_alignment()); } + if (new_value > MaxMetaspaceSize) { + return false; + } + size_t prev_value = Atomic::cmpxchg(new_value, &_capacity_until_GC, old_capacity_until_GC); if (old_capacity_until_GC != prev_value) { @@ -236,7 +240,7 @@ const double min_tmp = used_after_gc / maximum_used_percentage; size_t minimum_desired_capacity = - (size_t)MIN2(min_tmp, double(max_uintx)); + (size_t)MIN2(min_tmp, double(MaxMetaspaceSize)); // Don't shrink less than the initial generation size minimum_desired_capacity = MAX2(minimum_desired_capacity, MetaspaceSize); @@ -283,7 +287,7 @@ const double maximum_free_percentage = MaxMetaspaceFreeRatio / 100.0; const double minimum_used_percentage = 1.0 - maximum_free_percentage; const double max_tmp = used_after_gc / minimum_used_percentage; - size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx)); + size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(MaxMetaspaceSize)); maximum_desired_capacity = MAX2(maximum_desired_capacity, MetaspaceSize); log_trace(gc, metaspace)(" maximum_free_percentage: %6.2f minimum_used_percentage: %6.2f", @@ -1491,6 +1495,10 @@ // have incremented the HWM and therefore the allocation might still succeed. do { incremented = MetaspaceGC::inc_capacity_until_GC(delta_bytes, &after, &before); + if (!incremented && SafepointSynchronize::is_at_safepoint()) { + // Cannot expand metaspace more. + return NULL; + } res = allocate(word_size, mdtype); } while (!incremented && res == NULL);