annotate agent/src/share/classes/sun/jvm/hotspot/runtime/VFrame.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 c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2006, 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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class VFrame {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 protected Frame fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 protected RegisterMap regMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 protected JavaThread thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 protected VFrame(Frame f, RegisterMap regMap, JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 this.regMap = (RegisterMap) regMap.clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (f != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // the frame is null if we create a deoptimizedVFrame from a vframeArray
a61af66fc99e Initial load
duke
parents:
diff changeset
41 fr = (Frame) f.clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this.thread = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 /** Factory method for creating vframes. The "unsafe" flag turns off
a61af66fc99e Initial load
duke
parents:
diff changeset
48 an assertion which the runtime system uses to ensure integrity,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 but which must not be applied in the debugging situation. The
a61af66fc99e Initial load
duke
parents:
diff changeset
50 "mayBeImprecise" flag should be set to true for the case of the
a61af66fc99e Initial load
duke
parents:
diff changeset
51 top frame in the debugging system (obtained via
a61af66fc99e Initial load
duke
parents:
diff changeset
52 JavaThread.getCurrentFrameGuess()). */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public static VFrame newVFrame(Frame f, RegisterMap regMap, JavaThread thread, boolean unsafe, boolean mayBeImprecise) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (f.isInterpretedFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return new InterpretedVFrame(f, regMap, thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (!VM.getVM().isCore()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 CodeBlob cb;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (unsafe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 cb = VM.getVM().getCodeCache().findBlobUnsafe(f.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
62 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 cb = VM.getVM().getCodeCache().findBlob(f.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (cb != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (cb.isNMethod()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 NMethod nm = (NMethod) cb;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Compiled method (native stub or Java code)
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ScopeDesc scope = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // FIXME: should revisit the check of isDebugging(); should not be necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (mayBeImprecise || VM.getVM().isDebugging()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 scope = nm.getScopeDescNearDbg(f.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 scope = nm.getScopeDescAt(f.getPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return new CompiledVFrame(f, regMap, thread, scope, mayBeImprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
3908
7588156f5cf9 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 1552
diff changeset
80 if (f.isRuntimeFrame()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // This is a conversion frame. Skip this frame and try again.
a61af66fc99e Initial load
duke
parents:
diff changeset
82 RegisterMap tempMap = regMap.copy();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Frame s = f.sender(tempMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return newVFrame(s, tempMap, thread, unsafe, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // External frame
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return new ExternalVFrame(f, regMap, thread, mayBeImprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 /** Factory method for creating vframes. This is equivalent to
a61af66fc99e Initial load
duke
parents:
diff changeset
94 calling the above version with the "unsafe" and "imprecise"
a61af66fc99e Initial load
duke
parents:
diff changeset
95 flags set to false. */
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public static VFrame newVFrame(Frame f, RegisterMap regMap, JavaThread thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return newVFrame(f, regMap, thread, false, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 /** Accessors */
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public Frame getFrame() { return fr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public RegisterMap getRegisterMap() { return regMap; }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public JavaThread getThread() { return thread; }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /** Returns the sender vframe */
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public VFrame sender() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 Assert.that(isTop(), "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return sender(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 /** Returns the sender vframe; takes argument for debugging situation */
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public VFrame sender(boolean mayBeImprecise) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 RegisterMap tempMap = (RegisterMap) getRegisterMap().clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (fr.isFirstFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Frame s = fr.realSender(tempMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // ia64 in 1.4.1 only has java frames and no entryFrame
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // so "s" can be null here for the first frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (s == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Assert.that(VM.getVM().getCPU().equals("ia64"), "Only ia64 should have null here");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 if (s.isFirstFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return VFrame.newVFrame(s, tempMap, getThread(), VM.getVM().isDebugging(), mayBeImprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 /** Returns the next javaVFrame on the stack (skipping all other
a61af66fc99e Initial load
duke
parents:
diff changeset
133 kinds of frames). In the debugging situation, allows the
a61af66fc99e Initial load
duke
parents:
diff changeset
134 "imprecise" flag to propagate up the stack. We must not assert
a61af66fc99e Initial load
duke
parents:
diff changeset
135 that a ScopeDesc exists for the topmost compiled frame on the
a61af66fc99e Initial load
duke
parents:
diff changeset
136 stack. */
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public JavaVFrame javaSender() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 boolean imprecise = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // Hack for debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (VM.getVM().isDebugging()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (!isJavaFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 imprecise = mayBeImpreciseDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 VFrame f = sender(imprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 while (f != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (f.isJavaFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return (JavaVFrame) f;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 f = f.sender(imprecise);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 /** Answers if the this is the top vframe in the frame, i.e., if the
a61af66fc99e Initial load
duke
parents:
diff changeset
157 sender vframe is in the caller frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public boolean isTop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 /** Returns top vframe within same frame (see isTop()) */
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public VFrame top() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 VFrame vf = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 while (!vf.isTop()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 vf = vf.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 /** Type testing operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public boolean isEntryFrame() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public boolean isJavaFrame() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public boolean isInterpretedFrame() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean isCompiledFrame() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 public boolean isDeoptimized() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 /** An indication of whether this VFrame is "precise" or a best
a61af66fc99e Initial load
duke
parents:
diff changeset
179 guess. This is used in the debugging system to handle the top
a61af66fc99e Initial load
duke
parents:
diff changeset
180 frame on the stack, which, since the system will in general not
a61af66fc99e Initial load
duke
parents:
diff changeset
181 be at a safepoint, has to make some guesses about exactly where
a61af66fc99e Initial load
duke
parents:
diff changeset
182 in the execution it is. Any debugger should indicate to the user
a61af66fc99e Initial load
duke
parents:
diff changeset
183 that the information for this frame may not be 100% correct.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 FIXME: may need to move this up into VFrame instead of keeping
a61af66fc99e Initial load
duke
parents:
diff changeset
185 it in CompiledVFrame. */
a61af66fc99e Initial load
duke
parents:
diff changeset
186 public boolean mayBeImpreciseDbg() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 /** Printing operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 printOn(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public void printOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (VM.getVM().wizardMode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 fr.printValueOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 public void printValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 printValueOn(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 public void printValueOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 printOn(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }