Mercurial > hg > graal-compiler
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 |
rev | line source |
---|---|
0 | 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 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
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 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.code; | |
26 | |
27 import java.util.*; | |
28 import sun.jvm.hotspot.debugger.*; | |
29 import sun.jvm.hotspot.memory.*; | |
30 import sun.jvm.hotspot.runtime.*; | |
31 import sun.jvm.hotspot.types.*; | |
32 import sun.jvm.hotspot.utilities.*; | |
33 | |
34 public class CodeCache { | |
35 private static AddressField heapField; | |
989 | 36 private static AddressField scavengeRootNMethodsField; |
0 | 37 private static VirtualConstructor virtualConstructor; |
38 | |
39 private CodeHeap heap; | |
40 | |
41 static { | |
42 VM.registerVMInitializedObserver(new Observer() { | |
43 public void update(Observable o, Object data) { | |
44 initialize(VM.getVM().getTypeDataBase()); | |
45 } | |
46 }); | |
47 } | |
48 | |
49 private static synchronized void initialize(TypeDataBase db) { | |
50 Type type = db.lookupType("CodeCache"); | |
51 | |
52 heapField = type.getAddressField("_heap"); | |
989 | 53 scavengeRootNMethodsField = type.getAddressField("_scavenge_root_nmethods"); |
0 | 54 |
55 virtualConstructor = new VirtualConstructor(db); | |
56 // Add mappings for all possible CodeBlob subclasses | |
57 virtualConstructor.addMapping("BufferBlob", BufferBlob.class); | |
58 virtualConstructor.addMapping("nmethod", NMethod.class); | |
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 | 63 virtualConstructor.addMapping("SafepointBlob", SafepointBlob.class); |
64 virtualConstructor.addMapping("DeoptimizationBlob", DeoptimizationBlob.class); | |
65 if (VM.getVM().isServerCompiler()) { | |
66 virtualConstructor.addMapping("ExceptionBlob", ExceptionBlob.class); | |
67 virtualConstructor.addMapping("UncommonTrapBlob", UncommonTrapBlob.class); | |
68 } | |
69 } | |
70 | |
71 public CodeCache() { | |
72 heap = (CodeHeap) VMObjectFactory.newObject(CodeHeap.class, heapField.getValue()); | |
73 } | |
74 | |
989 | 75 public NMethod scavengeRootMethods() { |
76 return (NMethod) VMObjectFactory.newObject(NMethod.class, scavengeRootNMethodsField.getValue()); | |
77 } | |
78 | |
0 | 79 public boolean contains(Address p) { |
80 return getHeap().contains(p); | |
81 } | |
82 | |
83 /** When VM.getVM().isDebugging() returns true, this behaves like | |
84 findBlobUnsafe */ | |
85 public CodeBlob findBlob(Address start) { | |
86 CodeBlob result = findBlobUnsafe(start); | |
87 if (result == null) return null; | |
88 if (VM.getVM().isDebugging()) { | |
89 return result; | |
90 } | |
91 // We could potientially look up non_entrant methods | |
92 // NOTE: this is effectively a "guarantee", and is slightly different from the one in the VM | |
93 if (Assert.ASSERTS_ENABLED) { | |
94 Assert.that(!(result.isZombie() || result.isLockedByVM()), "unsafe access to zombie method"); | |
95 } | |
96 return result; | |
97 } | |
98 | |
99 public CodeBlob findBlobUnsafe(Address start) { | |
100 CodeBlob result = null; | |
101 | |
102 try { | |
103 result = (CodeBlob) virtualConstructor.instantiateWrapperFor(getHeap().findStart(start)); | |
104 } | |
105 catch (WrongTypeException wte) { | |
106 Address cbAddr = null; | |
107 try { | |
108 cbAddr = getHeap().findStart(start); | |
109 } | |
110 catch (Exception findEx) { | |
111 findEx.printStackTrace(); | |
112 } | |
113 | |
114 String message = "Couldn't deduce type of CodeBlob "; | |
115 if (cbAddr != null) { | |
116 message = message + "@" + cbAddr + " "; | |
117 } | |
118 message = message + "for PC=" + start; | |
119 | |
120 throw new RuntimeException(message, wte); | |
121 } | |
122 if (result == null) return null; | |
123 if (Assert.ASSERTS_ENABLED) { | |
124 // The HeapBlock that contains this blob is outside of the blob | |
125 // but it shouldn't be an error to find a blob based on the | |
126 // pointer to the HeapBlock. | |
127 Assert.that(result.blobContains(start) || result.blobContains(start.addOffsetTo(8)), | |
128 "found wrong CodeBlob"); | |
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 | 134 return result; |
135 } | |
136 | |
137 public NMethod findNMethod(Address start) { | |
138 CodeBlob cb = findBlob(start); | |
139 if (Assert.ASSERTS_ENABLED) { | |
140 Assert.that(cb == null || cb.isNMethod(), "did not find an nmethod"); | |
141 } | |
142 return (NMethod) cb; | |
143 } | |
144 | |
145 public NMethod findNMethodUnsafe(Address start) { | |
146 CodeBlob cb = findBlobUnsafe(start); | |
147 if (Assert.ASSERTS_ENABLED) { | |
148 Assert.that(cb == null || cb.isNMethod(), "did not find an nmethod"); | |
149 } | |
150 return (NMethod) cb; | |
151 } | |
152 | |
153 /** Routine for instantiating appropriately-typed wrapper for a | |
154 CodeBlob. Used by CodeCache, Runtime1, etc. */ | |
155 public CodeBlob createCodeBlobWrapper(Address codeBlobAddr) { | |
156 try { | |
157 return (CodeBlob) virtualConstructor.instantiateWrapperFor(codeBlobAddr); | |
158 } | |
159 catch (Exception e) { | |
160 String message = "Unable to deduce type of CodeBlob from address " + codeBlobAddr + | |
161 " (expected type nmethod, RuntimeStub, "; | |
162 if (VM.getVM().isClientCompiler()) { | |
163 message = message + " or "; | |
164 } | |
165 message = message + "SafepointBlob"; | |
166 if (VM.getVM().isServerCompiler()) { | |
167 message = message + ", DeoptimizationBlob, or ExceptionBlob"; | |
168 } | |
169 message = message + ")"; | |
170 throw new RuntimeException(message); | |
171 } | |
172 } | |
173 | |
174 public void iterate(CodeCacheVisitor visitor) { | |
175 CodeHeap heap = getHeap(); | |
176 Address ptr = heap.begin(); | |
177 Address end = heap.end(); | |
178 | |
179 visitor.prologue(ptr, end); | |
180 CodeBlob lastBlob = null; | |
181 while (ptr != null && ptr.lessThan(end)) { | |
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 | 185 if (blob != null) { |
186 visitor.visit(blob); | |
187 if (blob == lastBlob) { | |
188 throw new InternalError("saw same blob twice"); | |
189 } | |
190 lastBlob = blob; | |
191 } | |
192 } catch (RuntimeException e) { | |
193 e.printStackTrace(); | |
194 } | |
195 Address next = heap.nextBlock(ptr); | |
196 if (next != null && next.lessThan(ptr)) { | |
197 throw new InternalError("pointer moved backwards"); | |
198 } | |
199 ptr = next; | |
200 } | |
201 visitor.epilogue(); | |
202 } | |
203 | |
204 //-------------------------------------------------------------------------------- | |
205 // Internals only below this point | |
206 // | |
207 | |
208 private CodeHeap getHeap() { | |
209 return heap; | |
210 } | |
211 } |