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