annotate src/share/vm/classfile/metadataOnStackMark.cpp @ 21810:0366a71eda74

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