< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page

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

  59 #include "opto/loopnode.hpp"
  60 #include "opto/machnode.hpp"
  61 #include "opto/macro.hpp"
  62 #include "opto/matcher.hpp"
  63 #include "opto/mathexactnode.hpp"
  64 #include "opto/memnode.hpp"
  65 #include "opto/mulnode.hpp"
  66 #include "opto/narrowptrnode.hpp"
  67 #include "opto/node.hpp"
  68 #include "opto/opcodes.hpp"
  69 #include "opto/output.hpp"
  70 #include "opto/parse.hpp"
  71 #include "opto/phaseX.hpp"
  72 #include "opto/rootnode.hpp"
  73 #include "opto/runtime.hpp"
  74 #include "opto/stringopts.hpp"
  75 #include "opto/type.hpp"
  76 #include "opto/vector.hpp"
  77 #include "opto/vectornode.hpp"
  78 #include "runtime/globals_extension.hpp"

 383   // as dead to be conservative about the dead node count at any
 384   // given time.
 385   if (!dead->is_Con()) {
 386     record_dead_node(dead->_idx);
 387   }
 388   if (dead->is_macro()) {
 389     remove_macro_node(dead);
 390   }
 391   if (dead->is_expensive()) {
 392     remove_expensive_node(dead);
 393   }
 394   if (dead->Opcode() == Op_Opaque4) {
 395     remove_template_assertion_predicate_opaq(dead);
 396   }
 397   if (dead->is_ParsePredicate()) {
 398     remove_parse_predicate(dead->as_ParsePredicate());
 399   }
 400   if (dead->for_post_loop_opts_igvn()) {
 401     remove_from_post_loop_opts_igvn(dead);
 402   }



 403   if (dead->is_Call()) {
 404     remove_useless_late_inlines(                &_late_inlines, dead);
 405     remove_useless_late_inlines(         &_string_late_inlines, dead);
 406     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 407     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 408 
 409     if (dead->is_CallStaticJava()) {
 410       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 411     }
 412   }
 413   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 414   bs->unregister_potential_barrier_node(dead);
 415 }
 416 
 417 // Disconnect all useless nodes by disconnecting those at the boundary.
 418 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist) {
 419   uint next = 0;
 420   while (next < useful.size()) {
 421     Node *n = useful.at(next++);
 422     if (n->is_SafePoint()) {

 424       // beyond that point.
 425       n->as_SafePoint()->delete_replaced_nodes();
 426     }
 427     // Use raw traversal of out edges since this code removes out edges
 428     int max = n->outcnt();
 429     for (int j = 0; j < max; ++j) {
 430       Node* child = n->raw_out(j);
 431       if (!useful.member(child)) {
 432         assert(!child->is_top() || child != top(),
 433                "If top is cached in Compile object it is in useful list");
 434         // Only need to remove this out-edge to the useless node
 435         n->raw_del_out(j);
 436         --j;
 437         --max;
 438       }
 439     }
 440     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 441       assert(useful.member(n->unique_out()), "do not push a useless node");
 442       worklist.push(n->unique_out());
 443     }



 444   }
 445 
 446   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 447   remove_useless_nodes(_parse_predicates,   useful); // remove useless Parse Predicate nodes
 448   remove_useless_nodes(_template_assertion_predicate_opaqs, useful); // remove useless Assertion Predicate opaque nodes
 449   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 450   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass






 451   remove_useless_unstable_if_traps(useful);          // remove useless unstable_if traps
 452   remove_useless_coarsened_locks(useful);            // remove useless coarsened locks nodes
 453 #ifdef ASSERT
 454   if (_modified_nodes != nullptr) {
 455     _modified_nodes->remove_useless_nodes(useful.member_set());
 456   }
 457 #endif
 458 
 459   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 460   bs->eliminate_useless_gc_barriers(useful, this);
 461   // clean up the late inline lists
 462   remove_useless_late_inlines(                &_late_inlines, useful);
 463   remove_useless_late_inlines(         &_string_late_inlines, useful);
 464   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
 465   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 466   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
 467 }
 468 
 469 // ============================================================================
 470 //------------------------------CompileWrapper---------------------------------

 609 // the continuation bci for on stack replacement.
 610 
 611 
 612 Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
 613                   Options options, DirectiveSet* directive)
 614                 : Phase(Compiler),
 615                   _compile_id(ci_env->compile_id()),
 616                   _options(options),
 617                   _method(target),
 618                   _entry_bci(osr_bci),
 619                   _ilt(nullptr),
 620                   _stub_function(nullptr),
 621                   _stub_name(nullptr),
 622                   _stub_entry_point(nullptr),
 623                   _max_node_limit(MaxNodeLimit),
 624                   _post_loop_opts_phase(false),
 625                   _inlining_progress(false),
 626                   _inlining_incrementally(false),
 627                   _do_cleanup(false),
 628                   _has_reserved_stack_access(target->has_reserved_stack_access()),

 629 #ifndef PRODUCT
 630                   _igv_idx(0),
 631                   _trace_opto_output(directive->TraceOptoOutputOption),
 632 #endif
 633                   _has_method_handle_invokes(false),
 634                   _clinit_barrier_on_entry(false),
 635                   _stress_seed(0),
 636                   _comp_arena(mtCompiler),
 637                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 638                   _env(ci_env),
 639                   _directive(directive),
 640                   _log(ci_env->log()),
 641                   _failure_reason(nullptr),
 642                   _first_failure_details(nullptr),
 643                   _intrinsics        (comp_arena(), 0, 0, nullptr),
 644                   _macro_nodes       (comp_arena(), 8, 0, nullptr),
 645                   _parse_predicates  (comp_arena(), 8, 0, nullptr),
 646                   _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
 647                   _expensive_nodes   (comp_arena(), 8, 0, nullptr),
 648                   _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),

 649                   _unstable_if_traps (comp_arena(), 8, 0, nullptr),
 650                   _coarsened_locks   (comp_arena(), 8, 0, nullptr),
 651                   _congraph(nullptr),
 652                   NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 653                   _unique(0),
 654                   _dead_node_count(0),
 655                   _dead_node_list(comp_arena()),
 656                   _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 657                   _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 658                   _node_arena(&_node_arena_one),
 659                   _mach_constant_base_node(nullptr),
 660                   _Compile_types(mtCompiler),
 661                   _initial_gvn(nullptr),
 662                   _igvn_worklist(nullptr),
 663                   _types(nullptr),
 664                   _node_hash(nullptr),
 665                   _late_inlines(comp_arena(), 2, 0, nullptr),
 666                   _string_late_inlines(comp_arena(), 2, 0, nullptr),
 667                   _boxing_late_inlines(comp_arena(), 2, 0, nullptr),
 668                   _vector_reboxing_late_inlines(comp_arena(), 2, 0, nullptr),

 731 
 732   // GVN that will be run immediately on new nodes
 733   uint estimated_size = method()->code_size()*4+64;
 734   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 735   _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
 736   _types = new (comp_arena()) Type_Array(comp_arena());
 737   _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
 738   PhaseGVN gvn;
 739   set_initial_gvn(&gvn);
 740 
 741   print_inlining_init();
 742   { // Scope for timing the parser
 743     TracePhase tp("parse", &timers[_t_parser]);
 744 
 745     // Put top into the hash table ASAP.
 746     initial_gvn()->transform(top());
 747 
 748     // Set up tf(), start(), and find a CallGenerator.
 749     CallGenerator* cg = nullptr;
 750     if (is_osr_compilation()) {
 751       const TypeTuple *domain = StartOSRNode::osr_domain();
 752       const TypeTuple *range = TypeTuple::make_range(method()->signature());
 753       init_tf(TypeFunc::make(domain, range));
 754       StartNode* s = new StartOSRNode(root(), domain);
 755       initial_gvn()->set_type_bottom(s);
 756       init_start(s);
 757       cg = CallGenerator::for_osr(method(), entry_bci());
 758     } else {
 759       // Normal case.
 760       init_tf(TypeFunc::make(method()));
 761       StartNode* s = new StartNode(root(), tf()->domain());
 762       initial_gvn()->set_type_bottom(s);
 763       init_start(s);
 764       if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {
 765         // With java.lang.ref.reference.get() we must go through the
 766         // intrinsic - even when get() is the root
 767         // method of the compile - so that, if necessary, the value in
 768         // the referent field of the reference object gets recorded by
 769         // the pre-barrier code.
 770         cg = find_intrinsic(method(), false);
 771       }
 772       if (cg == nullptr) {
 773         float past_uses = method()->interpreter_invocation_count();
 774         float expected_uses = past_uses;
 775         cg = CallGenerator::for_inline(method(), expected_uses);
 776       }
 777     }
 778     if (failing())  return;
 779     if (cg == nullptr) {
 780       const char* reason = InlineTree::check_can_parse(method());
 781       assert(reason != nullptr, "expect reason for parse failure");

 867     print_ideal_ir("print_ideal");
 868   }
 869 #endif
 870 
 871 #ifdef ASSERT
 872   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 873   bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
 874 #endif
 875 
 876   // Dump compilation data to replay it.
 877   if (directive->DumpReplayOption) {
 878     env()->dump_replay_data(_compile_id);
 879   }
 880   if (directive->DumpInlineOption && (ilt() != nullptr)) {
 881     env()->dump_inline_data(_compile_id);
 882   }
 883 
 884   // Now that we know the size of all the monitors we can add a fixed slot
 885   // for the original deopt pc.
 886   int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);










 887   set_fixed_slots(next_slot);
 888 
 889   // Compute when to use implicit null checks. Used by matching trap based
 890   // nodes and NullCheck optimization.
 891   set_allowed_deopt_reasons();
 892 
 893   // Now generate code
 894   Code_Gen();
 895 }
 896 
 897 //------------------------------Compile----------------------------------------
 898 // Compile a runtime stub
 899 Compile::Compile( ciEnv* ci_env,
 900                   TypeFunc_generator generator,
 901                   address stub_function,
 902                   const char *stub_name,
 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_entry_point(nullptr),
 915     _max_node_limit(MaxNodeLimit),
 916     _post_loop_opts_phase(false),
 917     _inlining_progress(false),
 918     _inlining_incrementally(false),
 919     _has_reserved_stack_access(false),

 920 #ifndef PRODUCT
 921     _igv_idx(0),
 922     _trace_opto_output(directive->TraceOptoOutputOption),
 923 #endif
 924     _has_method_handle_invokes(false),
 925     _clinit_barrier_on_entry(false),
 926     _stress_seed(0),
 927     _comp_arena(mtCompiler),
 928     _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 929     _env(ci_env),
 930     _directive(directive),
 931     _log(ci_env->log()),
 932     _failure_reason(nullptr),
 933     _first_failure_details(nullptr),
 934     _congraph(nullptr),
 935     NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 936     _unique(0),
 937     _dead_node_count(0),
 938     _dead_node_list(comp_arena()),
 939     _node_arena_one(mtCompiler),

1040 
1041   _fixed_slots = 0;
1042   set_has_split_ifs(false);
1043   set_has_loops(false); // first approximation
1044   set_has_stringbuilder(false);
1045   set_has_boxed_value(false);
1046   _trap_can_recompile = false;  // no traps emitted yet
1047   _major_progress = true; // start out assuming good things will happen
1048   set_has_unsafe_access(false);
1049   set_max_vector_size(0);
1050   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1051   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1052   set_decompile_count(0);
1053 
1054 #ifndef PRODUCT
1055   Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1056 #endif
1057 
1058   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1059   _loop_opts_cnt = LoopOptsCount;




1060   set_do_inlining(Inline);
1061   set_max_inline_size(MaxInlineSize);
1062   set_freq_inline_size(FreqInlineSize);
1063   set_do_scheduling(OptoScheduling);
1064 
1065   set_do_vector_loop(false);
1066   set_has_monitors(false);
1067 
1068   if (AllowVectorizeOnDemand) {
1069     if (has_method() && _directive->VectorizeOption) {
1070       set_do_vector_loop(true);
1071       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());})
1072     } else if (has_method() && method()->name() != 0 &&
1073                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1074       set_do_vector_loop(true);
1075     }
1076   }
1077   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1078   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());})
1079 

1328   // If this method has already thrown a range-check,
1329   // assume it was because we already tried range smearing
1330   // and it failed.
1331   uint already_trapped = trap_count(Deoptimization::Reason_range_check);
1332   return !already_trapped;
1333 }
1334 
1335 
1336 //------------------------------flatten_alias_type-----------------------------
1337 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1338   assert(do_aliasing(), "Aliasing should be enabled");
1339   int offset = tj->offset();
1340   TypePtr::PTR ptr = tj->ptr();
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       if (!ik->equals(canonical_holder) || tj->offset() != offset) {
1489         if( is_known_inst ) {
1490           tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, nullptr, offset, to->instance_id());
1491         } else {
1492           tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, nullptr, offset);
1493         }
1494       }
1495     }
1496   }
1497 
1498   // Klass pointers to object array klasses need some flattening
1499   const TypeKlassPtr *tk = tj->isa_klassptr();
1500   if( tk ) {
1501     // If we are referencing a field within a Klass, we need
1502     // to assume the worst case of an Object.  Both exact and
1503     // inexact types must flatten to the same alias class so
1504     // use NotNull as the PTR.
1505     if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1506       tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1507                                        env()->Object_klass(),
1508                                        offset);
1509     }
1510 
1511     if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1512       ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1513       if (!k || !k->is_loaded()) {                  // Only fails for some -Xcomp runs
1514         tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), offset);
1515       } else {
1516         tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, offset);
1517       }
1518     }
1519 
1520     // Check for precise loads from the primary supertype array and force them
1521     // to the supertype cache alias index.  Check for generic array loads from
1522     // the primary supertype array and also force them to the supertype cache
1523     // alias index.  Since the same load can reach both, we need to merge
1524     // these 2 disparate memories into the same alias class.  Since the
1525     // primary supertype array is read-only, there's no chance of confusion
1526     // where we bypass an array load and an array store.
1527     int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1528     if (offset == Type::OffsetBot ||
1529         (offset >= primary_supers_offset &&
1530          offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1531         offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1532       offset = in_bytes(Klass::secondary_super_cache_offset());
1533       tj = tk = tk->with_offset(offset);
1534     }
1535   }
1536 
1537   // Flatten all Raw pointers together.
1538   if (tj->base() == Type::RawPtr)
1539     tj = TypeRawPtr::BOTTOM;

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



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

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

1706     if (flat->isa_aryptr()) {
1707 #ifdef ASSERT
1708       const int header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1709       // (T_BYTE has the weakest alignment and size restrictions...)
1710       assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1711 #endif

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







1714       }
1715     }
1716     if (flat->isa_klassptr()) {
1717       if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1718         alias_type(idx)->set_rewritable(false);
1719       if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
1720         alias_type(idx)->set_rewritable(false);
1721       if (flat->offset() == in_bytes(Klass::access_flags_offset()))
1722         alias_type(idx)->set_rewritable(false);
1723       if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1724         alias_type(idx)->set_rewritable(false);


1725       if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1726         alias_type(idx)->set_rewritable(false);
1727     }
1728     // %%% (We would like to finalize JavaThread::threadObj_offset(),
1729     // but the base pointer type is not distinctive enough to identify
1730     // references into JavaThread.)
1731 
1732     // Check for final fields.
1733     const TypeInstPtr* tinst = flat->isa_instptr();
1734     if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1735       ciField* field;
1736       if (tinst->const_oop() != nullptr &&
1737           tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1738           tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1739         // static field
1740         ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1741         field = k->get_field_by_offset(tinst->offset(), true);




1742       } else {
1743         ciInstanceKlass *k = tinst->instance_klass();
1744         field = k->get_field_by_offset(tinst->offset(), false);
1745       }
1746       assert(field == nullptr ||
1747              original_field == nullptr ||
1748              (field->holder() == original_field->holder() &&
1749               field->offset_in_bytes() == original_field->offset_in_bytes() &&
1750               field->is_static() == original_field->is_static()), "wrong field?");
1751       // Set field() and is_rewritable() attributes.
1752       if (field != nullptr)  alias_type(idx)->set_field(field);







1753     }
1754   }
1755 
1756   // Fill the cache for next time.
1757   ace->_adr_type = adr_type;
1758   ace->_index    = idx;
1759   assert(alias_type(adr_type) == alias_type(idx),  "type must be installed");

1760 
1761   // Might as well try to fill the cache for the flattened version, too.
1762   AliasCacheEntry* face = probe_alias_cache(flat);
1763   if (face->_adr_type == nullptr) {
1764     face->_adr_type = flat;
1765     face->_index    = idx;
1766     assert(alias_type(flat) == alias_type(idx), "flat type must work too");

1767   }
1768 
1769   return alias_type(idx);
1770 }
1771 
1772 
1773 Compile::AliasType* Compile::alias_type(ciField* field) {
1774   const TypeOopPtr* t;
1775   if (field->is_static())
1776     t = TypeInstPtr::make(field->holder()->java_mirror());
1777   else
1778     t = TypeOopPtr::make_from_klass_raw(field->holder());
1779   AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1780   assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1781   return atp;
1782 }
1783 
1784 
1785 //------------------------------have_alias_type--------------------------------
1786 bool Compile::have_alias_type(const TypePtr* adr_type) {

1866   assert(!C->major_progress(), "not cleared");
1867 
1868   if (_for_post_loop_igvn.length() > 0) {
1869     while (_for_post_loop_igvn.length() > 0) {
1870       Node* n = _for_post_loop_igvn.pop();
1871       n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1872       igvn._worklist.push(n);
1873     }
1874     igvn.optimize();
1875     if (failing()) return;
1876     assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1877     assert(C->parse_predicate_count() == 0, "all parse predicates should have been removed now");
1878 
1879     // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1880     if (C->major_progress()) {
1881       C->clear_major_progress(); // ensure that major progress is now clear
1882     }
1883   }
1884 }
1885 




























































































































































































































































































































































































































1886 void Compile::record_unstable_if_trap(UnstableIfTrap* trap) {
1887   if (OptimizeUnstableIf) {
1888     _unstable_if_traps.append(trap);
1889   }
1890 }
1891 
1892 void Compile::remove_useless_unstable_if_traps(Unique_Node_List& useful) {
1893   for (int i = _unstable_if_traps.length() - 1; i >= 0; i--) {
1894     UnstableIfTrap* trap = _unstable_if_traps.at(i);
1895     Node* n = trap->uncommon_trap();
1896     if (!useful.member(n)) {
1897       _unstable_if_traps.delete_at(i); // replaces i-th with last element which is known to be useful (already processed)
1898     }
1899   }
1900 }
1901 
1902 // Remove the unstable if trap associated with 'unc' from candidates. It is either dead
1903 // or fold-compares case. Return true if succeed or not found.
1904 //
1905 // In rare cases, the found trap has been processed. It is too late to delete it. Return

1941       assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
1942       Bytecodes::Code c = iter.cur_bc();
1943       Node* lhs = nullptr;
1944       Node* rhs = nullptr;
1945       if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
1946         lhs = unc->peek_operand(0);
1947         rhs = unc->peek_operand(1);
1948       } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
1949         lhs = unc->peek_operand(0);
1950       }
1951 
1952       ResourceMark rm;
1953       const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
1954       assert(live_locals.is_valid(), "broken liveness info");
1955       int len = (int)live_locals.size();
1956 
1957       for (int i = 0; i < len; i++) {
1958         Node* local = unc->local(jvms, i);
1959         // kill local using the liveness of next_bci.
1960         // give up when the local looks like an operand to secure reexecution.
1961         if (!live_locals.at(i) && !local->is_top() && local != lhs && local!= rhs) {
1962           uint idx = jvms->locoff() + i;
1963 #ifdef ASSERT
1964           if (PrintOpto && Verbose) {
1965             tty->print("[unstable_if] kill local#%d: ", idx);
1966             local->dump();
1967             tty->cr();
1968           }
1969 #endif
1970           igvn.replace_input_of(unc, idx, top());
1971           modified = true;
1972         }
1973       }
1974     }
1975 
1976     // keep the mondified trap for late query
1977     if (modified) {
1978       trap->set_modified();
1979     } else {
1980       _unstable_if_traps.delete_at(i);
1981     }
1982   }
1983   igvn.optimize();
1984 }
1985 
1986 // StringOpts and late inlining of string methods
1987 void Compile::inline_string_calls(bool parse_time) {
1988   {
1989     // remove useless nodes to make the usage analysis simpler
1990     ResourceMark rm;
1991     PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
1992   }
1993 
1994   {
1995     ResourceMark rm;
1996     print_method(PHASE_BEFORE_STRINGOPTS, 3);

2151 
2152   if (_string_late_inlines.length() > 0) {
2153     assert(has_stringbuilder(), "inconsistent");
2154 
2155     inline_string_calls(false);
2156 
2157     if (failing())  return;
2158 
2159     inline_incrementally_cleanup(igvn);
2160   }
2161 
2162   set_inlining_incrementally(false);
2163 }
2164 
2165 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2166   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2167   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2168   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2169   // as if "inlining_incrementally() == true" were set.
2170   assert(inlining_incrementally() == false, "not allowed");
2171   assert(_modified_nodes == nullptr, "not allowed");



2172   assert(_late_inlines.length() > 0, "sanity");
2173 
2174   while (_late_inlines.length() > 0) {
2175     igvn_worklist()->ensure_empty(); // should be done with igvn
2176 
2177     while (inline_incrementally_one()) {
2178       assert(!failing(), "inconsistent");
2179     }
2180     if (failing())  return;
2181 
2182     inline_incrementally_cleanup(igvn);
2183   }

2184 }
2185 
2186 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2187   if (_loop_opts_cnt > 0) {
2188     while (major_progress() && (_loop_opts_cnt > 0)) {
2189       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2190       PhaseIdealLoop::optimize(igvn, mode);
2191       _loop_opts_cnt--;
2192       if (failing())  return false;
2193       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2194     }
2195   }
2196   return true;
2197 }
2198 
2199 // Remove edges from "root" to each SafePoint at a backward branch.
2200 // They were inserted during parsing (see add_safepoint()) to make
2201 // infinite loops without calls or exceptions visible to root, i.e.,
2202 // useful.
2203 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2310     print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2311   }
2312   assert(!has_vbox_nodes(), "sanity");
2313 
2314   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2315     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2316     igvn_worklist()->ensure_empty(); // should be done with igvn
2317     {
2318       ResourceMark rm;
2319       PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2320     }
2321     igvn.reset_from_gvn(initial_gvn());
2322     igvn.optimize();
2323     if (failing()) return;
2324   }
2325 
2326   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2327   // safepoints
2328   remove_root_to_sfpts_edges(igvn);
2329 





2330   if (failing())  return;
2331 
2332   // Perform escape analysis
2333   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2334     if (has_loops()) {
2335       // Cleanup graph (remove dead nodes).
2336       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2337       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2338       if (failing())  return;
2339     }
2340     bool progress;
2341     print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2342     do {
2343       ConnectionGraph::do_analysis(this, &igvn);
2344 
2345       if (failing())  return;
2346 
2347       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2348 
2349       // Optimize out fields loads from scalar replaceable allocations.

2433   if (failing())  return;
2434 
2435   // Loop transforms on the ideal graph.  Range Check Elimination,
2436   // peeling, unrolling, etc.
2437   if (!optimize_loops(igvn, LoopOptsDefault)) {
2438     return;
2439   }
2440 
2441   if (failing())  return;
2442 
2443   C->clear_major_progress(); // ensure that major progress is now clear
2444 
2445   process_for_post_loop_opts_igvn(igvn);
2446 
2447   if (failing())  return;
2448 
2449 #ifdef ASSERT
2450   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2451 #endif
2452 








2453   {
2454     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2455     print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);
2456     PhaseMacroExpand  mex(igvn);
2457     if (mex.expand_macro_nodes()) {
2458       assert(failing(), "must bail out w/ explicit message");
2459       return;
2460     }
2461     print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
2462   }
2463 




2464   {
2465     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2466     if (bs->expand_barriers(this, igvn)) {
2467       assert(failing(), "must bail out w/ explicit message");
2468       return;
2469     }
2470     print_method(PHASE_BARRIER_EXPANSION, 2);
2471   }
2472 
2473   if (C->max_vector_size() > 0) {
2474     C->optimize_logic_cones(igvn);
2475     igvn.optimize();
2476     if (failing()) return;
2477   }
2478 
2479   DEBUG_ONLY( _modified_nodes = nullptr; )

2480 
2481   assert(igvn._worklist.size() == 0, "not empty");
2482 
2483   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2484 
2485   if (_late_inlines.length() > 0) {
2486     // More opportunities to optimize virtual and MH calls.
2487     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2488     process_late_inline_calls_no_inline(igvn);
2489     if (failing())  return;
2490   }
2491  } // (End scope of igvn; run destructor if necessary for asserts.)
2492 
2493  check_no_dead_use();
2494 
2495  process_print_inlining();
2496 
2497  // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
2498  // to remove hashes to unlock nodes for modifications.
2499  C->node_hash()->clear();
2500 
2501  // A method with only infinite loops has no edges entering loops from root
2502  {
2503    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2504    if (final_graph_reshaping()) {
2505      assert(failing(), "must bail out w/ explicit message");
2506      return;
2507    }
2508  }
2509 
2510  print_method(PHASE_OPTIMIZE_FINISHED, 2);

3098             // Accumulate any precedence edges
3099             if (mem->in(i) != nullptr) {
3100               n->add_prec(mem->in(i));
3101             }
3102           }
3103           // Everything above this point has been processed.
3104           done = true;
3105         }
3106         // Eliminate the previous StoreCM
3107         prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
3108         assert(mem->outcnt() == 0, "should be dead");
3109         mem->disconnect_inputs(this);
3110       } else {
3111         prev = mem;
3112       }
3113       mem = prev->in(MemNode::Memory);
3114     }
3115   }
3116 }
3117 

3118 //------------------------------final_graph_reshaping_impl----------------------
3119 // Implement items 1-5 from final_graph_reshaping below.
3120 void Compile::final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
3121 
3122   if ( n->outcnt() == 0 ) return; // dead node
3123   uint nop = n->Opcode();
3124 
3125   // Check for 2-input instruction with "last use" on right input.
3126   // Swap to left input.  Implements item (2).
3127   if( n->req() == 3 &&          // two-input instruction
3128       n->in(1)->outcnt() > 1 && // left use is NOT a last use
3129       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
3130       n->in(2)->outcnt() == 1 &&// right use IS a last use
3131       !n->in(2)->is_Con() ) {   // right use is not a constant
3132     // Check for commutative opcode
3133     switch( nop ) {
3134     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
3135     case Op_MaxI:  case Op_MaxL:  case Op_MaxF:  case Op_MaxD:
3136     case Op_MinI:  case Op_MinL:  case Op_MinF:  case Op_MinD:
3137     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:

3250       if (n->outcnt() > 1 &&
3251           !n->is_Proj() &&
3252           nop != Op_CreateEx &&
3253           nop != Op_CheckCastPP &&
3254           nop != Op_DecodeN &&
3255           nop != Op_DecodeNKlass &&
3256           !n->is_Mem() &&
3257           !n->is_Phi()) {
3258         Node *x = n->clone();
3259         call->set_req(TypeFunc::Parms, x);
3260       }
3261     }
3262     break;
3263   }
3264 
3265   case Op_StoreCM:
3266     {
3267       // Convert OopStore dependence into precedence edge
3268       Node* prec = n->in(MemNode::OopStore);
3269       n->del_req(MemNode::OopStore);
3270       n->add_prec(prec);















3271       eliminate_redundant_card_marks(n);
3272     }
3273 
3274     // fall through
3275 
3276   case Op_StoreB:
3277   case Op_StoreC:
3278   case Op_StoreI:
3279   case Op_StoreL:
3280   case Op_CompareAndSwapB:
3281   case Op_CompareAndSwapS:
3282   case Op_CompareAndSwapI:
3283   case Op_CompareAndSwapL:
3284   case Op_CompareAndSwapP:
3285   case Op_CompareAndSwapN:
3286   case Op_WeakCompareAndSwapB:
3287   case Op_WeakCompareAndSwapS:
3288   case Op_WeakCompareAndSwapI:
3289   case Op_WeakCompareAndSwapL:
3290   case Op_WeakCompareAndSwapP:

3871           // Replace all nodes with identical edges as m with m
3872           k->subsume_by(m, this);
3873         }
3874       }
3875     }
3876     break;
3877   }
3878   case Op_CmpUL: {
3879     if (!Matcher::has_match_rule(Op_CmpUL)) {
3880       // No support for unsigned long comparisons
3881       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
3882       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
3883       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
3884       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
3885       Node* andl = new AndLNode(orl, remove_sign_mask);
3886       Node* cmp = new CmpLNode(andl, n->in(2));
3887       n->subsume_by(cmp, this);
3888     }
3889     break;
3890   }







3891   default:
3892     assert(!n->is_Call(), "");
3893     assert(!n->is_Mem(), "");
3894     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
3895     break;
3896   }
3897 }
3898 
3899 //------------------------------final_graph_reshaping_walk---------------------
3900 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3901 // requires that the walk visits a node's inputs before visiting the node.
3902 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
3903   Unique_Node_List sfpt;
3904 
3905   frc._visited.set(root->_idx); // first, mark node as visited
3906   uint cnt = root->req();
3907   Node *n = root;
3908   uint  i = 0;
3909   while (true) {
3910     if (i < cnt) {

4250   }
4251 }
4252 
4253 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4254   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4255 }
4256 
4257 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4258   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4259 }
4260 
4261 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4262   if (holder->is_initialized()) {
4263     return false;
4264   }
4265   if (holder->is_being_initialized()) {
4266     if (accessing_method->holder() == holder) {
4267       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4268       // <init>, or a static method. In all those cases, there was an initialization
4269       // barrier on the holder klass passed.
4270       if (accessing_method->is_static_initializer() ||
4271           accessing_method->is_object_initializer() ||
4272           accessing_method->is_static()) {
4273         return false;
4274       }
4275     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4276       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4277       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4278       // child class can become fully initialized while its parent class is still being initialized.
4279       if (accessing_method->is_static_initializer()) {
4280         return false;
4281       }
4282     }
4283     ciMethod* root = method(); // the root method of compilation
4284     if (root != accessing_method) {
4285       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4286     }
4287   }
4288   return true;
4289 }
4290 
4291 #ifndef PRODUCT
4292 //------------------------------verify_bidirectional_edges---------------------
4293 // For each input edge to a node (ie - for each Use-Def edge), verify that
4294 // there is a corresponding Def-Use edge.
4295 void Compile::verify_bidirectional_edges(Unique_Node_List &visited) {
4296   // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4297   uint stack_size = live_nodes() >> 4;
4298   Node_List nstack(MAX2(stack_size, (uint)OptoNodeListSize));
4299   nstack.push(_root);

4315       if (in != nullptr && !in->is_top()) {
4316         // Count instances of `next`
4317         int cnt = 0;
4318         for (uint idx = 0; idx < in->_outcnt; idx++) {
4319           if (in->_out[idx] == n) {
4320             cnt++;
4321           }
4322         }
4323         assert(cnt > 0, "Failed to find Def-Use edge.");
4324         // Check for duplicate edges
4325         // walk the input array downcounting the input edges to n
4326         for (uint j = 0; j < length; j++) {
4327           if (n->in(j) == in) {
4328             cnt--;
4329           }
4330         }
4331         assert(cnt == 0, "Mismatched edge count.");
4332       } else if (in == nullptr) {
4333         assert(i == 0 || i >= n->req() ||
4334                n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||

4335                (n->is_Unlock() && i == (n->req() - 1)) ||
4336                (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4337               "only region, phi, arraycopy, unlock or membar nodes have null data edges");
4338       } else {
4339         assert(in->is_top(), "sanity");
4340         // Nothing to check.
4341       }
4342     }
4343   }
4344 }
4345 
4346 //------------------------------verify_graph_edges---------------------------
4347 // Walk the Graph and verify that there is a one-to-one correspondence
4348 // between Use-Def edges and Def-Use edges in the graph.
4349 void Compile::verify_graph_edges(bool no_dead_code) {
4350   if (VerifyGraphEdges) {
4351     Unique_Node_List visited;
4352 
4353     // Call graph walk to check edges
4354     verify_bidirectional_edges(visited);
4355     if (no_dead_code) {
4356       // Now make sure that no visited node is used by an unvisited node.
4357       bool dead_nodes = false;

4447 // (1) subklass is already limited to a subtype of superklass => always ok
4448 // (2) subklass does not overlap with superklass => always fail
4449 // (3) superklass has NO subtypes and we can check with a simple compare.
4450 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
4451   if (skip) {
4452     return SSC_full_test;       // Let caller generate the general case.
4453   }
4454 
4455   if (subk->is_java_subtype_of(superk)) {
4456     return SSC_always_true; // (0) and (1)  this test cannot fail
4457   }
4458 
4459   if (!subk->maybe_java_subtype_of(superk)) {
4460     return SSC_always_false; // (2) true path dead; no dynamic test needed
4461   }
4462 
4463   const Type* superelem = superk;
4464   if (superk->isa_aryklassptr()) {
4465     int ignored;
4466     superelem = superk->is_aryklassptr()->base_element_type(ignored);









4467   }
4468 
4469   if (superelem->isa_instklassptr()) {
4470     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4471     if (!ik->has_subklass()) {
4472       if (!ik->is_final()) {
4473         // Add a dependency if there is a chance of a later subclass.
4474         dependencies()->assert_leaf_type(ik);
4475       }
4476       if (!superk->maybe_java_subtype_of(subk)) {
4477         return SSC_always_false;
4478       }
4479       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
4480     }
4481   } else {
4482     // A primitive array type has no subtypes.
4483     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
4484   }
4485 
4486   return SSC_full_test;

5007       const Type* t = igvn.type_or_null(n);
5008       assert((t == nullptr) || (t == t->remove_speculative()), "no more speculative types");
5009       if (n->is_Type()) {
5010         t = n->as_Type()->type();
5011         assert(t == t->remove_speculative(), "no more speculative types");
5012       }
5013       // Iterate over outs - endless loops is unreachable from below
5014       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
5015         Node *m = n->fast_out(i);
5016         if (not_a_node(m)) {
5017           continue;
5018         }
5019         worklist.push(m);
5020       }
5021     }
5022     igvn.check_no_speculative_types();
5023 #endif
5024   }
5025 }
5026 





















5027 // Auxiliary methods to support randomized stressing/fuzzing.
5028 
5029 int Compile::random() {
5030   _stress_seed = os::next_random(_stress_seed);
5031   return static_cast<int>(_stress_seed);
5032 }
5033 
5034 // This method can be called the arbitrary number of times, with current count
5035 // as the argument. The logic allows selecting a single candidate from the
5036 // running list of candidates as follows:
5037 //    int count = 0;
5038 //    Cand* selected = null;
5039 //    while(cand = cand->next()) {
5040 //      if (randomized_select(++count)) {
5041 //        selected = cand;
5042 //      }
5043 //    }
5044 //
5045 // Including count equalizes the chances any candidate is "selected".
5046 // This is useful when we don't have the complete list of candidates to choose

  39 #include "gc/shared/barrierSet.hpp"
  40 #include "gc/shared/c2/barrierSetC2.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "jvm_io.h"
  43 #include "memory/allocation.hpp"
  44 #include "memory/resourceArea.hpp"
  45 #include "opto/addnode.hpp"
  46 #include "opto/block.hpp"
  47 #include "opto/c2compiler.hpp"
  48 #include "opto/callGenerator.hpp"
  49 #include "opto/callnode.hpp"
  50 #include "opto/castnode.hpp"
  51 #include "opto/cfgnode.hpp"
  52 #include "opto/chaitin.hpp"
  53 #include "opto/compile.hpp"
  54 #include "opto/connode.hpp"
  55 #include "opto/convertnode.hpp"
  56 #include "opto/divnode.hpp"
  57 #include "opto/escape.hpp"
  58 #include "opto/idealGraphPrinter.hpp"
  59 #include "opto/inlinetypenode.hpp"
  60 #include "opto/loopnode.hpp"
  61 #include "opto/machnode.hpp"
  62 #include "opto/macro.hpp"
  63 #include "opto/matcher.hpp"
  64 #include "opto/mathexactnode.hpp"
  65 #include "opto/memnode.hpp"
  66 #include "opto/mulnode.hpp"
  67 #include "opto/narrowptrnode.hpp"
  68 #include "opto/node.hpp"
  69 #include "opto/opcodes.hpp"
  70 #include "opto/output.hpp"
  71 #include "opto/parse.hpp"
  72 #include "opto/phaseX.hpp"
  73 #include "opto/rootnode.hpp"
  74 #include "opto/runtime.hpp"
  75 #include "opto/stringopts.hpp"
  76 #include "opto/type.hpp"
  77 #include "opto/vector.hpp"
  78 #include "opto/vectornode.hpp"
  79 #include "runtime/globals_extension.hpp"

 384   // as dead to be conservative about the dead node count at any
 385   // given time.
 386   if (!dead->is_Con()) {
 387     record_dead_node(dead->_idx);
 388   }
 389   if (dead->is_macro()) {
 390     remove_macro_node(dead);
 391   }
 392   if (dead->is_expensive()) {
 393     remove_expensive_node(dead);
 394   }
 395   if (dead->Opcode() == Op_Opaque4) {
 396     remove_template_assertion_predicate_opaq(dead);
 397   }
 398   if (dead->is_ParsePredicate()) {
 399     remove_parse_predicate(dead->as_ParsePredicate());
 400   }
 401   if (dead->for_post_loop_opts_igvn()) {
 402     remove_from_post_loop_opts_igvn(dead);
 403   }
 404   if (dead->is_InlineType()) {
 405     remove_inline_type(dead);
 406   }
 407   if (dead->is_Call()) {
 408     remove_useless_late_inlines(                &_late_inlines, dead);
 409     remove_useless_late_inlines(         &_string_late_inlines, dead);
 410     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 411     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 412 
 413     if (dead->is_CallStaticJava()) {
 414       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 415     }
 416   }
 417   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 418   bs->unregister_potential_barrier_node(dead);
 419 }
 420 
 421 // Disconnect all useless nodes by disconnecting those at the boundary.
 422 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist) {
 423   uint next = 0;
 424   while (next < useful.size()) {
 425     Node *n = useful.at(next++);
 426     if (n->is_SafePoint()) {

 428       // beyond that point.
 429       n->as_SafePoint()->delete_replaced_nodes();
 430     }
 431     // Use raw traversal of out edges since this code removes out edges
 432     int max = n->outcnt();
 433     for (int j = 0; j < max; ++j) {
 434       Node* child = n->raw_out(j);
 435       if (!useful.member(child)) {
 436         assert(!child->is_top() || child != top(),
 437                "If top is cached in Compile object it is in useful list");
 438         // Only need to remove this out-edge to the useless node
 439         n->raw_del_out(j);
 440         --j;
 441         --max;
 442       }
 443     }
 444     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 445       assert(useful.member(n->unique_out()), "do not push a useless node");
 446       worklist.push(n->unique_out());
 447     }
 448     if (n->outcnt() == 0) {
 449       worklist.push(n);
 450     }
 451   }
 452 
 453   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 454   remove_useless_nodes(_parse_predicates,   useful); // remove useless Parse Predicate nodes
 455   remove_useless_nodes(_template_assertion_predicate_opaqs, useful); // remove useless Assertion Predicate opaque nodes
 456   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 457   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
 458   remove_useless_nodes(_inline_type_nodes,  useful); // remove useless inline type nodes
 459 #ifdef ASSERT
 460   if (_modified_nodes != nullptr) {
 461     _modified_nodes->remove_useless_nodes(useful.member_set());
 462   }
 463 #endif
 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*/);)
 480 }
 481 
 482 // ============================================================================
 483 //------------------------------CompileWrapper---------------------------------

 622 // the continuation bci for on stack replacement.
 623 
 624 
 625 Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
 626                   Options options, DirectiveSet* directive)
 627                 : Phase(Compiler),
 628                   _compile_id(ci_env->compile_id()),
 629                   _options(options),
 630                   _method(target),
 631                   _entry_bci(osr_bci),
 632                   _ilt(nullptr),
 633                   _stub_function(nullptr),
 634                   _stub_name(nullptr),
 635                   _stub_entry_point(nullptr),
 636                   _max_node_limit(MaxNodeLimit),
 637                   _post_loop_opts_phase(false),
 638                   _inlining_progress(false),
 639                   _inlining_incrementally(false),
 640                   _do_cleanup(false),
 641                   _has_reserved_stack_access(target->has_reserved_stack_access()),
 642                   _has_circular_inline_type(false),
 643 #ifndef PRODUCT
 644                   _igv_idx(0),
 645                   _trace_opto_output(directive->TraceOptoOutputOption),
 646 #endif
 647                   _has_method_handle_invokes(false),
 648                   _clinit_barrier_on_entry(false),
 649                   _stress_seed(0),
 650                   _comp_arena(mtCompiler),
 651                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 652                   _env(ci_env),
 653                   _directive(directive),
 654                   _log(ci_env->log()),
 655                   _failure_reason(nullptr),
 656                   _first_failure_details(nullptr),
 657                   _intrinsics        (comp_arena(), 0, 0, nullptr),
 658                   _macro_nodes       (comp_arena(), 8, 0, nullptr),
 659                   _parse_predicates  (comp_arena(), 8, 0, nullptr),
 660                   _template_assertion_predicate_opaqs (comp_arena(), 8, 0, nullptr),
 661                   _expensive_nodes   (comp_arena(), 8, 0, nullptr),
 662                   _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
 663                   _inline_type_nodes (comp_arena(), 8, 0, nullptr),
 664                   _unstable_if_traps (comp_arena(), 8, 0, nullptr),
 665                   _coarsened_locks   (comp_arena(), 8, 0, nullptr),
 666                   _congraph(nullptr),
 667                   NOT_PRODUCT(_igv_printer(nullptr) COMMA)
 668                   _unique(0),
 669                   _dead_node_count(0),
 670                   _dead_node_list(comp_arena()),
 671                   _node_arena_one(mtCompiler, Arena::Tag::tag_node),
 672                   _node_arena_two(mtCompiler, Arena::Tag::tag_node),
 673                   _node_arena(&_node_arena_one),
 674                   _mach_constant_base_node(nullptr),
 675                   _Compile_types(mtCompiler),
 676                   _initial_gvn(nullptr),
 677                   _igvn_worklist(nullptr),
 678                   _types(nullptr),
 679                   _node_hash(nullptr),
 680                   _late_inlines(comp_arena(), 2, 0, nullptr),
 681                   _string_late_inlines(comp_arena(), 2, 0, nullptr),
 682                   _boxing_late_inlines(comp_arena(), 2, 0, nullptr),
 683                   _vector_reboxing_late_inlines(comp_arena(), 2, 0, nullptr),

 746 
 747   // GVN that will be run immediately on new nodes
 748   uint estimated_size = method()->code_size()*4+64;
 749   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 750   _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
 751   _types = new (comp_arena()) Type_Array(comp_arena());
 752   _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
 753   PhaseGVN gvn;
 754   set_initial_gvn(&gvn);
 755 
 756   print_inlining_init();
 757   { // Scope for timing the parser
 758     TracePhase tp("parse", &timers[_t_parser]);
 759 
 760     // Put top into the hash table ASAP.
 761     initial_gvn()->transform(top());
 762 
 763     // Set up tf(), start(), and find a CallGenerator.
 764     CallGenerator* cg = nullptr;
 765     if (is_osr_compilation()) {
 766       init_tf(TypeFunc::make(method(), /* is_osr_compilation = */ true));
 767       StartNode* s = new StartOSRNode(root(), tf()->domain_sig());


 768       initial_gvn()->set_type_bottom(s);
 769       init_start(s);
 770       cg = CallGenerator::for_osr(method(), entry_bci());
 771     } else {
 772       // Normal case.
 773       init_tf(TypeFunc::make(method()));
 774       StartNode* s = new StartNode(root(), tf()->domain_cc());
 775       initial_gvn()->set_type_bottom(s);
 776       init_start(s);
 777       if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {
 778         // With java.lang.ref.reference.get() we must go through the
 779         // intrinsic - even when get() is the root
 780         // method of the compile - so that, if necessary, the value in
 781         // the referent field of the reference object gets recorded by
 782         // the pre-barrier code.
 783         cg = find_intrinsic(method(), false);
 784       }
 785       if (cg == nullptr) {
 786         float past_uses = method()->interpreter_invocation_count();
 787         float expected_uses = past_uses;
 788         cg = CallGenerator::for_inline(method(), expected_uses);
 789       }
 790     }
 791     if (failing())  return;
 792     if (cg == nullptr) {
 793       const char* reason = InlineTree::check_can_parse(method());
 794       assert(reason != nullptr, "expect reason for parse failure");

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

1064 
1065   _fixed_slots = 0;
1066   set_has_split_ifs(false);
1067   set_has_loops(false); // first approximation
1068   set_has_stringbuilder(false);
1069   set_has_boxed_value(false);
1070   _trap_can_recompile = false;  // no traps emitted yet
1071   _major_progress = true; // start out assuming good things will happen
1072   set_has_unsafe_access(false);
1073   set_max_vector_size(0);
1074   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1075   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1076   set_decompile_count(0);
1077 
1078 #ifndef PRODUCT
1079   Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1080 #endif
1081 
1082   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1083   _loop_opts_cnt = LoopOptsCount;
1084   _has_flat_accesses = false;
1085   _flat_accesses_share_alias = true;
1086   _scalarize_in_safepoints = false;
1087 
1088   set_do_inlining(Inline);
1089   set_max_inline_size(MaxInlineSize);
1090   set_freq_inline_size(FreqInlineSize);
1091   set_do_scheduling(OptoScheduling);
1092 
1093   set_do_vector_loop(false);
1094   set_has_monitors(false);
1095 
1096   if (AllowVectorizeOnDemand) {
1097     if (has_method() && _directive->VectorizeOption) {
1098       set_do_vector_loop(true);
1099       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());})
1100     } else if (has_method() && method()->name() != 0 &&
1101                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1102       set_do_vector_loop(true);
1103     }
1104   }
1105   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1106   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());})
1107 

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

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

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

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

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

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

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

2423       assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
2424       Bytecodes::Code c = iter.cur_bc();
2425       Node* lhs = nullptr;
2426       Node* rhs = nullptr;
2427       if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
2428         lhs = unc->peek_operand(0);
2429         rhs = unc->peek_operand(1);
2430       } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
2431         lhs = unc->peek_operand(0);
2432       }
2433 
2434       ResourceMark rm;
2435       const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
2436       assert(live_locals.is_valid(), "broken liveness info");
2437       int len = (int)live_locals.size();
2438 
2439       for (int i = 0; i < len; i++) {
2440         Node* local = unc->local(jvms, i);
2441         // kill local using the liveness of next_bci.
2442         // give up when the local looks like an operand to secure reexecution.
2443         if (!live_locals.at(i) && !local->is_top() && local != lhs && local != rhs) {
2444           uint idx = jvms->locoff() + i;
2445 #ifdef ASSERT
2446           if (PrintOpto && Verbose) {
2447             tty->print("[unstable_if] kill local#%d: ", idx);
2448             local->dump();
2449             tty->cr();
2450           }
2451 #endif
2452           igvn.replace_input_of(unc, idx, top());
2453           modified = true;
2454         }
2455       }
2456     }
2457 
2458     // keep the modified trap for late query
2459     if (modified) {
2460       trap->set_modified();
2461     } else {
2462       _unstable_if_traps.delete_at(i);
2463     }
2464   }
2465   igvn.optimize();
2466 }
2467 
2468 // StringOpts and late inlining of string methods
2469 void Compile::inline_string_calls(bool parse_time) {
2470   {
2471     // remove useless nodes to make the usage analysis simpler
2472     ResourceMark rm;
2473     PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
2474   }
2475 
2476   {
2477     ResourceMark rm;
2478     print_method(PHASE_BEFORE_STRINGOPTS, 3);

2633 
2634   if (_string_late_inlines.length() > 0) {
2635     assert(has_stringbuilder(), "inconsistent");
2636 
2637     inline_string_calls(false);
2638 
2639     if (failing())  return;
2640 
2641     inline_incrementally_cleanup(igvn);
2642   }
2643 
2644   set_inlining_incrementally(false);
2645 }
2646 
2647 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2648   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2649   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2650   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2651   // as if "inlining_incrementally() == true" were set.
2652   assert(inlining_incrementally() == false, "not allowed");
2653 #ifdef ASSERT
2654   Unique_Node_List* modified_nodes = _modified_nodes;
2655   _modified_nodes = nullptr;
2656 #endif
2657   assert(_late_inlines.length() > 0, "sanity");
2658 
2659   while (_late_inlines.length() > 0) {
2660     igvn_worklist()->ensure_empty(); // should be done with igvn
2661 
2662     while (inline_incrementally_one()) {
2663       assert(!failing(), "inconsistent");
2664     }
2665     if (failing())  return;
2666 
2667     inline_incrementally_cleanup(igvn);
2668   }
2669   DEBUG_ONLY( _modified_nodes = modified_nodes; )
2670 }
2671 
2672 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2673   if (_loop_opts_cnt > 0) {
2674     while (major_progress() && (_loop_opts_cnt > 0)) {
2675       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2676       PhaseIdealLoop::optimize(igvn, mode);
2677       _loop_opts_cnt--;
2678       if (failing())  return false;
2679       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2680     }
2681   }
2682   return true;
2683 }
2684 
2685 // Remove edges from "root" to each SafePoint at a backward branch.
2686 // They were inserted during parsing (see add_safepoint()) to make
2687 // infinite loops without calls or exceptions visible to root, i.e.,
2688 // useful.
2689 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2796     print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2797   }
2798   assert(!has_vbox_nodes(), "sanity");
2799 
2800   if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2801     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2802     igvn_worklist()->ensure_empty(); // should be done with igvn
2803     {
2804       ResourceMark rm;
2805       PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2806     }
2807     igvn.reset_from_gvn(initial_gvn());
2808     igvn.optimize();
2809     if (failing()) return;
2810   }
2811 
2812   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2813   // safepoints
2814   remove_root_to_sfpts_edges(igvn);
2815 
2816   // Process inline type nodes now that all inlining is over
2817   process_inline_types(igvn);
2818 
2819   adjust_flat_array_access_aliases(igvn);
2820 
2821   if (failing())  return;
2822 
2823   // Perform escape analysis
2824   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2825     if (has_loops()) {
2826       // Cleanup graph (remove dead nodes).
2827       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2828       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2829       if (failing())  return;
2830     }
2831     bool progress;
2832     print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2833     do {
2834       ConnectionGraph::do_analysis(this, &igvn);
2835 
2836       if (failing())  return;
2837 
2838       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2839 
2840       // Optimize out fields loads from scalar replaceable allocations.

2924   if (failing())  return;
2925 
2926   // Loop transforms on the ideal graph.  Range Check Elimination,
2927   // peeling, unrolling, etc.
2928   if (!optimize_loops(igvn, LoopOptsDefault)) {
2929     return;
2930   }
2931 
2932   if (failing())  return;
2933 
2934   C->clear_major_progress(); // ensure that major progress is now clear
2935 
2936   process_for_post_loop_opts_igvn(igvn);
2937 
2938   if (failing())  return;
2939 
2940 #ifdef ASSERT
2941   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2942 #endif
2943 
2944   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2945 
2946   if (_late_inlines.length() > 0) {
2947     // More opportunities to optimize virtual and MH calls.
2948     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2949     process_late_inline_calls_no_inline(igvn);
2950   }
2951 
2952   {
2953     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2954     print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);
2955     PhaseMacroExpand  mex(igvn);
2956     if (mex.expand_macro_nodes()) {
2957       assert(failing(), "must bail out w/ explicit message");
2958       return;
2959     }
2960     print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
2961   }
2962 
2963   // Process inline type nodes again and remove them. From here
2964   // on we don't need to keep track of field values anymore.
2965   process_inline_types(igvn, /* remove= */ true);
2966 
2967   {
2968     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2969     if (bs->expand_barriers(this, igvn)) {
2970       assert(failing(), "must bail out w/ explicit message");
2971       return;
2972     }
2973     print_method(PHASE_BARRIER_EXPANSION, 2);
2974   }
2975 
2976   if (C->max_vector_size() > 0) {
2977     C->optimize_logic_cones(igvn);
2978     igvn.optimize();
2979     if (failing()) return;
2980   }
2981 
2982   DEBUG_ONLY( _modified_nodes = nullptr; )
2983   DEBUG_ONLY( _late_inlines.clear(); )
2984 
2985   assert(igvn._worklist.size() == 0, "not empty");









2986  } // (End scope of igvn; run destructor if necessary for asserts.)
2987 
2988  check_no_dead_use();
2989 
2990  process_print_inlining();
2991 
2992  // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
2993  // to remove hashes to unlock nodes for modifications.
2994  C->node_hash()->clear();
2995 
2996  // A method with only infinite loops has no edges entering loops from root
2997  {
2998    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2999    if (final_graph_reshaping()) {
3000      assert(failing(), "must bail out w/ explicit message");
3001      return;
3002    }
3003  }
3004 
3005  print_method(PHASE_OPTIMIZE_FINISHED, 2);

3593             // Accumulate any precedence edges
3594             if (mem->in(i) != nullptr) {
3595               n->add_prec(mem->in(i));
3596             }
3597           }
3598           // Everything above this point has been processed.
3599           done = true;
3600         }
3601         // Eliminate the previous StoreCM
3602         prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
3603         assert(mem->outcnt() == 0, "should be dead");
3604         mem->disconnect_inputs(this);
3605       } else {
3606         prev = mem;
3607       }
3608       mem = prev->in(MemNode::Memory);
3609     }
3610   }
3611 }
3612 
3613 
3614 //------------------------------final_graph_reshaping_impl----------------------
3615 // Implement items 1-5 from final_graph_reshaping below.
3616 void Compile::final_graph_reshaping_impl(Node *n, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
3617 
3618   if ( n->outcnt() == 0 ) return; // dead node
3619   uint nop = n->Opcode();
3620 
3621   // Check for 2-input instruction with "last use" on right input.
3622   // Swap to left input.  Implements item (2).
3623   if( n->req() == 3 &&          // two-input instruction
3624       n->in(1)->outcnt() > 1 && // left use is NOT a last use
3625       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
3626       n->in(2)->outcnt() == 1 &&// right use IS a last use
3627       !n->in(2)->is_Con() ) {   // right use is not a constant
3628     // Check for commutative opcode
3629     switch( nop ) {
3630     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
3631     case Op_MaxI:  case Op_MaxL:  case Op_MaxF:  case Op_MaxD:
3632     case Op_MinI:  case Op_MinL:  case Op_MinF:  case Op_MinD:
3633     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:

3746       if (n->outcnt() > 1 &&
3747           !n->is_Proj() &&
3748           nop != Op_CreateEx &&
3749           nop != Op_CheckCastPP &&
3750           nop != Op_DecodeN &&
3751           nop != Op_DecodeNKlass &&
3752           !n->is_Mem() &&
3753           !n->is_Phi()) {
3754         Node *x = n->clone();
3755         call->set_req(TypeFunc::Parms, x);
3756       }
3757     }
3758     break;
3759   }
3760 
3761   case Op_StoreCM:
3762     {
3763       // Convert OopStore dependence into precedence edge
3764       Node* prec = n->in(MemNode::OopStore);
3765       n->del_req(MemNode::OopStore);
3766       if (prec->is_MergeMem()) {
3767         MergeMemNode* mm = prec->as_MergeMem();
3768         Node* base = mm->base_memory();
3769         for (int i = AliasIdxRaw + 1; i < num_alias_types(); i++) {
3770           const TypePtr* adr_type = get_adr_type(i);
3771           if (adr_type->is_flat()) {
3772             Node* m = mm->memory_at(i);
3773             n->add_prec(m);
3774           }
3775         }
3776         if (mm->outcnt() == 0) {
3777           mm->disconnect_inputs(this);
3778         }
3779       } else {
3780         n->add_prec(prec);
3781       }
3782       eliminate_redundant_card_marks(n);
3783     }
3784 
3785     // fall through
3786 
3787   case Op_StoreB:
3788   case Op_StoreC:
3789   case Op_StoreI:
3790   case Op_StoreL:
3791   case Op_CompareAndSwapB:
3792   case Op_CompareAndSwapS:
3793   case Op_CompareAndSwapI:
3794   case Op_CompareAndSwapL:
3795   case Op_CompareAndSwapP:
3796   case Op_CompareAndSwapN:
3797   case Op_WeakCompareAndSwapB:
3798   case Op_WeakCompareAndSwapS:
3799   case Op_WeakCompareAndSwapI:
3800   case Op_WeakCompareAndSwapL:
3801   case Op_WeakCompareAndSwapP:

4382           // Replace all nodes with identical edges as m with m
4383           k->subsume_by(m, this);
4384         }
4385       }
4386     }
4387     break;
4388   }
4389   case Op_CmpUL: {
4390     if (!Matcher::has_match_rule(Op_CmpUL)) {
4391       // No support for unsigned long comparisons
4392       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
4393       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
4394       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
4395       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
4396       Node* andl = new AndLNode(orl, remove_sign_mask);
4397       Node* cmp = new CmpLNode(andl, n->in(2));
4398       n->subsume_by(cmp, this);
4399     }
4400     break;
4401   }
4402 #ifdef ASSERT
4403   case Op_InlineType: {
4404     n->dump(-1);
4405     assert(false, "inline type node was not removed");
4406     break;
4407   }
4408 #endif
4409   default:
4410     assert(!n->is_Call(), "");
4411     assert(!n->is_Mem(), "");
4412     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
4413     break;
4414   }
4415 }
4416 
4417 //------------------------------final_graph_reshaping_walk---------------------
4418 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
4419 // requires that the walk visits a node's inputs before visiting the node.
4420 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
4421   Unique_Node_List sfpt;
4422 
4423   frc._visited.set(root->_idx); // first, mark node as visited
4424   uint cnt = root->req();
4425   Node *n = root;
4426   uint  i = 0;
4427   while (true) {
4428     if (i < cnt) {

4768   }
4769 }
4770 
4771 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4772   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4773 }
4774 
4775 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4776   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4777 }
4778 
4779 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4780   if (holder->is_initialized()) {
4781     return false;
4782   }
4783   if (holder->is_being_initialized()) {
4784     if (accessing_method->holder() == holder) {
4785       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4786       // <init>, or a static method. In all those cases, there was an initialization
4787       // barrier on the holder klass passed.
4788       if (accessing_method->is_class_initializer() ||
4789           accessing_method->is_object_constructor() ||
4790           accessing_method->is_static()) {
4791         return false;
4792       }
4793     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4794       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4795       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4796       // child class can become fully initialized while its parent class is still being initialized.
4797       if (accessing_method->is_class_initializer()) {
4798         return false;
4799       }
4800     }
4801     ciMethod* root = method(); // the root method of compilation
4802     if (root != accessing_method) {
4803       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4804     }
4805   }
4806   return true;
4807 }
4808 
4809 #ifndef PRODUCT
4810 //------------------------------verify_bidirectional_edges---------------------
4811 // For each input edge to a node (ie - for each Use-Def edge), verify that
4812 // there is a corresponding Def-Use edge.
4813 void Compile::verify_bidirectional_edges(Unique_Node_List &visited) {
4814   // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4815   uint stack_size = live_nodes() >> 4;
4816   Node_List nstack(MAX2(stack_size, (uint)OptoNodeListSize));
4817   nstack.push(_root);

4833       if (in != nullptr && !in->is_top()) {
4834         // Count instances of `next`
4835         int cnt = 0;
4836         for (uint idx = 0; idx < in->_outcnt; idx++) {
4837           if (in->_out[idx] == n) {
4838             cnt++;
4839           }
4840         }
4841         assert(cnt > 0, "Failed to find Def-Use edge.");
4842         // Check for duplicate edges
4843         // walk the input array downcounting the input edges to n
4844         for (uint j = 0; j < length; j++) {
4845           if (n->in(j) == in) {
4846             cnt--;
4847           }
4848         }
4849         assert(cnt == 0, "Mismatched edge count.");
4850       } else if (in == nullptr) {
4851         assert(i == 0 || i >= n->req() ||
4852                n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||
4853                (n->is_Allocate() && i >= AllocateNode::InlineType) ||
4854                (n->is_Unlock() && i == (n->req() - 1)) ||
4855                (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4856               "only region, phi, arraycopy, allocate, unlock or membar nodes have null data edges");
4857       } else {
4858         assert(in->is_top(), "sanity");
4859         // Nothing to check.
4860       }
4861     }
4862   }
4863 }
4864 
4865 //------------------------------verify_graph_edges---------------------------
4866 // Walk the Graph and verify that there is a one-to-one correspondence
4867 // between Use-Def edges and Def-Use edges in the graph.
4868 void Compile::verify_graph_edges(bool no_dead_code) {
4869   if (VerifyGraphEdges) {
4870     Unique_Node_List visited;
4871 
4872     // Call graph walk to check edges
4873     verify_bidirectional_edges(visited);
4874     if (no_dead_code) {
4875       // Now make sure that no visited node is used by an unvisited node.
4876       bool dead_nodes = false;

4966 // (1) subklass is already limited to a subtype of superklass => always ok
4967 // (2) subklass does not overlap with superklass => always fail
4968 // (3) superklass has NO subtypes and we can check with a simple compare.
4969 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
4970   if (skip) {
4971     return SSC_full_test;       // Let caller generate the general case.
4972   }
4973 
4974   if (subk->is_java_subtype_of(superk)) {
4975     return SSC_always_true; // (0) and (1)  this test cannot fail
4976   }
4977 
4978   if (!subk->maybe_java_subtype_of(superk)) {
4979     return SSC_always_false; // (2) true path dead; no dynamic test needed
4980   }
4981 
4982   const Type* superelem = superk;
4983   if (superk->isa_aryklassptr()) {
4984     int ignored;
4985     superelem = superk->is_aryklassptr()->base_element_type(ignored);
4986 
4987     // TODO 8325106 Fix comment
4988     // Do not fold the subtype check to an array klass pointer comparison for [V? arrays.
4989     // [QMyValue is a subtype of [LMyValue but the klass for [QMyValue is not equal to
4990     // the klass for [LMyValue. Perform a full test.
4991     if (!superk->is_aryklassptr()->is_null_free() && superk->is_aryklassptr()->elem()->isa_instklassptr() &&
4992         superk->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->is_inlinetype()) {
4993       return SSC_full_test;
4994     }
4995   }
4996 
4997   if (superelem->isa_instklassptr()) {
4998     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4999     if (!ik->has_subklass()) {
5000       if (!ik->is_final()) {
5001         // Add a dependency if there is a chance of a later subclass.
5002         dependencies()->assert_leaf_type(ik);
5003       }
5004       if (!superk->maybe_java_subtype_of(subk)) {
5005         return SSC_always_false;
5006       }
5007       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
5008     }
5009   } else {
5010     // A primitive array type has no subtypes.
5011     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
5012   }
5013 
5014   return SSC_full_test;

5535       const Type* t = igvn.type_or_null(n);
5536       assert((t == nullptr) || (t == t->remove_speculative()), "no more speculative types");
5537       if (n->is_Type()) {
5538         t = n->as_Type()->type();
5539         assert(t == t->remove_speculative(), "no more speculative types");
5540       }
5541       // Iterate over outs - endless loops is unreachable from below
5542       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
5543         Node *m = n->fast_out(i);
5544         if (not_a_node(m)) {
5545           continue;
5546         }
5547         worklist.push(m);
5548       }
5549     }
5550     igvn.check_no_speculative_types();
5551 #endif
5552   }
5553 }
5554 
5555 Node* Compile::optimize_acmp(PhaseGVN* phase, Node* a, Node* b) {
5556   const TypeInstPtr* ta = phase->type(a)->isa_instptr();
5557   const TypeInstPtr* tb = phase->type(b)->isa_instptr();
5558   if (!EnableValhalla || ta == nullptr || tb == nullptr ||
5559       ta->is_zero_type() || tb->is_zero_type() ||
5560       !ta->can_be_inline_type() || !tb->can_be_inline_type()) {
5561     // Use old acmp if one operand is null or not an inline type
5562     return new CmpPNode(a, b);
5563   } else if (ta->is_inlinetypeptr() || tb->is_inlinetypeptr()) {
5564     // We know that one operand is an inline type. Therefore,
5565     // new acmp will only return true if both operands are nullptr.
5566     // Check if both operands are null by or'ing the oops.
5567     a = phase->transform(new CastP2XNode(nullptr, a));
5568     b = phase->transform(new CastP2XNode(nullptr, b));
5569     a = phase->transform(new OrXNode(a, b));
5570     return new CmpXNode(a, phase->MakeConX(0));
5571   }
5572   // Use new acmp
5573   return nullptr;
5574 }
5575 
5576 // Auxiliary methods to support randomized stressing/fuzzing.
5577 
5578 int Compile::random() {
5579   _stress_seed = os::next_random(_stress_seed);
5580   return static_cast<int>(_stress_seed);
5581 }
5582 
5583 // This method can be called the arbitrary number of times, with current count
5584 // as the argument. The logic allows selecting a single candidate from the
5585 // running list of candidates as follows:
5586 //    int count = 0;
5587 //    Cand* selected = null;
5588 //    while(cand = cand->next()) {
5589 //      if (randomized_select(++count)) {
5590 //        selected = cand;
5591 //      }
5592 //    }
5593 //
5594 // Including count equalizes the chances any candidate is "selected".
5595 // This is useful when we don't have the complete list of candidates to choose
< prev index next >