447 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
448 // the Compile* pointer is stored in the current ciEnv:
449 ciEnv* env = compile->env();
450 assert(env == ciEnv::current(), "must already be a ciEnv active");
451 assert(env->compiler_data() == NULL, "compile already active?");
452 env->set_compiler_data(compile);
453 assert(compile == Compile::current(), "sanity");
454
455 compile->set_type_dict(NULL);
456 compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
457 compile->clone_map().set_clone_idx(0);
458 compile->set_type_hwm(NULL);
459 compile->set_type_last_size(0);
460 compile->set_last_tf(NULL, NULL);
461 compile->set_indexSet_arena(NULL);
462 compile->set_indexSet_free_block_list(NULL);
463 compile->init_type_arena();
464 Type::Initialize(compile);
465 _compile->set_scratch_buffer_blob(NULL);
466 _compile->begin_method();
467 _compile->clone_map().set_debug(_compile->has_method() && _compile->method_has_option(_compile->clone_map().debug_option_name));
468 }
469 CompileWrapper::~CompileWrapper() {
470 _compile->end_method();
471 if (_compile->scratch_buffer_blob() != NULL)
472 BufferBlob::free(_compile->scratch_buffer_blob());
473 _compile->env()->set_compiler_data(NULL);
474 }
475
476
477 //----------------------------print_compile_messages---------------------------
478 void Compile::print_compile_messages() {
479 #ifndef PRODUCT
480 // Check if recompiling
481 if (_subsume_loads == false && PrintOpto) {
482 // Recompiling without allowing machine instructions to subsume loads
483 tty->print_cr("*********************************************************");
484 tty->print_cr("** Bailout: Recompile without subsuming loads **");
485 tty->print_cr("*********************************************************");
486 }
487 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
488 // Recompiling without escape analysis
489 tty->print_cr("*********************************************************");
490 tty->print_cr("** Bailout: Recompile without escape analysis **");
491 tty->print_cr("*********************************************************");
492 }
493 if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {
494 // Recompiling without boxing elimination
495 tty->print_cr("*********************************************************");
496 tty->print_cr("** Bailout: Recompile without boxing elimination **");
497 tty->print_cr("*********************************************************");
498 }
499 if (env()->break_at_compile()) {
500 // Open the debugger when compiling this method.
501 tty->print("### Breaking when compiling: ");
502 method()->print_short_name();
503 tty->cr();
504 BREAKPOINT;
505 }
506
507 if( PrintOpto ) {
508 if (is_osr_compilation()) {
509 tty->print("[OSR]%3d", _compile_id);
510 } else {
511 tty->print("%3d", _compile_id);
512 }
513 }
514 #endif
515 }
516
517
518 //-----------------------init_scratch_buffer_blob------------------------------
519 // Construct a temporary BufferBlob and cache it for this compile.
600
601 if (is_branch) // Restore label.
602 n->as_MachBranch()->label_set(saveL, save_bnum);
603
604 // End scratch_emit_size section.
605 set_in_scratch_emit_size(false);
606
607 return buf.insts_size();
608 }
609
610
611 // ============================================================================
612 //------------------------------Compile standard-------------------------------
613 debug_only( int Compile::_debug_idx = 100000; )
614
615 // Compile a method. entry_bci is -1 for normal compilations and indicates
616 // the continuation bci for on stack replacement.
617
618
619 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci,
620 bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing )
621 : Phase(Compiler),
622 _env(ci_env),
623 _log(ci_env->log()),
624 _compile_id(ci_env->compile_id()),
625 _save_argument_registers(false),
626 _stub_name(NULL),
627 _stub_function(NULL),
628 _stub_entry_point(NULL),
629 _method(target),
630 _entry_bci(osr_bci),
631 _initial_gvn(NULL),
632 _for_igvn(NULL),
633 _warm_calls(NULL),
634 _subsume_loads(subsume_loads),
635 _do_escape_analysis(do_escape_analysis),
636 _eliminate_boxing(eliminate_boxing),
637 _failure_reason(NULL),
638 _code_buffer("Compile::Fill_buffer"),
639 _orig_pc_slot(0),
640 _orig_pc_slot_offset_in_bytes(0),
641 _has_method_handle_invokes(false),
642 _mach_constant_base_node(NULL),
643 _node_bundling_limit(0),
644 _node_bundling_base(NULL),
645 _java_calls(0),
646 _inner_loops(0),
647 _scratch_const_size(-1),
648 _in_scratch_emit_size(false),
649 _dead_node_list(comp_arena()),
650 _dead_node_count(0),
651 #ifndef PRODUCT
652 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")),
653 _in_dump_cnt(0),
654 _printer(IdealGraphPrinter::printer()),
655 #endif
656 _congraph(NULL),
657 _comp_arena(mtCompiler),
658 _node_arena(mtCompiler),
659 _old_arena(mtCompiler),
660 _Compile_types(mtCompiler),
661 _replay_inline_data(NULL),
662 _late_inlines(comp_arena(), 2, 0, NULL),
663 _string_late_inlines(comp_arena(), 2, 0, NULL),
664 _boxing_late_inlines(comp_arena(), 2, 0, NULL),
665 _late_inlines_pos(0),
666 _number_of_mh_late_inlines(0),
667 _inlining_progress(false),
668 _inlining_incrementally(false),
669 _print_inlining_list(NULL),
670 _print_inlining_stream(NULL),
671 _print_inlining_idx(0),
672 _print_inlining_output(NULL),
673 _interpreter_frame_size(0),
674 _max_node_limit(MaxNodeLimit) {
675 C = this;
676
677 CompileWrapper cw(this);
678
679 if (CITimeVerbose) {
680 tty->print(" ");
681 target->holder()->name()->print();
682 tty->print(".");
683 target->print_short_name();
684 tty->print(" ");
685 }
686 TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);
687 TraceTime t2(NULL, &_t_methodCompilation, CITime, false);
688
689 #ifndef PRODUCT
690 bool print_opto_assembly = PrintOptoAssembly || _method->has_option("PrintOptoAssembly");
691 if (!print_opto_assembly) {
692 bool print_assembly = (PrintAssembly || _method->should_print_assembly());
693 if (print_assembly && !Disassembler::can_decode()) {
694 tty->print_cr("PrintAssembly request changed to PrintOptoAssembly");
695 print_opto_assembly = true;
696 }
697 }
698 set_print_assembly(print_opto_assembly);
699 set_parsed_irreducible_loop(false);
700
701 if (method()->has_option("ReplayInline")) {
702 _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
703 }
704 #endif
705 set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining));
706 set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics"));
707 set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it
708
709 if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )) {
710 // Make sure the method being compiled gets its own MDO,
711 // so we can at least track the decompile_count().
712 // Need MDO to record RTM code generation state.
713 method()->ensure_method_data();
714 }
715
716 Init(::AliasLevel);
717
718
719 print_compile_messages();
720
721 _ilt = InlineTree::build_inline_tree_root();
722
723 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
724 assert(num_alias_types() >= AliasIdxRaw, "");
725
726 #define MINIMUM_NODE_HASH 1023
820 }
821 }
822
823 // Note: Large methods are capped off in do_one_bytecode().
824 if (failing()) return;
825
826 // After parsing, node notes are no longer automagic.
827 // They must be propagated by register_new_node_with_optimizer(),
828 // clone(), or the like.
829 set_default_node_notes(NULL);
830
831 for (;;) {
832 int successes = Inline_Warm();
833 if (failing()) return;
834 if (successes == 0) break;
835 }
836
837 // Drain the list.
838 Finish_Warm();
839 #ifndef PRODUCT
840 if (_printer && _printer->should_print(_method)) {
841 _printer->print_inlining(this);
842 }
843 #endif
844
845 if (failing()) return;
846 NOT_PRODUCT( verify_graph_edges(); )
847
848 // Now optimize
849 Optimize();
850 if (failing()) return;
851 NOT_PRODUCT( verify_graph_edges(); )
852
853 #ifndef PRODUCT
854 if (PrintIdeal) {
855 ttyLocker ttyl; // keep the following output all in one block
856 // This output goes directly to the tty, not the compiler log.
857 // To enable tools to match it up with the compilation activity,
858 // be sure to tag this tty output with the compile ID.
859 if (xtty != NULL) {
860 xtty->head("ideal compile_id='%d'%s", compile_id(),
861 is_osr_compilation() ? " compile_kind='osr'" :
862 "");
863 }
864 root()->dump(9999);
865 if (xtty != NULL) {
866 xtty->tail("ideal");
867 }
868 }
869 #endif
870
871 NOT_PRODUCT( verify_barriers(); )
872
873 // Dump compilation data to replay it.
874 if (method()->has_option("DumpReplay")) {
875 env()->dump_replay_data(_compile_id);
876 }
877 if (method()->has_option("DumpInline") && (ilt() != NULL)) {
878 env()->dump_inline_data(_compile_id);
879 }
880
881 // Now that we know the size of all the monitors we can add a fixed slot
882 // for the original deopt pc.
883
884 _orig_pc_slot = fixed_slots();
885 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
886 set_fixed_slots(next_slot);
887
888 // Compute when to use implicit null checks. Used by matching trap based
889 // nodes and NullCheck optimization.
890 set_allowed_deopt_reasons();
891
892 // Now generate code
893 Code_Gen();
894 if (failing()) return;
895
896 // Check if we want to skip execution of all compiled code.
897 {
901 return;
902 }
903 #endif
904 TracePhase tp("install_code", &timers[_t_registerMethod]);
905
906 if (is_osr_compilation()) {
907 _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
908 _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
909 } else {
910 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
911 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
912 }
913
914 env()->register_method(_method, _entry_bci,
915 &_code_offsets,
916 _orig_pc_slot_offset_in_bytes,
917 code_buffer(),
918 frame_size_in_words(), _oop_map_set,
919 &_handler_table, &_inc_table,
920 compiler,
921 env()->comp_level(),
922 has_unsafe_access(),
923 SharedRuntime::is_wide_vector(max_vector_size()),
924 rtm_state()
925 );
926
927 if (log() != NULL) // Print code cache state into compiler log
928 log()->code_cache_state();
929 }
930 }
931
932 //------------------------------Compile----------------------------------------
933 // Compile a runtime stub
934 Compile::Compile( ciEnv* ci_env,
935 TypeFunc_generator generator,
936 address stub_function,
937 const char *stub_name,
938 int is_fancy_jump,
939 bool pass_tls,
940 bool save_arg_registers,
941 bool return_pc )
942 : Phase(Compiler),
943 _env(ci_env),
944 _log(ci_env->log()),
945 _compile_id(0),
946 _save_argument_registers(save_arg_registers),
947 _method(NULL),
948 _stub_name(stub_name),
949 _stub_function(stub_function),
950 _stub_entry_point(NULL),
951 _entry_bci(InvocationEntryBci),
952 _initial_gvn(NULL),
953 _for_igvn(NULL),
954 _warm_calls(NULL),
955 _orig_pc_slot(0),
956 _orig_pc_slot_offset_in_bytes(0),
957 _subsume_loads(true),
958 _do_escape_analysis(false),
959 _eliminate_boxing(false),
960 _failure_reason(NULL),
961 _code_buffer("Compile::Fill_buffer"),
962 _has_method_handle_invokes(false),
963 _mach_constant_base_node(NULL),
1073 set_cached_top_node( new ConNode(Type::TOP) );
1074 set_recent_alloc(NULL, NULL);
1075
1076 // Create Debug Information Recorder to record scopes, oopmaps, etc.
1077 env()->set_oop_recorder(new OopRecorder(env()->arena()));
1078 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1079 env()->set_dependencies(new Dependencies(env()));
1080
1081 _fixed_slots = 0;
1082 set_has_split_ifs(false);
1083 set_has_loops(has_method() && method()->has_loops()); // first approximation
1084 set_has_stringbuilder(false);
1085 set_has_boxed_value(false);
1086 _trap_can_recompile = false; // no traps emitted yet
1087 _major_progress = true; // start out assuming good things will happen
1088 set_has_unsafe_access(false);
1089 set_max_vector_size(0);
1090 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1091 set_decompile_count(0);
1092
1093 set_do_freq_based_layout(BlockLayoutByFrequency || method_has_option("BlockLayoutByFrequency"));
1094 set_num_loop_opts(LoopOptsCount);
1095 set_do_inlining(Inline);
1096 set_max_inline_size(MaxInlineSize);
1097 set_freq_inline_size(FreqInlineSize);
1098 set_do_scheduling(OptoScheduling);
1099 set_do_count_invocations(false);
1100 set_do_method_data_update(false);
1101
1102 set_do_vector_loop(false);
1103
1104 bool do_vector = false;
1105 if (AllowVectorizeOnDemand) {
1106 if (has_method() && (method()->has_option("Vectorize") || method()->has_option("VectorizeDebug"))) {
1107 set_do_vector_loop(true);
1108 } else if (has_method() && method()->name() != 0 &&
1109 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1110 set_do_vector_loop(true);
1111 }
1112 #ifndef PRODUCT
1113 if (do_vector_loop() && Verbose) {
1114 tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());
1115 }
1116 #endif
1117 }
1118
1119 set_age_code(has_method() && method()->profile_aging());
1120 set_rtm_state(NoRTM); // No RTM lock eliding by default
1121 method_has_option_value("MaxNodeLimit", _max_node_limit);
1122 #if INCLUDE_RTM_OPT
1123 if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL)) {
1124 int rtm_state = method()->method_data()->rtm_state();
1125 if (method_has_option("NoRTMLockEliding") || ((rtm_state & NoRTM) != 0)) {
1126 // Don't generate RTM lock eliding code.
1127 set_rtm_state(NoRTM);
1128 } else if (method_has_option("UseRTMLockEliding") || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1129 // Generate RTM lock eliding code without abort ratio calculation code.
1130 set_rtm_state(UseRTM);
1131 } else if (UseRTMDeopt) {
1132 // Generate RTM lock eliding code and include abort ratio calculation
1133 // code if UseRTMDeopt is on.
1134 set_rtm_state(ProfileRTM);
1135 }
1136 }
1137 #endif
1138 if (debug_info()->recording_non_safepoints()) {
1139 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1140 (comp_arena(), 8, 0, NULL));
1141 set_default_node_notes(Node_Notes::make(this));
2074 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2075 }
2076
2077 {
2078 TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2079 igvn = PhaseIterGVN(gvn);
2080 igvn.optimize();
2081 }
2082 }
2083
2084 set_inlining_incrementally(false);
2085 }
2086
2087
2088 //------------------------------Optimize---------------------------------------
2089 // Given a graph, optimize it.
2090 void Compile::Optimize() {
2091 TracePhase tp("optimizer", &timers[_t_optimizer]);
2092
2093 #ifndef PRODUCT
2094 if (env()->break_at_compile()) {
2095 BREAKPOINT;
2096 }
2097
2098 #endif
2099
2100 ResourceMark rm;
2101 int loop_opts_cnt;
2102
2103 print_inlining_reinit();
2104
2105 NOT_PRODUCT( verify_graph_edges(); )
2106
2107 print_method(PHASE_AFTER_PARSING);
2108
2109 {
2110 // Iterative Global Value Numbering, including ideal transforms
2111 // Initialize IterGVN with types and values from parse-time GVN
2112 PhaseIterGVN igvn(initial_gvn());
2113 #ifdef ASSERT
2114 _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
4338 // from uniformly. In this case, we need to adjust the randomicity of the
4339 // selection, or else we will end up biasing the selection towards the latter
4340 // candidates.
4341 //
4342 // Quick back-envelope calculation shows that for the list of n candidates
4343 // the equal probability for the candidate to persist as "best" can be
4344 // achieved by replacing it with "next" k-th candidate with the probability
4345 // of 1/k. It can be easily shown that by the end of the run, the
4346 // probability for any candidate is converged to 1/n, thus giving the
4347 // uniform distribution among all the candidates.
4348 //
4349 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
4350 #define RANDOMIZED_DOMAIN_POW 29
4351 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
4352 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
4353 bool Compile::randomized_select(int count) {
4354 assert(count > 0, "only positive");
4355 return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
4356 }
4357
4358 const char* CloneMap::debug_option_name = "CloneMapDebug";
4359 CloneMap& Compile::clone_map() { return _clone_map; }
4360 void Compile::set_clone_map(Dict* d) { _clone_map._dict = d; }
4361
4362 void NodeCloneInfo::dump() const {
4363 tty->print(" {%d:%d} ", idx(), gen());
4364 }
4365
4366 void CloneMap::clone(Node* old, Node* nnn, int gen) {
4367 uint64_t val = value(old->_idx);
4368 NodeCloneInfo cio(val);
4369 assert(val != 0, "old node should be in the map");
4370 NodeCloneInfo cin(cio.idx(), gen + cio.gen());
4371 insert(nnn->_idx, cin.get());
4372 #ifndef PRODUCT
4373 if (is_debug()) {
4374 tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());
4375 }
4376 #endif
4377 }
4378
|
447 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
448 // the Compile* pointer is stored in the current ciEnv:
449 ciEnv* env = compile->env();
450 assert(env == ciEnv::current(), "must already be a ciEnv active");
451 assert(env->compiler_data() == NULL, "compile already active?");
452 env->set_compiler_data(compile);
453 assert(compile == Compile::current(), "sanity");
454
455 compile->set_type_dict(NULL);
456 compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
457 compile->clone_map().set_clone_idx(0);
458 compile->set_type_hwm(NULL);
459 compile->set_type_last_size(0);
460 compile->set_last_tf(NULL, NULL);
461 compile->set_indexSet_arena(NULL);
462 compile->set_indexSet_free_block_list(NULL);
463 compile->init_type_arena();
464 Type::Initialize(compile);
465 _compile->set_scratch_buffer_blob(NULL);
466 _compile->begin_method();
467 _compile->clone_map().set_debug(_compile->has_method() && _compile->directive()->CloneMapDebugOption);
468 }
469 CompileWrapper::~CompileWrapper() {
470 _compile->end_method();
471 if (_compile->scratch_buffer_blob() != NULL)
472 BufferBlob::free(_compile->scratch_buffer_blob());
473 _compile->env()->set_compiler_data(NULL);
474 }
475
476
477 //----------------------------print_compile_messages---------------------------
478 void Compile::print_compile_messages() {
479 #ifndef PRODUCT
480 // Check if recompiling
481 if (_subsume_loads == false && PrintOpto) {
482 // Recompiling without allowing machine instructions to subsume loads
483 tty->print_cr("*********************************************************");
484 tty->print_cr("** Bailout: Recompile without subsuming loads **");
485 tty->print_cr("*********************************************************");
486 }
487 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
488 // Recompiling without escape analysis
489 tty->print_cr("*********************************************************");
490 tty->print_cr("** Bailout: Recompile without escape analysis **");
491 tty->print_cr("*********************************************************");
492 }
493 if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {
494 // Recompiling without boxing elimination
495 tty->print_cr("*********************************************************");
496 tty->print_cr("** Bailout: Recompile without boxing elimination **");
497 tty->print_cr("*********************************************************");
498 }
499 if (C->directive()->BreakAtCompileOption) {
500 // Open the debugger when compiling this method.
501 tty->print("### Breaking when compiling: ");
502 method()->print_short_name();
503 tty->cr();
504 BREAKPOINT;
505 }
506
507 if( PrintOpto ) {
508 if (is_osr_compilation()) {
509 tty->print("[OSR]%3d", _compile_id);
510 } else {
511 tty->print("%3d", _compile_id);
512 }
513 }
514 #endif
515 }
516
517
518 //-----------------------init_scratch_buffer_blob------------------------------
519 // Construct a temporary BufferBlob and cache it for this compile.
600
601 if (is_branch) // Restore label.
602 n->as_MachBranch()->label_set(saveL, save_bnum);
603
604 // End scratch_emit_size section.
605 set_in_scratch_emit_size(false);
606
607 return buf.insts_size();
608 }
609
610
611 // ============================================================================
612 //------------------------------Compile standard-------------------------------
613 debug_only( int Compile::_debug_idx = 100000; )
614
615 // Compile a method. entry_bci is -1 for normal compilations and indicates
616 // the continuation bci for on stack replacement.
617
618
619 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci,
620 bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing, DirectiveSet* directive)
621 : Phase(Compiler),
622 _env(ci_env),
623 _directive(directive),
624 _log(ci_env->log()),
625 _compile_id(ci_env->compile_id()),
626 _save_argument_registers(false),
627 _stub_name(NULL),
628 _stub_function(NULL),
629 _stub_entry_point(NULL),
630 _method(target),
631 _entry_bci(osr_bci),
632 _initial_gvn(NULL),
633 _for_igvn(NULL),
634 _warm_calls(NULL),
635 _subsume_loads(subsume_loads),
636 _do_escape_analysis(do_escape_analysis),
637 _eliminate_boxing(eliminate_boxing),
638 _failure_reason(NULL),
639 _code_buffer("Compile::Fill_buffer"),
640 _orig_pc_slot(0),
641 _orig_pc_slot_offset_in_bytes(0),
642 _has_method_handle_invokes(false),
643 _mach_constant_base_node(NULL),
644 _node_bundling_limit(0),
645 _node_bundling_base(NULL),
646 _java_calls(0),
647 _inner_loops(0),
648 _scratch_const_size(-1),
649 _in_scratch_emit_size(false),
650 _dead_node_list(comp_arena()),
651 _dead_node_count(0),
652 #ifndef PRODUCT
653 _trace_opto_output(directive->TraceOptoOutputOption),
654 _in_dump_cnt(0),
655 _printer(IdealGraphPrinter::printer()),
656 #endif
657 _congraph(NULL),
658 _comp_arena(mtCompiler),
659 _node_arena(mtCompiler),
660 _old_arena(mtCompiler),
661 _Compile_types(mtCompiler),
662 _replay_inline_data(NULL),
663 _late_inlines(comp_arena(), 2, 0, NULL),
664 _string_late_inlines(comp_arena(), 2, 0, NULL),
665 _boxing_late_inlines(comp_arena(), 2, 0, NULL),
666 _late_inlines_pos(0),
667 _number_of_mh_late_inlines(0),
668 _inlining_progress(false),
669 _inlining_incrementally(false),
670 _print_inlining_list(NULL),
671 _print_inlining_stream(NULL),
672 _print_inlining_idx(0),
673 _print_inlining_output(NULL),
674 _interpreter_frame_size(0),
675 _max_node_limit(MaxNodeLimit) {
676 C = this;
677 #ifndef PRODUCT
678 if (_printer != NULL) {
679 _printer->set_compile(this);
680 }
681 #endif
682 CompileWrapper cw(this);
683
684 if (CITimeVerbose) {
685 tty->print(" ");
686 target->holder()->name()->print();
687 tty->print(".");
688 target->print_short_name();
689 tty->print(" ");
690 }
691 TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);
692 TraceTime t2(NULL, &_t_methodCompilation, CITime, false);
693
694 #ifndef PRODUCT
695 bool print_opto_assembly = directive->PrintOptoAssemblyOption;
696 if (!print_opto_assembly) {
697 bool print_assembly = directive->PrintAssemblyOption;
698 if (print_assembly && !Disassembler::can_decode()) {
699 tty->print_cr("PrintAssembly request changed to PrintOptoAssembly");
700 print_opto_assembly = true;
701 }
702 }
703 set_print_assembly(print_opto_assembly);
704 set_parsed_irreducible_loop(false);
705
706 if (directive->ReplayInlineOption) {
707 _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
708 }
709 #endif
710 set_print_inlining(directive->PrintInliningOption NOT_PRODUCT( || PrintOptoInlining));
711 set_print_intrinsics(directive->PrintIntrinsicsOption);
712 set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it
713
714 if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )) {
715 // Make sure the method being compiled gets its own MDO,
716 // so we can at least track the decompile_count().
717 // Need MDO to record RTM code generation state.
718 method()->ensure_method_data();
719 }
720
721 Init(::AliasLevel);
722
723
724 print_compile_messages();
725
726 _ilt = InlineTree::build_inline_tree_root();
727
728 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
729 assert(num_alias_types() >= AliasIdxRaw, "");
730
731 #define MINIMUM_NODE_HASH 1023
825 }
826 }
827
828 // Note: Large methods are capped off in do_one_bytecode().
829 if (failing()) return;
830
831 // After parsing, node notes are no longer automagic.
832 // They must be propagated by register_new_node_with_optimizer(),
833 // clone(), or the like.
834 set_default_node_notes(NULL);
835
836 for (;;) {
837 int successes = Inline_Warm();
838 if (failing()) return;
839 if (successes == 0) break;
840 }
841
842 // Drain the list.
843 Finish_Warm();
844 #ifndef PRODUCT
845 if (_printer && _printer->should_print(1)) {
846 _printer->print_inlining();
847 }
848 #endif
849
850 if (failing()) return;
851 NOT_PRODUCT( verify_graph_edges(); )
852
853 // Now optimize
854 Optimize();
855 if (failing()) return;
856 NOT_PRODUCT( verify_graph_edges(); )
857
858 #ifndef PRODUCT
859 if (PrintIdeal) {
860 ttyLocker ttyl; // keep the following output all in one block
861 // This output goes directly to the tty, not the compiler log.
862 // To enable tools to match it up with the compilation activity,
863 // be sure to tag this tty output with the compile ID.
864 if (xtty != NULL) {
865 xtty->head("ideal compile_id='%d'%s", compile_id(),
866 is_osr_compilation() ? " compile_kind='osr'" :
867 "");
868 }
869 root()->dump(9999);
870 if (xtty != NULL) {
871 xtty->tail("ideal");
872 }
873 }
874 #endif
875
876 NOT_PRODUCT( verify_barriers(); )
877
878 // Dump compilation data to replay it.
879 if (directive->DumpReplayOption) {
880 env()->dump_replay_data(_compile_id);
881 }
882 if (directive->DumpInlineOption && (ilt() != NULL)) {
883 env()->dump_inline_data(_compile_id);
884 }
885
886 // Now that we know the size of all the monitors we can add a fixed slot
887 // for the original deopt pc.
888
889 _orig_pc_slot = fixed_slots();
890 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
891 set_fixed_slots(next_slot);
892
893 // Compute when to use implicit null checks. Used by matching trap based
894 // nodes and NullCheck optimization.
895 set_allowed_deopt_reasons();
896
897 // Now generate code
898 Code_Gen();
899 if (failing()) return;
900
901 // Check if we want to skip execution of all compiled code.
902 {
906 return;
907 }
908 #endif
909 TracePhase tp("install_code", &timers[_t_registerMethod]);
910
911 if (is_osr_compilation()) {
912 _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
913 _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
914 } else {
915 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
916 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
917 }
918
919 env()->register_method(_method, _entry_bci,
920 &_code_offsets,
921 _orig_pc_slot_offset_in_bytes,
922 code_buffer(),
923 frame_size_in_words(), _oop_map_set,
924 &_handler_table, &_inc_table,
925 compiler,
926 has_unsafe_access(),
927 SharedRuntime::is_wide_vector(max_vector_size()),
928 _directive,
929 rtm_state()
930 );
931
932 if (log() != NULL) // Print code cache state into compiler log
933 log()->code_cache_state();
934 }
935 }
936
937 //------------------------------Compile----------------------------------------
938 // Compile a runtime stub
939 Compile::Compile( ciEnv* ci_env,
940 TypeFunc_generator generator,
941 address stub_function,
942 const char *stub_name,
943 int is_fancy_jump,
944 bool pass_tls,
945 bool save_arg_registers,
946 bool return_pc,
947 DirectiveSet* directive)
948 : Phase(Compiler),
949 _env(ci_env),
950 _directive(directive),
951 _log(ci_env->log()),
952 _compile_id(0),
953 _save_argument_registers(save_arg_registers),
954 _method(NULL),
955 _stub_name(stub_name),
956 _stub_function(stub_function),
957 _stub_entry_point(NULL),
958 _entry_bci(InvocationEntryBci),
959 _initial_gvn(NULL),
960 _for_igvn(NULL),
961 _warm_calls(NULL),
962 _orig_pc_slot(0),
963 _orig_pc_slot_offset_in_bytes(0),
964 _subsume_loads(true),
965 _do_escape_analysis(false),
966 _eliminate_boxing(false),
967 _failure_reason(NULL),
968 _code_buffer("Compile::Fill_buffer"),
969 _has_method_handle_invokes(false),
970 _mach_constant_base_node(NULL),
1080 set_cached_top_node( new ConNode(Type::TOP) );
1081 set_recent_alloc(NULL, NULL);
1082
1083 // Create Debug Information Recorder to record scopes, oopmaps, etc.
1084 env()->set_oop_recorder(new OopRecorder(env()->arena()));
1085 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1086 env()->set_dependencies(new Dependencies(env()));
1087
1088 _fixed_slots = 0;
1089 set_has_split_ifs(false);
1090 set_has_loops(has_method() && method()->has_loops()); // first approximation
1091 set_has_stringbuilder(false);
1092 set_has_boxed_value(false);
1093 _trap_can_recompile = false; // no traps emitted yet
1094 _major_progress = true; // start out assuming good things will happen
1095 set_has_unsafe_access(false);
1096 set_max_vector_size(0);
1097 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1098 set_decompile_count(0);
1099
1100 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1101 set_num_loop_opts(LoopOptsCount);
1102 set_do_inlining(Inline);
1103 set_max_inline_size(MaxInlineSize);
1104 set_freq_inline_size(FreqInlineSize);
1105 set_do_scheduling(OptoScheduling);
1106 set_do_count_invocations(false);
1107 set_do_method_data_update(false);
1108
1109 set_do_vector_loop(false);
1110
1111 bool do_vector = false;
1112 if (AllowVectorizeOnDemand) {
1113 if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
1114 set_do_vector_loop(true);
1115 } else if (has_method() && method()->name() != 0 &&
1116 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1117 set_do_vector_loop(true);
1118 }
1119 #ifndef PRODUCT
1120 if (do_vector_loop() && Verbose) {
1121 tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());
1122 }
1123 #endif
1124 }
1125
1126 set_age_code(has_method() && method()->profile_aging());
1127 set_rtm_state(NoRTM); // No RTM lock eliding by default
1128 _max_node_limit = _directive->MaxNodeLimitOption;
1129
1130 #if INCLUDE_RTM_OPT
1131 if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL)) {
1132 int rtm_state = method()->method_data()->rtm_state();
1133 if (method_has_option("NoRTMLockEliding") || ((rtm_state & NoRTM) != 0)) {
1134 // Don't generate RTM lock eliding code.
1135 set_rtm_state(NoRTM);
1136 } else if (method_has_option("UseRTMLockEliding") || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1137 // Generate RTM lock eliding code without abort ratio calculation code.
1138 set_rtm_state(UseRTM);
1139 } else if (UseRTMDeopt) {
1140 // Generate RTM lock eliding code and include abort ratio calculation
1141 // code if UseRTMDeopt is on.
1142 set_rtm_state(ProfileRTM);
1143 }
1144 }
1145 #endif
1146 if (debug_info()->recording_non_safepoints()) {
1147 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1148 (comp_arena(), 8, 0, NULL));
1149 set_default_node_notes(Node_Notes::make(this));
2082 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
2083 }
2084
2085 {
2086 TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
2087 igvn = PhaseIterGVN(gvn);
2088 igvn.optimize();
2089 }
2090 }
2091
2092 set_inlining_incrementally(false);
2093 }
2094
2095
2096 //------------------------------Optimize---------------------------------------
2097 // Given a graph, optimize it.
2098 void Compile::Optimize() {
2099 TracePhase tp("optimizer", &timers[_t_optimizer]);
2100
2101 #ifndef PRODUCT
2102 if (_directive->BreakAtCompileOption) {
2103 BREAKPOINT;
2104 }
2105
2106 #endif
2107
2108 ResourceMark rm;
2109 int loop_opts_cnt;
2110
2111 print_inlining_reinit();
2112
2113 NOT_PRODUCT( verify_graph_edges(); )
2114
2115 print_method(PHASE_AFTER_PARSING);
2116
2117 {
2118 // Iterative Global Value Numbering, including ideal transforms
2119 // Initialize IterGVN with types and values from parse-time GVN
2120 PhaseIterGVN igvn(initial_gvn());
2121 #ifdef ASSERT
2122 _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
4346 // from uniformly. In this case, we need to adjust the randomicity of the
4347 // selection, or else we will end up biasing the selection towards the latter
4348 // candidates.
4349 //
4350 // Quick back-envelope calculation shows that for the list of n candidates
4351 // the equal probability for the candidate to persist as "best" can be
4352 // achieved by replacing it with "next" k-th candidate with the probability
4353 // of 1/k. It can be easily shown that by the end of the run, the
4354 // probability for any candidate is converged to 1/n, thus giving the
4355 // uniform distribution among all the candidates.
4356 //
4357 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
4358 #define RANDOMIZED_DOMAIN_POW 29
4359 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
4360 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
4361 bool Compile::randomized_select(int count) {
4362 assert(count > 0, "only positive");
4363 return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
4364 }
4365
4366 CloneMap& Compile::clone_map() { return _clone_map; }
4367 void Compile::set_clone_map(Dict* d) { _clone_map._dict = d; }
4368
4369 void NodeCloneInfo::dump() const {
4370 tty->print(" {%d:%d} ", idx(), gen());
4371 }
4372
4373 void CloneMap::clone(Node* old, Node* nnn, int gen) {
4374 uint64_t val = value(old->_idx);
4375 NodeCloneInfo cio(val);
4376 assert(val != 0, "old node should be in the map");
4377 NodeCloneInfo cin(cio.idx(), gen + cio.gen());
4378 insert(nnn->_idx, cin.get());
4379 #ifndef PRODUCT
4380 if (is_debug()) {
4381 tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());
4382 }
4383 #endif
4384 }
4385
|