annotate agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 72088be4b386
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public class NMethod extends CodeBlob {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static long pcDescSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static CIntegerField zombieInstructionSizeField;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static sun.jvm.hotspot.types.OopField methodField;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 /** != InvocationEntryBci if this nmethod is an on-stack replacement method */
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static CIntegerField entryBCIField;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 /** To support simple linked-list chaining of nmethods */
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static AddressField linkField;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 /** Offsets for different nmethod parts */
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static CIntegerField exceptionOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static CIntegerField deoptOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private static CIntegerField origPCOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static CIntegerField stubOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static CIntegerField scopesDataOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static CIntegerField scopesPCsOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static CIntegerField dependenciesOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private static CIntegerField handlerTableOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private static CIntegerField nulChkTableOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private static CIntegerField nmethodEndOffsetField;
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 /** Offsets for entry points */
a61af66fc99e Initial load
duke
parents:
diff changeset
57 /** Entry point with class check */
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private static AddressField entryPointField;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 /** Entry point without class check */
a61af66fc99e Initial load
duke
parents:
diff changeset
60 private static AddressField verifiedEntryPointField;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 /** Entry point for on stack replacement */
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private static AddressField osrEntryPointField;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // FIXME: add access to flags (how?)
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 /** NMethod Flushing lock (if non-zero, then the nmethod is not removed) */
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private static JIntField lockCountField;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 /** not_entrant method removal. Each mark_sweep pass will update
a61af66fc99e Initial load
duke
parents:
diff changeset
70 this mark to current sweep invocation count if it is seen on the
a61af66fc99e Initial load
duke
parents:
diff changeset
71 stack. An not_entrant method can be removed when there is no
a61af66fc99e Initial load
duke
parents:
diff changeset
72 more activations, i.e., when the _stack_traversal_mark is less than
a61af66fc99e Initial load
duke
parents:
diff changeset
73 current sweep traversal index. */
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private static CIntegerField stackTraversalMarkField;
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 });
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 private static void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Type type = db.lookupType("nmethod");
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 zombieInstructionSizeField = type.getCIntegerField("_zombie_instruction_size");
a61af66fc99e Initial load
duke
parents:
diff changeset
88 methodField = type.getOopField("_method");
a61af66fc99e Initial load
duke
parents:
diff changeset
89 entryBCIField = type.getCIntegerField("_entry_bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
90 linkField = type.getAddressField("_link");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 exceptionOffsetField = type.getCIntegerField("_exception_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 deoptOffsetField = type.getCIntegerField("_deoptimize_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 origPCOffsetField = type.getCIntegerField("_orig_pc_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 stubOffsetField = type.getCIntegerField("_stub_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 scopesDataOffsetField = type.getCIntegerField("_scopes_data_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 scopesPCsOffsetField = type.getCIntegerField("_scopes_pcs_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 dependenciesOffsetField = type.getCIntegerField("_dependencies_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 handlerTableOffsetField = type.getCIntegerField("_handler_table_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
99 nulChkTableOffsetField = type.getCIntegerField("_nul_chk_table_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
100 nmethodEndOffsetField = type.getCIntegerField("_nmethod_end_offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
101 entryPointField = type.getAddressField("_entry_point");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 verifiedEntryPointField = type.getAddressField("_verified_entry_point");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 osrEntryPointField = type.getAddressField("_osr_entry_point");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 lockCountField = type.getJIntField("_lock_count");
a61af66fc99e Initial load
duke
parents:
diff changeset
105 stackTraversalMarkField = type.getCIntegerField("_stack_traversal_mark");
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 pcDescSize = db.lookupType("PcDesc").getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public NMethod(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public Address getAddress() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public Method getMethod() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return (Method) VM.getVM().getObjectHeap().newOop(methodField.getValue(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Type info
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public boolean isNMethod() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public boolean isJavaMethod() { return !getMethod().isNative(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public boolean isNativeMethod() { return getMethod().isNative(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public boolean isOSRMethod() { return getEntryBCI() != VM.getVM().getInvocationEntryBCI(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 /** Boundaries for different parts */
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public Address constantsBegin() { return instructionsBegin(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public Address constantsEnd() { return getEntryPoint(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public Address codeBegin() { return getEntryPoint(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 public Address codeEnd() { return headerBegin().addOffsetTo(getStubOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 public Address exceptionBegin() { return headerBegin().addOffsetTo(getExceptionOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public Address deoptBegin() { return headerBegin().addOffsetTo(getDeoptOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public Address stubBegin() { return headerBegin().addOffsetTo(getStubOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public Address stubEnd() { return headerBegin().addOffsetTo(getScopesDataOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public Address scopesDataBegin() { return headerBegin().addOffsetTo(getScopesDataOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public Address scopesDataEnd() { return headerBegin().addOffsetTo(getScopesPCsOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 public Address scopesPCsBegin() { return headerBegin().addOffsetTo(getScopesPCsOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 public Address scopesPCsEnd() { return headerBegin().addOffsetTo(getDependenciesOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public Address dependenciesBegin() { return headerBegin().addOffsetTo(getDependenciesOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public Address dependenciesEnd() { return headerBegin().addOffsetTo(getHandlerTableOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public Address handlerTableBegin() { return headerBegin().addOffsetTo(getHandlerTableOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public Address handlerTableEnd() { return headerBegin().addOffsetTo(getNulChkTableOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public Address nulChkTableBegin() { return headerBegin().addOffsetTo(getNulChkTableOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public Address nulChkTableEnd() { return headerBegin().addOffsetTo(getNMethodEndOffset()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 public int constantsSize() { return (int) constantsEnd() .minus(constantsBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public int codeSize() { return (int) codeEnd() .minus(codeBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 public int stubSize() { return (int) stubEnd() .minus(stubBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public int scopesDataSize() { return (int) scopesDataEnd() .minus(scopesDataBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 public int scopesPCsSize() { return (int) scopesPCsEnd() .minus(scopesPCsBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public int dependenciesSize() { return (int) dependenciesEnd().minus(dependenciesBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 public int handlerTableSize() { return (int) handlerTableEnd().minus(handlerTableBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public int nulChkTableSize() { return (int) nulChkTableEnd() .minus(nulChkTableBegin()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 public int origPCOffset() { return (int) origPCOffsetField.getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 public int totalSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return
a61af66fc99e Initial load
duke
parents:
diff changeset
162 constantsSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
163 codeSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
164 stubSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
165 scopesDataSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
166 scopesPCsSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
167 dependenciesSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
168 handlerTableSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
169 nulChkTableSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 public boolean constantsContains (Address addr) { return constantsBegin() .lessThanOrEqual(addr) && constantsEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public boolean codeContains (Address addr) { return codeBegin() .lessThanOrEqual(addr) && codeEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 public boolean stubContains (Address addr) { return stubBegin() .lessThanOrEqual(addr) && stubEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean scopesDataContains (Address addr) { return scopesDataBegin() .lessThanOrEqual(addr) && scopesDataEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 public boolean scopesPCsContains (Address addr) { return scopesPCsBegin() .lessThanOrEqual(addr) && scopesPCsEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public boolean handlerTableContains(Address addr) { return handlerTableBegin().lessThanOrEqual(addr) && handlerTableEnd().greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public boolean nulChkTableContains (Address addr) { return nulChkTableBegin() .lessThanOrEqual(addr) && nulChkTableEnd() .greaterThan(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 /** Entry points */
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public Address getEntryPoint() { return entryPointField.getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public Address getVerifiedEntryPoint() { return verifiedEntryPointField.getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // FIXME: add interpreter_entry_point()
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // FIXME: add lazy_interpreter_entry_point() for C2
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // **********
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // * FIXME: * ADD ACCESS TO FLAGS!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // **********
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // public boolean isInUse();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // public boolean isAlive();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // public boolean isNotEntrant();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // public boolean isZombie();
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // ********************************
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // * MAJOR FIXME: MAJOR HACK HERE *
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // ********************************
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public boolean isZombie() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // public boolean isUnloaded();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // public boolean isYoung();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // public boolean isOld();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // public int age();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // public boolean isMarkedForDeoptimization();
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // public boolean isMarkedForUnloading();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // public boolean isMarkedForReclamation();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // public int level();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // public int version();
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // FIXME: add mutators for above
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // FIXME: add exception cache access?
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 /** On-stack replacement support */
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // FIXME: add mutators
a61af66fc99e Initial load
duke
parents:
diff changeset
215 public int getOSREntryBCI() {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 Assert.that(getEntryBCI() != VM.getVM().getInvocationEntryBCI(), "wrong kind of nmethod");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return getEntryBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 public NMethod getLink() {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return (NMethod) VMObjectFactory.newObject(NMethod.class, linkField.getValue(addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 /** Tells whether frames described by this nmethod can be
a61af66fc99e Initial load
duke
parents:
diff changeset
227 deoptimized. Note: native wrappers cannot be deoptimized. */
a61af66fc99e Initial load
duke
parents:
diff changeset
228 public boolean canBeDeoptimized() { return isJavaMethod(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // FIXME: add inline cache support
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // FIXME: add flush()
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 public boolean isLockedByVM() { return lockCountField.getValue(addr) > 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // FIXME: add mark_as_seen_on_stack
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // FIXME: add can_not_entrant_be_converted
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // FIXME: add GC support
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // void follow_roots_or_mark_for_unloading(bool unloading_occurred, bool& marked_for_unloading);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // void follow_root_or_mark_for_unloading(oop* root, bool unloading_occurred, bool& marked_for_unloading);
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, void f(oop*));
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // void adjust_pointers();
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 /** Finds a PCDesc with real-pc equal to "pc" */
a61af66fc99e Initial load
duke
parents:
diff changeset
245 public PCDesc getPCDescAt(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // FIXME: consider adding cache like the one down in the VM
a61af66fc99e Initial load
duke
parents:
diff changeset
247 for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 PCDesc pcDesc = new PCDesc(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 if (pcDesc.getRealPC(this).equals(pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 return pcDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 /** ScopeDesc for an instruction */
a61af66fc99e Initial load
duke
parents:
diff changeset
257 public ScopeDesc getScopeDescAt(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 PCDesc pd = getPCDescAt(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 Assert.that(pd != null, "scope must be present");
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 return new ScopeDesc(this, pd.getScopeDecodeOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 /** This is only for use by the debugging system, and is only
a61af66fc99e Initial load
duke
parents:
diff changeset
266 intended for use in the topmost frame, where we are not
a61af66fc99e Initial load
duke
parents:
diff changeset
267 guaranteed to be at a PC for which we have a PCDesc. It finds
a61af66fc99e Initial load
duke
parents:
diff changeset
268 the PCDesc with realPC closest to the current PC. */
a61af66fc99e Initial load
duke
parents:
diff changeset
269 public PCDesc getPCDescNearDbg(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 PCDesc bestGuessPCDesc = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 long bestDistance = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
272 for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 PCDesc pcDesc = new PCDesc(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // In case pc is null
a61af66fc99e Initial load
duke
parents:
diff changeset
275 long distance = -pcDesc.getRealPC(this).minus(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if ((bestGuessPCDesc == null) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ((distance >= 0) && (distance < bestDistance))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 bestGuessPCDesc = pcDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 bestDistance = distance;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 return bestGuessPCDesc;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 /** This is only for use by the debugging system, and is only
a61af66fc99e Initial load
duke
parents:
diff changeset
286 intended for use in the topmost frame, where we are not
a61af66fc99e Initial load
duke
parents:
diff changeset
287 guaranteed to be at a PC for which we have a PCDesc. It finds
a61af66fc99e Initial load
duke
parents:
diff changeset
288 the ScopeDesc closest to the current PC. NOTE that this may
a61af66fc99e Initial load
duke
parents:
diff changeset
289 return NULL for compiled methods which don't have any
a61af66fc99e Initial load
duke
parents:
diff changeset
290 ScopeDescs! */
a61af66fc99e Initial load
duke
parents:
diff changeset
291 public ScopeDesc getScopeDescNearDbg(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 PCDesc pd = getPCDescNearDbg(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (pd == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 return new ScopeDesc(this, pd.getScopeDecodeOffset());
a61af66fc99e Initial load
duke
parents:
diff changeset
295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 public Map/*<Address, PcDesc>*/ getSafepoints() {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 Map safepoints = new HashMap(); // Map<Address, PcDesc>
a61af66fc99e Initial load
duke
parents:
diff changeset
299 sun.jvm.hotspot.debugger.Address p = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 for (p = scopesPCsBegin(); p.lessThan(scopesPCsEnd());
a61af66fc99e Initial load
duke
parents:
diff changeset
301 p = p.addOffsetTo(pcDescSize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 PCDesc pcDesc = new PCDesc(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
303 sun.jvm.hotspot.debugger.Address pc = pcDesc.getRealPC(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 safepoints.put(pc, pcDesc);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return safepoints;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // FIXME: add getPCOffsetForBCI()
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // FIXME: add embeddedOopAt()
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // FIXME: add isDependentOn()
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // FIXME: add isPatchableAt()
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 /** Support for code generation. Only here for proof-of-concept. */
a61af66fc99e Initial load
duke
parents:
diff changeset
315 public static int getEntryPointOffset() { return (int) entryPointField.getOffset(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 public static int getVerifiedEntryPointOffset() { return (int) verifiedEntryPointField.getOffset(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 public static int getOSREntryPointOffset() { return (int) osrEntryPointField.getOffset(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 public static int getEntryBCIOffset() { return (int) entryBCIField.getOffset(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 /** NOTE: renamed from "method_offset_in_bytes" */
a61af66fc99e Initial load
duke
parents:
diff changeset
320 public static int getMethodOffset() { return (int) methodField.getOffset(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 printOn(System.out);
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 Method method = getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 return "NMethod for " +
a61af66fc99e Initial load
duke
parents:
diff changeset
329 method.getMethodHolder().getName().asString() + "." +
a61af66fc99e Initial load
duke
parents:
diff changeset
330 method.getName().asString() + method.getSignature().asString() + "==>n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
331 super.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 public String flagsToString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // FIXME need access to flags...
a61af66fc99e Initial load
duke
parents:
diff changeset
336 return "";
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 public String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 Method method = getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
341 return "NMethod for " +
a61af66fc99e Initial load
duke
parents:
diff changeset
342 method.getMethodHolder().getName().asString() + "." +
a61af66fc99e Initial load
duke
parents:
diff changeset
343 method.getName().asString() +
a61af66fc99e Initial load
duke
parents:
diff changeset
344 method.getSignature().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
349 //
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351 private int getEntryBCI() { return (int) entryBCIField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 private int getExceptionOffset() { return (int) exceptionOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 private int getDeoptOffset() { return (int) deoptOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 private int getStubOffset() { return (int) stubOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 private int getScopesDataOffset() { return (int) scopesDataOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
356 private int getScopesPCsOffset() { return (int) scopesPCsOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 private int getDependenciesOffset() { return (int) dependenciesOffsetField.getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
358 private int getHandlerTableOffset() { return (int) handlerTableOffsetField.getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
359 private int getNulChkTableOffset() { return (int) nulChkTableOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 private int getNMethodEndOffset() { return (int) nmethodEndOffsetField .getValue(addr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }