annotate agent/src/share/classes/sun/jvm/hotspot/code/CodeCache.java @ 3908:7588156f5cf9

7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244) Reviewed-by: kvn
author never
date Mon, 05 Sep 2011 17:09:05 -0700
parents a80577f854f9
children 1d7922586cf6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
3388
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1040
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public class CodeCache {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static AddressField heapField;
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
36 private static AddressField scavengeRootNMethodsField;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static VirtualConstructor virtualConstructor;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private CodeHeap heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 });
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 Type type = db.lookupType("CodeCache");
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 heapField = type.getAddressField("_heap");
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
53 scavengeRootNMethodsField = type.getAddressField("_scavenge_root_nmethods");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 virtualConstructor = new VirtualConstructor(db);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // Add mappings for all possible CodeBlob subclasses
a61af66fc99e Initial load
duke
parents:
diff changeset
57 virtualConstructor.addMapping("BufferBlob", BufferBlob.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 virtualConstructor.addMapping("nmethod", NMethod.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 virtualConstructor.addMapping("RuntimeStub", RuntimeStub.class);
3388
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 1552
diff changeset
60 virtualConstructor.addMapping("RicochetBlob", RicochetBlob.class);
a80577f854f9 7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents: 1552
diff changeset
61 virtualConstructor.addMapping("AdapterBlob", AdapterBlob.class);
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 3388
diff changeset
62 virtualConstructor.addMapping("MethodHandlesAdapterBlob", MethodHandlesAdapterBlob.class);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 virtualConstructor.addMapping("SafepointBlob", SafepointBlob.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 virtualConstructor.addMapping("DeoptimizationBlob", DeoptimizationBlob.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (VM.getVM().isServerCompiler()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 virtualConstructor.addMapping("ExceptionBlob", ExceptionBlob.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 virtualConstructor.addMapping("UncommonTrapBlob", UncommonTrapBlob.class);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public CodeCache() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 heap = (CodeHeap) VMObjectFactory.newObject(CodeHeap.class, heapField.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
989
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
75 public NMethod scavengeRootMethods() {
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
76 return (NMethod) VMObjectFactory.newObject(NMethod.class, scavengeRootNMethodsField.getValue());
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
77 }
148e5441d916 6863023: need non-perm oops in code cache for JSR 292
jrose
parents: 0
diff changeset
78
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public boolean contains(Address p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return getHeap().contains(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 /** When VM.getVM().isDebugging() returns true, this behaves like
a61af66fc99e Initial load
duke
parents:
diff changeset
84 findBlobUnsafe */
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public CodeBlob findBlob(Address start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 CodeBlob result = findBlobUnsafe(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (result == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (VM.getVM().isDebugging()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // We could potientially look up non_entrant methods
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // NOTE: this is effectively a "guarantee", and is slightly different from the one in the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 Assert.that(!(result.isZombie() || result.isLockedByVM()), "unsafe access to zombie method");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public CodeBlob findBlobUnsafe(Address start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 CodeBlob result = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 result = (CodeBlob) virtualConstructor.instantiateWrapperFor(getHeap().findStart(start));
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 catch (WrongTypeException wte) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Address cbAddr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 cbAddr = getHeap().findStart(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 catch (Exception findEx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 findEx.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 String message = "Couldn't deduce type of CodeBlob ";
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (cbAddr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 message = message + "@" + cbAddr + " ";
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 message = message + "for PC=" + start;
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 throw new RuntimeException(message, wte);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (result == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // The HeapBlock that contains this blob is outside of the blob
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // but it shouldn't be an error to find a blob based on the
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // pointer to the HeapBlock.
a61af66fc99e Initial load
duke
parents:
diff changeset
127 Assert.that(result.blobContains(start) || result.blobContains(start.addOffsetTo(8)),
a61af66fc99e Initial load
duke
parents:
diff changeset
128 "found wrong CodeBlob");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 3388
diff changeset
130 if (result.isRicochetBlob()) {
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 3388
diff changeset
131 // This should probably be done for other SingletonBlobs
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 3388
diff changeset
132 return VM.getVM().ricochetBlob();
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 3388
diff changeset
133 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public NMethod findNMethod(Address start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 CodeBlob cb = findBlob(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 Assert.that(cb == null || cb.isNMethod(), "did not find an nmethod");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return (NMethod) cb;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public NMethod findNMethodUnsafe(Address start) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 CodeBlob cb = findBlobUnsafe(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 Assert.that(cb == null || cb.isNMethod(), "did not find an nmethod");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return (NMethod) cb;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 /** Routine for instantiating appropriately-typed wrapper for a
a61af66fc99e Initial load
duke
parents:
diff changeset
154 CodeBlob. Used by CodeCache, Runtime1, etc. */
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public CodeBlob createCodeBlobWrapper(Address codeBlobAddr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return (CodeBlob) virtualConstructor.instantiateWrapperFor(codeBlobAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 String message = "Unable to deduce type of CodeBlob from address " + codeBlobAddr +
a61af66fc99e Initial load
duke
parents:
diff changeset
161 " (expected type nmethod, RuntimeStub, ";
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (VM.getVM().isClientCompiler()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 message = message + " or ";
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 message = message + "SafepointBlob";
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (VM.getVM().isServerCompiler()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 message = message + ", DeoptimizationBlob, or ExceptionBlob";
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169 message = message + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
170 throw new RuntimeException(message);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public void iterate(CodeCacheVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 CodeHeap heap = getHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 Address ptr = heap.begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 Address end = heap.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 visitor.prologue(ptr, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 CodeBlob lastBlob = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 while (ptr != null && ptr.lessThan(end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 try {
1040
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 989
diff changeset
183 // Use findStart to get a pointer inside blob other findBlob asserts
873ec3787992 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 989
diff changeset
184 CodeBlob blob = findBlobUnsafe(heap.findStart(ptr));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (blob != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 visitor.visit(blob);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 if (blob == lastBlob) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 throw new InternalError("saw same blob twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 lastBlob = blob;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 } catch (RuntimeException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 Address next = heap.nextBlock(ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (next != null && next.lessThan(ptr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 throw new InternalError("pointer moved backwards");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 ptr = next;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
206 //
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 private CodeHeap getHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return heap;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }