< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page

  42 #include "gc/shared/c2/barrierSetC2.hpp"
  43 #include "jfr/jfrEvents.hpp"
  44 #include "jvm_io.h"
  45 #include "memory/allocation.hpp"
  46 #include "memory/arena.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "opto/addnode.hpp"
  49 #include "opto/block.hpp"
  50 #include "opto/c2compiler.hpp"
  51 #include "opto/callGenerator.hpp"
  52 #include "opto/callnode.hpp"
  53 #include "opto/castnode.hpp"
  54 #include "opto/cfgnode.hpp"
  55 #include "opto/chaitin.hpp"
  56 #include "opto/compile.hpp"
  57 #include "opto/connode.hpp"
  58 #include "opto/convertnode.hpp"
  59 #include "opto/divnode.hpp"
  60 #include "opto/escape.hpp"
  61 #include "opto/idealGraphPrinter.hpp"

  62 #include "opto/locknode.hpp"
  63 #include "opto/loopnode.hpp"
  64 #include "opto/machnode.hpp"
  65 #include "opto/macro.hpp"
  66 #include "opto/matcher.hpp"
  67 #include "opto/mathexactnode.hpp"
  68 #include "opto/memnode.hpp"

  69 #include "opto/mulnode.hpp"
  70 #include "opto/narrowptrnode.hpp"
  71 #include "opto/node.hpp"
  72 #include "opto/opaquenode.hpp"
  73 #include "opto/opcodes.hpp"
  74 #include "opto/output.hpp"
  75 #include "opto/parse.hpp"
  76 #include "opto/phaseX.hpp"
  77 #include "opto/rootnode.hpp"
  78 #include "opto/runtime.hpp"
  79 #include "opto/stringopts.hpp"
  80 #include "opto/type.hpp"
  81 #include "opto/vector.hpp"
  82 #include "opto/vectornode.hpp"
  83 #include "runtime/globals_extension.hpp"
  84 #include "runtime/sharedRuntime.hpp"
  85 #include "runtime/signature.hpp"
  86 #include "runtime/stubRoutines.hpp"
  87 #include "runtime/timer.hpp"
  88 #include "utilities/align.hpp"

 388   // as dead to be conservative about the dead node count at any
 389   // given time.
 390   if (!dead->is_Con()) {
 391     record_dead_node(dead->_idx);
 392   }
 393   if (dead->is_macro()) {
 394     remove_macro_node(dead);
 395   }
 396   if (dead->is_expensive()) {
 397     remove_expensive_node(dead);
 398   }
 399   if (dead->is_OpaqueTemplateAssertionPredicate()) {
 400     remove_template_assertion_predicate_opaque(dead->as_OpaqueTemplateAssertionPredicate());
 401   }
 402   if (dead->is_ParsePredicate()) {
 403     remove_parse_predicate(dead->as_ParsePredicate());
 404   }
 405   if (dead->for_post_loop_opts_igvn()) {
 406     remove_from_post_loop_opts_igvn(dead);
 407   }






 408   if (dead->for_merge_stores_igvn()) {
 409     remove_from_merge_stores_igvn(dead);
 410   }
 411   if (dead->is_Call()) {
 412     remove_useless_late_inlines(                &_late_inlines, dead);
 413     remove_useless_late_inlines(         &_string_late_inlines, dead);
 414     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 415     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 416 
 417     if (dead->is_CallStaticJava()) {
 418       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 419     }
 420   }
 421   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 422   bs->unregister_potential_barrier_node(dead);
 423 }
 424 
 425 // Disconnect all useless nodes by disconnecting those at the boundary.
 426 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist, const Unique_Node_List* root_and_safepoints) {
 427   uint next = 0;

 435     // Use raw traversal of out edges since this code removes out edges
 436     int max = n->outcnt();
 437     for (int j = 0; j < max; ++j) {
 438       Node* child = n->raw_out(j);
 439       if (!useful.member(child)) {
 440         assert(!child->is_top() || child != top(),
 441                "If top is cached in Compile object it is in useful list");
 442         // Only need to remove this out-edge to the useless node
 443         n->raw_del_out(j);
 444         --j;
 445         --max;
 446         if (child->is_data_proj_of_pure_function(n)) {
 447           worklist.push(n);
 448         }
 449       }
 450     }
 451     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 452       assert(useful.member(n->unique_out()), "do not push a useless node");
 453       worklist.push(n->unique_out());
 454     }



 455   }
 456 
 457   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 458   remove_useless_nodes(_parse_predicates,   useful); // remove useless Parse Predicate nodes
 459   // Remove useless Template Assertion Predicate opaque nodes
 460   remove_useless_nodes(_template_assertion_predicate_opaques, useful);
 461   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 462   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass







 463   remove_useless_nodes(_for_merge_stores_igvn, useful); // remove useless node recorded for merge stores IGVN pass
 464   remove_useless_unstable_if_traps(useful);          // remove useless unstable_if traps
 465   remove_useless_coarsened_locks(useful);            // remove useless coarsened locks nodes
 466 #ifdef ASSERT
 467   if (_modified_nodes != nullptr) {
 468     _modified_nodes->remove_useless_nodes(useful.member_set());
 469   }
 470 #endif
 471 
 472   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 473   bs->eliminate_useless_gc_barriers(useful, this);
 474   // clean up the late inline lists
 475   remove_useless_late_inlines(                &_late_inlines, useful);
 476   remove_useless_late_inlines(         &_string_late_inlines, useful);
 477   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
 478   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 479   DEBUG_ONLY(verify_graph_edges(true /*check for no_dead_code*/, root_and_safepoints);)
 480 }
 481 
 482 // ============================================================================

 629 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
 630                  Options options, DirectiveSet* directive)
 631     : Phase(Compiler),
 632       _compile_id(ci_env->compile_id()),
 633       _options(options),
 634       _method(target),
 635       _entry_bci(osr_bci),
 636       _ilt(nullptr),
 637       _stub_function(nullptr),
 638       _stub_name(nullptr),
 639       _stub_id(StubId::NO_STUBID),
 640       _stub_entry_point(nullptr),
 641       _max_node_limit(MaxNodeLimit),
 642       _post_loop_opts_phase(false),
 643       _merge_stores_phase(false),
 644       _allow_macro_nodes(true),
 645       _inlining_progress(false),
 646       _inlining_incrementally(false),
 647       _do_cleanup(false),
 648       _has_reserved_stack_access(target->has_reserved_stack_access()),

 649 #ifndef PRODUCT
 650       _igv_idx(0),
 651       _trace_opto_output(directive->TraceOptoOutputOption),
 652 #endif
 653       _clinit_barrier_on_entry(false),
 654       _stress_seed(0),
 655       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 656       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 657       _env(ci_env),
 658       _directive(directive),
 659       _log(ci_env->log()),
 660       _first_failure_details(nullptr),
 661       _intrinsics(comp_arena(), 0, 0, nullptr),
 662       _macro_nodes(comp_arena(), 8, 0, nullptr),
 663       _parse_predicates(comp_arena(), 8, 0, nullptr),
 664       _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
 665       _expensive_nodes(comp_arena(), 8, 0, nullptr),
 666       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),


 667       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 668       _unstable_if_traps(comp_arena(), 8, 0, nullptr),
 669       _coarsened_locks(comp_arena(), 8, 0, nullptr),
 670       _congraph(nullptr),
 671       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 672           _unique(0),
 673       _dead_node_count(0),
 674       _dead_node_list(comp_arena()),
 675       _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 676       _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 677       _node_arena(&_node_arena_one),
 678       _mach_constant_base_node(nullptr),
 679       _Compile_types(mtCompiler, Arena::Tag::tag_type),
 680       _initial_gvn(nullptr),
 681       _igvn_worklist(nullptr),
 682       _types(nullptr),
 683       _node_hash(nullptr),
 684       _late_inlines(comp_arena(), 2, 0, nullptr),
 685       _string_late_inlines(comp_arena(), 2, 0, nullptr),
 686       _boxing_late_inlines(comp_arena(), 2, 0, nullptr),

 755 #define MINIMUM_NODE_HASH  1023
 756 
 757   // GVN that will be run immediately on new nodes
 758   uint estimated_size = method()->code_size()*4+64;
 759   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 760   _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
 761   _types = new (comp_arena()) Type_Array(comp_arena());
 762   _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
 763   PhaseGVN gvn;
 764   set_initial_gvn(&gvn);
 765 
 766   { // Scope for timing the parser
 767     TracePhase tp(_t_parser);
 768 
 769     // Put top into the hash table ASAP.
 770     initial_gvn()->transform(top());
 771 
 772     // Set up tf(), start(), and find a CallGenerator.
 773     CallGenerator* cg = nullptr;
 774     if (is_osr_compilation()) {
 775       const TypeTuple *domain = StartOSRNode::osr_domain();
 776       const TypeTuple *range = TypeTuple::make_range(method()->signature());
 777       init_tf(TypeFunc::make(domain, range));
 778       StartNode* s = new StartOSRNode(root(), domain);
 779       initial_gvn()->set_type_bottom(s);
 780       verify_start(s);
 781       cg = CallGenerator::for_osr(method(), entry_bci());
 782     } else {
 783       // Normal case.
 784       init_tf(TypeFunc::make(method()));
 785       StartNode* s = new StartNode(root(), tf()->domain());
 786       initial_gvn()->set_type_bottom(s);
 787       verify_start(s);
 788       float past_uses = method()->interpreter_invocation_count();
 789       float expected_uses = past_uses;
 790       cg = CallGenerator::for_inline(method(), expected_uses);
 791     }
 792     if (failing())  return;
 793     if (cg == nullptr) {
 794       const char* reason = InlineTree::check_can_parse(method());
 795       assert(reason != nullptr, "expect reason for parse failure");
 796       stringStream ss;
 797       ss.print("cannot parse method: %s", reason);
 798       record_method_not_compilable(ss.as_string());
 799       return;
 800     }
 801 
 802     gvn.set_type(root(), root()->bottom_type());
 803 
 804     JVMState* jvms = build_start_state(start(), tf());
 805     if ((jvms = cg->generate(jvms)) == nullptr) {

 866     print_ideal_ir("print_ideal");
 867   }
 868 #endif
 869 
 870 #ifdef ASSERT
 871   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 872   bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
 873 #endif
 874 
 875   // Dump compilation data to replay it.
 876   if (directive->DumpReplayOption) {
 877     env()->dump_replay_data(_compile_id);
 878   }
 879   if (directive->DumpInlineOption && (ilt() != nullptr)) {
 880     env()->dump_inline_data(_compile_id);
 881   }
 882 
 883   // Now that we know the size of all the monitors we can add a fixed slot
 884   // for the original deopt pc.
 885   int next_slot = fixed_slots() + (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 }
 895 
 896 //------------------------------Compile----------------------------------------
 897 // Compile a runtime stub
 898 Compile::Compile(ciEnv* ci_env,
 899                  TypeFunc_generator generator,
 900                  address stub_function,
 901                  const char* stub_name,
 902                  StubId stub_id,
 903                  int is_fancy_jump,
 904                  bool pass_tls,
 905                  bool return_pc,
 906                  DirectiveSet* directive)
 907     : Phase(Compiler),
 908       _compile_id(0),
 909       _options(Options::for_runtime_stub()),
 910       _method(nullptr),
 911       _entry_bci(InvocationEntryBci),
 912       _stub_function(stub_function),
 913       _stub_name(stub_name),
 914       _stub_id(stub_id),
 915       _stub_entry_point(nullptr),
 916       _max_node_limit(MaxNodeLimit),
 917       _post_loop_opts_phase(false),
 918       _merge_stores_phase(false),
 919       _allow_macro_nodes(true),
 920       _inlining_progress(false),
 921       _inlining_incrementally(false),
 922       _has_reserved_stack_access(false),

 923 #ifndef PRODUCT
 924       _igv_idx(0),
 925       _trace_opto_output(directive->TraceOptoOutputOption),
 926 #endif
 927       _clinit_barrier_on_entry(false),
 928       _stress_seed(0),
 929       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 930       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 931       _env(ci_env),
 932       _directive(directive),
 933       _log(ci_env->log()),
 934       _first_failure_details(nullptr),
 935       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 936       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 937       _congraph(nullptr),
 938       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 939           _unique(0),
 940       _dead_node_count(0),
 941       _dead_node_list(comp_arena()),
 942       _node_arena_one(mtCompiler, Arena::Tag::tag_node),

1057   _fixed_slots = 0;
1058   set_has_split_ifs(false);
1059   set_has_loops(false); // first approximation
1060   set_has_stringbuilder(false);
1061   set_has_boxed_value(false);
1062   _trap_can_recompile = false;  // no traps emitted yet
1063   _major_progress = true; // start out assuming good things will happen
1064   set_has_unsafe_access(false);
1065   set_max_vector_size(0);
1066   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1067   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1068   set_decompile_count(0);
1069 
1070 #ifndef PRODUCT
1071   _phase_counter = 0;
1072   Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1073 #endif
1074 
1075   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1076   _loop_opts_cnt = LoopOptsCount;




1077   set_do_inlining(Inline);
1078   set_max_inline_size(MaxInlineSize);
1079   set_freq_inline_size(FreqInlineSize);
1080   set_do_scheduling(OptoScheduling);
1081 
1082   set_do_vector_loop(false);
1083   set_has_monitors(false);
1084   set_has_scoped_access(false);
1085 
1086   if (AllowVectorizeOnDemand) {
1087     if (has_method() && _directive->VectorizeOption) {
1088       set_do_vector_loop(true);
1089       NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());})
1090     } else if (has_method() && method()->name() != nullptr &&
1091                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1092       set_do_vector_loop(true);
1093     }
1094   }
1095   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1096   NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n",  method()->name()->as_quoted_ascii());})

1341 
1342   // Known instance (scalarizable allocation) alias only with itself.
1343   bool is_known_inst = tj->isa_oopptr() != nullptr &&
1344                        tj->is_oopptr()->is_known_instance();
1345 
1346   // Process weird unsafe references.
1347   if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1348     assert(InlineUnsafeOps || StressReflectiveCode, "indeterminate pointers come only from unsafe ops");
1349     assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1350     tj = TypeOopPtr::BOTTOM;
1351     ptr = tj->ptr();
1352     offset = tj->offset();
1353   }
1354 
1355   // Array pointers need some flattening
1356   const TypeAryPtr* ta = tj->isa_aryptr();
1357   if (ta && ta->is_stable()) {
1358     // Erase stability property for alias analysis.
1359     tj = ta = ta->cast_to_stable(false);
1360   }









1361   if( ta && is_known_inst ) {
1362     if ( offset != Type::OffsetBot &&
1363          offset > arrayOopDesc::length_offset_in_bytes() ) {
1364       offset = Type::OffsetBot; // Flatten constant access into array body only
1365       tj = ta = ta->
1366               remove_speculative()->
1367               cast_to_ptr_type(ptr)->
1368               with_offset(offset);
1369     }
1370   } else if (ta) {
1371     // For arrays indexed by constant indices, we flatten the alias
1372     // space to include all of the array body.  Only the header, klass
1373     // and array length can be accessed un-aliased.


1374     if( offset != Type::OffsetBot ) {
1375       if( ta->const_oop() ) { // MethodData* or Method*
1376         offset = Type::OffsetBot;   // Flatten constant access into array body
1377         tj = ta = ta->
1378                 remove_speculative()->
1379                 cast_to_ptr_type(ptr)->
1380                 cast_to_exactness(false)->
1381                 with_offset(offset);
1382       } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1383         // range is OK as-is.
1384         tj = ta = TypeAryPtr::RANGE;
1385       } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1386         tj = TypeInstPtr::KLASS; // all klass loads look alike
1387         ta = TypeAryPtr::RANGE; // generic ignored junk
1388         ptr = TypePtr::BotPTR;
1389       } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1390         tj = TypeInstPtr::MARK;
1391         ta = TypeAryPtr::RANGE; // generic ignored junk
1392         ptr = TypePtr::BotPTR;
1393       } else {                  // Random constant offset into array body
1394         offset = Type::OffsetBot;   // Flatten constant access into array body
1395         tj = ta = ta->
1396                 remove_speculative()->
1397                 cast_to_ptr_type(ptr)->
1398                 cast_to_exactness(false)->
1399                 with_offset(offset);
1400       }
1401     }
1402     // Arrays of fixed size alias with arrays of unknown size.
1403     if (ta->size() != TypeInt::POS) {
1404       const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1405       tj = ta = ta->
1406               remove_speculative()->
1407               cast_to_ptr_type(ptr)->
1408               with_ary(tary)->
1409               cast_to_exactness(false);
1410     }
1411     // Arrays of known objects become arrays of unknown objects.
1412     if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1413       const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1414       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,offset);
1415     }
1416     if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1417       const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1418       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,offset);





1419     }
1420     // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1421     // cannot be distinguished by bytecode alone.
1422     if (ta->elem() == TypeInt::BOOL) {
1423       const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1424       ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1425       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
1426     }
1427     // During the 2nd round of IterGVN, NotNull castings are removed.
1428     // Make sure the Bottom and NotNull variants alias the same.
1429     // Also, make sure exact and non-exact variants alias the same.
1430     if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != nullptr) {
1431       tj = ta = ta->
1432               remove_speculative()->
1433               cast_to_ptr_type(TypePtr::BotPTR)->
1434               cast_to_exactness(false)->
1435               with_offset(offset);
1436     }
1437   }
1438 
1439   // Oop pointers need some flattening
1440   const TypeInstPtr *to = tj->isa_instptr();
1441   if (to && to != TypeOopPtr::BOTTOM) {
1442     ciInstanceKlass* ik = to->instance_klass();
1443     if( ptr == TypePtr::Constant ) {
1444       if (ik != ciEnv::current()->Class_klass() ||
1445           offset < ik->layout_helper_size_in_bytes()) {

1455     } else if( is_known_inst ) {
1456       tj = to; // Keep NotNull and klass_is_exact for instance type
1457     } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1458       // During the 2nd round of IterGVN, NotNull castings are removed.
1459       // Make sure the Bottom and NotNull variants alias the same.
1460       // Also, make sure exact and non-exact variants alias the same.
1461       tj = to = to->
1462               remove_speculative()->
1463               cast_to_instance_id(TypeOopPtr::InstanceBot)->
1464               cast_to_ptr_type(TypePtr::BotPTR)->
1465               cast_to_exactness(false);
1466     }
1467     if (to->speculative() != nullptr) {
1468       tj = to = to->remove_speculative();
1469     }
1470     // Canonicalize the holder of this field
1471     if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1472       // First handle header references such as a LoadKlassNode, even if the
1473       // object's klass is unloaded at compile time (4965979).
1474       if (!is_known_inst) { // Do it only for non-instance types
1475         tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, nullptr, offset);
1476       }
1477     } else if (offset < 0 || offset >= ik->layout_helper_size_in_bytes()) {
1478       // Static fields are in the space above the normal instance
1479       // fields in the java.lang.Class instance.
1480       if (ik != ciEnv::current()->Class_klass()) {
1481         to = nullptr;
1482         tj = TypeOopPtr::BOTTOM;
1483         offset = tj->offset();
1484       }
1485     } else {
1486       ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
1487       assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1488       assert(tj->offset() == offset, "no change to offset expected");
1489       bool xk = to->klass_is_exact();
1490       int instance_id = to->instance_id();
1491 
1492       // If the input type's class is the holder: if exact, the type only includes interfaces implemented by the holder
1493       // but if not exact, it may include extra interfaces: build new type from the holder class to make sure only
1494       // its interfaces are included.
1495       if (xk && ik->equals(canonical_holder)) {
1496         assert(tj == TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id), "exact type should be canonical type");
1497       } else {
1498         assert(xk || !is_known_inst, "Known instance should be exact type");
1499         tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id);
1500       }
1501     }
1502   }
1503 
1504   // Klass pointers to object array klasses need some flattening
1505   const TypeKlassPtr *tk = tj->isa_klassptr();
1506   if( tk ) {
1507     // If we are referencing a field within a Klass, we need
1508     // to assume the worst case of an Object.  Both exact and
1509     // inexact types must flatten to the same alias class so
1510     // use NotNull as the PTR.
1511     if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1512       tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1513                                        env()->Object_klass(),
1514                                        offset);
1515     }
1516 
1517     if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1518       ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1519       if (!k || !k->is_loaded()) {                  // Only fails for some -Xcomp runs
1520         tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), offset);
1521       } else {
1522         tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, offset);
1523       }
1524     }
1525 
1526     // Check for precise loads from the primary supertype array and force them
1527     // to the supertype cache alias index.  Check for generic array loads from
1528     // the primary supertype array and also force them to the supertype cache
1529     // alias index.  Since the same load can reach both, we need to merge
1530     // these 2 disparate memories into the same alias class.  Since the
1531     // primary supertype array is read-only, there's no chance of confusion
1532     // where we bypass an array load and an array store.
1533     int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1534     if (offset == Type::OffsetBot ||
1535         (offset >= primary_supers_offset &&
1536          offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1537         offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1538       offset = in_bytes(Klass::secondary_super_cache_offset());
1539       tj = tk = tk->with_offset(offset);
1540     }
1541   }
1542 
1543   // Flatten all Raw pointers together.
1544   if (tj->base() == Type::RawPtr)
1545     tj = TypeRawPtr::BOTTOM;

1635   intptr_t key = (intptr_t) adr_type;
1636   key ^= key >> logAliasCacheSize;
1637   return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1638 }
1639 
1640 
1641 //-----------------------------grow_alias_types--------------------------------
1642 void Compile::grow_alias_types() {
1643   const int old_ats  = _max_alias_types; // how many before?
1644   const int new_ats  = old_ats;          // how many more?
1645   const int grow_ats = old_ats+new_ats;  // how many now?
1646   _max_alias_types = grow_ats;
1647   _alias_types =  REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1648   AliasType* ats =    NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1649   Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1650   for (int i = 0; i < new_ats; i++)  _alias_types[old_ats+i] = &ats[i];
1651 }
1652 
1653 
1654 //--------------------------------find_alias_type------------------------------
1655 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
1656   if (!do_aliasing()) {
1657     return alias_type(AliasIdxBot);
1658   }
1659 
1660   AliasCacheEntry* ace = probe_alias_cache(adr_type);
1661   if (ace->_adr_type == adr_type) {
1662     return alias_type(ace->_index);



1663   }
1664 
1665   // Handle special cases.
1666   if (adr_type == nullptr)          return alias_type(AliasIdxTop);
1667   if (adr_type == TypePtr::BOTTOM)  return alias_type(AliasIdxBot);
1668 
1669   // Do it the slow way.
1670   const TypePtr* flat = flatten_alias_type(adr_type);
1671 
1672 #ifdef ASSERT
1673   {
1674     ResourceMark rm;
1675     assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",
1676            Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));
1677     assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",
1678            Type::str(adr_type));
1679     if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1680       const TypeOopPtr* foop = flat->is_oopptr();
1681       // Scalarizable allocations have exact klass always.
1682       bool exact = !foop->klass_is_exact() || foop->is_known_instance();

1692     if (alias_type(i)->adr_type() == flat) {
1693       idx = i;
1694       break;
1695     }
1696   }
1697 
1698   if (idx == AliasIdxTop) {
1699     if (no_create)  return nullptr;
1700     // Grow the array if necessary.
1701     if (_num_alias_types == _max_alias_types)  grow_alias_types();
1702     // Add a new alias type.
1703     idx = _num_alias_types++;
1704     _alias_types[idx]->Init(idx, flat);
1705     if (flat == TypeInstPtr::KLASS)  alias_type(idx)->set_rewritable(false);
1706     if (flat == TypeAryPtr::RANGE)   alias_type(idx)->set_rewritable(false);
1707     if (flat->isa_instptr()) {
1708       if (flat->offset() == java_lang_Class::klass_offset()
1709           && flat->is_instptr()->instance_klass() == env()->Class_klass())
1710         alias_type(idx)->set_rewritable(false);
1711     }

1712     if (flat->isa_aryptr()) {
1713 #ifdef ASSERT
1714       const int header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1715       // (T_BYTE has the weakest alignment and size restrictions...)
1716       assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1717 #endif

1718       if (flat->offset() == TypePtr::OffsetBot) {
1719         alias_type(idx)->set_element(flat->is_aryptr()->elem());







1720       }
1721     }
1722     if (flat->isa_klassptr()) {
1723       if (UseCompactObjectHeaders) {
1724         if (flat->offset() == in_bytes(Klass::prototype_header_offset()))
1725           alias_type(idx)->set_rewritable(false);
1726       }
1727       if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1728         alias_type(idx)->set_rewritable(false);
1729       if (flat->offset() == in_bytes(Klass::access_flags_offset()))
1730         alias_type(idx)->set_rewritable(false);
1731       if (flat->offset() == in_bytes(Klass::misc_flags_offset()))
1732         alias_type(idx)->set_rewritable(false);
1733       if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1734         alias_type(idx)->set_rewritable(false);


1735       if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1736         alias_type(idx)->set_rewritable(false);
1737     }
1738     // %%% (We would like to finalize JavaThread::threadObj_offset(),
1739     // but the base pointer type is not distinctive enough to identify
1740     // references into JavaThread.)
1741 
1742     // Check for final fields.
1743     const TypeInstPtr* tinst = flat->isa_instptr();
1744     if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1745       ciField* field;
1746       if (tinst->const_oop() != nullptr &&
1747           tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1748           tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1749         // static field
1750         ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1751         field = k->get_field_by_offset(tinst->offset(), true);




1752       } else {
1753         ciInstanceKlass *k = tinst->instance_klass();
1754         field = k->get_field_by_offset(tinst->offset(), false);
1755       }
1756       assert(field == nullptr ||
1757              original_field == nullptr ||
1758              (field->holder() == original_field->holder() &&
1759               field->offset_in_bytes() == original_field->offset_in_bytes() &&
1760               field->is_static() == original_field->is_static()), "wrong field?");
1761       // Set field() and is_rewritable() attributes.
1762       if (field != nullptr)  alias_type(idx)->set_field(field);







1763     }
1764   }
1765 
1766   // Fill the cache for next time.
1767   ace->_adr_type = adr_type;
1768   ace->_index    = idx;
1769   assert(alias_type(adr_type) == alias_type(idx),  "type must be installed");

1770 
1771   // Might as well try to fill the cache for the flattened version, too.
1772   AliasCacheEntry* face = probe_alias_cache(flat);
1773   if (face->_adr_type == nullptr) {
1774     face->_adr_type = flat;
1775     face->_index    = idx;
1776     assert(alias_type(flat) == alias_type(idx), "flat type must work too");

1777   }
1778 
1779   return alias_type(idx);
1780 }
1781 
1782 
1783 Compile::AliasType* Compile::alias_type(ciField* field) {
1784   const TypeOopPtr* t;
1785   if (field->is_static())
1786     t = TypeInstPtr::make(field->holder()->java_mirror());
1787   else
1788     t = TypeOopPtr::make_from_klass_raw(field->holder());
1789   AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1790   assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1791   return atp;
1792 }
1793 
1794 
1795 //------------------------------have_alias_type--------------------------------
1796 bool Compile::have_alias_type(const TypePtr* adr_type) {

1878   assert(!C->major_progress(), "not cleared");
1879 
1880   if (_for_post_loop_igvn.length() > 0) {
1881     while (_for_post_loop_igvn.length() > 0) {
1882       Node* n = _for_post_loop_igvn.pop();
1883       n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1884       igvn._worklist.push(n);
1885     }
1886     igvn.optimize();
1887     if (failing()) return;
1888     assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1889     assert(C->parse_predicate_count() == 0, "all parse predicates should have been removed now");
1890 
1891     // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1892     if (C->major_progress()) {
1893       C->clear_major_progress(); // ensure that major progress is now clear
1894     }
1895   }
1896 }
1897 










































































































































































































































































































































































































































1898 void Compile::record_for_merge_stores_igvn(Node* n) {
1899   if (!n->for_merge_stores_igvn()) {
1900     assert(!_for_merge_stores_igvn.contains(n), "duplicate");
1901     n->add_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
1902     _for_merge_stores_igvn.append(n);
1903   }
1904 }
1905 
1906 void Compile::remove_from_merge_stores_igvn(Node* n) {
1907   n->remove_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
1908   _for_merge_stores_igvn.remove(n);
1909 }
1910 
1911 // We need to wait with merging stores until RangeCheck smearing has removed the RangeChecks during
1912 // the post loops IGVN phase. If we do it earlier, then there may still be some RangeChecks between
1913 // the stores, and we merge the wrong sequence of stores.
1914 // Example:
1915 //   StoreI RangeCheck StoreI StoreI RangeCheck StoreI
1916 // Apply MergeStores:
1917 //   StoreI RangeCheck [   StoreL  ] RangeCheck StoreI

1996       assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
1997       Bytecodes::Code c = iter.cur_bc();
1998       Node* lhs = nullptr;
1999       Node* rhs = nullptr;
2000       if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
2001         lhs = unc->peek_operand(0);
2002         rhs = unc->peek_operand(1);
2003       } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
2004         lhs = unc->peek_operand(0);
2005       }
2006 
2007       ResourceMark rm;
2008       const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
2009       assert(live_locals.is_valid(), "broken liveness info");
2010       int len = (int)live_locals.size();
2011 
2012       for (int i = 0; i < len; i++) {
2013         Node* local = unc->local(jvms, i);
2014         // kill local using the liveness of next_bci.
2015         // give up when the local looks like an operand to secure reexecution.
2016         if (!live_locals.at(i) && !local->is_top() && local != lhs && local!= rhs) {
2017           uint idx = jvms->locoff() + i;
2018 #ifdef ASSERT
2019           if (PrintOpto && Verbose) {
2020             tty->print("[unstable_if] kill local#%d: ", idx);
2021             local->dump();
2022             tty->cr();
2023           }
2024 #endif
2025           igvn.replace_input_of(unc, idx, top());
2026           modified = true;
2027         }
2028       }
2029     }
2030 
2031     // keep the mondified trap for late query
2032     if (modified) {
2033       trap->set_modified();
2034     } else {
2035       _unstable_if_traps.delete_at(i);
2036     }
2037   }
2038   igvn.optimize();
2039 }
2040 
2041 // StringOpts and late inlining of string methods
2042 void Compile::inline_string_calls(bool parse_time) {
2043   {
2044     // remove useless nodes to make the usage analysis simpler
2045     ResourceMark rm;
2046     PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
2047   }
2048 
2049   {
2050     ResourceMark rm;
2051     print_method(PHASE_BEFORE_STRINGOPTS, 3);

2223 
2224   if (_string_late_inlines.length() > 0) {
2225     assert(has_stringbuilder(), "inconsistent");
2226 
2227     inline_string_calls(false);
2228 
2229     if (failing())  return;
2230 
2231     inline_incrementally_cleanup(igvn);
2232   }
2233 
2234   set_inlining_incrementally(false);
2235 }
2236 
2237 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2238   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2239   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2240   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2241   // as if "inlining_incrementally() == true" were set.
2242   assert(inlining_incrementally() == false, "not allowed");
2243   assert(_modified_nodes == nullptr, "not allowed");



2244   assert(_late_inlines.length() > 0, "sanity");
2245 
2246   while (_late_inlines.length() > 0) {
2247     igvn_worklist()->ensure_empty(); // should be done with igvn
2248 
2249     while (inline_incrementally_one()) {
2250       assert(!failing_internal() || failure_is_artificial(), "inconsistent");
2251     }
2252     if (failing())  return;
2253 
2254     inline_incrementally_cleanup(igvn);
2255   }

2256 }
2257 
2258 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2259   if (_loop_opts_cnt > 0) {
2260     while (major_progress() && (_loop_opts_cnt > 0)) {
2261       TracePhase tp(_t_idealLoop);
2262       PhaseIdealLoop::optimize(igvn, mode);
2263       _loop_opts_cnt--;
2264       if (failing())  return false;
2265       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2266     }
2267   }
2268   return true;
2269 }
2270 
2271 // Remove edges from "root" to each SafePoint at a backward branch.
2272 // They were inserted during parsing (see add_safepoint()) to make
2273 // infinite loops without calls or exceptions visible to root, i.e.,
2274 // useful.
2275 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2379     print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2380   }
2381   assert(!has_vbox_nodes(), "sanity");
2382 
2383   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2384     Compile::TracePhase tp(_t_renumberLive);
2385     igvn_worklist()->ensure_empty(); // should be done with igvn
2386     {
2387       ResourceMark rm;
2388       PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2389     }
2390     igvn.reset();
2391     igvn.optimize();
2392     if (failing()) return;
2393   }
2394 
2395   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2396   // safepoints
2397   remove_root_to_sfpts_edges(igvn);
2398 





2399   if (failing())  return;
2400 











2401   if (has_loops()) {
2402     print_method(PHASE_BEFORE_LOOP_OPTS, 2);
2403   }
2404 
2405   // Perform escape analysis
2406   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2407     if (has_loops()) {
2408       // Cleanup graph (remove dead nodes).
2409       TracePhase tp(_t_idealLoop);
2410       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2411       if (failing())  return;













2412     }

2413     bool progress;
2414     print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2415     do {
2416       ConnectionGraph::do_analysis(this, &igvn);
2417 
2418       if (failing())  return;
2419 
2420       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2421 
2422       // Optimize out fields loads from scalar replaceable allocations.
2423       igvn.optimize();
2424       print_method(PHASE_ITER_GVN_AFTER_EA, 2);
2425 
2426       if (failing()) return;
2427 
2428       if (congraph() != nullptr && macro_count() > 0) {
2429         TracePhase tp(_t_macroEliminate);
2430         PhaseMacroExpand mexp(igvn);
2431         mexp.eliminate_macro_nodes();
2432         if (failing()) return;


2433         print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
2434 
2435         igvn.set_delay_transform(false);
2436         igvn.optimize();
2437         if (failing()) return;
2438 
2439         print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2440       }
2441 
2442       ConnectionGraph::verify_ram_nodes(this, root());
2443       if (failing())  return;
2444 
2445       progress = do_iterative_escape_analysis() &&
2446                  (macro_count() < mcount) &&
2447                  ConnectionGraph::has_candidates(this);
2448       // Try again if candidates exist and made progress
2449       // by removing some allocations and/or locks.
2450     } while (progress);
2451   }
2452 





2453   // Loop transforms on the ideal graph.  Range Check Elimination,
2454   // peeling, unrolling, etc.
2455 
2456   // Set loop opts counter
2457   if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2458     {
2459       TracePhase tp(_t_idealLoop);
2460       PhaseIdealLoop::optimize(igvn, LoopOptsDefault);
2461       _loop_opts_cnt--;
2462       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
2463       if (failing())  return;
2464     }
2465     // Loop opts pass if partial peeling occurred in previous pass
2466     if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
2467       TracePhase tp(_t_idealLoop);
2468       PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
2469       _loop_opts_cnt--;
2470       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
2471       if (failing())  return;
2472     }

2509   // Loop transforms on the ideal graph.  Range Check Elimination,
2510   // peeling, unrolling, etc.
2511   if (!optimize_loops(igvn, LoopOptsDefault)) {
2512     return;
2513   }
2514 
2515   if (failing())  return;
2516 
2517   C->clear_major_progress(); // ensure that major progress is now clear
2518 
2519   process_for_post_loop_opts_igvn(igvn);
2520 
2521   process_for_merge_stores_igvn(igvn);
2522 
2523   if (failing())  return;
2524 
2525 #ifdef ASSERT
2526   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2527 #endif
2528 








2529   {
2530     TracePhase tp(_t_macroExpand);







2531     print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);
2532     PhaseMacroExpand  mex(igvn);
2533     // Do not allow new macro nodes once we start to eliminate and expand
2534     C->reset_allow_macro_nodes();
2535     // Last attempt to eliminate macro nodes before expand
2536     mex.eliminate_macro_nodes();
2537     if (failing()) {
2538       return;
2539     }
2540     mex.eliminate_opaque_looplimit_macro_nodes();
2541     if (failing()) {
2542       return;
2543     }
2544     print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
2545     if (mex.expand_macro_nodes()) {
2546       assert(failing(), "must bail out w/ explicit message");
2547       return;
2548     }
2549     print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
2550   }
2551 




2552   {
2553     TracePhase tp(_t_barrierExpand);
2554     if (bs->expand_barriers(this, igvn)) {
2555       assert(failing(), "must bail out w/ explicit message");
2556       return;
2557     }
2558     print_method(PHASE_BARRIER_EXPANSION, 2);
2559   }
2560 
2561   if (C->max_vector_size() > 0) {
2562     C->optimize_logic_cones(igvn);
2563     igvn.optimize();
2564     if (failing()) return;
2565   }
2566 
2567   DEBUG_ONLY( _modified_nodes = nullptr; )

2568 
2569   assert(igvn._worklist.size() == 0, "not empty");
2570 
2571   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2572 
2573   if (_late_inlines.length() > 0) {
2574     // More opportunities to optimize virtual and MH calls.
2575     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2576     process_late_inline_calls_no_inline(igvn);
2577     if (failing())  return;
2578   }
2579  } // (End scope of igvn; run destructor if necessary for asserts.)
2580 
2581  check_no_dead_use();
2582 
2583  // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
2584  // to remove hashes to unlock nodes for modifications.
2585  C->node_hash()->clear();
2586 
2587  // A method with only infinite loops has no edges entering loops from root
2588  {
2589    TracePhase tp(_t_graphReshaping);
2590    if (final_graph_reshaping()) {
2591      assert(failing(), "must bail out w/ explicit message");
2592      return;
2593    }
2594  }
2595 
2596  print_method(PHASE_OPTIMIZE_FINISHED, 2);
2597  DEBUG_ONLY(set_phase_optimize_finished();)
2598 }

3304   case Op_CmpD3:
3305   case Op_StoreD:
3306   case Op_LoadD:
3307   case Op_LoadD_unaligned:
3308     frc.inc_double_count();
3309     break;
3310   case Op_Opaque1:              // Remove Opaque Nodes before matching
3311     n->subsume_by(n->in(1), this);
3312     break;
3313   case Op_CallLeafPure: {
3314     // If the pure call is not supported, then lower to a CallLeaf.
3315     if (!Matcher::match_rule_supported(Op_CallLeafPure)) {
3316       CallNode* call = n->as_Call();
3317       CallNode* new_call = new CallLeafNode(call->tf(), call->entry_point(),
3318                                             call->_name, TypeRawPtr::BOTTOM);
3319       new_call->init_req(TypeFunc::Control, call->in(TypeFunc::Control));
3320       new_call->init_req(TypeFunc::I_O, C->top());
3321       new_call->init_req(TypeFunc::Memory, C->top());
3322       new_call->init_req(TypeFunc::ReturnAdr, C->top());
3323       new_call->init_req(TypeFunc::FramePtr, C->top());
3324       for (unsigned int i = TypeFunc::Parms; i < call->tf()->domain()->cnt(); i++) {
3325         new_call->init_req(i, call->in(i));
3326       }
3327       n->subsume_by(new_call, this);
3328     }
3329     frc.inc_call_count();
3330     break;
3331   }
3332   case Op_CallStaticJava:
3333   case Op_CallJava:
3334   case Op_CallDynamicJava:
3335     frc.inc_java_call_count(); // Count java call site;
3336   case Op_CallRuntime:
3337   case Op_CallLeaf:
3338   case Op_CallLeafVector:
3339   case Op_CallLeafNoFP: {
3340     assert (n->is_Call(), "");
3341     CallNode *call = n->as_Call();
3342     // Count call sites where the FP mode bit would have to be flipped.
3343     // Do not count uncommon runtime calls:
3344     // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,

3350       int nop = n->Opcode();
3351       // Clone shared simple arguments to uncommon calls, item (1).
3352       if (n->outcnt() > 1 &&
3353           !n->is_Proj() &&
3354           nop != Op_CreateEx &&
3355           nop != Op_CheckCastPP &&
3356           nop != Op_DecodeN &&
3357           nop != Op_DecodeNKlass &&
3358           !n->is_Mem() &&
3359           !n->is_Phi()) {
3360         Node *x = n->clone();
3361         call->set_req(TypeFunc::Parms, x);
3362       }
3363     }
3364     break;
3365   }
3366   case Op_StoreB:
3367   case Op_StoreC:
3368   case Op_StoreI:
3369   case Op_StoreL:

3370   case Op_CompareAndSwapB:
3371   case Op_CompareAndSwapS:
3372   case Op_CompareAndSwapI:
3373   case Op_CompareAndSwapL:
3374   case Op_CompareAndSwapP:
3375   case Op_CompareAndSwapN:
3376   case Op_WeakCompareAndSwapB:
3377   case Op_WeakCompareAndSwapS:
3378   case Op_WeakCompareAndSwapI:
3379   case Op_WeakCompareAndSwapL:
3380   case Op_WeakCompareAndSwapP:
3381   case Op_WeakCompareAndSwapN:
3382   case Op_CompareAndExchangeB:
3383   case Op_CompareAndExchangeS:
3384   case Op_CompareAndExchangeI:
3385   case Op_CompareAndExchangeL:
3386   case Op_CompareAndExchangeP:
3387   case Op_CompareAndExchangeN:
3388   case Op_GetAndAddS:
3389   case Op_GetAndAddB:

3902           k->subsume_by(m, this);
3903         }
3904       }
3905     }
3906     break;
3907   }
3908   case Op_CmpUL: {
3909     if (!Matcher::has_match_rule(Op_CmpUL)) {
3910       // No support for unsigned long comparisons
3911       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
3912       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
3913       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
3914       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
3915       Node* andl = new AndLNode(orl, remove_sign_mask);
3916       Node* cmp = new CmpLNode(andl, n->in(2));
3917       n->subsume_by(cmp, this);
3918     }
3919     break;
3920   }
3921 #ifdef ASSERT





3922   case Op_ConNKlass: {
3923     const TypePtr* tp = n->as_Type()->type()->make_ptr();
3924     ciKlass* klass = tp->is_klassptr()->exact_klass();
3925     assert(klass->is_in_encoding_range(), "klass cannot be compressed");
3926     break;
3927   }
3928 #endif
3929   default:
3930     assert(!n->is_Call(), "");
3931     assert(!n->is_Mem(), "");
3932     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
3933     break;
3934   }
3935 }
3936 
3937 //------------------------------final_graph_reshaping_walk---------------------
3938 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3939 // requires that the walk visits a node's inputs before visiting the node.
3940 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
3941   Unique_Node_List sfpt;

4277   }
4278 }
4279 
4280 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4281   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4282 }
4283 
4284 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4285   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4286 }
4287 
4288 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4289   if (holder->is_initialized()) {
4290     return false;
4291   }
4292   if (holder->is_being_initialized()) {
4293     if (accessing_method->holder() == holder) {
4294       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4295       // <init>, or a static method. In all those cases, there was an initialization
4296       // barrier on the holder klass passed.
4297       if (accessing_method->is_static_initializer() ||
4298           accessing_method->is_object_initializer() ||
4299           accessing_method->is_static()) {
4300         return false;
4301       }
4302     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4303       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4304       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4305       // child class can become fully initialized while its parent class is still being initialized.
4306       if (accessing_method->is_static_initializer()) {
4307         return false;
4308       }
4309     }
4310     ciMethod* root = method(); // the root method of compilation
4311     if (root != accessing_method) {
4312       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4313     }
4314   }
4315   return true;
4316 }
4317 
4318 #ifndef PRODUCT
4319 //------------------------------verify_bidirectional_edges---------------------
4320 // For each input edge to a node (ie - for each Use-Def edge), verify that
4321 // there is a corresponding Def-Use edge.
4322 void Compile::verify_bidirectional_edges(Unique_Node_List& visited, const Unique_Node_List* root_and_safepoints) const {
4323   // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4324   uint stack_size = live_nodes() >> 4;
4325   Node_List nstack(MAX2(stack_size, (uint) OptoNodeListSize));
4326   if (root_and_safepoints != nullptr) {

4356       if (in != nullptr && !in->is_top()) {
4357         // Count instances of `next`
4358         int cnt = 0;
4359         for (uint idx = 0; idx < in->_outcnt; idx++) {
4360           if (in->_out[idx] == n) {
4361             cnt++;
4362           }
4363         }
4364         assert(cnt > 0, "Failed to find Def-Use edge.");
4365         // Check for duplicate edges
4366         // walk the input array downcounting the input edges to n
4367         for (uint j = 0; j < length; j++) {
4368           if (n->in(j) == in) {
4369             cnt--;
4370           }
4371         }
4372         assert(cnt == 0, "Mismatched edge count.");
4373       } else if (in == nullptr) {
4374         assert(i == 0 || i >= n->req() ||
4375                n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||

4376                (n->is_Unlock() && i == (n->req() - 1)) ||
4377                (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4378               "only region, phi, arraycopy, unlock or membar nodes have null data edges");
4379       } else {
4380         assert(in->is_top(), "sanity");
4381         // Nothing to check.
4382       }
4383     }
4384   }
4385 }
4386 
4387 //------------------------------verify_graph_edges---------------------------
4388 // Walk the Graph and verify that there is a one-to-one correspondence
4389 // between Use-Def edges and Def-Use edges in the graph.
4390 void Compile::verify_graph_edges(bool no_dead_code, const Unique_Node_List* root_and_safepoints) const {
4391   if (VerifyGraphEdges) {
4392     Unique_Node_List visited;
4393 
4394     // Call graph walk to check edges
4395     verify_bidirectional_edges(visited, root_and_safepoints);
4396     if (no_dead_code) {
4397       // Now make sure that no visited node is used by an unvisited node.
4398       bool dead_nodes = false;

4509 // (1) subklass is already limited to a subtype of superklass => always ok
4510 // (2) subklass does not overlap with superklass => always fail
4511 // (3) superklass has NO subtypes and we can check with a simple compare.
4512 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
4513   if (skip) {
4514     return SSC_full_test;       // Let caller generate the general case.
4515   }
4516 
4517   if (subk->is_java_subtype_of(superk)) {
4518     return SSC_always_true; // (0) and (1)  this test cannot fail
4519   }
4520 
4521   if (!subk->maybe_java_subtype_of(superk)) {
4522     return SSC_always_false; // (2) true path dead; no dynamic test needed
4523   }
4524 
4525   const Type* superelem = superk;
4526   if (superk->isa_aryklassptr()) {
4527     int ignored;
4528     superelem = superk->is_aryklassptr()->base_element_type(ignored);







4529   }
4530 
4531   if (superelem->isa_instklassptr()) {
4532     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4533     if (!ik->has_subklass()) {
4534       if (!ik->is_final()) {
4535         // Add a dependency if there is a chance of a later subclass.
4536         dependencies()->assert_leaf_type(ik);
4537       }
4538       if (!superk->maybe_java_subtype_of(subk)) {
4539         return SSC_always_false;
4540       }
4541       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
4542     }
4543   } else {
4544     // A primitive array type has no subtypes.
4545     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
4546   }
4547 
4548   return SSC_full_test;

4992       const Type* t = igvn.type_or_null(n);
4993       assert((t == nullptr) || (t == t->remove_speculative()), "no more speculative types");
4994       if (n->is_Type()) {
4995         t = n->as_Type()->type();
4996         assert(t == t->remove_speculative(), "no more speculative types");
4997       }
4998       // Iterate over outs - endless loops is unreachable from below
4999       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
5000         Node *m = n->fast_out(i);
5001         if (not_a_node(m)) {
5002           continue;
5003         }
5004         worklist.push(m);
5005       }
5006     }
5007     igvn.check_no_speculative_types();
5008 #endif
5009   }
5010 }
5011 





















5012 // Auxiliary methods to support randomized stressing/fuzzing.
5013 
5014 void Compile::initialize_stress_seed(const DirectiveSet* directive) {
5015   if (FLAG_IS_DEFAULT(StressSeed) || (FLAG_IS_ERGO(StressSeed) && directive->RepeatCompilationOption)) {
5016     _stress_seed = static_cast<uint>(Ticks::now().nanoseconds());
5017     FLAG_SET_ERGO(StressSeed, _stress_seed);
5018   } else {
5019     _stress_seed = StressSeed;
5020   }
5021   if (_log != nullptr) {
5022     _log->elem("stress_test seed='%u'", _stress_seed);
5023   }
5024 }
5025 
5026 int Compile::random() {
5027   _stress_seed = os::next_random(_stress_seed);
5028   return static_cast<int>(_stress_seed);
5029 }
5030 
5031 // This method can be called the arbitrary number of times, with current count

5347   } else {
5348     _debug_network_printer->update_compiled_method(C->method());
5349   }
5350   tty->print_cr("Method printed over network stream to IGV");
5351   _debug_network_printer->print(name, C->root(), visible_nodes, fr);
5352 }
5353 #endif // !PRODUCT
5354 
5355 Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {
5356   if (type != nullptr && phase->type(value)->higher_equal(type)) {
5357     return value;
5358   }
5359   Node* result = nullptr;
5360   if (bt == T_BYTE) {
5361     result = phase->transform(new LShiftINode(value, phase->intcon(24)));
5362     result = new RShiftINode(result, phase->intcon(24));
5363   } else if (bt == T_BOOLEAN) {
5364     result = new AndINode(value, phase->intcon(0xFF));
5365   } else if (bt == T_CHAR) {
5366     result = new AndINode(value,phase->intcon(0xFFFF));


5367   } else {
5368     assert(bt == T_SHORT, "unexpected narrow type");
5369     result = phase->transform(new LShiftINode(value, phase->intcon(16)));
5370     result = new RShiftINode(result, phase->intcon(16));
5371   }
5372   if (transform_res) {
5373     result = phase->transform(result);
5374   }
5375   return result;
5376 }
5377 
5378 void Compile::record_method_not_compilable_oom() {
5379   record_method_not_compilable(CompilationMemoryStatistic::failure_reason_memlimit());
5380 }
5381 
5382 #ifndef PRODUCT
5383 // Collects all the control inputs from nodes on the worklist and from their data dependencies
5384 static void find_candidate_control_inputs(Unique_Node_List& worklist, Unique_Node_List& candidates) {
5385   // Follow non-control edges until we reach CFG nodes
5386   for (uint i = 0; i < worklist.size(); i++) {

  42 #include "gc/shared/c2/barrierSetC2.hpp"
  43 #include "jfr/jfrEvents.hpp"
  44 #include "jvm_io.h"
  45 #include "memory/allocation.hpp"
  46 #include "memory/arena.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "opto/addnode.hpp"
  49 #include "opto/block.hpp"
  50 #include "opto/c2compiler.hpp"
  51 #include "opto/callGenerator.hpp"
  52 #include "opto/callnode.hpp"
  53 #include "opto/castnode.hpp"
  54 #include "opto/cfgnode.hpp"
  55 #include "opto/chaitin.hpp"
  56 #include "opto/compile.hpp"
  57 #include "opto/connode.hpp"
  58 #include "opto/convertnode.hpp"
  59 #include "opto/divnode.hpp"
  60 #include "opto/escape.hpp"
  61 #include "opto/idealGraphPrinter.hpp"
  62 #include "opto/inlinetypenode.hpp"
  63 #include "opto/locknode.hpp"
  64 #include "opto/loopnode.hpp"
  65 #include "opto/machnode.hpp"
  66 #include "opto/macro.hpp"
  67 #include "opto/matcher.hpp"
  68 #include "opto/mathexactnode.hpp"
  69 #include "opto/memnode.hpp"
  70 #include "opto/movenode.hpp"
  71 #include "opto/mulnode.hpp"
  72 #include "opto/narrowptrnode.hpp"
  73 #include "opto/node.hpp"
  74 #include "opto/opaquenode.hpp"
  75 #include "opto/opcodes.hpp"
  76 #include "opto/output.hpp"
  77 #include "opto/parse.hpp"
  78 #include "opto/phaseX.hpp"
  79 #include "opto/rootnode.hpp"
  80 #include "opto/runtime.hpp"
  81 #include "opto/stringopts.hpp"
  82 #include "opto/type.hpp"
  83 #include "opto/vector.hpp"
  84 #include "opto/vectornode.hpp"
  85 #include "runtime/globals_extension.hpp"
  86 #include "runtime/sharedRuntime.hpp"
  87 #include "runtime/signature.hpp"
  88 #include "runtime/stubRoutines.hpp"
  89 #include "runtime/timer.hpp"
  90 #include "utilities/align.hpp"

 390   // as dead to be conservative about the dead node count at any
 391   // given time.
 392   if (!dead->is_Con()) {
 393     record_dead_node(dead->_idx);
 394   }
 395   if (dead->is_macro()) {
 396     remove_macro_node(dead);
 397   }
 398   if (dead->is_expensive()) {
 399     remove_expensive_node(dead);
 400   }
 401   if (dead->is_OpaqueTemplateAssertionPredicate()) {
 402     remove_template_assertion_predicate_opaque(dead->as_OpaqueTemplateAssertionPredicate());
 403   }
 404   if (dead->is_ParsePredicate()) {
 405     remove_parse_predicate(dead->as_ParsePredicate());
 406   }
 407   if (dead->for_post_loop_opts_igvn()) {
 408     remove_from_post_loop_opts_igvn(dead);
 409   }
 410   if (dead->is_InlineType()) {
 411     remove_inline_type(dead);
 412   }
 413   if (dead->is_LoadFlat() || dead->is_StoreFlat()) {
 414     remove_flat_access(dead);
 415   }
 416   if (dead->for_merge_stores_igvn()) {
 417     remove_from_merge_stores_igvn(dead);
 418   }
 419   if (dead->is_Call()) {
 420     remove_useless_late_inlines(                &_late_inlines, dead);
 421     remove_useless_late_inlines(         &_string_late_inlines, dead);
 422     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 423     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 424 
 425     if (dead->is_CallStaticJava()) {
 426       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 427     }
 428   }
 429   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 430   bs->unregister_potential_barrier_node(dead);
 431 }
 432 
 433 // Disconnect all useless nodes by disconnecting those at the boundary.
 434 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist, const Unique_Node_List* root_and_safepoints) {
 435   uint next = 0;

 443     // Use raw traversal of out edges since this code removes out edges
 444     int max = n->outcnt();
 445     for (int j = 0; j < max; ++j) {
 446       Node* child = n->raw_out(j);
 447       if (!useful.member(child)) {
 448         assert(!child->is_top() || child != top(),
 449                "If top is cached in Compile object it is in useful list");
 450         // Only need to remove this out-edge to the useless node
 451         n->raw_del_out(j);
 452         --j;
 453         --max;
 454         if (child->is_data_proj_of_pure_function(n)) {
 455           worklist.push(n);
 456         }
 457       }
 458     }
 459     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 460       assert(useful.member(n->unique_out()), "do not push a useless node");
 461       worklist.push(n->unique_out());
 462     }
 463     if (n->outcnt() == 0) {
 464       worklist.push(n);
 465     }
 466   }
 467 
 468   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 469   remove_useless_nodes(_parse_predicates,   useful); // remove useless Parse Predicate nodes
 470   // Remove useless Template Assertion Predicate opaque nodes
 471   remove_useless_nodes(_template_assertion_predicate_opaques, useful);
 472   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 473   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
 474   remove_useless_nodes(_inline_type_nodes,  useful); // remove useless inline type nodes
 475   remove_useless_nodes(_flat_access_nodes, useful);  // remove useless flat access nodes
 476 #ifdef ASSERT
 477   if (_modified_nodes != nullptr) {
 478     _modified_nodes->remove_useless_nodes(useful.member_set());
 479   }
 480 #endif
 481   remove_useless_nodes(_for_merge_stores_igvn, useful); // remove useless node recorded for merge stores IGVN pass
 482   remove_useless_unstable_if_traps(useful);          // remove useless unstable_if traps
 483   remove_useless_coarsened_locks(useful);            // remove useless coarsened locks nodes
 484 #ifdef ASSERT
 485   if (_modified_nodes != nullptr) {
 486     _modified_nodes->remove_useless_nodes(useful.member_set());
 487   }
 488 #endif
 489 
 490   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 491   bs->eliminate_useless_gc_barriers(useful, this);
 492   // clean up the late inline lists
 493   remove_useless_late_inlines(                &_late_inlines, useful);
 494   remove_useless_late_inlines(         &_string_late_inlines, useful);
 495   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
 496   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 497   DEBUG_ONLY(verify_graph_edges(true /*check for no_dead_code*/, root_and_safepoints);)
 498 }
 499 
 500 // ============================================================================

 647 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
 648                  Options options, DirectiveSet* directive)
 649     : Phase(Compiler),
 650       _compile_id(ci_env->compile_id()),
 651       _options(options),
 652       _method(target),
 653       _entry_bci(osr_bci),
 654       _ilt(nullptr),
 655       _stub_function(nullptr),
 656       _stub_name(nullptr),
 657       _stub_id(StubId::NO_STUBID),
 658       _stub_entry_point(nullptr),
 659       _max_node_limit(MaxNodeLimit),
 660       _post_loop_opts_phase(false),
 661       _merge_stores_phase(false),
 662       _allow_macro_nodes(true),
 663       _inlining_progress(false),
 664       _inlining_incrementally(false),
 665       _do_cleanup(false),
 666       _has_reserved_stack_access(target->has_reserved_stack_access()),
 667       _has_circular_inline_type(false),
 668 #ifndef PRODUCT
 669       _igv_idx(0),
 670       _trace_opto_output(directive->TraceOptoOutputOption),
 671 #endif
 672       _clinit_barrier_on_entry(false),
 673       _stress_seed(0),
 674       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 675       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 676       _env(ci_env),
 677       _directive(directive),
 678       _log(ci_env->log()),
 679       _first_failure_details(nullptr),
 680       _intrinsics(comp_arena(), 0, 0, nullptr),
 681       _macro_nodes(comp_arena(), 8, 0, nullptr),
 682       _parse_predicates(comp_arena(), 8, 0, nullptr),
 683       _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
 684       _expensive_nodes(comp_arena(), 8, 0, nullptr),
 685       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 686       _inline_type_nodes (comp_arena(), 8, 0, nullptr),
 687       _flat_access_nodes(comp_arena(), 8, 0, nullptr),
 688       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 689       _unstable_if_traps(comp_arena(), 8, 0, nullptr),
 690       _coarsened_locks(comp_arena(), 8, 0, nullptr),
 691       _congraph(nullptr),
 692       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 693           _unique(0),
 694       _dead_node_count(0),
 695       _dead_node_list(comp_arena()),
 696       _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 697       _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 698       _node_arena(&_node_arena_one),
 699       _mach_constant_base_node(nullptr),
 700       _Compile_types(mtCompiler, Arena::Tag::tag_type),
 701       _initial_gvn(nullptr),
 702       _igvn_worklist(nullptr),
 703       _types(nullptr),
 704       _node_hash(nullptr),
 705       _late_inlines(comp_arena(), 2, 0, nullptr),
 706       _string_late_inlines(comp_arena(), 2, 0, nullptr),
 707       _boxing_late_inlines(comp_arena(), 2, 0, nullptr),

 776 #define MINIMUM_NODE_HASH  1023
 777 
 778   // GVN that will be run immediately on new nodes
 779   uint estimated_size = method()->code_size()*4+64;
 780   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 781   _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
 782   _types = new (comp_arena()) Type_Array(comp_arena());
 783   _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
 784   PhaseGVN gvn;
 785   set_initial_gvn(&gvn);
 786 
 787   { // Scope for timing the parser
 788     TracePhase tp(_t_parser);
 789 
 790     // Put top into the hash table ASAP.
 791     initial_gvn()->transform(top());
 792 
 793     // Set up tf(), start(), and find a CallGenerator.
 794     CallGenerator* cg = nullptr;
 795     if (is_osr_compilation()) {
 796       init_tf(TypeFunc::make(method(), /* is_osr_compilation = */ true));
 797       StartNode* s = new StartOSRNode(root(), tf()->domain_sig());


 798       initial_gvn()->set_type_bottom(s);
 799       verify_start(s);
 800       cg = CallGenerator::for_osr(method(), entry_bci());
 801     } else {
 802       // Normal case.
 803       init_tf(TypeFunc::make(method()));
 804       StartNode* s = new StartNode(root(), tf()->domain_cc());
 805       initial_gvn()->set_type_bottom(s);
 806       verify_start(s);
 807       float past_uses = method()->interpreter_invocation_count();
 808       float expected_uses = past_uses;
 809       cg = CallGenerator::for_inline(method(), expected_uses);
 810     }
 811     if (failing())  return;
 812     if (cg == nullptr) {
 813       const char* reason = InlineTree::check_can_parse(method());
 814       assert(reason != nullptr, "expect reason for parse failure");
 815       stringStream ss;
 816       ss.print("cannot parse method: %s", reason);
 817       record_method_not_compilable(ss.as_string());
 818       return;
 819     }
 820 
 821     gvn.set_type(root(), root()->bottom_type());
 822 
 823     JVMState* jvms = build_start_state(start(), tf());
 824     if ((jvms = cg->generate(jvms)) == nullptr) {

 885     print_ideal_ir("print_ideal");
 886   }
 887 #endif
 888 
 889 #ifdef ASSERT
 890   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 891   bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
 892 #endif
 893 
 894   // Dump compilation data to replay it.
 895   if (directive->DumpReplayOption) {
 896     env()->dump_replay_data(_compile_id);
 897   }
 898   if (directive->DumpInlineOption && (ilt() != nullptr)) {
 899     env()->dump_inline_data(_compile_id);
 900   }
 901 
 902   // Now that we know the size of all the monitors we can add a fixed slot
 903   // for the original deopt pc.
 904   int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);
 905   if (needs_stack_repair()) {
 906     // One extra slot for the special stack increment value
 907     next_slot += 2;
 908   }
 909   // TODO 8284443 Only reserve extra slot if needed
 910   if (InlineTypeReturnedAsFields) {
 911     // One extra slot to hold the null marker for a nullable
 912     // inline type return if we run out of registers.
 913     next_slot += 2;
 914   }
 915   set_fixed_slots(next_slot);
 916 
 917   // Compute when to use implicit null checks. Used by matching trap based
 918   // nodes and NullCheck optimization.
 919   set_allowed_deopt_reasons();
 920 
 921   // Now generate code
 922   Code_Gen();
 923 }
 924 
 925 //------------------------------Compile----------------------------------------
 926 // Compile a runtime stub
 927 Compile::Compile(ciEnv* ci_env,
 928                  TypeFunc_generator generator,
 929                  address stub_function,
 930                  const char* stub_name,
 931                  StubId stub_id,
 932                  int is_fancy_jump,
 933                  bool pass_tls,
 934                  bool return_pc,
 935                  DirectiveSet* directive)
 936     : Phase(Compiler),
 937       _compile_id(0),
 938       _options(Options::for_runtime_stub()),
 939       _method(nullptr),
 940       _entry_bci(InvocationEntryBci),
 941       _stub_function(stub_function),
 942       _stub_name(stub_name),
 943       _stub_id(stub_id),
 944       _stub_entry_point(nullptr),
 945       _max_node_limit(MaxNodeLimit),
 946       _post_loop_opts_phase(false),
 947       _merge_stores_phase(false),
 948       _allow_macro_nodes(true),
 949       _inlining_progress(false),
 950       _inlining_incrementally(false),
 951       _has_reserved_stack_access(false),
 952       _has_circular_inline_type(false),
 953 #ifndef PRODUCT
 954       _igv_idx(0),
 955       _trace_opto_output(directive->TraceOptoOutputOption),
 956 #endif
 957       _clinit_barrier_on_entry(false),
 958       _stress_seed(0),
 959       _comp_arena(mtCompiler, Arena::Tag::tag_comp),
 960       _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 961       _env(ci_env),
 962       _directive(directive),
 963       _log(ci_env->log()),
 964       _first_failure_details(nullptr),
 965       _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 966       _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
 967       _congraph(nullptr),
 968       NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 969           _unique(0),
 970       _dead_node_count(0),
 971       _dead_node_list(comp_arena()),
 972       _node_arena_one(mtCompiler, Arena::Tag::tag_node),

1087   _fixed_slots = 0;
1088   set_has_split_ifs(false);
1089   set_has_loops(false); // first approximation
1090   set_has_stringbuilder(false);
1091   set_has_boxed_value(false);
1092   _trap_can_recompile = false;  // no traps emitted yet
1093   _major_progress = true; // start out assuming good things will happen
1094   set_has_unsafe_access(false);
1095   set_max_vector_size(0);
1096   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1097   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1098   set_decompile_count(0);
1099 
1100 #ifndef PRODUCT
1101   _phase_counter = 0;
1102   Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1103 #endif
1104 
1105   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1106   _loop_opts_cnt = LoopOptsCount;
1107   _has_flat_accesses = false;
1108   _flat_accesses_share_alias = true;
1109   _scalarize_in_safepoints = false;
1110 
1111   set_do_inlining(Inline);
1112   set_max_inline_size(MaxInlineSize);
1113   set_freq_inline_size(FreqInlineSize);
1114   set_do_scheduling(OptoScheduling);
1115 
1116   set_do_vector_loop(false);
1117   set_has_monitors(false);
1118   set_has_scoped_access(false);
1119 
1120   if (AllowVectorizeOnDemand) {
1121     if (has_method() && _directive->VectorizeOption) {
1122       set_do_vector_loop(true);
1123       NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n",  method()->name()->as_quoted_ascii());})
1124     } else if (has_method() && method()->name() != nullptr &&
1125                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1126       set_do_vector_loop(true);
1127     }
1128   }
1129   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1130   NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n",  method()->name()->as_quoted_ascii());})

1375 
1376   // Known instance (scalarizable allocation) alias only with itself.
1377   bool is_known_inst = tj->isa_oopptr() != nullptr &&
1378                        tj->is_oopptr()->is_known_instance();
1379 
1380   // Process weird unsafe references.
1381   if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1382     assert(InlineUnsafeOps || StressReflectiveCode, "indeterminate pointers come only from unsafe ops");
1383     assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1384     tj = TypeOopPtr::BOTTOM;
1385     ptr = tj->ptr();
1386     offset = tj->offset();
1387   }
1388 
1389   // Array pointers need some flattening
1390   const TypeAryPtr* ta = tj->isa_aryptr();
1391   if (ta && ta->is_stable()) {
1392     // Erase stability property for alias analysis.
1393     tj = ta = ta->cast_to_stable(false);
1394   }
1395   if (ta && ta->is_not_flat()) {
1396     // Erase not flat property for alias analysis.
1397     tj = ta = ta->cast_to_not_flat(false);
1398   }
1399   if (ta && ta->is_not_null_free()) {
1400     // Erase not null free property for alias analysis.
1401     tj = ta = ta->cast_to_not_null_free(false);
1402   }
1403 
1404   if( ta && is_known_inst ) {
1405     if ( offset != Type::OffsetBot &&
1406          offset > arrayOopDesc::length_offset_in_bytes() ) {
1407       offset = Type::OffsetBot; // Flatten constant access into array body only
1408       tj = ta = ta->
1409               remove_speculative()->
1410               cast_to_ptr_type(ptr)->
1411               with_offset(offset);
1412     }
1413   } else if (ta) {
1414     // For arrays indexed by constant indices, we flatten the alias
1415     // space to include all of the array body.  Only the header, klass
1416     // and array length can be accessed un-aliased.
1417     // For flat inline type array, each field has its own slice so
1418     // we must include the field offset.
1419     if( offset != Type::OffsetBot ) {
1420       if( ta->const_oop() ) { // MethodData* or Method*
1421         offset = Type::OffsetBot;   // Flatten constant access into array body
1422         tj = ta = ta->
1423                 remove_speculative()->
1424                 cast_to_ptr_type(ptr)->
1425                 cast_to_exactness(false)->
1426                 with_offset(offset);
1427       } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1428         // range is OK as-is.
1429         tj = ta = TypeAryPtr::RANGE;
1430       } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1431         tj = TypeInstPtr::KLASS; // all klass loads look alike
1432         ta = TypeAryPtr::RANGE; // generic ignored junk
1433         ptr = TypePtr::BotPTR;
1434       } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1435         tj = TypeInstPtr::MARK;
1436         ta = TypeAryPtr::RANGE; // generic ignored junk
1437         ptr = TypePtr::BotPTR;
1438       } else {                  // Random constant offset into array body
1439         offset = Type::OffsetBot;   // Flatten constant access into array body
1440         tj = ta = ta->
1441                 remove_speculative()->
1442                 cast_to_ptr_type(ptr)->
1443                 cast_to_exactness(false)->
1444                 with_offset(offset);
1445       }
1446     }
1447     // Arrays of fixed size alias with arrays of unknown size.
1448     if (ta->size() != TypeInt::POS) {
1449       const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1450       tj = ta = ta->
1451               remove_speculative()->
1452               cast_to_ptr_type(ptr)->
1453               with_ary(tary)->
1454               cast_to_exactness(false);
1455     }
1456     // Arrays of known objects become arrays of unknown objects.
1457     if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1458       const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1459       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,Type::Offset(offset), ta->field_offset());
1460     }
1461     if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1462       const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1463       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,Type::Offset(offset), ta->field_offset());
1464     }
1465     // Initially all flattened array accesses share a single slice
1466     if (ta->is_flat() && ta->elem() != TypeInstPtr::BOTTOM && _flat_accesses_share_alias) {
1467       const TypeAry* tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size(), /* stable= */ false, /* flat= */ true);
1468       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,Type::Offset(offset), Type::Offset(Type::OffsetBot));
1469     }
1470     // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1471     // cannot be distinguished by bytecode alone.
1472     if (ta->elem() == TypeInt::BOOL) {
1473       const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1474       ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1475       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,Type::Offset(offset), ta->field_offset());
1476     }
1477     // During the 2nd round of IterGVN, NotNull castings are removed.
1478     // Make sure the Bottom and NotNull variants alias the same.
1479     // Also, make sure exact and non-exact variants alias the same.
1480     if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != nullptr) {
1481       tj = ta = ta->
1482               remove_speculative()->
1483               cast_to_ptr_type(TypePtr::BotPTR)->
1484               cast_to_exactness(false)->
1485               with_offset(offset);
1486     }
1487   }
1488 
1489   // Oop pointers need some flattening
1490   const TypeInstPtr *to = tj->isa_instptr();
1491   if (to && to != TypeOopPtr::BOTTOM) {
1492     ciInstanceKlass* ik = to->instance_klass();
1493     if( ptr == TypePtr::Constant ) {
1494       if (ik != ciEnv::current()->Class_klass() ||
1495           offset < ik->layout_helper_size_in_bytes()) {

1505     } else if( is_known_inst ) {
1506       tj = to; // Keep NotNull and klass_is_exact for instance type
1507     } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1508       // During the 2nd round of IterGVN, NotNull castings are removed.
1509       // Make sure the Bottom and NotNull variants alias the same.
1510       // Also, make sure exact and non-exact variants alias the same.
1511       tj = to = to->
1512               remove_speculative()->
1513               cast_to_instance_id(TypeOopPtr::InstanceBot)->
1514               cast_to_ptr_type(TypePtr::BotPTR)->
1515               cast_to_exactness(false);
1516     }
1517     if (to->speculative() != nullptr) {
1518       tj = to = to->remove_speculative();
1519     }
1520     // Canonicalize the holder of this field
1521     if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1522       // First handle header references such as a LoadKlassNode, even if the
1523       // object's klass is unloaded at compile time (4965979).
1524       if (!is_known_inst) { // Do it only for non-instance types
1525         tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, nullptr, Type::Offset(offset));
1526       }
1527     } else if (offset < 0 || offset >= ik->layout_helper_size_in_bytes()) {
1528       // Static fields are in the space above the normal instance
1529       // fields in the java.lang.Class instance.
1530       if (ik != ciEnv::current()->Class_klass()) {
1531         to = nullptr;
1532         tj = TypeOopPtr::BOTTOM;
1533         offset = tj->offset();
1534       }
1535     } else {
1536       ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
1537       assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1538       assert(tj->offset() == offset, "no change to offset expected");
1539       bool xk = to->klass_is_exact();
1540       int instance_id = to->instance_id();
1541 
1542       // If the input type's class is the holder: if exact, the type only includes interfaces implemented by the holder
1543       // but if not exact, it may include extra interfaces: build new type from the holder class to make sure only
1544       // its interfaces are included.
1545       if (xk && ik->equals(canonical_holder)) {
1546         assert(tj == TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, Type::Offset(offset), instance_id), "exact type should be canonical type");
1547       } else {
1548         assert(xk || !is_known_inst, "Known instance should be exact type");
1549         tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, Type::Offset(offset), instance_id);
1550       }
1551     }
1552   }
1553 
1554   // Klass pointers to object array klasses need some flattening
1555   const TypeKlassPtr *tk = tj->isa_klassptr();
1556   if( tk ) {
1557     // If we are referencing a field within a Klass, we need
1558     // to assume the worst case of an Object.  Both exact and
1559     // inexact types must flatten to the same alias class so
1560     // use NotNull as the PTR.
1561     if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1562       tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1563                                        env()->Object_klass(),
1564                                        Type::Offset(offset));
1565     }
1566 
1567     if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1568       ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1569       if (!k || !k->is_loaded()) {                  // Only fails for some -Xcomp runs
1570         tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), Type::Offset(offset));
1571       } else {
1572         tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, Type::Offset(offset), tk->is_not_flat(), tk->is_not_null_free(), tk->is_flat(), tk->is_null_free(), tk->is_atomic(), tk->is_aryklassptr()->is_refined_type());
1573       }
1574     }

1575     // Check for precise loads from the primary supertype array and force them
1576     // to the supertype cache alias index.  Check for generic array loads from
1577     // the primary supertype array and also force them to the supertype cache
1578     // alias index.  Since the same load can reach both, we need to merge
1579     // these 2 disparate memories into the same alias class.  Since the
1580     // primary supertype array is read-only, there's no chance of confusion
1581     // where we bypass an array load and an array store.
1582     int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1583     if (offset == Type::OffsetBot ||
1584         (offset >= primary_supers_offset &&
1585          offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1586         offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1587       offset = in_bytes(Klass::secondary_super_cache_offset());
1588       tj = tk = tk->with_offset(offset);
1589     }
1590   }
1591 
1592   // Flatten all Raw pointers together.
1593   if (tj->base() == Type::RawPtr)
1594     tj = TypeRawPtr::BOTTOM;

1684   intptr_t key = (intptr_t) adr_type;
1685   key ^= key >> logAliasCacheSize;
1686   return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1687 }
1688 
1689 
1690 //-----------------------------grow_alias_types--------------------------------
1691 void Compile::grow_alias_types() {
1692   const int old_ats  = _max_alias_types; // how many before?
1693   const int new_ats  = old_ats;          // how many more?
1694   const int grow_ats = old_ats+new_ats;  // how many now?
1695   _max_alias_types = grow_ats;
1696   _alias_types =  REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1697   AliasType* ats =    NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1698   Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1699   for (int i = 0; i < new_ats; i++)  _alias_types[old_ats+i] = &ats[i];
1700 }
1701 
1702 
1703 //--------------------------------find_alias_type------------------------------
1704 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field, bool uncached) {
1705   if (!do_aliasing()) {
1706     return alias_type(AliasIdxBot);
1707   }
1708 
1709   AliasCacheEntry* ace = nullptr;
1710   if (!uncached) {
1711     ace = probe_alias_cache(adr_type);
1712     if (ace->_adr_type == adr_type) {
1713       return alias_type(ace->_index);
1714     }
1715   }
1716 
1717   // Handle special cases.
1718   if (adr_type == nullptr)          return alias_type(AliasIdxTop);
1719   if (adr_type == TypePtr::BOTTOM)  return alias_type(AliasIdxBot);
1720 
1721   // Do it the slow way.
1722   const TypePtr* flat = flatten_alias_type(adr_type);
1723 
1724 #ifdef ASSERT
1725   {
1726     ResourceMark rm;
1727     assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",
1728            Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));
1729     assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",
1730            Type::str(adr_type));
1731     if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1732       const TypeOopPtr* foop = flat->is_oopptr();
1733       // Scalarizable allocations have exact klass always.
1734       bool exact = !foop->klass_is_exact() || foop->is_known_instance();

1744     if (alias_type(i)->adr_type() == flat) {
1745       idx = i;
1746       break;
1747     }
1748   }
1749 
1750   if (idx == AliasIdxTop) {
1751     if (no_create)  return nullptr;
1752     // Grow the array if necessary.
1753     if (_num_alias_types == _max_alias_types)  grow_alias_types();
1754     // Add a new alias type.
1755     idx = _num_alias_types++;
1756     _alias_types[idx]->Init(idx, flat);
1757     if (flat == TypeInstPtr::KLASS)  alias_type(idx)->set_rewritable(false);
1758     if (flat == TypeAryPtr::RANGE)   alias_type(idx)->set_rewritable(false);
1759     if (flat->isa_instptr()) {
1760       if (flat->offset() == java_lang_Class::klass_offset()
1761           && flat->is_instptr()->instance_klass() == env()->Class_klass())
1762         alias_type(idx)->set_rewritable(false);
1763     }
1764     ciField* field = nullptr;
1765     if (flat->isa_aryptr()) {
1766 #ifdef ASSERT
1767       const int header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1768       // (T_BYTE has the weakest alignment and size restrictions...)
1769       assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1770 #endif
1771       const Type* elemtype = flat->is_aryptr()->elem();
1772       if (flat->offset() == TypePtr::OffsetBot) {
1773         alias_type(idx)->set_element(elemtype);
1774       }
1775       int field_offset = flat->is_aryptr()->field_offset().get();
1776       if (flat->is_flat() &&
1777           field_offset != Type::OffsetBot) {
1778         ciInlineKlass* vk = elemtype->inline_klass();
1779         field_offset += vk->payload_offset();
1780         field = vk->get_field_by_offset(field_offset, false);
1781       }
1782     }
1783     if (flat->isa_klassptr()) {
1784       if (UseCompactObjectHeaders) {
1785         if (flat->offset() == in_bytes(Klass::prototype_header_offset()))
1786           alias_type(idx)->set_rewritable(false);
1787       }
1788       if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1789         alias_type(idx)->set_rewritable(false);
1790       if (flat->offset() == in_bytes(Klass::access_flags_offset()))
1791         alias_type(idx)->set_rewritable(false);
1792       if (flat->offset() == in_bytes(Klass::misc_flags_offset()))
1793         alias_type(idx)->set_rewritable(false);
1794       if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1795         alias_type(idx)->set_rewritable(false);
1796       if (flat->offset() == in_bytes(Klass::layout_helper_offset()))
1797         alias_type(idx)->set_rewritable(false);
1798       if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1799         alias_type(idx)->set_rewritable(false);
1800     }
1801     // %%% (We would like to finalize JavaThread::threadObj_offset(),
1802     // but the base pointer type is not distinctive enough to identify
1803     // references into JavaThread.)
1804 
1805     // Check for final fields.
1806     const TypeInstPtr* tinst = flat->isa_instptr();
1807     if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {

1808       if (tinst->const_oop() != nullptr &&
1809           tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1810           tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1811         // static field
1812         ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1813         field = k->get_field_by_offset(tinst->offset(), true);
1814       } else if (tinst->is_inlinetypeptr()) {
1815         // Inline type field
1816         ciInlineKlass* vk = tinst->inline_klass();
1817         field = vk->get_field_by_offset(tinst->offset(), false);
1818       } else {
1819         ciInstanceKlass *k = tinst->instance_klass();
1820         field = k->get_field_by_offset(tinst->offset(), false);
1821       }
1822     }
1823     assert(field == nullptr ||
1824            original_field == nullptr ||
1825            (field->holder() == original_field->holder() &&
1826             field->offset_in_bytes() == original_field->offset_in_bytes() &&
1827             field->is_static() == original_field->is_static()), "wrong field?");
1828     // Set field() and is_rewritable() attributes.
1829     if (field != nullptr) {
1830       alias_type(idx)->set_field(field);
1831       if (flat->isa_aryptr()) {
1832         // Fields of flat arrays are rewritable although they are declared final
1833         assert(flat->is_flat(), "must be a flat array");
1834         alias_type(idx)->set_rewritable(true);
1835       }
1836     }
1837   }
1838 
1839   // Fill the cache for next time.
1840   if (!uncached) {
1841     ace->_adr_type = adr_type;
1842     ace->_index    = idx;
1843     assert(alias_type(adr_type) == alias_type(idx),  "type must be installed");
1844 
1845     // Might as well try to fill the cache for the flattened version, too.
1846     AliasCacheEntry* face = probe_alias_cache(flat);
1847     if (face->_adr_type == nullptr) {
1848       face->_adr_type = flat;
1849       face->_index    = idx;
1850       assert(alias_type(flat) == alias_type(idx), "flat type must work too");
1851     }
1852   }
1853 
1854   return alias_type(idx);
1855 }
1856 
1857 
1858 Compile::AliasType* Compile::alias_type(ciField* field) {
1859   const TypeOopPtr* t;
1860   if (field->is_static())
1861     t = TypeInstPtr::make(field->holder()->java_mirror());
1862   else
1863     t = TypeOopPtr::make_from_klass_raw(field->holder());
1864   AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1865   assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1866   return atp;
1867 }
1868 
1869 
1870 //------------------------------have_alias_type--------------------------------
1871 bool Compile::have_alias_type(const TypePtr* adr_type) {

1953   assert(!C->major_progress(), "not cleared");
1954 
1955   if (_for_post_loop_igvn.length() > 0) {
1956     while (_for_post_loop_igvn.length() > 0) {
1957       Node* n = _for_post_loop_igvn.pop();
1958       n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1959       igvn._worklist.push(n);
1960     }
1961     igvn.optimize();
1962     if (failing()) return;
1963     assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1964     assert(C->parse_predicate_count() == 0, "all parse predicates should have been removed now");
1965 
1966     // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1967     if (C->major_progress()) {
1968       C->clear_major_progress(); // ensure that major progress is now clear
1969     }
1970   }
1971 }
1972 
1973 void Compile::add_inline_type(Node* n) {
1974   assert(n->is_InlineType(), "unexpected node");
1975   _inline_type_nodes.push(n);
1976 }
1977 
1978 void Compile::remove_inline_type(Node* n) {
1979   assert(n->is_InlineType(), "unexpected node");
1980   if (_inline_type_nodes.contains(n)) {
1981     _inline_type_nodes.remove(n);
1982   }
1983 }
1984 
1985 // Does the return value keep otherwise useless inline type allocations alive?
1986 static bool return_val_keeps_allocations_alive(Node* ret_val) {
1987   ResourceMark rm;
1988   Unique_Node_List wq;
1989   wq.push(ret_val);
1990   bool some_allocations = false;
1991   for (uint i = 0; i < wq.size(); i++) {
1992     Node* n = wq.at(i);
1993     if (n->outcnt() > 1) {
1994       // Some other use for the allocation
1995       return false;
1996     } else if (n->is_InlineType()) {
1997       wq.push(n->in(1));
1998     } else if (n->is_Phi()) {
1999       for (uint j = 1; j < n->req(); j++) {
2000         wq.push(n->in(j));
2001       }
2002     } else if (n->is_CheckCastPP() &&
2003                n->in(1)->is_Proj() &&
2004                n->in(1)->in(0)->is_Allocate()) {
2005       some_allocations = true;
2006     } else if (n->is_CheckCastPP()) {
2007       wq.push(n->in(1));
2008     }
2009   }
2010   return some_allocations;
2011 }
2012 
2013 void Compile::process_inline_types(PhaseIterGVN &igvn, bool remove) {
2014   // Make sure that the return value does not keep an otherwise unused allocation alive
2015   if (tf()->returns_inline_type_as_fields()) {
2016     Node* ret = nullptr;
2017     for (uint i = 1; i < root()->req(); i++) {
2018       Node* in = root()->in(i);
2019       if (in->Opcode() == Op_Return) {
2020         assert(ret == nullptr, "only one return");
2021         ret = in;
2022       }
2023     }
2024     if (ret != nullptr) {
2025       Node* ret_val = ret->in(TypeFunc::Parms);
2026       if (igvn.type(ret_val)->isa_oopptr() &&
2027           return_val_keeps_allocations_alive(ret_val)) {
2028         igvn.replace_input_of(ret, TypeFunc::Parms, InlineTypeNode::tagged_klass(igvn.type(ret_val)->inline_klass(), igvn));
2029         assert(ret_val->outcnt() == 0, "should be dead now");
2030         igvn.remove_dead_node(ret_val);
2031       }
2032     }
2033   }
2034   if (_inline_type_nodes.length() == 0) {
2035     return;
2036   }
2037   // Scalarize inline types in safepoint debug info.
2038   // Delay this until all inlining is over to avoid getting inconsistent debug info.
2039   set_scalarize_in_safepoints(true);
2040   for (int i = _inline_type_nodes.length()-1; i >= 0; i--) {
2041     InlineTypeNode* vt = _inline_type_nodes.at(i)->as_InlineType();
2042     vt->make_scalar_in_safepoints(&igvn);
2043     igvn.record_for_igvn(vt);
2044   }
2045   if (remove) {
2046     // Remove inline type nodes by replacing them with their oop input
2047     while (_inline_type_nodes.length() > 0) {
2048       InlineTypeNode* vt = _inline_type_nodes.pop()->as_InlineType();
2049       if (vt->outcnt() == 0) {
2050         igvn.remove_dead_node(vt);
2051         continue;
2052       }
2053       for (DUIterator i = vt->outs(); vt->has_out(i); i++) {
2054         DEBUG_ONLY(bool must_be_buffered = false);
2055         Node* u = vt->out(i);
2056         // Check if any users are blackholes. If so, rewrite them to use either the
2057         // allocated buffer, or individual components, instead of the inline type node
2058         // that goes away.
2059         if (u->is_Blackhole()) {
2060           BlackholeNode* bh = u->as_Blackhole();
2061 
2062           // Unlink the old input
2063           int idx = bh->find_edge(vt);
2064           assert(idx != -1, "The edge should be there");
2065           bh->del_req(idx);
2066           --i;
2067 
2068           if (vt->is_allocated(&igvn)) {
2069             // Already has the allocated instance, blackhole that
2070             bh->add_req(vt->get_oop());
2071           } else {
2072             // Not allocated yet, blackhole the components
2073             for (uint c = 0; c < vt->field_count(); c++) {
2074               bh->add_req(vt->field_value(c));
2075             }
2076           }
2077 
2078           // Node modified, record for IGVN
2079           igvn.record_for_igvn(bh);
2080         }
2081 #ifdef ASSERT
2082         // Verify that inline type is buffered when replacing by oop
2083         else if (u->is_InlineType()) {
2084           // InlineType uses don't need buffering because they are about to be replaced as well
2085         } else if (u->is_Phi()) {
2086           // TODO 8302217 Remove this once InlineTypeNodes are reliably pushed through
2087         } else {
2088           must_be_buffered = true;
2089         }
2090         if (must_be_buffered && !vt->is_allocated(&igvn)) {
2091           vt->dump(0);
2092           u->dump(0);
2093           assert(false, "Should have been buffered");
2094         }
2095 #endif
2096       }
2097       igvn.replace_node(vt, vt->get_oop());
2098     }
2099   }
2100   igvn.optimize();
2101 }
2102 
2103 void Compile::add_flat_access(Node* n) {
2104   assert(n != nullptr && (n->Opcode() == Op_LoadFlat || n->Opcode() == Op_StoreFlat), "unexpected node %s", n == nullptr ? "nullptr" : n->Name());
2105   assert(!_flat_access_nodes.contains(n), "duplicate insertion");
2106   _flat_access_nodes.push(n);
2107 }
2108 
2109 void Compile::remove_flat_access(Node* n) {
2110   assert(n != nullptr && (n->Opcode() == Op_LoadFlat || n->Opcode() == Op_StoreFlat), "unexpected node %s", n == nullptr ? "nullptr" : n->Name());
2111   _flat_access_nodes.remove_if_existing(n);
2112 }
2113 
2114 void Compile::process_flat_accesses(PhaseIterGVN& igvn) {
2115   assert(igvn._worklist.size() == 0, "should be empty");
2116   igvn.set_delay_transform(true);
2117   for (int i = _flat_access_nodes.length() - 1; i >= 0; i--) {
2118     Node* n = _flat_access_nodes.at(i);
2119     assert(n != nullptr, "unexpected nullptr");
2120     if (n->is_LoadFlat()) {
2121       n->as_LoadFlat()->expand_atomic(igvn);
2122     } else {
2123       n->as_StoreFlat()->expand_atomic(igvn);
2124     }
2125   }
2126   _flat_access_nodes.clear_and_deallocate();
2127   igvn.set_delay_transform(false);
2128   igvn.optimize();
2129 }
2130 
2131 void Compile::adjust_flat_array_access_aliases(PhaseIterGVN& igvn) {
2132   if (!_has_flat_accesses) {
2133     return;
2134   }
2135   // Initially, all flat array accesses share the same slice to
2136   // keep dependencies with Object[] array accesses (that could be
2137   // to a flat array) correct. We're done with parsing so we
2138   // now know all flat array accesses in this compile
2139   // unit. Let's move flat array accesses to their own slice,
2140   // one per element field. This should help memory access
2141   // optimizations.
2142   ResourceMark rm;
2143   Unique_Node_List wq;
2144   wq.push(root());
2145 
2146   Node_List mergememnodes;
2147   Node_List memnodes;
2148 
2149   // Alias index currently shared by all flat memory accesses
2150   int index = get_alias_index(TypeAryPtr::INLINES);
2151 
2152   // Find MergeMem nodes and flat array accesses
2153   for (uint i = 0; i < wq.size(); i++) {
2154     Node* n = wq.at(i);
2155     if (n->is_Mem()) {
2156       const TypePtr* adr_type = nullptr;
2157       adr_type = get_adr_type(get_alias_index(n->adr_type()));
2158       if (adr_type == TypeAryPtr::INLINES) {
2159         memnodes.push(n);
2160       }
2161     } else if (n->is_MergeMem()) {
2162       MergeMemNode* mm = n->as_MergeMem();
2163       if (mm->memory_at(index) != mm->base_memory()) {
2164         mergememnodes.push(n);
2165       }
2166     }
2167     for (uint j = 0; j < n->req(); j++) {
2168       Node* m = n->in(j);
2169       if (m != nullptr) {
2170         wq.push(m);
2171       }
2172     }
2173   }
2174 
2175   if (memnodes.size() > 0) {
2176     _flat_accesses_share_alias = false;
2177 
2178     // We are going to change the slice for the flat array
2179     // accesses so we need to clear the cache entries that refer to
2180     // them.
2181     for (uint i = 0; i < AliasCacheSize; i++) {
2182       AliasCacheEntry* ace = &_alias_cache[i];
2183       if (ace->_adr_type != nullptr &&
2184           ace->_adr_type->is_flat()) {
2185         ace->_adr_type = nullptr;
2186         ace->_index = (i != 0) ? 0 : AliasIdxTop; // Make sure the nullptr adr_type resolves to AliasIdxTop
2187       }
2188     }
2189 
2190     // Find what aliases we are going to add
2191     int start_alias = num_alias_types()-1;
2192     int stop_alias = 0;
2193 
2194     for (uint i = 0; i < memnodes.size(); i++) {
2195       Node* m = memnodes.at(i);
2196       const TypePtr* adr_type = nullptr;
2197       adr_type = m->adr_type();
2198 #ifdef ASSERT
2199       m->as_Mem()->set_adr_type(adr_type);
2200 #endif
2201       int idx = get_alias_index(adr_type);
2202       start_alias = MIN2(start_alias, idx);
2203       stop_alias = MAX2(stop_alias, idx);
2204     }
2205 
2206     assert(stop_alias >= start_alias, "should have expanded aliases");
2207 
2208     Node_Stack stack(0);
2209 #ifdef ASSERT
2210     VectorSet seen(Thread::current()->resource_area());
2211 #endif
2212     // Now let's fix the memory graph so each flat array access
2213     // is moved to the right slice. Start from the MergeMem nodes.
2214     uint last = unique();
2215     for (uint i = 0; i < mergememnodes.size(); i++) {
2216       MergeMemNode* current = mergememnodes.at(i)->as_MergeMem();
2217       Node* n = current->memory_at(index);
2218       MergeMemNode* mm = nullptr;
2219       do {
2220         // Follow memory edges through memory accesses, phis and
2221         // narrow membars and push nodes on the stack. Once we hit
2222         // bottom memory, we pop element off the stack one at a
2223         // time, in reverse order, and move them to the right slice
2224         // by changing their memory edges.
2225         if ((n->is_Phi() && n->adr_type() != TypePtr::BOTTOM) || n->is_Mem() || n->adr_type() == TypeAryPtr::INLINES) {
2226           assert(!seen.test_set(n->_idx), "");
2227           // Uses (a load for instance) will need to be moved to the
2228           // right slice as well and will get a new memory state
2229           // that we don't know yet. The use could also be the
2230           // backedge of a loop. We put a place holder node between
2231           // the memory node and its uses. We replace that place
2232           // holder with the correct memory state once we know it,
2233           // i.e. when nodes are popped off the stack. Using the
2234           // place holder make the logic work in the presence of
2235           // loops.
2236           if (n->outcnt() > 1) {
2237             Node* place_holder = nullptr;
2238             assert(!n->has_out_with(Op_Node), "");
2239             for (DUIterator k = n->outs(); n->has_out(k); k++) {
2240               Node* u = n->out(k);
2241               if (u != current && u->_idx < last) {
2242                 bool success = false;
2243                 for (uint l = 0; l < u->req(); l++) {
2244                   if (!stack.is_empty() && u == stack.node() && l == stack.index()) {
2245                     continue;
2246                   }
2247                   Node* in = u->in(l);
2248                   if (in == n) {
2249                     if (place_holder == nullptr) {
2250                       place_holder = new Node(1);
2251                       place_holder->init_req(0, n);
2252                     }
2253                     igvn.replace_input_of(u, l, place_holder);
2254                     success = true;
2255                   }
2256                 }
2257                 if (success) {
2258                   --k;
2259                 }
2260               }
2261             }
2262           }
2263           if (n->is_Phi()) {
2264             stack.push(n, 1);
2265             n = n->in(1);
2266           } else if (n->is_Mem()) {
2267             stack.push(n, n->req());
2268             n = n->in(MemNode::Memory);
2269           } else {
2270             assert(n->is_Proj() && n->in(0)->Opcode() == Op_MemBarCPUOrder, "");
2271             stack.push(n, n->req());
2272             n = n->in(0)->in(TypeFunc::Memory);
2273           }
2274         } else {
2275           assert(n->adr_type() == TypePtr::BOTTOM || (n->Opcode() == Op_Node && n->_idx >= last) || (n->is_Proj() && n->in(0)->is_Initialize()), "");
2276           // Build a new MergeMem node to carry the new memory state
2277           // as we build it. IGVN should fold extraneous MergeMem
2278           // nodes.
2279           mm = MergeMemNode::make(n);
2280           igvn.register_new_node_with_optimizer(mm);
2281           while (stack.size() > 0) {
2282             Node* m = stack.node();
2283             uint idx = stack.index();
2284             if (m->is_Mem()) {
2285               // Move memory node to its new slice
2286               const TypePtr* adr_type = m->adr_type();
2287               int alias = get_alias_index(adr_type);
2288               Node* prev = mm->memory_at(alias);
2289               igvn.replace_input_of(m, MemNode::Memory, prev);
2290               mm->set_memory_at(alias, m);
2291             } else if (m->is_Phi()) {
2292               // We need as many new phis as there are new aliases
2293               igvn.replace_input_of(m, idx, mm);
2294               if (idx == m->req()-1) {
2295                 Node* r = m->in(0);
2296                 for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2297                   const TypePtr* adr_type = get_adr_type(j);
2298                   if (!adr_type->isa_aryptr() || !adr_type->is_flat() || j == (uint)index) {
2299                     continue;
2300                   }
2301                   Node* phi = new PhiNode(r, Type::MEMORY, get_adr_type(j));
2302                   igvn.register_new_node_with_optimizer(phi);
2303                   for (uint k = 1; k < m->req(); k++) {
2304                     phi->init_req(k, m->in(k)->as_MergeMem()->memory_at(j));
2305                   }
2306                   mm->set_memory_at(j, phi);
2307                 }
2308                 Node* base_phi = new PhiNode(r, Type::MEMORY, TypePtr::BOTTOM);
2309                 igvn.register_new_node_with_optimizer(base_phi);
2310                 for (uint k = 1; k < m->req(); k++) {
2311                   base_phi->init_req(k, m->in(k)->as_MergeMem()->base_memory());
2312                 }
2313                 mm->set_base_memory(base_phi);
2314               }
2315             } else {
2316               // This is a MemBarCPUOrder node from
2317               // Parse::array_load()/Parse::array_store(), in the
2318               // branch that handles flat arrays hidden under
2319               // an Object[] array. We also need one new membar per
2320               // new alias to keep the unknown access that the
2321               // membars protect properly ordered with accesses to
2322               // known flat array.
2323               assert(m->is_Proj(), "projection expected");
2324               Node* ctrl = m->in(0)->in(TypeFunc::Control);
2325               igvn.replace_input_of(m->in(0), TypeFunc::Control, top());
2326               for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2327                 const TypePtr* adr_type = get_adr_type(j);
2328                 if (!adr_type->isa_aryptr() || !adr_type->is_flat() || j == (uint)index) {
2329                   continue;
2330                 }
2331                 MemBarNode* mb = new MemBarCPUOrderNode(this, j, nullptr);
2332                 igvn.register_new_node_with_optimizer(mb);
2333                 Node* mem = mm->memory_at(j);
2334                 mb->init_req(TypeFunc::Control, ctrl);
2335                 mb->init_req(TypeFunc::Memory, mem);
2336                 ctrl = new ProjNode(mb, TypeFunc::Control);
2337                 igvn.register_new_node_with_optimizer(ctrl);
2338                 mem = new ProjNode(mb, TypeFunc::Memory);
2339                 igvn.register_new_node_with_optimizer(mem);
2340                 mm->set_memory_at(j, mem);
2341               }
2342               igvn.replace_node(m->in(0)->as_Multi()->proj_out(TypeFunc::Control), ctrl);
2343             }
2344             if (idx < m->req()-1) {
2345               idx += 1;
2346               stack.set_index(idx);
2347               n = m->in(idx);
2348               break;
2349             }
2350             // Take care of place holder nodes
2351             if (m->has_out_with(Op_Node)) {
2352               Node* place_holder = m->find_out_with(Op_Node);
2353               if (place_holder != nullptr) {
2354                 Node* mm_clone = mm->clone();
2355                 igvn.register_new_node_with_optimizer(mm_clone);
2356                 Node* hook = new Node(1);
2357                 hook->init_req(0, mm);
2358                 igvn.replace_node(place_holder, mm_clone);
2359                 hook->destruct(&igvn);
2360               }
2361               assert(!m->has_out_with(Op_Node), "place holder should be gone now");
2362             }
2363             stack.pop();
2364           }
2365         }
2366       } while(stack.size() > 0);
2367       // Fix the memory state at the MergeMem we started from
2368       igvn.rehash_node_delayed(current);
2369       for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2370         const TypePtr* adr_type = get_adr_type(j);
2371         if (!adr_type->isa_aryptr() || !adr_type->is_flat()) {
2372           continue;
2373         }
2374         current->set_memory_at(j, mm);
2375       }
2376       current->set_memory_at(index, current->base_memory());
2377     }
2378     igvn.optimize();
2379   }
2380   print_method(PHASE_SPLIT_INLINES_ARRAY, 2);
2381 #ifdef ASSERT
2382   if (!_flat_accesses_share_alias) {
2383     wq.clear();
2384     wq.push(root());
2385     for (uint i = 0; i < wq.size(); i++) {
2386       Node* n = wq.at(i);
2387       assert(n->adr_type() != TypeAryPtr::INLINES, "should have been removed from the graph");
2388       for (uint j = 0; j < n->req(); j++) {
2389         Node* m = n->in(j);
2390         if (m != nullptr) {
2391           wq.push(m);
2392         }
2393       }
2394     }
2395   }
2396 #endif
2397 }
2398 
2399 void Compile::record_for_merge_stores_igvn(Node* n) {
2400   if (!n->for_merge_stores_igvn()) {
2401     assert(!_for_merge_stores_igvn.contains(n), "duplicate");
2402     n->add_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
2403     _for_merge_stores_igvn.append(n);
2404   }
2405 }
2406 
2407 void Compile::remove_from_merge_stores_igvn(Node* n) {
2408   n->remove_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
2409   _for_merge_stores_igvn.remove(n);
2410 }
2411 
2412 // We need to wait with merging stores until RangeCheck smearing has removed the RangeChecks during
2413 // the post loops IGVN phase. If we do it earlier, then there may still be some RangeChecks between
2414 // the stores, and we merge the wrong sequence of stores.
2415 // Example:
2416 //   StoreI RangeCheck StoreI StoreI RangeCheck StoreI
2417 // Apply MergeStores:
2418 //   StoreI RangeCheck [   StoreL  ] RangeCheck StoreI

2497       assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
2498       Bytecodes::Code c = iter.cur_bc();
2499       Node* lhs = nullptr;
2500       Node* rhs = nullptr;
2501       if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
2502         lhs = unc->peek_operand(0);
2503         rhs = unc->peek_operand(1);
2504       } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
2505         lhs = unc->peek_operand(0);
2506       }
2507 
2508       ResourceMark rm;
2509       const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
2510       assert(live_locals.is_valid(), "broken liveness info");
2511       int len = (int)live_locals.size();
2512 
2513       for (int i = 0; i < len; i++) {
2514         Node* local = unc->local(jvms, i);
2515         // kill local using the liveness of next_bci.
2516         // give up when the local looks like an operand to secure reexecution.
2517         if (!live_locals.at(i) && !local->is_top() && local != lhs && local != rhs) {
2518           uint idx = jvms->locoff() + i;
2519 #ifdef ASSERT
2520           if (PrintOpto && Verbose) {
2521             tty->print("[unstable_if] kill local#%d: ", idx);
2522             local->dump();
2523             tty->cr();
2524           }
2525 #endif
2526           igvn.replace_input_of(unc, idx, top());
2527           modified = true;
2528         }
2529       }
2530     }
2531 
2532     // keep the modified trap for late query
2533     if (modified) {
2534       trap->set_modified();
2535     } else {
2536       _unstable_if_traps.delete_at(i);
2537     }
2538   }
2539   igvn.optimize();
2540 }
2541 
2542 // StringOpts and late inlining of string methods
2543 void Compile::inline_string_calls(bool parse_time) {
2544   {
2545     // remove useless nodes to make the usage analysis simpler
2546     ResourceMark rm;
2547     PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
2548   }
2549 
2550   {
2551     ResourceMark rm;
2552     print_method(PHASE_BEFORE_STRINGOPTS, 3);

2724 
2725   if (_string_late_inlines.length() > 0) {
2726     assert(has_stringbuilder(), "inconsistent");
2727 
2728     inline_string_calls(false);
2729 
2730     if (failing())  return;
2731 
2732     inline_incrementally_cleanup(igvn);
2733   }
2734 
2735   set_inlining_incrementally(false);
2736 }
2737 
2738 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2739   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2740   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2741   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2742   // as if "inlining_incrementally() == true" were set.
2743   assert(inlining_incrementally() == false, "not allowed");
2744 #ifdef ASSERT
2745   Unique_Node_List* modified_nodes = _modified_nodes;
2746   _modified_nodes = nullptr;
2747 #endif
2748   assert(_late_inlines.length() > 0, "sanity");
2749 
2750   while (_late_inlines.length() > 0) {
2751     igvn_worklist()->ensure_empty(); // should be done with igvn
2752 
2753     while (inline_incrementally_one()) {
2754       assert(!failing_internal() || failure_is_artificial(), "inconsistent");
2755     }
2756     if (failing())  return;
2757 
2758     inline_incrementally_cleanup(igvn);
2759   }
2760   DEBUG_ONLY( _modified_nodes = modified_nodes; )
2761 }
2762 
2763 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2764   if (_loop_opts_cnt > 0) {
2765     while (major_progress() && (_loop_opts_cnt > 0)) {
2766       TracePhase tp(_t_idealLoop);
2767       PhaseIdealLoop::optimize(igvn, mode);
2768       _loop_opts_cnt--;
2769       if (failing())  return false;
2770       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2771     }
2772   }
2773   return true;
2774 }
2775 
2776 // Remove edges from "root" to each SafePoint at a backward branch.
2777 // They were inserted during parsing (see add_safepoint()) to make
2778 // infinite loops without calls or exceptions visible to root, i.e.,
2779 // useful.
2780 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2884     print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2885   }
2886   assert(!has_vbox_nodes(), "sanity");
2887 
2888   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2889     Compile::TracePhase tp(_t_renumberLive);
2890     igvn_worklist()->ensure_empty(); // should be done with igvn
2891     {
2892       ResourceMark rm;
2893       PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2894     }
2895     igvn.reset();
2896     igvn.optimize();
2897     if (failing()) return;
2898   }
2899 
2900   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2901   // safepoints
2902   remove_root_to_sfpts_edges(igvn);
2903 
2904   // Process inline type nodes now that all inlining is over
2905   process_inline_types(igvn);
2906 
2907   adjust_flat_array_access_aliases(igvn);
2908 
2909   if (failing())  return;
2910 
2911   if (C->macro_count() > 0) {
2912     // Eliminate some macro nodes before EA to reduce analysis pressure
2913     PhaseMacroExpand mexp(igvn);
2914     mexp.eliminate_macro_nodes(/* eliminate_locks= */ false);
2915     if (failing()) {
2916       return;
2917     }
2918     igvn.set_delay_transform(false);
2919     print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2920   }
2921 
2922   if (has_loops()) {
2923     print_method(PHASE_BEFORE_LOOP_OPTS, 2);
2924   }
2925 
2926   // Perform escape analysis
2927   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2928     if (has_loops()) {
2929       // Cleanup graph (remove dead nodes).
2930       TracePhase tp(_t_idealLoop);
2931       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2932       if (failing()) {
2933         return;
2934       }
2935       print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2936       if (C->macro_count() > 0) {
2937         // Eliminate some macro nodes before EA to reduce analysis pressure
2938         PhaseMacroExpand mexp(igvn);
2939         mexp.eliminate_macro_nodes(/* eliminate_locks= */ false);
2940         if (failing()) {
2941           return;
2942         }
2943         igvn.set_delay_transform(false);
2944         print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2945       }
2946     }
2947 
2948     bool progress;

2949     do {
2950       ConnectionGraph::do_analysis(this, &igvn);
2951 
2952       if (failing())  return;
2953 
2954       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2955 
2956       // Optimize out fields loads from scalar replaceable allocations.
2957       igvn.optimize();
2958       print_method(PHASE_ITER_GVN_AFTER_EA, 2);
2959 
2960       if (failing()) return;
2961 
2962       if (congraph() != nullptr && macro_count() > 0) {
2963         TracePhase tp(_t_macroEliminate);
2964         PhaseMacroExpand mexp(igvn);
2965         mexp.eliminate_macro_nodes();
2966         if (failing()) {
2967           return;
2968         }
2969         print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
2970 
2971         igvn.set_delay_transform(false);



2972         print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2973       }
2974 
2975       ConnectionGraph::verify_ram_nodes(this, root());
2976       if (failing())  return;
2977 
2978       progress = do_iterative_escape_analysis() &&
2979                  (macro_count() < mcount) &&
2980                  ConnectionGraph::has_candidates(this);
2981       // Try again if candidates exist and made progress
2982       // by removing some allocations and/or locks.
2983     } while (progress);
2984   }
2985 
2986   process_flat_accesses(igvn);
2987   if (failing()) {
2988     return;
2989   }
2990 
2991   // Loop transforms on the ideal graph.  Range Check Elimination,
2992   // peeling, unrolling, etc.
2993 
2994   // Set loop opts counter
2995   if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2996     {
2997       TracePhase tp(_t_idealLoop);
2998       PhaseIdealLoop::optimize(igvn, LoopOptsDefault);
2999       _loop_opts_cnt--;
3000       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
3001       if (failing())  return;
3002     }
3003     // Loop opts pass if partial peeling occurred in previous pass
3004     if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
3005       TracePhase tp(_t_idealLoop);
3006       PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
3007       _loop_opts_cnt--;
3008       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
3009       if (failing())  return;
3010     }

3047   // Loop transforms on the ideal graph.  Range Check Elimination,
3048   // peeling, unrolling, etc.
3049   if (!optimize_loops(igvn, LoopOptsDefault)) {
3050     return;
3051   }
3052 
3053   if (failing())  return;
3054 
3055   C->clear_major_progress(); // ensure that major progress is now clear
3056 
3057   process_for_post_loop_opts_igvn(igvn);
3058 
3059   process_for_merge_stores_igvn(igvn);
3060 
3061   if (failing())  return;
3062 
3063 #ifdef ASSERT
3064   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
3065 #endif
3066 
3067   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
3068 
3069   if (_late_inlines.length() > 0) {
3070     // More opportunities to optimize virtual and MH calls.
3071     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
3072     process_late_inline_calls_no_inline(igvn);
3073   }
3074 
3075   {
3076     TracePhase tp(_t_macroExpand);
3077     PhaseMacroExpand mex(igvn);
3078     // Last attempt to eliminate macro nodes.
3079     mex.eliminate_macro_nodes();
3080     if (failing()) {
3081       return;
3082     }
3083 
3084     print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);

3085     // Do not allow new macro nodes once we start to eliminate and expand
3086     C->reset_allow_macro_nodes();
3087     // Last attempt to eliminate macro nodes before expand
3088     mex.eliminate_macro_nodes();
3089     if (failing()) {
3090       return;
3091     }
3092     mex.eliminate_opaque_looplimit_macro_nodes();
3093     if (failing()) {
3094       return;
3095     }
3096     print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
3097     if (mex.expand_macro_nodes()) {
3098       assert(failing(), "must bail out w/ explicit message");
3099       return;
3100     }
3101     print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
3102   }
3103 
3104   // Process inline type nodes again and remove them. From here
3105   // on we don't need to keep track of field values anymore.
3106   process_inline_types(igvn, /* remove= */ true);
3107 
3108   {
3109     TracePhase tp(_t_barrierExpand);
3110     if (bs->expand_barriers(this, igvn)) {
3111       assert(failing(), "must bail out w/ explicit message");
3112       return;
3113     }
3114     print_method(PHASE_BARRIER_EXPANSION, 2);
3115   }
3116 
3117   if (C->max_vector_size() > 0) {
3118     C->optimize_logic_cones(igvn);
3119     igvn.optimize();
3120     if (failing()) return;
3121   }
3122 
3123   DEBUG_ONLY( _modified_nodes = nullptr; )
3124   DEBUG_ONLY( _late_inlines.clear(); )
3125 
3126   assert(igvn._worklist.size() == 0, "not empty");









3127  } // (End scope of igvn; run destructor if necessary for asserts.)
3128 
3129  check_no_dead_use();
3130 
3131  // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
3132  // to remove hashes to unlock nodes for modifications.
3133  C->node_hash()->clear();
3134 
3135  // A method with only infinite loops has no edges entering loops from root
3136  {
3137    TracePhase tp(_t_graphReshaping);
3138    if (final_graph_reshaping()) {
3139      assert(failing(), "must bail out w/ explicit message");
3140      return;
3141    }
3142  }
3143 
3144  print_method(PHASE_OPTIMIZE_FINISHED, 2);
3145  DEBUG_ONLY(set_phase_optimize_finished();)
3146 }

3852   case Op_CmpD3:
3853   case Op_StoreD:
3854   case Op_LoadD:
3855   case Op_LoadD_unaligned:
3856     frc.inc_double_count();
3857     break;
3858   case Op_Opaque1:              // Remove Opaque Nodes before matching
3859     n->subsume_by(n->in(1), this);
3860     break;
3861   case Op_CallLeafPure: {
3862     // If the pure call is not supported, then lower to a CallLeaf.
3863     if (!Matcher::match_rule_supported(Op_CallLeafPure)) {
3864       CallNode* call = n->as_Call();
3865       CallNode* new_call = new CallLeafNode(call->tf(), call->entry_point(),
3866                                             call->_name, TypeRawPtr::BOTTOM);
3867       new_call->init_req(TypeFunc::Control, call->in(TypeFunc::Control));
3868       new_call->init_req(TypeFunc::I_O, C->top());
3869       new_call->init_req(TypeFunc::Memory, C->top());
3870       new_call->init_req(TypeFunc::ReturnAdr, C->top());
3871       new_call->init_req(TypeFunc::FramePtr, C->top());
3872       for (unsigned int i = TypeFunc::Parms; i < call->tf()->domain_sig()->cnt(); i++) {
3873         new_call->init_req(i, call->in(i));
3874       }
3875       n->subsume_by(new_call, this);
3876     }
3877     frc.inc_call_count();
3878     break;
3879   }
3880   case Op_CallStaticJava:
3881   case Op_CallJava:
3882   case Op_CallDynamicJava:
3883     frc.inc_java_call_count(); // Count java call site;
3884   case Op_CallRuntime:
3885   case Op_CallLeaf:
3886   case Op_CallLeafVector:
3887   case Op_CallLeafNoFP: {
3888     assert (n->is_Call(), "");
3889     CallNode *call = n->as_Call();
3890     // Count call sites where the FP mode bit would have to be flipped.
3891     // Do not count uncommon runtime calls:
3892     // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,

3898       int nop = n->Opcode();
3899       // Clone shared simple arguments to uncommon calls, item (1).
3900       if (n->outcnt() > 1 &&
3901           !n->is_Proj() &&
3902           nop != Op_CreateEx &&
3903           nop != Op_CheckCastPP &&
3904           nop != Op_DecodeN &&
3905           nop != Op_DecodeNKlass &&
3906           !n->is_Mem() &&
3907           !n->is_Phi()) {
3908         Node *x = n->clone();
3909         call->set_req(TypeFunc::Parms, x);
3910       }
3911     }
3912     break;
3913   }
3914   case Op_StoreB:
3915   case Op_StoreC:
3916   case Op_StoreI:
3917   case Op_StoreL:
3918   case Op_StoreLSpecial:
3919   case Op_CompareAndSwapB:
3920   case Op_CompareAndSwapS:
3921   case Op_CompareAndSwapI:
3922   case Op_CompareAndSwapL:
3923   case Op_CompareAndSwapP:
3924   case Op_CompareAndSwapN:
3925   case Op_WeakCompareAndSwapB:
3926   case Op_WeakCompareAndSwapS:
3927   case Op_WeakCompareAndSwapI:
3928   case Op_WeakCompareAndSwapL:
3929   case Op_WeakCompareAndSwapP:
3930   case Op_WeakCompareAndSwapN:
3931   case Op_CompareAndExchangeB:
3932   case Op_CompareAndExchangeS:
3933   case Op_CompareAndExchangeI:
3934   case Op_CompareAndExchangeL:
3935   case Op_CompareAndExchangeP:
3936   case Op_CompareAndExchangeN:
3937   case Op_GetAndAddS:
3938   case Op_GetAndAddB:

4451           k->subsume_by(m, this);
4452         }
4453       }
4454     }
4455     break;
4456   }
4457   case Op_CmpUL: {
4458     if (!Matcher::has_match_rule(Op_CmpUL)) {
4459       // No support for unsigned long comparisons
4460       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
4461       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
4462       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
4463       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
4464       Node* andl = new AndLNode(orl, remove_sign_mask);
4465       Node* cmp = new CmpLNode(andl, n->in(2));
4466       n->subsume_by(cmp, this);
4467     }
4468     break;
4469   }
4470 #ifdef ASSERT
4471   case Op_InlineType: {
4472     n->dump(-1);
4473     assert(false, "inline type node was not removed");
4474     break;
4475   }
4476   case Op_ConNKlass: {
4477     const TypePtr* tp = n->as_Type()->type()->make_ptr();
4478     ciKlass* klass = tp->is_klassptr()->exact_klass();
4479     assert(klass->is_in_encoding_range(), "klass cannot be compressed");
4480     break;
4481   }
4482 #endif
4483   default:
4484     assert(!n->is_Call(), "");
4485     assert(!n->is_Mem(), "");
4486     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
4487     break;
4488   }
4489 }
4490 
4491 //------------------------------final_graph_reshaping_walk---------------------
4492 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
4493 // requires that the walk visits a node's inputs before visiting the node.
4494 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
4495   Unique_Node_List sfpt;

4831   }
4832 }
4833 
4834 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4835   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4836 }
4837 
4838 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4839   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4840 }
4841 
4842 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4843   if (holder->is_initialized()) {
4844     return false;
4845   }
4846   if (holder->is_being_initialized()) {
4847     if (accessing_method->holder() == holder) {
4848       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4849       // <init>, or a static method. In all those cases, there was an initialization
4850       // barrier on the holder klass passed.
4851       if (accessing_method->is_class_initializer() ||
4852           accessing_method->is_object_constructor() ||
4853           accessing_method->is_static()) {
4854         return false;
4855       }
4856     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4857       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4858       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4859       // child class can become fully initialized while its parent class is still being initialized.
4860       if (accessing_method->is_class_initializer()) {
4861         return false;
4862       }
4863     }
4864     ciMethod* root = method(); // the root method of compilation
4865     if (root != accessing_method) {
4866       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4867     }
4868   }
4869   return true;
4870 }
4871 
4872 #ifndef PRODUCT
4873 //------------------------------verify_bidirectional_edges---------------------
4874 // For each input edge to a node (ie - for each Use-Def edge), verify that
4875 // there is a corresponding Def-Use edge.
4876 void Compile::verify_bidirectional_edges(Unique_Node_List& visited, const Unique_Node_List* root_and_safepoints) const {
4877   // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4878   uint stack_size = live_nodes() >> 4;
4879   Node_List nstack(MAX2(stack_size, (uint) OptoNodeListSize));
4880   if (root_and_safepoints != nullptr) {

4910       if (in != nullptr && !in->is_top()) {
4911         // Count instances of `next`
4912         int cnt = 0;
4913         for (uint idx = 0; idx < in->_outcnt; idx++) {
4914           if (in->_out[idx] == n) {
4915             cnt++;
4916           }
4917         }
4918         assert(cnt > 0, "Failed to find Def-Use edge.");
4919         // Check for duplicate edges
4920         // walk the input array downcounting the input edges to n
4921         for (uint j = 0; j < length; j++) {
4922           if (n->in(j) == in) {
4923             cnt--;
4924           }
4925         }
4926         assert(cnt == 0, "Mismatched edge count.");
4927       } else if (in == nullptr) {
4928         assert(i == 0 || i >= n->req() ||
4929                n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||
4930                (n->is_Allocate() && i >= AllocateNode::InlineType) ||
4931                (n->is_Unlock() && i == (n->req() - 1)) ||
4932                (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4933               "only region, phi, arraycopy, allocate, unlock or membar nodes have null data edges");
4934       } else {
4935         assert(in->is_top(), "sanity");
4936         // Nothing to check.
4937       }
4938     }
4939   }
4940 }
4941 
4942 //------------------------------verify_graph_edges---------------------------
4943 // Walk the Graph and verify that there is a one-to-one correspondence
4944 // between Use-Def edges and Def-Use edges in the graph.
4945 void Compile::verify_graph_edges(bool no_dead_code, const Unique_Node_List* root_and_safepoints) const {
4946   if (VerifyGraphEdges) {
4947     Unique_Node_List visited;
4948 
4949     // Call graph walk to check edges
4950     verify_bidirectional_edges(visited, root_and_safepoints);
4951     if (no_dead_code) {
4952       // Now make sure that no visited node is used by an unvisited node.
4953       bool dead_nodes = false;

5064 // (1) subklass is already limited to a subtype of superklass => always ok
5065 // (2) subklass does not overlap with superklass => always fail
5066 // (3) superklass has NO subtypes and we can check with a simple compare.
5067 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
5068   if (skip) {
5069     return SSC_full_test;       // Let caller generate the general case.
5070   }
5071 
5072   if (subk->is_java_subtype_of(superk)) {
5073     return SSC_always_true; // (0) and (1)  this test cannot fail
5074   }
5075 
5076   if (!subk->maybe_java_subtype_of(superk)) {
5077     return SSC_always_false; // (2) true path dead; no dynamic test needed
5078   }
5079 
5080   const Type* superelem = superk;
5081   if (superk->isa_aryklassptr()) {
5082     int ignored;
5083     superelem = superk->is_aryklassptr()->base_element_type(ignored);
5084 
5085     // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays
5086     // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test.
5087     if (!superk->is_aryklassptr()->is_null_free() && superk->is_aryklassptr()->elem()->isa_instklassptr() &&
5088         superk->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->is_inlinetype()) {
5089       return SSC_full_test;
5090     }
5091   }
5092 
5093   if (superelem->isa_instklassptr()) {
5094     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
5095     if (!ik->has_subklass()) {
5096       if (!ik->is_final()) {
5097         // Add a dependency if there is a chance of a later subclass.
5098         dependencies()->assert_leaf_type(ik);
5099       }
5100       if (!superk->maybe_java_subtype_of(subk)) {
5101         return SSC_always_false;
5102       }
5103       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
5104     }
5105   } else {
5106     // A primitive array type has no subtypes.
5107     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
5108   }
5109 
5110   return SSC_full_test;

5554       const Type* t = igvn.type_or_null(n);
5555       assert((t == nullptr) || (t == t->remove_speculative()), "no more speculative types");
5556       if (n->is_Type()) {
5557         t = n->as_Type()->type();
5558         assert(t == t->remove_speculative(), "no more speculative types");
5559       }
5560       // Iterate over outs - endless loops is unreachable from below
5561       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
5562         Node *m = n->fast_out(i);
5563         if (not_a_node(m)) {
5564           continue;
5565         }
5566         worklist.push(m);
5567       }
5568     }
5569     igvn.check_no_speculative_types();
5570 #endif
5571   }
5572 }
5573 
5574 Node* Compile::optimize_acmp(PhaseGVN* phase, Node* a, Node* b) {
5575   const TypeInstPtr* ta = phase->type(a)->isa_instptr();
5576   const TypeInstPtr* tb = phase->type(b)->isa_instptr();
5577   if (!EnableValhalla || ta == nullptr || tb == nullptr ||
5578       ta->is_zero_type() || tb->is_zero_type() ||
5579       !ta->can_be_inline_type() || !tb->can_be_inline_type()) {
5580     // Use old acmp if one operand is null or not an inline type
5581     return new CmpPNode(a, b);
5582   } else if (ta->is_inlinetypeptr() || tb->is_inlinetypeptr()) {
5583     // We know that one operand is an inline type. Therefore,
5584     // new acmp will only return true if both operands are nullptr.
5585     // Check if both operands are null by or'ing the oops.
5586     a = phase->transform(new CastP2XNode(nullptr, a));
5587     b = phase->transform(new CastP2XNode(nullptr, b));
5588     a = phase->transform(new OrXNode(a, b));
5589     return new CmpXNode(a, phase->MakeConX(0));
5590   }
5591   // Use new acmp
5592   return nullptr;
5593 }
5594 
5595 // Auxiliary methods to support randomized stressing/fuzzing.
5596 
5597 void Compile::initialize_stress_seed(const DirectiveSet* directive) {
5598   if (FLAG_IS_DEFAULT(StressSeed) || (FLAG_IS_ERGO(StressSeed) && directive->RepeatCompilationOption)) {
5599     _stress_seed = static_cast<uint>(Ticks::now().nanoseconds());
5600     FLAG_SET_ERGO(StressSeed, _stress_seed);
5601   } else {
5602     _stress_seed = StressSeed;
5603   }
5604   if (_log != nullptr) {
5605     _log->elem("stress_test seed='%u'", _stress_seed);
5606   }
5607 }
5608 
5609 int Compile::random() {
5610   _stress_seed = os::next_random(_stress_seed);
5611   return static_cast<int>(_stress_seed);
5612 }
5613 
5614 // This method can be called the arbitrary number of times, with current count

5930   } else {
5931     _debug_network_printer->update_compiled_method(C->method());
5932   }
5933   tty->print_cr("Method printed over network stream to IGV");
5934   _debug_network_printer->print(name, C->root(), visible_nodes, fr);
5935 }
5936 #endif // !PRODUCT
5937 
5938 Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {
5939   if (type != nullptr && phase->type(value)->higher_equal(type)) {
5940     return value;
5941   }
5942   Node* result = nullptr;
5943   if (bt == T_BYTE) {
5944     result = phase->transform(new LShiftINode(value, phase->intcon(24)));
5945     result = new RShiftINode(result, phase->intcon(24));
5946   } else if (bt == T_BOOLEAN) {
5947     result = new AndINode(value, phase->intcon(0xFF));
5948   } else if (bt == T_CHAR) {
5949     result = new AndINode(value,phase->intcon(0xFFFF));
5950   } else if (bt == T_FLOAT) {
5951     result = new MoveI2FNode(value);
5952   } else {
5953     assert(bt == T_SHORT, "unexpected narrow type");
5954     result = phase->transform(new LShiftINode(value, phase->intcon(16)));
5955     result = new RShiftINode(result, phase->intcon(16));
5956   }
5957   if (transform_res) {
5958     result = phase->transform(result);
5959   }
5960   return result;
5961 }
5962 
5963 void Compile::record_method_not_compilable_oom() {
5964   record_method_not_compilable(CompilationMemoryStatistic::failure_reason_memlimit());
5965 }
5966 
5967 #ifndef PRODUCT
5968 // Collects all the control inputs from nodes on the worklist and from their data dependencies
5969 static void find_candidate_control_inputs(Unique_Node_List& worklist, Unique_Node_List& candidates) {
5970   // Follow non-control edges until we reach CFG nodes
5971   for (uint i = 0; i < worklist.size(); i++) {
< prev index next >