Mercurial > hg > truffle
annotate src/share/vm/runtime/vframe_hp.cpp @ 1937:4853c5cad3aa
More deoptmization tracing.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Thu, 23 Dec 2010 22:14:31 +0100 |
parents | c18cbe5936b8 |
children | 06f017f7daa7 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
903
diff
changeset
|
2 * Copyright (c) 1997, 2009, 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:
903
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
903
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:
903
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_vframe_hp.cpp.incl" | |
27 | |
28 | |
29 // ------------- compiledVFrame -------------- | |
30 | |
31 StackValueCollection* compiledVFrame::locals() const { | |
32 // Natives has no scope | |
33 if (scope() == NULL) return new StackValueCollection(0); | |
34 GrowableArray<ScopeValue*>* scv_list = scope()->locals(); | |
35 if (scv_list == NULL) return new StackValueCollection(0); | |
36 | |
37 // scv_list is the list of ScopeValues describing the JVM stack state. | |
38 // There is one scv_list entry for every JVM stack state in use. | |
39 int length = scv_list->length(); | |
40 StackValueCollection* result = new StackValueCollection(length); | |
41 // In rare instances set_locals may have occurred in which case | |
42 // there are local values that are not described by the ScopeValue anymore | |
43 GrowableArray<jvmtiDeferredLocalVariable*>* deferred = NULL; | |
44 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = thread()->deferred_locals(); | |
45 if (list != NULL ) { | |
46 // In real life this never happens or is typically a single element search | |
47 for (int i = 0; i < list->length(); i++) { | |
48 if (list->at(i)->matches((vframe*)this)) { | |
49 deferred = list->at(i)->locals(); | |
50 break; | |
51 } | |
52 } | |
53 } | |
54 | |
1937
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
55 if (TraceDeoptimization) { |
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
56 tty->print_cr("bci=%d length=%d", this->bci(), length); |
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
57 tty->print_cr(err_msg("method name = %s", this->method()->name()->as_C_string())); |
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
58 tty->print_cr("relative pc=%d", this->fr().pc() - this->nm()->code_begin()); |
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
59 } |
4853c5cad3aa
More deoptmization tracing.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1552
diff
changeset
|
60 |
0 | 61 for( int i = 0; i < length; i++ ) { |
62 result->add( create_stack_value(scv_list->at(i)) ); | |
63 } | |
64 | |
65 // Replace specified locals with any deferred writes that are present | |
66 if (deferred != NULL) { | |
67 for ( int l = 0; l < deferred->length() ; l ++) { | |
68 jvmtiDeferredLocalVariable* val = deferred->at(l); | |
69 switch (val->type()) { | |
70 case T_BOOLEAN: | |
71 result->set_int_at(val->index(), val->value().z); | |
72 break; | |
73 case T_CHAR: | |
74 result->set_int_at(val->index(), val->value().c); | |
75 break; | |
76 case T_FLOAT: | |
77 result->set_float_at(val->index(), val->value().f); | |
78 break; | |
79 case T_DOUBLE: | |
80 result->set_double_at(val->index(), val->value().d); | |
81 break; | |
82 case T_BYTE: | |
83 result->set_int_at(val->index(), val->value().b); | |
84 break; | |
85 case T_SHORT: | |
86 result->set_int_at(val->index(), val->value().s); | |
87 break; | |
88 case T_INT: | |
89 result->set_int_at(val->index(), val->value().i); | |
90 break; | |
91 case T_LONG: | |
92 result->set_long_at(val->index(), val->value().j); | |
93 break; | |
94 case T_OBJECT: | |
95 { | |
96 Handle obj((oop)val->value().l); | |
97 result->set_obj_at(val->index(), obj); | |
98 } | |
99 break; | |
100 default: | |
101 ShouldNotReachHere(); | |
102 } | |
103 } | |
104 } | |
105 | |
106 return result; | |
107 } | |
108 | |
109 | |
110 void compiledVFrame::set_locals(StackValueCollection* values) const { | |
111 | |
112 fatal("Should use update_local for each local update"); | |
113 } | |
114 | |
115 void compiledVFrame::update_local(BasicType type, int index, jvalue value) { | |
116 | |
117 #ifdef ASSERT | |
118 | |
119 assert(fr().is_deoptimized_frame(), "frame must be scheduled for deoptimization"); | |
120 #endif /* ASSERT */ | |
121 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred = thread()->deferred_locals(); | |
122 if (deferred != NULL ) { | |
123 // See if this vframe has already had locals with deferred writes | |
124 int f; | |
125 for ( f = 0 ; f < deferred->length() ; f++ ) { | |
126 if (deferred->at(f)->matches(this)) { | |
127 // Matching, vframe now see if the local already had deferred write | |
128 GrowableArray<jvmtiDeferredLocalVariable*>* locals = deferred->at(f)->locals(); | |
129 int l; | |
130 for (l = 0 ; l < locals->length() ; l++ ) { | |
131 if (locals->at(l)->index() == index) { | |
132 locals->at(l)->set_value(value); | |
133 return; | |
134 } | |
135 } | |
136 // No matching local already present. Push a new value onto the deferred collection | |
137 locals->push(new jvmtiDeferredLocalVariable(index, type, value)); | |
138 return; | |
139 } | |
140 } | |
141 // No matching vframe must push a new vframe | |
142 } else { | |
143 // No deferred updates pending for this thread. | |
144 // allocate in C heap | |
145 deferred = new(ResourceObj::C_HEAP) GrowableArray<jvmtiDeferredLocalVariableSet*> (1, true); | |
146 thread()->set_deferred_locals(deferred); | |
147 } | |
148 deferred->push(new jvmtiDeferredLocalVariableSet(method(), bci(), fr().id())); | |
149 assert(deferred->top()->id() == fr().id(), "Huh? Must match"); | |
150 deferred->top()->set_local_at(index, type, value); | |
151 } | |
152 | |
153 StackValueCollection* compiledVFrame::expressions() const { | |
154 // Natives has no scope | |
155 if (scope() == NULL) return new StackValueCollection(0); | |
156 GrowableArray<ScopeValue*>* scv_list = scope()->expressions(); | |
157 if (scv_list == NULL) return new StackValueCollection(0); | |
158 | |
159 // scv_list is the list of ScopeValues describing the JVM stack state. | |
160 // There is one scv_list entry for every JVM stack state in use. | |
161 int length = scv_list->length(); | |
162 StackValueCollection* result = new StackValueCollection(length); | |
163 for( int i = 0; i < length; i++ ) | |
164 result->add( create_stack_value(scv_list->at(i)) ); | |
165 | |
166 return result; | |
167 } | |
168 | |
169 | |
170 // The implementation of the following two methods was factorized into the | |
171 // class StackValue because it is also used from within deoptimization.cpp for | |
172 // rematerialization and relocking of non-escaping objects. | |
173 | |
174 StackValue *compiledVFrame::create_stack_value(ScopeValue *sv) const { | |
175 return StackValue::create_stack_value(&_fr, register_map(), sv); | |
176 } | |
177 | |
178 BasicLock* compiledVFrame::resolve_monitor_lock(Location location) const { | |
179 return StackValue::resolve_monitor_lock(&_fr, location); | |
180 } | |
181 | |
182 | |
183 GrowableArray<MonitorInfo*>* compiledVFrame::monitors() const { | |
184 // Natives has no scope | |
185 if (scope() == NULL) { | |
186 nmethod* nm = code(); | |
187 methodOop method = nm->method(); | |
188 assert(method->is_native(), ""); | |
189 if (!method->is_synchronized()) { | |
190 return new GrowableArray<MonitorInfo*>(0); | |
191 } | |
192 // This monitor is really only needed for UseBiasedLocking, but | |
193 // return it in all cases for now as it might be useful for stack | |
194 // traces and tools as well | |
195 GrowableArray<MonitorInfo*> *monitors = new GrowableArray<MonitorInfo*>(1); | |
196 // Casting away const | |
197 frame& fr = (frame&) _fr; | |
198 MonitorInfo* info = new MonitorInfo(fr.compiled_synchronized_native_monitor_owner(nm), | |
818
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
199 fr.compiled_synchronized_native_monitor(nm), false, false); |
0 | 200 monitors->push(info); |
201 return monitors; | |
202 } | |
203 GrowableArray<MonitorValue*>* monitors = scope()->monitors(); | |
204 if (monitors == NULL) { | |
205 return new GrowableArray<MonitorInfo*>(0); | |
206 } | |
207 GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(monitors->length()); | |
208 for (int index = 0; index < monitors->length(); index++) { | |
209 MonitorValue* mv = monitors->at(index); | |
818
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
210 ScopeValue* ov = mv->owner(); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
211 StackValue *owner_sv = create_stack_value(ov); // it is an oop |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
212 if (ov->is_object() && owner_sv->obj_is_scalar_replaced()) { // The owner object was scalar replaced |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
213 assert(mv->eliminated(), "monitor should be eliminated for scalar replaced object"); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
214 // Put klass for scalar replaced object. |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
215 ScopeValue* kv = ((ObjectValue *)ov)->klass(); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
216 assert(kv->is_constant_oop(), "klass should be oop constant for scalar replaced object"); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
217 KlassHandle k(((ConstantOopReadValue*)kv)->value()()); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
218 result->push(new MonitorInfo(k->as_klassOop(), resolve_monitor_lock(mv->basic_lock()), |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
219 mv->eliminated(), true)); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
220 } else { |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
221 result->push(new MonitorInfo(owner_sv->get_obj()(), resolve_monitor_lock(mv->basic_lock()), |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
222 mv->eliminated(), false)); |
b109e761e927
6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents:
196
diff
changeset
|
223 } |
0 | 224 } |
225 return result; | |
226 } | |
227 | |
228 | |
229 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, nmethod* nm) | |
230 : javaVFrame(fr, reg_map, thread) { | |
231 _scope = NULL; | |
232 // Compiled method (native stub or Java code) | |
233 // native wrappers have no scope data, it is implied | |
234 if (!nm->is_native_method()) { | |
235 _scope = nm->scope_desc_at(_fr.pc()); | |
236 } | |
237 } | |
238 | |
239 compiledVFrame::compiledVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread, ScopeDesc* scope) | |
240 : javaVFrame(fr, reg_map, thread) { | |
241 _scope = scope; | |
242 guarantee(_scope != NULL, "scope must be present"); | |
243 } | |
244 | |
245 | |
246 bool compiledVFrame::is_top() const { | |
247 // FIX IT: Remove this when new native stubs are in place | |
248 if (scope() == NULL) return true; | |
249 return scope()->is_top(); | |
250 } | |
251 | |
252 | |
253 nmethod* compiledVFrame::code() const { | |
254 return CodeCache::find_nmethod(_fr.pc()); | |
255 } | |
256 | |
257 | |
258 methodOop compiledVFrame::method() const { | |
259 if (scope() == NULL) { | |
260 // native nmethods have no scope the method is implied | |
261 nmethod* nm = code(); | |
262 assert(nm->is_native_method(), "must be native"); | |
263 return nm->method(); | |
264 } | |
265 return scope()->method()(); | |
266 } | |
267 | |
268 | |
269 int compiledVFrame::bci() const { | |
270 int raw = raw_bci(); | |
271 return raw == SynchronizationEntryBCI ? 0 : raw; | |
272 } | |
273 | |
274 | |
275 int compiledVFrame::raw_bci() const { | |
276 if (scope() == NULL) { | |
277 // native nmethods have no scope the method/bci is implied | |
278 nmethod* nm = code(); | |
279 assert(nm->is_native_method(), "must be native"); | |
280 return 0; | |
281 } | |
282 return scope()->bci(); | |
283 } | |
284 | |
900
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
285 bool compiledVFrame::should_reexecute() const { |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
286 if (scope() == NULL) { |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
287 // native nmethods have no scope the method/bci is implied |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
288 nmethod* nm = code(); |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
289 assert(nm->is_native_method(), "must be native"); |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
290 return false; |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
291 } |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
292 return scope()->should_reexecute(); |
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
818
diff
changeset
|
293 } |
0 | 294 |
295 vframe* compiledVFrame::sender() const { | |
296 const frame f = fr(); | |
297 if (scope() == NULL) { | |
298 // native nmethods have no scope the method/bci is implied | |
299 nmethod* nm = code(); | |
300 assert(nm->is_native_method(), "must be native"); | |
301 return vframe::sender(); | |
302 } else { | |
303 return scope()->is_top() | |
304 ? vframe::sender() | |
305 : new compiledVFrame(&f, register_map(), thread(), scope()->sender()); | |
306 } | |
307 } | |
308 | |
309 jvmtiDeferredLocalVariableSet::jvmtiDeferredLocalVariableSet(methodOop method, int bci, intptr_t* id) { | |
310 _method = method; | |
311 _bci = bci; | |
312 _id = id; | |
313 // Alway will need at least one, must be on C heap | |
314 _locals = new(ResourceObj::C_HEAP) GrowableArray<jvmtiDeferredLocalVariable*> (1, true); | |
315 } | |
316 | |
317 jvmtiDeferredLocalVariableSet::~jvmtiDeferredLocalVariableSet() { | |
318 for (int i = 0; i < _locals->length() ; i++ ) { | |
319 delete _locals->at(i); | |
320 } | |
321 // Free growableArray and c heap for elements | |
322 delete _locals; | |
323 } | |
324 | |
325 bool jvmtiDeferredLocalVariableSet::matches(vframe* vf) { | |
326 if (!vf->is_compiled_frame()) return false; | |
327 compiledVFrame* cvf = (compiledVFrame*)vf; | |
328 return cvf->fr().id() == id() && cvf->method() == method() && cvf->bci() == bci(); | |
329 } | |
330 | |
331 void jvmtiDeferredLocalVariableSet::set_local_at(int idx, BasicType type, jvalue val) { | |
332 int i; | |
333 for ( i = 0 ; i < locals()->length() ; i++ ) { | |
334 if ( locals()->at(i)->index() == idx) { | |
335 assert(locals()->at(i)->type() == type, "Wrong type"); | |
336 locals()->at(i)->set_value(val); | |
337 return; | |
338 } | |
339 } | |
340 locals()->push(new jvmtiDeferredLocalVariable(idx, type, val)); | |
341 } | |
342 | |
343 void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) { | |
344 | |
345 f->do_oop((oop*) &_method); | |
346 for ( int i = 0; i < locals()->length(); i++ ) { | |
347 if ( locals()->at(i)->type() == T_OBJECT) { | |
348 f->do_oop(locals()->at(i)->oop_addr()); | |
349 } | |
350 } | |
351 } | |
352 | |
353 jvmtiDeferredLocalVariable::jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value) { | |
354 _index = index; | |
355 _type = type; | |
356 _value = value; | |
357 } | |
358 | |
359 | |
360 #ifndef PRODUCT | |
361 void compiledVFrame::verify() const { | |
362 Unimplemented(); | |
363 } | |
364 #endif // PRODUCT |