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