--- old/src/hotspot/share/memory/metaspaceClosure.cpp 2020-07-31 23:33:54.204045889 -0700 +++ new/src/hotspot/share/memory/metaspaceClosure.cpp 2020-07-31 23:33:54.008038511 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, 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 @@ -37,8 +37,11 @@ void MetaspaceClosure::push_impl(MetaspaceClosure::Ref* ref) { if (_nest_level < MAX_NEST_LEVEL) { do_push(ref); - delete ref; + if (!ref->keep_after_pushing()) { + delete ref; + } } else { + do_pending_ref(ref); ref->set_next(_pending_refs); _pending_refs = ref; } @@ -59,9 +62,15 @@ assert(w == _default, "must be"); read_only = ref->is_read_only_by_default(); } + if (_nest_level == 0) { + assert(_enclosing_ref == NULL, "must be"); + } _nest_level ++; if (do_ref(ref, read_only)) { // true means we want to iterate the embedded pointer in + Ref* saved = _enclosing_ref; + _enclosing_ref = ref; ref->metaspace_pointers_do(this); + _enclosing_ref = saved; } _nest_level --; } @@ -73,7 +82,9 @@ Ref* ref = _pending_refs; _pending_refs = _pending_refs->next(); do_push(ref); - delete ref; + if (!ref->keep_after_pushing()) { + delete ref; + } } }