src/share/vm/classfile/metadataOnStackMark.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/classfile/metadataOnStackMark.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,73 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/metadataOnStackMark.hpp"
    1.30 +#include "code/codeCache.hpp"
    1.31 +#include "compiler/compileBroker.hpp"
    1.32 +#include "oops/metadata.hpp"
    1.33 +#include "prims/jvmtiImpl.hpp"
    1.34 +#include "runtime/synchronizer.hpp"
    1.35 +#include "runtime/thread.hpp"
    1.36 +#include "services/threadService.hpp"
    1.37 +#include "utilities/growableArray.hpp"
    1.38 +
    1.39 +
    1.40 +// Keep track of marked on-stack metadata so it can be cleared.
    1.41 +GrowableArray<Metadata*>* _marked_objects = NULL;
    1.42 +NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;)
    1.43 +
    1.44 +// Walk metadata on the stack and mark it so that redefinition doesn't delete
    1.45 +// it.  Class unloading also walks the previous versions and might try to
    1.46 +// delete it, so this class is used by class unloading also.
    1.47 +MetadataOnStackMark::MetadataOnStackMark() {
    1.48 +  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
    1.49 +  NOT_PRODUCT(_is_active = true;)
    1.50 +  if (_marked_objects == NULL) {
    1.51 +    _marked_objects = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(1000, true);
    1.52 +  }
    1.53 +  Threads::metadata_do(Metadata::mark_on_stack);
    1.54 +  CodeCache::alive_nmethods_do(nmethod::mark_on_stack);
    1.55 +  CompileBroker::mark_on_stack();
    1.56 +  JvmtiCurrentBreakpoints::metadata_do(Metadata::mark_on_stack);
    1.57 +  ThreadService::metadata_do(Metadata::mark_on_stack);
    1.58 +}
    1.59 +
    1.60 +MetadataOnStackMark::~MetadataOnStackMark() {
    1.61 +  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
    1.62 +  // Unmark everything that was marked.   Can't do the same walk because
    1.63 +  // redefine classes messes up the code cache so the set of methods
    1.64 +  // might not be the same.
    1.65 +  for (int i = 0; i< _marked_objects->length(); i++) {
    1.66 +    _marked_objects->at(i)->set_on_stack(false);
    1.67 +  }
    1.68 +  _marked_objects->clear();   // reuse growable array for next time.
    1.69 +  NOT_PRODUCT(_is_active = false;)
    1.70 +}
    1.71 +
    1.72 +// Record which objects are marked so we can unmark the same objects.
    1.73 +void MetadataOnStackMark::record(Metadata* m) {
    1.74 +  assert(_is_active, "metadata on stack marking is active");
    1.75 +  _marked_objects->push(m);
    1.76 +}

mercurial