1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_ValueStack.hpp"
28 #include "ci/ciArray.hpp"
29 #include "ci/ciInstance.hpp"
30 #include "ci/ciObject.hpp"
31
32
33 #ifndef PRODUCT
34
basic_type_name(BasicType type)35 const char* InstructionPrinter::basic_type_name(BasicType type) {
36 switch (type) {
37 case T_BOOLEAN: return "boolean";
38 case T_BYTE : return "byte";
39 case T_CHAR : return "char";
40 case T_SHORT : return "short";
41 case T_INT : return "int";
42 case T_LONG : return "long";
43 case T_FLOAT : return "float";
44 case T_DOUBLE : return "double";
45 case T_ARRAY : return "array";
46 case T_OBJECT : return "object";
47 default : return "???";
48 }
49 }
50
51
cond_name(If::Condition cond)52 const char* InstructionPrinter::cond_name(If::Condition cond) {
53 switch (cond) {
54 case If::eql: return "==";
55 case If::neq: return "!=";
56 case If::lss: return "<";
57 case If::leq: return "<=";
58 case If::gtr: return ">";
59 case If::geq: return ">=";
60 case If::aeq: return "|>=|";
61 case If::beq: return "|<=|";
62 default:
63 ShouldNotReachHere();
64 return NULL;
65 }
66 }
67
68
op_name(Bytecodes::Code op)69 const char* InstructionPrinter::op_name(Bytecodes::Code op) {
70 switch (op) {
71 // arithmetic ops
72 case Bytecodes::_iadd : // fall through
73 case Bytecodes::_ladd : // fall through
74 case Bytecodes::_fadd : // fall through
75 case Bytecodes::_dadd : return "+";
76 case Bytecodes::_isub : // fall through
77 case Bytecodes::_lsub : // fall through
78 case Bytecodes::_fsub : // fall through
79 case Bytecodes::_dsub : return "-";
80 case Bytecodes::_imul : // fall through
81 case Bytecodes::_lmul : // fall through
82 case Bytecodes::_fmul : // fall through
83 case Bytecodes::_dmul : return "*";
84 case Bytecodes::_idiv : // fall through
85 case Bytecodes::_ldiv : // fall through
86 case Bytecodes::_fdiv : // fall through
87 case Bytecodes::_ddiv : return "/";
88 case Bytecodes::_irem : // fall through
89 case Bytecodes::_lrem : // fall through
90 case Bytecodes::_frem : // fall through
91 case Bytecodes::_drem : return "%";
92 // shift ops
93 case Bytecodes::_ishl : // fall through
94 case Bytecodes::_lshl : return "<<";
95 case Bytecodes::_ishr : // fall through
96 case Bytecodes::_lshr : return ">>";
97 case Bytecodes::_iushr: // fall through
98 case Bytecodes::_lushr: return ">>>";
99 // logic ops
100 case Bytecodes::_iand : // fall through
101 case Bytecodes::_land : return "&";
102 case Bytecodes::_ior : // fall through
103 case Bytecodes::_lor : return "|";
104 case Bytecodes::_ixor : // fall through
105 case Bytecodes::_lxor : return "^";
106 default : return Bytecodes::name(op);
107 }
108 }
109
110
is_illegal_phi(Value v)111 bool InstructionPrinter::is_illegal_phi(Value v) {
112 Phi* phi = v ? v->as_Phi() : NULL;
113 if (phi && phi->is_illegal()) {
114 return true;
115 }
116 return false;
117 }
118
119
is_phi_of_block(Value v,BlockBegin * b)120 bool InstructionPrinter::is_phi_of_block(Value v, BlockBegin* b) {
121 Phi* phi = v ? v->as_Phi() : NULL;
122 return phi && phi->block() == b;
123 }
124
125
print_klass(ciKlass * klass)126 void InstructionPrinter::print_klass(ciKlass* klass) {
127 klass->name()->print_symbol_on(output());
128 }
129
130
print_object(Value obj)131 void InstructionPrinter::print_object(Value obj) {
132 ValueType* type = obj->type();
133 if (type->as_ObjectConstant() != NULL) {
134 ciObject* value = type->as_ObjectConstant()->value();
135 if (value->is_null_object()) {
136 output()->print("null");
137 } else if (!value->is_loaded()) {
138 output()->print("<unloaded object " INTPTR_FORMAT ">", p2i(value));
139 } else {
140 output()->print("<object " INTPTR_FORMAT " klass=", p2i(value->constant_encoding()));
141 print_klass(value->klass());
142 output()->print(">");
143 }
144 } else if (type->as_InstanceConstant() != NULL) {
145 ciInstance* value = type->as_InstanceConstant()->value();
146 if (value->is_loaded()) {
147 output()->print("<instance " INTPTR_FORMAT " klass=", p2i(value->constant_encoding()));
148 print_klass(value->klass());
149 output()->print(">");
150 } else {
151 output()->print("<unloaded instance " INTPTR_FORMAT ">", p2i(value));
152 }
153 } else if (type->as_ArrayConstant() != NULL) {
154 output()->print("<array " INTPTR_FORMAT ">", p2i(type->as_ArrayConstant()->value()->constant_encoding()));
155 } else if (type->as_ClassConstant() != NULL) {
156 ciInstanceKlass* klass = type->as_ClassConstant()->value();
157 if (!klass->is_loaded()) {
158 output()->print("<unloaded> ");
159 }
160 output()->print("class ");
161 print_klass(klass);
162 } else if (type->as_MethodConstant() != NULL) {
163 ciMethod* m = type->as_MethodConstant()->value();
164 output()->print("<method %s.%s>", m->holder()->name()->as_utf8(), m->name()->as_utf8());
165 } else {
166 output()->print("???");
167 }
168 }
169
170
print_temp(Value value)171 void InstructionPrinter::print_temp(Value value) {
172 output()->print("%c%d", value->type()->tchar(), value->id());
173 }
174
175
print_field(AccessField * field)176 void InstructionPrinter::print_field(AccessField* field) {
177 print_value(field->obj());
178 output()->print("._%d", field->offset());
179 }
180
181
print_indexed(AccessIndexed * indexed)182 void InstructionPrinter::print_indexed(AccessIndexed* indexed) {
183 print_value(indexed->array());
184 output()->put('[');
185 print_value(indexed->index());
186 output()->put(']');
187 if (indexed->length() != NULL) {
188 output()->put('(');
189 print_value(indexed->length());
190 output()->put(')');
191 }
192 }
193
194
print_monitor(AccessMonitor * monitor)195 void InstructionPrinter::print_monitor(AccessMonitor* monitor) {
196 output()->print("monitor[%d](", monitor->monitor_no());
197 print_value(monitor->obj());
198 output()->put(')');
199 }
200
201
print_op2(Op2 * instr)202 void InstructionPrinter::print_op2(Op2* instr) {
203 print_value(instr->x());
204 output()->print(" %s ", op_name(instr->op()));
205 print_value(instr->y());
206 }
207
208
print_value(Value value)209 void InstructionPrinter::print_value(Value value) {
210 if (value == NULL) {
211 output()->print("NULL");
212 } else {
213 print_temp(value);
214 }
215 }
216
217
print_instr(Instruction * instr)218 void InstructionPrinter::print_instr(Instruction* instr) {
219 instr->visit(this);
220 }
221
222
print_stack(ValueStack * stack)223 void InstructionPrinter::print_stack(ValueStack* stack) {
224 int start_position = output()->position();
225 if (stack->stack_is_empty()) {
226 output()->print("empty stack");
227 } else {
228 output()->print("stack [");
229 for (int i = 0; i < stack->stack_size();) {
230 if (i > 0) output()->print(", ");
231 output()->print("%d:", i);
232 Value value = stack->stack_at_inc(i);
233 print_value(value);
234 Phi* phi = value->as_Phi();
235 if (phi != NULL) {
236 if (phi->operand()->is_valid()) {
237 output()->print(" ");
238 phi->operand()->print(output());
239 }
240 }
241 }
242 output()->put(']');
243 }
244 if (!stack->no_active_locks()) {
245 // print out the lines on the line below this
246 // one at the same indentation level.
247 output()->cr();
248 fill_to(start_position, ' ');
249 output()->print("locks [");
250 for (int i = i = 0; i < stack->locks_size(); i++) {
251 Value t = stack->lock_at(i);
252 if (i > 0) output()->print(", ");
253 output()->print("%d:", i);
254 if (t == NULL) {
255 // synchronized methods push null on the lock stack
256 output()->print("this");
257 } else {
258 print_value(t);
259 }
260 }
261 output()->print("]");
262 }
263 }
264
265
print_inline_level(BlockBegin * block)266 void InstructionPrinter::print_inline_level(BlockBegin* block) {
267 output()->print_cr("inlining depth %d", block->scope()->level());
268 }
269
270
print_unsafe_op(UnsafeOp * op,const char * name)271 void InstructionPrinter::print_unsafe_op(UnsafeOp* op, const char* name) {
272 output()->print("%s", name);
273 output()->print(".(");
274 }
275
print_unsafe_raw_op(UnsafeRawOp * op,const char * name)276 void InstructionPrinter::print_unsafe_raw_op(UnsafeRawOp* op, const char* name) {
277 print_unsafe_op(op, name);
278 output()->print("base ");
279 print_value(op->base());
280 if (op->has_index()) {
281 output()->print(", index "); print_value(op->index());
282 output()->print(", log2_scale %d", op->log2_scale());
283 }
284 }
285
286
print_unsafe_object_op(UnsafeObjectOp * op,const char * name)287 void InstructionPrinter::print_unsafe_object_op(UnsafeObjectOp* op, const char* name) {
288 print_unsafe_op(op, name);
289 print_value(op->object());
290 output()->print(", ");
291 print_value(op->offset());
292 }
293
294
print_phi(int i,Value v,BlockBegin * b)295 void InstructionPrinter::print_phi(int i, Value v, BlockBegin* b) {
296 Phi* phi = v->as_Phi();
297 output()->print("%2d ", i);
298 print_value(v);
299 // print phi operands
300 if (phi && phi->block() == b) {
301 output()->print(" [");
302 for (int j = 0; j < phi->operand_count(); j ++) {
303 output()->print(" ");
304 Value opd = phi->operand_at(j);
305 if (opd) print_value(opd);
306 else output()->print("NULL");
307 }
308 output()->print("] ");
309 }
310 print_alias(v);
311 }
312
313
print_alias(Value v)314 void InstructionPrinter::print_alias(Value v) {
315 if (v != v->subst()) {
316 output()->print("alias "); print_value(v->subst());
317 }
318 }
319
320
fill_to(int pos,char filler)321 void InstructionPrinter::fill_to(int pos, char filler) {
322 while (output()->position() < pos) output()->put(filler);
323 }
324
325
print_head()326 void InstructionPrinter::print_head() {
327 const char filler = '_';
328 fill_to(bci_pos , filler); output()->print("bci" );
329 fill_to(use_pos , filler); output()->print("use" );
330 fill_to(temp_pos , filler); output()->print("tid" );
331 fill_to(instr_pos, filler); output()->print("instr");
332 fill_to(end_pos , filler);
333 output()->cr();
334 }
335
336
print_line(Instruction * instr)337 void InstructionPrinter::print_line(Instruction* instr) {
338 // print instruction data on one line
339 if (instr->is_pinned()) output()->put('.');
340 if (instr->has_printable_bci()) {
341 fill_to(bci_pos ); output()->print("%d", instr->printable_bci());
342 }
343 fill_to(use_pos ); output()->print("%d", instr->use_count());
344 fill_to(temp_pos ); print_temp(instr);
345 fill_to(instr_pos); print_instr(instr);
346 output()->cr();
347 // add a line for StateSplit instructions w/ non-empty stacks
348 // (make it robust so we can print incomplete instructions)
349 StateSplit* split = instr->as_StateSplit();
350 if (split != NULL && split->state() != NULL && !split->state()->stack_is_empty()) {
351 fill_to(instr_pos); print_stack(split->state());
352 output()->cr();
353 }
354 }
355
356
do_Phi(Phi * x)357 void InstructionPrinter::do_Phi(Phi* x) {
358 output()->print("phi function"); // make that more detailed later
359 if (x->is_illegal())
360 output()->print(" (illegal)");
361 }
362
363
do_Local(Local * x)364 void InstructionPrinter::do_Local(Local* x) {
365 output()->print("local[index %d]", x->java_index());
366 }
367
368
do_Constant(Constant * x)369 void InstructionPrinter::do_Constant(Constant* x) {
370 ValueType* t = x->type();
371 switch (t->tag()) {
372 case intTag : output()->print("%d" , t->as_IntConstant ()->value()); break;
373 case longTag : output()->print(JLONG_FORMAT, t->as_LongConstant()->value()); output()->print("L"); break;
374 case floatTag : output()->print("%g" , t->as_FloatConstant ()->value()); break;
375 case doubleTag : output()->print("%gD" , t->as_DoubleConstant()->value()); break;
376 case objectTag : print_object(x); break;
377 case addressTag: output()->print("bci:%d", t->as_AddressConstant()->value()); break;
378 default : output()->print("???"); break;
379 }
380 }
381
382
do_LoadField(LoadField * x)383 void InstructionPrinter::do_LoadField(LoadField* x) {
384 print_field(x);
385 output()->print(" (%c)", type2char(x->field()->type()->basic_type()));
386 output()->print(" %s", x->field()->name()->as_utf8());
387 }
388
389
do_StoreField(StoreField * x)390 void InstructionPrinter::do_StoreField(StoreField* x) {
391 print_field(x);
392 output()->print(" := ");
393 print_value(x->value());
394 output()->print(" (%c)", type2char(x->field()->type()->basic_type()));
395 output()->print(" %s", x->field()->name()->as_utf8());
396 }
397
398
do_ArrayLength(ArrayLength * x)399 void InstructionPrinter::do_ArrayLength(ArrayLength* x) {
400 print_value(x->array());
401 output()->print(".length");
402 }
403
404
do_LoadIndexed(LoadIndexed * x)405 void InstructionPrinter::do_LoadIndexed(LoadIndexed* x) {
406 print_indexed(x);
407 output()->print(" (%c)", type2char(x->elt_type()));
408 if (x->check_flag(Instruction::NeedsRangeCheckFlag)) {
409 output()->print(" [rc]");
410 }
411 }
412
413
do_StoreIndexed(StoreIndexed * x)414 void InstructionPrinter::do_StoreIndexed(StoreIndexed* x) {
415 print_indexed(x);
416 output()->print(" := ");
417 print_value(x->value());
418 output()->print(" (%c)", type2char(x->elt_type()));
419 if (x->check_flag(Instruction::NeedsRangeCheckFlag)) {
420 output()->print(" [rc]");
421 }
422 }
423
do_NegateOp(NegateOp * x)424 void InstructionPrinter::do_NegateOp(NegateOp* x) {
425 output()->put('-');
426 print_value(x->x());
427 }
428
429
do_ArithmeticOp(ArithmeticOp * x)430 void InstructionPrinter::do_ArithmeticOp(ArithmeticOp* x) {
431 print_op2(x);
432 }
433
434
do_ShiftOp(ShiftOp * x)435 void InstructionPrinter::do_ShiftOp(ShiftOp* x) {
436 print_op2(x);
437 }
438
439
do_LogicOp(LogicOp * x)440 void InstructionPrinter::do_LogicOp(LogicOp* x) {
441 print_op2(x);
442 }
443
444
do_CompareOp(CompareOp * x)445 void InstructionPrinter::do_CompareOp(CompareOp* x) {
446 print_op2(x);
447 }
448
449
do_IfOp(IfOp * x)450 void InstructionPrinter::do_IfOp(IfOp* x) {
451 print_value(x->x());
452 output()->print(" %s ", cond_name(x->cond()));
453 print_value(x->y());
454 output()->print(" ? ");
455 print_value(x->tval());
456 output()->print(" : ");
457 print_value(x->fval());
458 }
459
460
do_Convert(Convert * x)461 void InstructionPrinter::do_Convert(Convert* x) {
462 output()->print("%s(", Bytecodes::name(x->op()));
463 print_value(x->value());
464 output()->put(')');
465 }
466
467
do_NullCheck(NullCheck * x)468 void InstructionPrinter::do_NullCheck(NullCheck* x) {
469 output()->print("null_check(");
470 print_value(x->obj());
471 output()->put(')');
472 if (!x->can_trap()) {
473 output()->print(" (eliminated)");
474 }
475 }
476
477
do_TypeCast(TypeCast * x)478 void InstructionPrinter::do_TypeCast(TypeCast* x) {
479 output()->print("type_cast(");
480 print_value(x->obj());
481 output()->print(") ");
482 if (x->declared_type()->is_klass())
483 print_klass(x->declared_type()->as_klass());
484 else
485 output()->print("%s", type2name(x->declared_type()->basic_type()));
486 }
487
488
do_Invoke(Invoke * x)489 void InstructionPrinter::do_Invoke(Invoke* x) {
490 if (x->receiver() != NULL) {
491 print_value(x->receiver());
492 output()->print(".");
493 }
494
495 output()->print("%s(", Bytecodes::name(x->code()));
496 for (int i = 0; i < x->number_of_arguments(); i++) {
497 if (i > 0) output()->print(", ");
498 print_value(x->argument_at(i));
499 }
500 output()->print_cr(")");
501 fill_to(instr_pos);
502 output()->print("%s.%s%s",
503 x->target()->holder()->name()->as_utf8(),
504 x->target()->name()->as_utf8(),
505 x->target()->signature()->as_symbol()->as_utf8());
506 }
507
508
do_NewInstance(NewInstance * x)509 void InstructionPrinter::do_NewInstance(NewInstance* x) {
510 output()->print("new instance ");
511 print_klass(x->klass());
512 }
513
514
do_NewTypeArray(NewTypeArray * x)515 void InstructionPrinter::do_NewTypeArray(NewTypeArray* x) {
516 output()->print("new %s array [", basic_type_name(x->elt_type()));
517 print_value(x->length());
518 output()->put(']');
519 }
520
521
do_NewObjectArray(NewObjectArray * x)522 void InstructionPrinter::do_NewObjectArray(NewObjectArray* x) {
523 output()->print("new object array [");
524 print_value(x->length());
525 output()->print("] ");
526 print_klass(x->klass());
527 }
528
529
do_NewMultiArray(NewMultiArray * x)530 void InstructionPrinter::do_NewMultiArray(NewMultiArray* x) {
531 output()->print("new multi array [");
532 Values* dims = x->dims();
533 for (int i = 0; i < dims->length(); i++) {
534 if (i > 0) output()->print(", ");
535 print_value(dims->at(i));
536 }
537 output()->print("] ");
538 print_klass(x->klass());
539 }
540
541
do_MonitorEnter(MonitorEnter * x)542 void InstructionPrinter::do_MonitorEnter(MonitorEnter* x) {
543 output()->print("enter ");
544 print_monitor(x);
545 }
546
547
do_MonitorExit(MonitorExit * x)548 void InstructionPrinter::do_MonitorExit(MonitorExit* x) {
549 output()->print("exit ");
550 print_monitor(x);
551 }
552
553
do_Intrinsic(Intrinsic * x)554 void InstructionPrinter::do_Intrinsic(Intrinsic* x) {
555 const char* name = vmIntrinsics::name_at(x->id());
556 if (name[0] == '_') name++; // strip leading bug from _hashCode, etc.
557 const char* kname = vmSymbols::name_for(vmIntrinsics::class_for(x->id()));
558 if (strchr(name, '_') == NULL) {
559 kname = NULL;
560 } else {
561 const char* kptr = strrchr(kname, '/');
562 if (kptr != NULL) kname = kptr + 1;
563 }
564 if (kname == NULL)
565 output()->print("%s(", name);
566 else
567 output()->print("%s.%s(", kname, name);
568 for (int i = 0; i < x->number_of_arguments(); i++) {
569 if (i > 0) output()->print(", ");
570 print_value(x->argument_at(i));
571 }
572 output()->put(')');
573 }
574
575
do_BlockBegin(BlockBegin * x)576 void InstructionPrinter::do_BlockBegin(BlockBegin* x) {
577 // print block id
578 BlockEnd* end = x->end();
579 output()->print("B%d ", x->block_id());
580
581 // print flags
582 bool printed_flag = false;
583 if (x->is_set(BlockBegin::std_entry_flag)) {
584 if (!printed_flag) output()->print("(");
585 output()->print("S"); printed_flag = true;
586 }
587 if (x->is_set(BlockBegin::osr_entry_flag)) {
588 if (!printed_flag) output()->print("(");
589 output()->print("O"); printed_flag = true;
590 }
591 if (x->is_set(BlockBegin::exception_entry_flag)) {
592 if (!printed_flag) output()->print("(");
593 output()->print("E"); printed_flag = true;
594 }
595 if (x->is_set(BlockBegin::subroutine_entry_flag)) {
596 if (!printed_flag) output()->print("(");
597 output()->print("s"); printed_flag = true;
598 }
599 if (x->is_set(BlockBegin::parser_loop_header_flag)) {
600 if (!printed_flag) output()->print("(");
601 output()->print("LH"); printed_flag = true;
602 }
603 if (x->is_set(BlockBegin::backward_branch_target_flag)) {
604 if (!printed_flag) output()->print("(");
605 output()->print("b"); printed_flag = true;
606 }
607 if (x->is_set(BlockBegin::was_visited_flag)) {
608 if (!printed_flag) output()->print("(");
609 output()->print("V"); printed_flag = true;
610 }
611 if (printed_flag) output()->print(") ");
612
613 // print block bci range
614 output()->print("[%d, %d]", x->bci(), (end == NULL ? -1 : end->printable_bci()));
615
616 // print block successors
617 if (end != NULL && end->number_of_sux() > 0) {
618 output()->print(" ->");
619 for (int i = 0; i < end->number_of_sux(); i++) {
620 output()->print(" B%d", end->sux_at(i)->block_id());
621 }
622 }
623 // print exception handlers
624 if (x->number_of_exception_handlers() > 0) {
625 output()->print(" (xhandlers ");
626 for (int i = 0; i < x->number_of_exception_handlers(); i++) {
627 if (i > 0) output()->print(" ");
628 output()->print("B%d", x->exception_handler_at(i)->block_id());
629 }
630 output()->put(')');
631 }
632
633 // print dominator block
634 if (x->dominator() != NULL) {
635 output()->print(" dom B%d", x->dominator()->block_id());
636 }
637
638 // print predecessors and successors
639 if (x->successors()->length() > 0) {
640 output()->print(" sux:");
641 for (int i = 0; i < x->successors()->length(); i ++) {
642 output()->print(" B%d", x->successors()->at(i)->block_id());
643 }
644 }
645
646 if (x->number_of_preds() > 0) {
647 output()->print(" pred:");
648 for (int i = 0; i < x->number_of_preds(); i ++) {
649 output()->print(" B%d", x->pred_at(i)->block_id());
650 }
651 }
652
653 if (!_print_phis) {
654 return;
655 }
656
657 // print phi functions
658 bool has_phis_in_locals = false;
659 bool has_phis_on_stack = false;
660
661 if (x->end() && x->end()->state()) {
662 ValueStack* state = x->state();
663
664 int i = 0;
665 while (!has_phis_on_stack && i < state->stack_size()) {
666 Value v = state->stack_at_inc(i);
667 has_phis_on_stack = is_phi_of_block(v, x);
668 }
669
670 do {
671 for (i = 0; !has_phis_in_locals && i < state->locals_size();) {
672 Value v = state->local_at(i);
673 has_phis_in_locals = is_phi_of_block(v, x);
674 // also ignore illegal HiWords
675 if (v && !v->type()->is_illegal()) i += v->type()->size(); else i ++;
676 }
677 state = state->caller_state();
678 } while (state != NULL);
679
680 }
681
682 // print values in locals
683 if (has_phis_in_locals) {
684 output()->cr(); output()->print_cr("Locals:");
685
686 ValueStack* state = x->state();
687 do {
688 for (int i = 0; i < state->locals_size();) {
689 Value v = state->local_at(i);
690 if (v) {
691 print_phi(i, v, x); output()->cr();
692 // also ignore illegal HiWords
693 i += (v->type()->is_illegal() ? 1 : v->type()->size());
694 } else {
695 i ++;
696 }
697 }
698 output()->cr();
699 state = state->caller_state();
700 } while (state != NULL);
701 }
702
703 // print values on stack
704 if (has_phis_on_stack) {
705 output()->print_cr("Stack:");
706 int i = 0;
707 while (i < x->state()->stack_size()) {
708 int o = i;
709 Value v = x->state()->stack_at_inc(i);
710 if (v) {
711 print_phi(o, v, x); output()->cr();
712 }
713 }
714 }
715 }
716
717
do_CheckCast(CheckCast * x)718 void InstructionPrinter::do_CheckCast(CheckCast* x) {
719 output()->print("checkcast(");
720 print_value(x->obj());
721 output()->print(") ");
722 print_klass(x->klass());
723 }
724
725
do_InstanceOf(InstanceOf * x)726 void InstructionPrinter::do_InstanceOf(InstanceOf* x) {
727 output()->print("instanceof(");
728 print_value(x->obj());
729 output()->print(") ");
730 print_klass(x->klass());
731 }
732
733
do_Goto(Goto * x)734 void InstructionPrinter::do_Goto(Goto* x) {
735 output()->print("goto B%d", x->default_sux()->block_id());
736 if (x->is_safepoint()) output()->print(" (safepoint)");
737 }
738
739
do_If(If * x)740 void InstructionPrinter::do_If(If* x) {
741 output()->print("if ");
742 print_value(x->x());
743 output()->print(" %s ", cond_name(x->cond()));
744 print_value(x->y());
745 output()->print(" then B%d else B%d", x->sux_at(0)->block_id(), x->sux_at(1)->block_id());
746 if (x->is_safepoint()) output()->print(" (safepoint)");
747 }
748
749
do_IfInstanceOf(IfInstanceOf * x)750 void InstructionPrinter::do_IfInstanceOf(IfInstanceOf* x) {
751 output()->print("<IfInstanceOf>");
752 }
753
754
do_TableSwitch(TableSwitch * x)755 void InstructionPrinter::do_TableSwitch(TableSwitch* x) {
756 output()->print("tableswitch ");
757 if (x->is_safepoint()) output()->print("(safepoint) ");
758 print_value(x->tag());
759 output()->cr();
760 int l = x->length();
761 for (int i = 0; i < l; i++) {
762 fill_to(instr_pos);
763 output()->print_cr("case %5d: B%d", x->lo_key() + i, x->sux_at(i)->block_id());
764 }
765 fill_to(instr_pos);
766 output()->print("default : B%d", x->default_sux()->block_id());
767 }
768
769
do_LookupSwitch(LookupSwitch * x)770 void InstructionPrinter::do_LookupSwitch(LookupSwitch* x) {
771 output()->print("lookupswitch ");
772 if (x->is_safepoint()) output()->print("(safepoint) ");
773 print_value(x->tag());
774 output()->cr();
775 int l = x->length();
776 for (int i = 0; i < l; i++) {
777 fill_to(instr_pos);
778 output()->print_cr("case %5d: B%d", x->key_at(i), x->sux_at(i)->block_id());
779 }
780 fill_to(instr_pos);
781 output()->print("default : B%d", x->default_sux()->block_id());
782 }
783
784
do_Return(Return * x)785 void InstructionPrinter::do_Return(Return* x) {
786 if (x->result() == NULL) {
787 output()->print("return");
788 } else {
789 output()->print("%creturn ", x->type()->tchar());
790 print_value(x->result());
791 }
792 }
793
794
do_Throw(Throw * x)795 void InstructionPrinter::do_Throw(Throw* x) {
796 output()->print("throw ");
797 print_value(x->exception());
798 }
799
800
do_Base(Base * x)801 void InstructionPrinter::do_Base(Base* x) {
802 output()->print("std entry B%d", x->std_entry()->block_id());
803 if (x->number_of_sux() > 1) {
804 output()->print(" osr entry B%d", x->osr_entry()->block_id());
805 }
806 }
807
808
do_OsrEntry(OsrEntry * x)809 void InstructionPrinter::do_OsrEntry(OsrEntry* x) {
810 output()->print("osr entry");
811 }
812
813
do_ExceptionObject(ExceptionObject * x)814 void InstructionPrinter::do_ExceptionObject(ExceptionObject* x) {
815 output()->print("incoming exception");
816 }
817
818
do_RoundFP(RoundFP * x)819 void InstructionPrinter::do_RoundFP(RoundFP* x) {
820 output()->print("round_fp ");
821 print_value(x->input());
822 }
823
824
do_UnsafeGetRaw(UnsafeGetRaw * x)825 void InstructionPrinter::do_UnsafeGetRaw(UnsafeGetRaw* x) {
826 print_unsafe_raw_op(x, "UnsafeGetRaw");
827 output()->put(')');
828 }
829
830
do_UnsafePutRaw(UnsafePutRaw * x)831 void InstructionPrinter::do_UnsafePutRaw(UnsafePutRaw* x) {
832 print_unsafe_raw_op(x, "UnsafePutRaw");
833 output()->print(", value ");
834 print_value(x->value());
835 output()->put(')');
836 }
837
838
do_UnsafeGetObject(UnsafeGetObject * x)839 void InstructionPrinter::do_UnsafeGetObject(UnsafeGetObject* x) {
840 print_unsafe_object_op(x, "UnsafeGetObject");
841 output()->put(')');
842 }
843
844
do_UnsafePutObject(UnsafePutObject * x)845 void InstructionPrinter::do_UnsafePutObject(UnsafePutObject* x) {
846 print_unsafe_object_op(x, "UnsafePutObject");
847 output()->print(", value ");
848 print_value(x->value());
849 output()->put(')');
850 }
851
do_UnsafeGetAndSetObject(UnsafeGetAndSetObject * x)852 void InstructionPrinter::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
853 print_unsafe_object_op(x, x->is_add()?"UnsafeGetAndSetObject (add)":"UnsafeGetAndSetObject");
854 output()->print(", value ");
855 print_value(x->value());
856 output()->put(')');
857 }
858
do_RangeCheckPredicate(RangeCheckPredicate * x)859 void InstructionPrinter::do_RangeCheckPredicate(RangeCheckPredicate* x) {
860
861 if (x->x() != NULL && x->y() != NULL) {
862 output()->print("if ");
863 print_value(x->x());
864 output()->print(" %s ", cond_name(x->cond()));
865 print_value(x->y());
866 output()->print(" then deoptimize!");
867 } else {
868 output()->print("always deoptimize!");
869 }
870 }
871
872 #ifdef ASSERT
do_Assert(Assert * x)873 void InstructionPrinter::do_Assert(Assert* x) {
874 output()->print("assert ");
875 print_value(x->x());
876 output()->print(" %s ", cond_name(x->cond()));
877 print_value(x->y());
878 }
879 #endif
880
do_ProfileCall(ProfileCall * x)881 void InstructionPrinter::do_ProfileCall(ProfileCall* x) {
882 output()->print("profile ");
883 print_value(x->recv());
884 output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
885 if (x->known_holder() != NULL) {
886 output()->print(", ");
887 print_klass(x->known_holder());
888 output()->print(" ");
889 }
890 for (int i = 0; i < x->nb_profiled_args(); i++) {
891 if (i > 0) output()->print(", ");
892 print_value(x->profiled_arg_at(i));
893 if (x->arg_needs_null_check(i)) {
894 output()->print(" [NC]");
895 }
896 }
897 output()->put(')');
898 }
899
do_ProfileReturnType(ProfileReturnType * x)900 void InstructionPrinter::do_ProfileReturnType(ProfileReturnType* x) {
901 output()->print("profile ret type ");
902 print_value(x->ret());
903 output()->print(" %s.%s", x->method()->holder()->name()->as_utf8(), x->method()->name()->as_utf8());
904 output()->put(')');
905 }
do_ProfileInvoke(ProfileInvoke * x)906 void InstructionPrinter::do_ProfileInvoke(ProfileInvoke* x) {
907 output()->print("profile_invoke ");
908 output()->print(" %s.%s", x->inlinee()->holder()->name()->as_utf8(), x->inlinee()->name()->as_utf8());
909 output()->put(')');
910
911 }
912
do_RuntimeCall(RuntimeCall * x)913 void InstructionPrinter::do_RuntimeCall(RuntimeCall* x) {
914 output()->print("call_rt %s(", x->entry_name());
915 for (int i = 0; i < x->number_of_arguments(); i++) {
916 if (i > 0) output()->print(", ");
917 print_value(x->argument_at(i));
918 }
919 output()->put(')');
920 }
921
do_MemBar(MemBar * x)922 void InstructionPrinter::do_MemBar(MemBar* x) {
923 if (os::is_MP()) {
924 LIR_Code code = x->code();
925 switch (code) {
926 case lir_membar_acquire : output()->print("membar_acquire"); break;
927 case lir_membar_release : output()->print("membar_release"); break;
928 case lir_membar : output()->print("membar"); break;
929 case lir_membar_loadload : output()->print("membar_loadload"); break;
930 case lir_membar_storestore: output()->print("membar_storestore"); break;
931 case lir_membar_loadstore : output()->print("membar_loadstore"); break;
932 case lir_membar_storeload : output()->print("membar_storeload"); break;
933 default : ShouldNotReachHere(); break;
934 }
935 }
936 }
937
938 #endif // PRODUCT
939