coleenp@4490: /* coleenp@4490: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. coleenp@4490: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. coleenp@4490: * coleenp@4490: * This code is free software; you can redistribute it and/or modify it coleenp@4490: * under the terms of the GNU General Public License version 2 only, as coleenp@4490: * published by the Free Software Foundation. coleenp@4490: * coleenp@4490: * This code is distributed in the hope that it will be useful, but WITHOUT coleenp@4490: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or coleenp@4490: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License coleenp@4490: * version 2 for more details (a copy is included in the LICENSE file that coleenp@4490: * accompanied this code). coleenp@4490: * coleenp@4490: * You should have received a copy of the GNU General Public License version coleenp@4490: * 2 along with this work; if not, write to the Free Software Foundation, coleenp@4490: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. coleenp@4490: * coleenp@4490: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA coleenp@4490: * or visit www.oracle.com if you need additional information or have any coleenp@4490: * questions. coleenp@4490: * coleenp@4490: */ coleenp@4490: coleenp@4490: #include "precompiled.hpp" coleenp@4490: #include "classfile/metadataOnStackMark.hpp" coleenp@4490: #include "code/codeCache.hpp" coleenp@4490: #include "compiler/compileBroker.hpp" coleenp@4490: #include "oops/metadata.hpp" coleenp@6063: #include "prims/jvmtiImpl.hpp" coleenp@4490: #include "runtime/synchronizer.hpp" coleenp@4490: #include "runtime/thread.hpp" sla@6122: #include "services/threadService.hpp" coleenp@4490: #include "utilities/growableArray.hpp" coleenp@4490: coleenp@4490: coleenp@4490: // Keep track of marked on-stack metadata so it can be cleared. coleenp@4490: GrowableArray* _marked_objects = NULL; coleenp@4490: NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;) coleenp@4490: coleenp@4490: // Walk metadata on the stack and mark it so that redefinition doesn't delete coleenp@4490: // it. Class unloading also walks the previous versions and might try to coleenp@4490: // delete it, so this class is used by class unloading also. coleenp@4490: MetadataOnStackMark::MetadataOnStackMark() { coleenp@4490: assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); coleenp@4490: NOT_PRODUCT(_is_active = true;) coleenp@4490: if (_marked_objects == NULL) { coleenp@4490: _marked_objects = new (ResourceObj::C_HEAP, mtClass) GrowableArray(1000, true); coleenp@4490: } stefank@6992: coleenp@4490: Threads::metadata_do(Metadata::mark_on_stack); stefank@6992: if (JvmtiExport::has_redefined_a_class()) { stefank@6992: CodeCache::alive_nmethods_do(nmethod::mark_on_stack); stefank@6992: } coleenp@4490: CompileBroker::mark_on_stack(); coleenp@6063: JvmtiCurrentBreakpoints::metadata_do(Metadata::mark_on_stack); sla@6122: ThreadService::metadata_do(Metadata::mark_on_stack); coleenp@4490: } coleenp@4490: coleenp@4490: MetadataOnStackMark::~MetadataOnStackMark() { coleenp@4490: assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); coleenp@4490: // Unmark everything that was marked. Can't do the same walk because coleenp@4490: // redefine classes messes up the code cache so the set of methods coleenp@4490: // might not be the same. coleenp@4490: for (int i = 0; i< _marked_objects->length(); i++) { coleenp@4490: _marked_objects->at(i)->set_on_stack(false); coleenp@4490: } coleenp@4490: _marked_objects->clear(); // reuse growable array for next time. coleenp@4490: NOT_PRODUCT(_is_active = false;) coleenp@4490: } coleenp@4490: coleenp@4490: // Record which objects are marked so we can unmark the same objects. coleenp@4490: void MetadataOnStackMark::record(Metadata* m) { coleenp@4490: assert(_is_active, "metadata on stack marking is active"); coleenp@4490: _marked_objects->push(m); coleenp@4490: }