296 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
297 // the Compile* pointer is stored in the current ciEnv:
298 ciEnv* env = compile->env();
299 assert(env == ciEnv::current(), "must already be a ciEnv active");
300 assert(env->compiler_data() == NULL, "compile already active?");
301 env->set_compiler_data(compile);
302 assert(compile == Compile::current(), "sanity");
303
304 compile->set_type_dict(NULL);
305 compile->set_type_hwm(NULL);
306 compile->set_type_last_size(0);
307 compile->set_last_tf(NULL, NULL);
308 compile->set_indexSet_arena(NULL);
309 compile->set_indexSet_free_block_list(NULL);
310 compile->init_type_arena();
311 Type::Initialize(compile);
312 _compile->set_scratch_buffer_blob(NULL);
313 _compile->begin_method();
314 }
315 CompileWrapper::~CompileWrapper() {
316 if (_compile->failing()) {
317 _compile->print_method("Failed");
318 }
319 _compile->end_method();
320 if (_compile->scratch_buffer_blob() != NULL)
321 BufferBlob::free(_compile->scratch_buffer_blob());
322 _compile->env()->set_compiler_data(NULL);
323 }
324
325
326 //----------------------------print_compile_messages---------------------------
327 void Compile::print_compile_messages() {
328 #ifndef PRODUCT
329 // Check if recompiling
330 if (_subsume_loads == false && PrintOpto) {
331 // Recompiling without allowing machine instructions to subsume loads
332 tty->print_cr("*********************************************************");
333 tty->print_cr("** Bailout: Recompile without subsuming loads **");
334 tty->print_cr("*********************************************************");
335 }
336 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
337 // Recompiling without escape analysis
338 tty->print_cr("*********************************************************");
587
588 // Perform escape analysis
589 if (_do_escape_analysis)
590 _congraph = new ConnectionGraph(this);
591 if (_congraph != NULL) {
592 NOT_PRODUCT( TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, TimeCompiler); )
593 _congraph->compute_escape();
594 if (failing()) return;
595
596 #ifndef PRODUCT
597 if (PrintEscapeAnalysis) {
598 _congraph->dump();
599 }
600 #endif
601 }
602 // Now optimize
603 Optimize();
604 if (failing()) return;
605 NOT_PRODUCT( verify_graph_edges(); )
606
607 #ifndef PRODUCT
608 if (PrintIdeal) {
609 ttyLocker ttyl; // keep the following output all in one block
610 // This output goes directly to the tty, not the compiler log.
611 // To enable tools to match it up with the compilation activity,
612 // be sure to tag this tty output with the compile ID.
613 if (xtty != NULL) {
614 xtty->head("ideal compile_id='%d'%s", compile_id(),
615 is_osr_compilation() ? " compile_kind='osr'" :
616 "");
617 }
618 root()->dump(9999);
619 if (xtty != NULL) {
620 xtty->tail("ideal");
621 }
622 }
623 #endif
624
625 // Now that we know the size of all the monitors we can add a fixed slot
626 // for the original deopt pc.
1464 }
1465
1466
1467 //------------------------------Optimize---------------------------------------
1468 // Given a graph, optimize it.
1469 void Compile::Optimize() {
1470 TracePhase t1("optimizer", &_t_optimizer, true);
1471
1472 #ifndef PRODUCT
1473 if (env()->break_at_compile()) {
1474 BREAKPOINT;
1475 }
1476
1477 #endif
1478
1479 ResourceMark rm;
1480 int loop_opts_cnt;
1481
1482 NOT_PRODUCT( verify_graph_edges(); )
1483
1484 print_method("Start");
1485
1486 {
1487 // Iterative Global Value Numbering, including ideal transforms
1488 // Initialize IterGVN with types and values from parse-time GVN
1489 PhaseIterGVN igvn(initial_gvn());
1490 {
1491 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); )
1492 igvn.optimize();
1493 }
1494
1495 print_method("Iter GVN 1", 2);
1496
1497 if (failing()) return;
1498
1499 // get rid of the connection graph since it's information is not
1500 // updated by optimizations
1501 _congraph = NULL;
1502
1503
1504 // Loop transforms on the ideal graph. Range Check Elimination,
1671 }
1672
1673 // Perform any platform dependent postallocation verifications.
1674 debug_only( _regalloc->pd_postallocate_verify_hook(); )
1675
1676 // Apply peephole optimizations
1677 if( OptoPeephole ) {
1678 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); )
1679 PhasePeephole peep( _regalloc, cfg);
1680 peep.do_transform();
1681 }
1682
1683 // Convert Nodes to instruction bits in a buffer
1684 {
1685 // %%%% workspace merge brought two timers together for one job
1686 TracePhase t2a("output", &_t_output, true);
1687 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); )
1688 Output();
1689 }
1690
1691 print_method("End");
1692
1693 // He's dead, Jim.
1694 _cfg = (PhaseCFG*)0xdeadbeef;
1695 _regalloc = (PhaseChaitin*)0xdeadbeef;
1696 }
1697
1698
1699 //------------------------------dump_asm---------------------------------------
1700 // Dump formatted assembly
1701 #ifndef PRODUCT
1702 void Compile::dump_asm(int *pcs, uint pc_limit) {
1703 bool cut_short = false;
1704 tty->print_cr("#");
1705 tty->print("# "); _tf->dump(); tty->cr();
1706 tty->print_cr("#");
1707
1708 // For all blocks
1709 int pc = 0x0; // Program counter
1710 char starts_bundle = ' ';
1711 _regalloc->dump_frame();
2449 }
2450 }
2451 }
2452 #endif
2453
2454 // The Compile object keeps track of failure reasons separately from the ciEnv.
2455 // This is required because there is not quite a 1-1 relation between the
2456 // ciEnv and its compilation task and the Compile object. Note that one
2457 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
2458 // to backtrack and retry without subsuming loads. Other than this backtracking
2459 // behavior, the Compile's failure reason is quietly copied up to the ciEnv
2460 // by the logic in C2Compiler.
2461 void Compile::record_failure(const char* reason) {
2462 if (log() != NULL) {
2463 log()->elem("failure reason='%s' phase='compile'", reason);
2464 }
2465 if (_failure_reason == NULL) {
2466 // Record the first failure reason.
2467 _failure_reason = reason;
2468 }
2469 _root = NULL; // flush the graph, too
2470 }
2471
2472 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog)
2473 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false)
2474 {
2475 if (dolog) {
2476 C = Compile::current();
2477 _log = C->log();
2478 } else {
2479 C = NULL;
2480 _log = NULL;
2481 }
2482 if (_log != NULL) {
2483 _log->begin_head("phase name='%s' nodes='%d'", name, C->unique());
2484 _log->stamp();
2485 _log->end_head();
2486 }
2487 }
2488
|
296 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
297 // the Compile* pointer is stored in the current ciEnv:
298 ciEnv* env = compile->env();
299 assert(env == ciEnv::current(), "must already be a ciEnv active");
300 assert(env->compiler_data() == NULL, "compile already active?");
301 env->set_compiler_data(compile);
302 assert(compile == Compile::current(), "sanity");
303
304 compile->set_type_dict(NULL);
305 compile->set_type_hwm(NULL);
306 compile->set_type_last_size(0);
307 compile->set_last_tf(NULL, NULL);
308 compile->set_indexSet_arena(NULL);
309 compile->set_indexSet_free_block_list(NULL);
310 compile->init_type_arena();
311 Type::Initialize(compile);
312 _compile->set_scratch_buffer_blob(NULL);
313 _compile->begin_method();
314 }
315 CompileWrapper::~CompileWrapper() {
316 _compile->end_method();
317 if (_compile->scratch_buffer_blob() != NULL)
318 BufferBlob::free(_compile->scratch_buffer_blob());
319 _compile->env()->set_compiler_data(NULL);
320 }
321
322
323 //----------------------------print_compile_messages---------------------------
324 void Compile::print_compile_messages() {
325 #ifndef PRODUCT
326 // Check if recompiling
327 if (_subsume_loads == false && PrintOpto) {
328 // Recompiling without allowing machine instructions to subsume loads
329 tty->print_cr("*********************************************************");
330 tty->print_cr("** Bailout: Recompile without subsuming loads **");
331 tty->print_cr("*********************************************************");
332 }
333 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
334 // Recompiling without escape analysis
335 tty->print_cr("*********************************************************");
584
585 // Perform escape analysis
586 if (_do_escape_analysis)
587 _congraph = new ConnectionGraph(this);
588 if (_congraph != NULL) {
589 NOT_PRODUCT( TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, TimeCompiler); )
590 _congraph->compute_escape();
591 if (failing()) return;
592
593 #ifndef PRODUCT
594 if (PrintEscapeAnalysis) {
595 _congraph->dump();
596 }
597 #endif
598 }
599 // Now optimize
600 Optimize();
601 if (failing()) return;
602 NOT_PRODUCT( verify_graph_edges(); )
603
604 print_method("Before Matching");
605
606 #ifndef PRODUCT
607 if (PrintIdeal) {
608 ttyLocker ttyl; // keep the following output all in one block
609 // This output goes directly to the tty, not the compiler log.
610 // To enable tools to match it up with the compilation activity,
611 // be sure to tag this tty output with the compile ID.
612 if (xtty != NULL) {
613 xtty->head("ideal compile_id='%d'%s", compile_id(),
614 is_osr_compilation() ? " compile_kind='osr'" :
615 "");
616 }
617 root()->dump(9999);
618 if (xtty != NULL) {
619 xtty->tail("ideal");
620 }
621 }
622 #endif
623
624 // Now that we know the size of all the monitors we can add a fixed slot
625 // for the original deopt pc.
1463 }
1464
1465
1466 //------------------------------Optimize---------------------------------------
1467 // Given a graph, optimize it.
1468 void Compile::Optimize() {
1469 TracePhase t1("optimizer", &_t_optimizer, true);
1470
1471 #ifndef PRODUCT
1472 if (env()->break_at_compile()) {
1473 BREAKPOINT;
1474 }
1475
1476 #endif
1477
1478 ResourceMark rm;
1479 int loop_opts_cnt;
1480
1481 NOT_PRODUCT( verify_graph_edges(); )
1482
1483 print_method("After Parsing");
1484
1485 {
1486 // Iterative Global Value Numbering, including ideal transforms
1487 // Initialize IterGVN with types and values from parse-time GVN
1488 PhaseIterGVN igvn(initial_gvn());
1489 {
1490 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); )
1491 igvn.optimize();
1492 }
1493
1494 print_method("Iter GVN 1", 2);
1495
1496 if (failing()) return;
1497
1498 // get rid of the connection graph since it's information is not
1499 // updated by optimizations
1500 _congraph = NULL;
1501
1502
1503 // Loop transforms on the ideal graph. Range Check Elimination,
1670 }
1671
1672 // Perform any platform dependent postallocation verifications.
1673 debug_only( _regalloc->pd_postallocate_verify_hook(); )
1674
1675 // Apply peephole optimizations
1676 if( OptoPeephole ) {
1677 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); )
1678 PhasePeephole peep( _regalloc, cfg);
1679 peep.do_transform();
1680 }
1681
1682 // Convert Nodes to instruction bits in a buffer
1683 {
1684 // %%%% workspace merge brought two timers together for one job
1685 TracePhase t2a("output", &_t_output, true);
1686 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); )
1687 Output();
1688 }
1689
1690 print_method("Final Code");
1691
1692 // He's dead, Jim.
1693 _cfg = (PhaseCFG*)0xdeadbeef;
1694 _regalloc = (PhaseChaitin*)0xdeadbeef;
1695 }
1696
1697
1698 //------------------------------dump_asm---------------------------------------
1699 // Dump formatted assembly
1700 #ifndef PRODUCT
1701 void Compile::dump_asm(int *pcs, uint pc_limit) {
1702 bool cut_short = false;
1703 tty->print_cr("#");
1704 tty->print("# "); _tf->dump(); tty->cr();
1705 tty->print_cr("#");
1706
1707 // For all blocks
1708 int pc = 0x0; // Program counter
1709 char starts_bundle = ' ';
1710 _regalloc->dump_frame();
2448 }
2449 }
2450 }
2451 #endif
2452
2453 // The Compile object keeps track of failure reasons separately from the ciEnv.
2454 // This is required because there is not quite a 1-1 relation between the
2455 // ciEnv and its compilation task and the Compile object. Note that one
2456 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
2457 // to backtrack and retry without subsuming loads. Other than this backtracking
2458 // behavior, the Compile's failure reason is quietly copied up to the ciEnv
2459 // by the logic in C2Compiler.
2460 void Compile::record_failure(const char* reason) {
2461 if (log() != NULL) {
2462 log()->elem("failure reason='%s' phase='compile'", reason);
2463 }
2464 if (_failure_reason == NULL) {
2465 // Record the first failure reason.
2466 _failure_reason = reason;
2467 }
2468 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
2469 C->print_method(_failure_reason);
2470 }
2471 _root = NULL; // flush the graph, too
2472 }
2473
2474 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog)
2475 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false)
2476 {
2477 if (dolog) {
2478 C = Compile::current();
2479 _log = C->log();
2480 } else {
2481 C = NULL;
2482 _log = NULL;
2483 }
2484 if (_log != NULL) {
2485 _log->begin_head("phase name='%s' nodes='%d'", name, C->unique());
2486 _log->stamp();
2487 _log->end_head();
2488 }
2489 }
2490
|