src/share/vm/classfile/metadataOnStackMark.cpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6122
0b9ea9a72436
child 7333
b12a2a9b05ca
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

coleenp@4490 1 /*
coleenp@4490 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
coleenp@4490 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@4490 4 *
coleenp@4490 5 * This code is free software; you can redistribute it and/or modify it
coleenp@4490 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@4490 7 * published by the Free Software Foundation.
coleenp@4490 8 *
coleenp@4490 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@4490 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@4490 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@4490 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@4490 13 * accompanied this code).
coleenp@4490 14 *
coleenp@4490 15 * You should have received a copy of the GNU General Public License version
coleenp@4490 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@4490 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@4490 18 *
coleenp@4490 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@4490 20 * or visit www.oracle.com if you need additional information or have any
coleenp@4490 21 * questions.
coleenp@4490 22 *
coleenp@4490 23 */
coleenp@4490 24
coleenp@4490 25 #include "precompiled.hpp"
coleenp@4490 26 #include "classfile/metadataOnStackMark.hpp"
coleenp@4490 27 #include "code/codeCache.hpp"
coleenp@4490 28 #include "compiler/compileBroker.hpp"
coleenp@4490 29 #include "oops/metadata.hpp"
coleenp@6063 30 #include "prims/jvmtiImpl.hpp"
coleenp@4490 31 #include "runtime/synchronizer.hpp"
coleenp@4490 32 #include "runtime/thread.hpp"
sla@6122 33 #include "services/threadService.hpp"
coleenp@4490 34 #include "utilities/growableArray.hpp"
coleenp@4490 35
coleenp@4490 36
coleenp@4490 37 // Keep track of marked on-stack metadata so it can be cleared.
coleenp@4490 38 GrowableArray<Metadata*>* _marked_objects = NULL;
coleenp@4490 39 NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;)
coleenp@4490 40
coleenp@4490 41 // Walk metadata on the stack and mark it so that redefinition doesn't delete
coleenp@4490 42 // it. Class unloading also walks the previous versions and might try to
coleenp@4490 43 // delete it, so this class is used by class unloading also.
coleenp@4490 44 MetadataOnStackMark::MetadataOnStackMark() {
coleenp@4490 45 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
coleenp@4490 46 NOT_PRODUCT(_is_active = true;)
coleenp@4490 47 if (_marked_objects == NULL) {
coleenp@4490 48 _marked_objects = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(1000, true);
coleenp@4490 49 }
stefank@6992 50
coleenp@4490 51 Threads::metadata_do(Metadata::mark_on_stack);
stefank@6992 52 if (JvmtiExport::has_redefined_a_class()) {
stefank@6992 53 CodeCache::alive_nmethods_do(nmethod::mark_on_stack);
stefank@6992 54 }
coleenp@4490 55 CompileBroker::mark_on_stack();
coleenp@6063 56 JvmtiCurrentBreakpoints::metadata_do(Metadata::mark_on_stack);
sla@6122 57 ThreadService::metadata_do(Metadata::mark_on_stack);
coleenp@4490 58 }
coleenp@4490 59
coleenp@4490 60 MetadataOnStackMark::~MetadataOnStackMark() {
coleenp@4490 61 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
coleenp@4490 62 // Unmark everything that was marked. Can't do the same walk because
coleenp@4490 63 // redefine classes messes up the code cache so the set of methods
coleenp@4490 64 // might not be the same.
coleenp@4490 65 for (int i = 0; i< _marked_objects->length(); i++) {
coleenp@4490 66 _marked_objects->at(i)->set_on_stack(false);
coleenp@4490 67 }
coleenp@4490 68 _marked_objects->clear(); // reuse growable array for next time.
coleenp@4490 69 NOT_PRODUCT(_is_active = false;)
coleenp@4490 70 }
coleenp@4490 71
coleenp@4490 72 // Record which objects are marked so we can unmark the same objects.
coleenp@4490 73 void MetadataOnStackMark::record(Metadata* m) {
coleenp@4490 74 assert(_is_active, "metadata on stack marking is active");
coleenp@4490 75 _marked_objects->push(m);
coleenp@4490 76 }

mercurial