< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page

  34 #include "compiler/disassembler.hpp"
  35 #include "compiler/oopMap.hpp"
  36 #include "gc/shared/barrierSet.hpp"
  37 #include "gc/shared/c2/barrierSetC2.hpp"
  38 #include "jfr/jfrEvents.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "opto/addnode.hpp"
  41 #include "opto/block.hpp"
  42 #include "opto/c2compiler.hpp"
  43 #include "opto/callGenerator.hpp"
  44 #include "opto/callnode.hpp"
  45 #include "opto/castnode.hpp"
  46 #include "opto/cfgnode.hpp"
  47 #include "opto/chaitin.hpp"
  48 #include "opto/compile.hpp"
  49 #include "opto/connode.hpp"
  50 #include "opto/convertnode.hpp"
  51 #include "opto/divnode.hpp"
  52 #include "opto/escape.hpp"
  53 #include "opto/idealGraphPrinter.hpp"

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

 374   // Constant node that has no out-edges and has only one in-edge from
 375   // root is usually dead. However, sometimes reshaping walk makes
 376   // it reachable by adding use edges. So, we will NOT count Con nodes
 377   // as dead to be conservative about the dead node count at any
 378   // given time.
 379   if (!dead->is_Con()) {
 380     record_dead_node(dead->_idx);
 381   }
 382   if (dead->is_macro()) {
 383     remove_macro_node(dead);
 384   }
 385   if (dead->is_expensive()) {
 386     remove_expensive_node(dead);
 387   }
 388   if (dead->Opcode() == Op_Opaque4) {
 389     remove_skeleton_predicate_opaq(dead);
 390   }
 391   if (dead->for_post_loop_opts_igvn()) {
 392     remove_from_post_loop_opts_igvn(dead);
 393   }



 394   if (dead->is_Call()) {
 395     remove_useless_late_inlines(                &_late_inlines, dead);
 396     remove_useless_late_inlines(         &_string_late_inlines, dead);
 397     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 398     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 399 
 400     if (dead->is_CallStaticJava()) {
 401       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 402     }
 403   }
 404   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 405   bs->unregister_potential_barrier_node(dead);
 406 }
 407 
 408 // Disconnect all useless nodes by disconnecting those at the boundary.
 409 void Compile::disconnect_useless_nodes(Unique_Node_List &useful, Unique_Node_List* worklist) {
 410   uint next = 0;
 411   while (next < useful.size()) {
 412     Node *n = useful.at(next++);
 413     if (n->is_SafePoint()) {
 414       // We're done with a parsing phase. Replaced nodes are not valid
 415       // beyond that point.
 416       n->as_SafePoint()->delete_replaced_nodes();
 417     }
 418     // Use raw traversal of out edges since this code removes out edges
 419     int max = n->outcnt();
 420     for (int j = 0; j < max; ++j) {
 421       Node* child = n->raw_out(j);
 422       if (!useful.member(child)) {
 423         assert(!child->is_top() || child != top(),
 424                "If top is cached in Compile object it is in useful list");
 425         // Only need to remove this out-edge to the useless node
 426         n->raw_del_out(j);
 427         --j;
 428         --max;
 429       }
 430     }
 431     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 432       worklist->push(n->unique_out());
 433     }



 434   }
 435 
 436   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 437   remove_useless_nodes(_predicate_opaqs,    useful); // remove useless predicate opaque nodes
 438   remove_useless_nodes(_skeleton_predicate_opaqs, useful);
 439   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 440   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass






 441   remove_useless_unstable_if_traps(useful);          // remove useless unstable_if traps
 442   remove_useless_coarsened_locks(useful);            // remove useless coarsened locks nodes
 443 #ifdef ASSERT
 444   if (_modified_nodes != NULL) {
 445     _modified_nodes->remove_useless_nodes(useful.member_set());
 446   }
 447 #endif
 448 
 449   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 450   bs->eliminate_useless_gc_barriers(useful, this);
 451   // clean up the late inline lists
 452   remove_useless_late_inlines(                &_late_inlines, useful);
 453   remove_useless_late_inlines(         &_string_late_inlines, useful);
 454   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
 455   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 456   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
 457 }
 458 
 459 // ============================================================================
 460 //------------------------------CompileWrapper---------------------------------

 600                   _has_reserved_stack_access(target->has_reserved_stack_access()),
 601 #ifndef PRODUCT
 602                   _igv_idx(0),
 603                   _trace_opto_output(directive->TraceOptoOutputOption),
 604 #endif
 605                   _has_method_handle_invokes(false),
 606                   _clinit_barrier_on_entry(false),
 607                   _stress_seed(0),
 608                   _comp_arena(mtCompiler),
 609                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 610                   _env(ci_env),
 611                   _directive(directive),
 612                   _log(ci_env->log()),
 613                   _failure_reason(NULL),
 614                   _intrinsics        (comp_arena(), 0, 0, NULL),
 615                   _macro_nodes       (comp_arena(), 8, 0, NULL),
 616                   _predicate_opaqs   (comp_arena(), 8, 0, NULL),
 617                   _skeleton_predicate_opaqs (comp_arena(), 8, 0, NULL),
 618                   _expensive_nodes   (comp_arena(), 8, 0, NULL),
 619                   _for_post_loop_igvn(comp_arena(), 8, 0, NULL),

 620                   _unstable_if_traps (comp_arena(), 8, 0, NULL),
 621                   _coarsened_locks   (comp_arena(), 8, 0, NULL),
 622                   _congraph(NULL),
 623                   NOT_PRODUCT(_igv_printer(NULL) COMMA)
 624                   _dead_node_list(comp_arena()),
 625                   _dead_node_count(0),
 626                   _node_arena(mtCompiler),
 627                   _old_arena(mtCompiler),
 628                   _mach_constant_base_node(NULL),
 629                   _Compile_types(mtCompiler),
 630                   _initial_gvn(NULL),
 631                   _for_igvn(NULL),
 632                   _late_inlines(comp_arena(), 2, 0, NULL),
 633                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 634                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),
 635                   _vector_reboxing_late_inlines(comp_arena(), 2, 0, NULL),
 636                   _late_inlines_pos(0),
 637                   _number_of_mh_late_inlines(0),
 638                   _print_inlining_stream(NULL),
 639                   _print_inlining_list(NULL),

 705   // Node list that Iterative GVN will start with
 706   Unique_Node_List for_igvn(comp_arena());
 707   set_for_igvn(&for_igvn);
 708 
 709   // GVN that will be run immediately on new nodes
 710   uint estimated_size = method()->code_size()*4+64;
 711   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 712   PhaseGVN gvn(node_arena(), estimated_size);
 713   set_initial_gvn(&gvn);
 714 
 715   print_inlining_init();
 716   { // Scope for timing the parser
 717     TracePhase tp("parse", &timers[_t_parser]);
 718 
 719     // Put top into the hash table ASAP.
 720     initial_gvn()->transform_no_reclaim(top());
 721 
 722     // Set up tf(), start(), and find a CallGenerator.
 723     CallGenerator* cg = NULL;
 724     if (is_osr_compilation()) {
 725       const TypeTuple *domain = StartOSRNode::osr_domain();
 726       const TypeTuple *range = TypeTuple::make_range(method()->signature());
 727       init_tf(TypeFunc::make(domain, range));
 728       StartNode* s = new StartOSRNode(root(), domain);
 729       initial_gvn()->set_type_bottom(s);
 730       init_start(s);
 731       cg = CallGenerator::for_osr(method(), entry_bci());
 732     } else {
 733       // Normal case.
 734       init_tf(TypeFunc::make(method()));
 735       StartNode* s = new StartNode(root(), tf()->domain());
 736       initial_gvn()->set_type_bottom(s);
 737       init_start(s);
 738       if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {
 739         // With java.lang.ref.reference.get() we must go through the
 740         // intrinsic - even when get() is the root
 741         // method of the compile - so that, if necessary, the value in
 742         // the referent field of the reference object gets recorded by
 743         // the pre-barrier code.
 744         cg = find_intrinsic(method(), false);
 745       }
 746       if (cg == NULL) {
 747         float past_uses = method()->interpreter_invocation_count();
 748         float expected_uses = past_uses;
 749         cg = CallGenerator::for_inline(method(), expected_uses);
 750       }
 751     }
 752     if (failing())  return;
 753     if (cg == NULL) {
 754       record_method_not_compilable("cannot parse method");
 755       return;

 834     print_ideal_ir("print_ideal");
 835   }
 836 #endif
 837 
 838 #ifdef ASSERT
 839   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 840   bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
 841 #endif
 842 
 843   // Dump compilation data to replay it.
 844   if (directive->DumpReplayOption) {
 845     env()->dump_replay_data(_compile_id);
 846   }
 847   if (directive->DumpInlineOption && (ilt() != NULL)) {
 848     env()->dump_inline_data(_compile_id);
 849   }
 850 
 851   // Now that we know the size of all the monitors we can add a fixed slot
 852   // for the original deopt pc.
 853   int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);










 854   set_fixed_slots(next_slot);
 855 
 856   // Compute when to use implicit null checks. Used by matching trap based
 857   // nodes and NullCheck optimization.
 858   set_allowed_deopt_reasons();
 859 
 860   // Now generate code
 861   Code_Gen();
 862 }
 863 
 864 //------------------------------Compile----------------------------------------
 865 // Compile a runtime stub
 866 Compile::Compile( ciEnv* ci_env,
 867                   TypeFunc_generator generator,
 868                   address stub_function,
 869                   const char *stub_name,
 870                   int is_fancy_jump,
 871                   bool pass_tls,
 872                   bool return_pc,
 873                   DirectiveSet* directive)

 985   // Create Debug Information Recorder to record scopes, oopmaps, etc.
 986   env()->set_oop_recorder(new OopRecorder(env()->arena()));
 987   env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
 988   env()->set_dependencies(new Dependencies(env()));
 989 
 990   _fixed_slots = 0;
 991   set_has_split_ifs(false);
 992   set_has_loops(false); // first approximation
 993   set_has_stringbuilder(false);
 994   set_has_boxed_value(false);
 995   _trap_can_recompile = false;  // no traps emitted yet
 996   _major_progress = true; // start out assuming good things will happen
 997   set_has_unsafe_access(false);
 998   set_max_vector_size(0);
 999   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1000   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1001   set_decompile_count(0);
1002 
1003   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1004   _loop_opts_cnt = LoopOptsCount;




1005   set_do_inlining(Inline);
1006   set_max_inline_size(MaxInlineSize);
1007   set_freq_inline_size(FreqInlineSize);
1008   set_do_scheduling(OptoScheduling);
1009 
1010   set_do_vector_loop(false);
1011   set_has_monitors(false);
1012 
1013   if (AllowVectorizeOnDemand) {
1014     if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
1015       set_do_vector_loop(true);
1016       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());})
1017     } else if (has_method() && method()->name() != 0 &&
1018                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1019       set_do_vector_loop(true);
1020     }
1021   }
1022   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1023   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());})
1024 

1288 bool Compile::allow_range_check_smearing() const {
1289   // If this method has already thrown a range-check,
1290   // assume it was because we already tried range smearing
1291   // and it failed.
1292   uint already_trapped = trap_count(Deoptimization::Reason_range_check);
1293   return !already_trapped;
1294 }
1295 
1296 
1297 //------------------------------flatten_alias_type-----------------------------
1298 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1299   int offset = tj->offset();
1300   TypePtr::PTR ptr = tj->ptr();
1301 
1302   // Known instance (scalarizable allocation) alias only with itself.
1303   bool is_known_inst = tj->isa_oopptr() != NULL &&
1304                        tj->is_oopptr()->is_known_instance();
1305 
1306   // Process weird unsafe references.
1307   if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1308     assert(InlineUnsafeOps || StressReflectiveCode, "indeterminate pointers come only from unsafe ops");

1309     assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1310     tj = TypeOopPtr::BOTTOM;
1311     ptr = tj->ptr();
1312     offset = tj->offset();
1313   }
1314 
1315   // Array pointers need some flattening
1316   const TypeAryPtr* ta = tj->isa_aryptr();
1317   if (ta && ta->is_stable()) {
1318     // Erase stability property for alias analysis.
1319     tj = ta = ta->cast_to_stable(false);
1320   }









1321   if( ta && is_known_inst ) {
1322     if ( offset != Type::OffsetBot &&
1323          offset > arrayOopDesc::length_offset_in_bytes() ) {
1324       offset = Type::OffsetBot; // Flatten constant access into array body only
1325       tj = ta = ta->
1326               remove_speculative()->
1327               cast_to_ptr_type(ptr)->
1328               with_offset(offset);
1329     }
1330   } else if( ta && _AliasLevel >= 2 ) {
1331     // For arrays indexed by constant indices, we flatten the alias
1332     // space to include all of the array body.  Only the header, klass
1333     // and array length can be accessed un-aliased.


1334     if( offset != Type::OffsetBot ) {
1335       if( ta->const_oop() ) { // MethodData* or Method*
1336         offset = Type::OffsetBot;   // Flatten constant access into array body
1337         tj = ta = ta->
1338                 remove_speculative()->
1339                 cast_to_ptr_type(ptr)->
1340                 cast_to_exactness(false)->
1341                 with_offset(offset);
1342       } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1343         // range is OK as-is.
1344         tj = ta = TypeAryPtr::RANGE;
1345       } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1346         tj = TypeInstPtr::KLASS; // all klass loads look alike
1347         ta = TypeAryPtr::RANGE; // generic ignored junk
1348         ptr = TypePtr::BotPTR;
1349       } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1350         tj = TypeInstPtr::MARK;
1351         ta = TypeAryPtr::RANGE; // generic ignored junk
1352         ptr = TypePtr::BotPTR;
1353       } else {                  // Random constant offset into array body
1354         offset = Type::OffsetBot;   // Flatten constant access into array body
1355         tj = ta = ta->
1356                 remove_speculative()->
1357                 cast_to_ptr_type(ptr)->
1358                 cast_to_exactness(false)->
1359                 with_offset(offset);
1360       }
1361     }
1362     // Arrays of fixed size alias with arrays of unknown size.
1363     if (ta->size() != TypeInt::POS) {
1364       const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1365       tj = ta = ta->
1366               remove_speculative()->
1367               cast_to_ptr_type(ptr)->
1368               with_ary(tary)->
1369               cast_to_exactness(false);
1370     }
1371     // Arrays of known objects become arrays of unknown objects.
1372     if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1373       const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1374       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);
1375     }
1376     if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1377       const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1378       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);





1379     }
1380     // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1381     // cannot be distinguished by bytecode alone.
1382     if (ta->elem() == TypeInt::BOOL) {
1383       const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1384       ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1385       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
1386     }
1387     // During the 2nd round of IterGVN, NotNull castings are removed.
1388     // Make sure the Bottom and NotNull variants alias the same.
1389     // Also, make sure exact and non-exact variants alias the same.
1390     if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != NULL) {
1391       tj = ta = ta->
1392               remove_speculative()->
1393               cast_to_ptr_type(TypePtr::BotPTR)->
1394               cast_to_exactness(false)->
1395               with_offset(offset);
1396     }
1397   }
1398 
1399   // Oop pointers need some flattening
1400   const TypeInstPtr *to = tj->isa_instptr();
1401   if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1402     ciInstanceKlass* ik = to->instance_klass();
1403     if( ptr == TypePtr::Constant ) {
1404       if (ik != ciEnv::current()->Class_klass() ||
1405           offset < ik->layout_helper_size_in_bytes()) {

1415     } else if( is_known_inst ) {
1416       tj = to; // Keep NotNull and klass_is_exact for instance type
1417     } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1418       // During the 2nd round of IterGVN, NotNull castings are removed.
1419       // Make sure the Bottom and NotNull variants alias the same.
1420       // Also, make sure exact and non-exact variants alias the same.
1421       tj = to = to->
1422               remove_speculative()->
1423               cast_to_instance_id(TypeOopPtr::InstanceBot)->
1424               cast_to_ptr_type(TypePtr::BotPTR)->
1425               cast_to_exactness(false);
1426     }
1427     if (to->speculative() != NULL) {
1428       tj = to = to->remove_speculative();
1429     }
1430     // Canonicalize the holder of this field
1431     if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1432       // First handle header references such as a LoadKlassNode, even if the
1433       // object's klass is unloaded at compile time (4965979).
1434       if (!is_known_inst) { // Do it only for non-instance types
1435         tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset);
1436       }
1437     } else if (offset < 0 || offset >= ik->layout_helper_size_in_bytes()) {
1438       // Static fields are in the space above the normal instance
1439       // fields in the java.lang.Class instance.
1440       if (ik != ciEnv::current()->Class_klass()) {
1441         to = NULL;
1442         tj = TypeOopPtr::BOTTOM;
1443         offset = tj->offset();
1444       }
1445     } else {
1446       ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
1447       assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1448       if (!ik->equals(canonical_holder) || tj->offset() != offset) {
1449         if( is_known_inst ) {
1450           tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id());
1451         } else {
1452           tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset);
1453         }
1454       }
1455     }
1456   }
1457 
1458   // Klass pointers to object array klasses need some flattening
1459   const TypeKlassPtr *tk = tj->isa_klassptr();
1460   if( tk ) {
1461     // If we are referencing a field within a Klass, we need
1462     // to assume the worst case of an Object.  Both exact and
1463     // inexact types must flatten to the same alias class so
1464     // use NotNull as the PTR.
1465     if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1466       tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1467                                        env()->Object_klass(),
1468                                        offset);
1469     }
1470 
1471     if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1472       ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1473       if (!k || !k->is_loaded()) {                  // Only fails for some -Xcomp runs
1474         tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), offset);
1475       } else {
1476         tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, offset);
1477       }
1478     }
1479 
1480     // Check for precise loads from the primary supertype array and force them
1481     // to the supertype cache alias index.  Check for generic array loads from
1482     // the primary supertype array and also force them to the supertype cache
1483     // alias index.  Since the same load can reach both, we need to merge
1484     // these 2 disparate memories into the same alias class.  Since the
1485     // primary supertype array is read-only, there's no chance of confusion
1486     // where we bypass an array load and an array store.
1487     int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1488     if (offset == Type::OffsetBot ||
1489         (offset >= primary_supers_offset &&
1490          offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1491         offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1492       offset = in_bytes(Klass::secondary_super_cache_offset());
1493       tj = tk = tk->with_offset(offset);
1494     }
1495   }
1496 

1614   intptr_t key = (intptr_t) adr_type;
1615   key ^= key >> logAliasCacheSize;
1616   return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1617 }
1618 
1619 
1620 //-----------------------------grow_alias_types--------------------------------
1621 void Compile::grow_alias_types() {
1622   const int old_ats  = _max_alias_types; // how many before?
1623   const int new_ats  = old_ats;          // how many more?
1624   const int grow_ats = old_ats+new_ats;  // how many now?
1625   _max_alias_types = grow_ats;
1626   _alias_types =  REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1627   AliasType* ats =    NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1628   Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1629   for (int i = 0; i < new_ats; i++)  _alias_types[old_ats+i] = &ats[i];
1630 }
1631 
1632 
1633 //--------------------------------find_alias_type------------------------------
1634 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
1635   if (_AliasLevel == 0)
1636     return alias_type(AliasIdxBot);
1637 
1638   AliasCacheEntry* ace = probe_alias_cache(adr_type);
1639   if (ace->_adr_type == adr_type) {
1640     return alias_type(ace->_index);



1641   }
1642 
1643   // Handle special cases.
1644   if (adr_type == NULL)             return alias_type(AliasIdxTop);
1645   if (adr_type == TypePtr::BOTTOM)  return alias_type(AliasIdxBot);
1646 
1647   // Do it the slow way.
1648   const TypePtr* flat = flatten_alias_type(adr_type);
1649 
1650 #ifdef ASSERT
1651   {
1652     ResourceMark rm;
1653     assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",
1654            Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));
1655     assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",
1656            Type::str(adr_type));
1657     if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1658       const TypeOopPtr* foop = flat->is_oopptr();
1659       // Scalarizable allocations have exact klass always.
1660       bool exact = !foop->klass_is_exact() || foop->is_known_instance();

1670     if (alias_type(i)->adr_type() == flat) {
1671       idx = i;
1672       break;
1673     }
1674   }
1675 
1676   if (idx == AliasIdxTop) {
1677     if (no_create)  return NULL;
1678     // Grow the array if necessary.
1679     if (_num_alias_types == _max_alias_types)  grow_alias_types();
1680     // Add a new alias type.
1681     idx = _num_alias_types++;
1682     _alias_types[idx]->Init(idx, flat);
1683     if (flat == TypeInstPtr::KLASS)  alias_type(idx)->set_rewritable(false);
1684     if (flat == TypeAryPtr::RANGE)   alias_type(idx)->set_rewritable(false);
1685     if (flat->isa_instptr()) {
1686       if (flat->offset() == java_lang_Class::klass_offset()
1687           && flat->is_instptr()->instance_klass() == env()->Class_klass())
1688         alias_type(idx)->set_rewritable(false);
1689     }

1690     if (flat->isa_aryptr()) {
1691 #ifdef ASSERT
1692       const int header_size_min  = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1693       // (T_BYTE has the weakest alignment and size restrictions...)
1694       assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1695 #endif

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







1698       }
1699     }
1700     if (flat->isa_klassptr()) {
1701       if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1702         alias_type(idx)->set_rewritable(false);
1703       if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
1704         alias_type(idx)->set_rewritable(false);
1705       if (flat->offset() == in_bytes(Klass::access_flags_offset()))
1706         alias_type(idx)->set_rewritable(false);
1707       if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1708         alias_type(idx)->set_rewritable(false);


1709       if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1710         alias_type(idx)->set_rewritable(false);
1711     }
1712     // %%% (We would like to finalize JavaThread::threadObj_offset(),
1713     // but the base pointer type is not distinctive enough to identify
1714     // references into JavaThread.)
1715 
1716     // Check for final fields.
1717     const TypeInstPtr* tinst = flat->isa_instptr();
1718     if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1719       ciField* field;
1720       if (tinst->const_oop() != NULL &&
1721           tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1722           tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1723         // static field
1724         ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1725         field = k->get_field_by_offset(tinst->offset(), true);




1726       } else {
1727         ciInstanceKlass *k = tinst->instance_klass();
1728         field = k->get_field_by_offset(tinst->offset(), false);
1729       }
1730       assert(field == NULL ||
1731              original_field == NULL ||
1732              (field->holder() == original_field->holder() &&
1733               field->offset() == original_field->offset() &&
1734               field->is_static() == original_field->is_static()), "wrong field?");
1735       // Set field() and is_rewritable() attributes.
1736       if (field != NULL)  alias_type(idx)->set_field(field);







1737     }
1738   }
1739 
1740   // Fill the cache for next time.
1741   ace->_adr_type = adr_type;
1742   ace->_index    = idx;
1743   assert(alias_type(adr_type) == alias_type(idx),  "type must be installed");

1744 
1745   // Might as well try to fill the cache for the flattened version, too.
1746   AliasCacheEntry* face = probe_alias_cache(flat);
1747   if (face->_adr_type == NULL) {
1748     face->_adr_type = flat;
1749     face->_index    = idx;
1750     assert(alias_type(flat) == alias_type(idx), "flat type must work too");

1751   }
1752 
1753   return alias_type(idx);
1754 }
1755 
1756 
1757 Compile::AliasType* Compile::alias_type(ciField* field) {
1758   const TypeOopPtr* t;
1759   if (field->is_static())
1760     t = TypeInstPtr::make(field->holder()->java_mirror());
1761   else
1762     t = TypeOopPtr::make_from_klass_raw(field->holder());
1763   AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1764   assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1765   return atp;
1766 }
1767 
1768 
1769 //------------------------------have_alias_type--------------------------------
1770 bool Compile::have_alias_type(const TypePtr* adr_type) {

1847   C->set_post_loop_opts_phase(); // no more loop opts allowed
1848 
1849   assert(!C->major_progress(), "not cleared");
1850 
1851   if (_for_post_loop_igvn.length() > 0) {
1852     while (_for_post_loop_igvn.length() > 0) {
1853       Node* n = _for_post_loop_igvn.pop();
1854       n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1855       igvn._worklist.push(n);
1856     }
1857     igvn.optimize();
1858     assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1859 
1860     // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1861     if (C->major_progress()) {
1862       C->clear_major_progress(); // ensure that major progress is now clear
1863     }
1864   }
1865 }
1866 





















































































































































































































































































































































































































1867 void Compile::record_unstable_if_trap(UnstableIfTrap* trap) {
1868   if (OptimizeUnstableIf) {
1869     _unstable_if_traps.append(trap);
1870   }
1871 }
1872 
1873 void Compile::remove_useless_unstable_if_traps(Unique_Node_List& useful) {
1874   for (int i = _unstable_if_traps.length() - 1; i >= 0; i--) {
1875     UnstableIfTrap* trap = _unstable_if_traps.at(i);
1876     Node* n = trap->uncommon_trap();
1877     if (!useful.member(n)) {
1878       _unstable_if_traps.delete_at(i); // replaces i-th with last element which is known to be useful (already processed)
1879     }
1880   }
1881 }
1882 
1883 // Remove the unstable if trap associated with 'unc' from candidates. It is either dead
1884 // or fold-compares case. Return true if succeed or not found.
1885 //
1886 // In rare cases, the found trap has been processed. It is too late to delete it. Return

2136     assert(has_stringbuilder(), "inconsistent");
2137     for_igvn()->clear();
2138     initial_gvn()->replace_with(&igvn);
2139 
2140     inline_string_calls(false);
2141 
2142     if (failing())  return;
2143 
2144     inline_incrementally_cleanup(igvn);
2145   }
2146 
2147   set_inlining_incrementally(false);
2148 }
2149 
2150 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2151   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2152   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2153   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == NULL"
2154   // as if "inlining_incrementally() == true" were set.
2155   assert(inlining_incrementally() == false, "not allowed");
2156   assert(_modified_nodes == NULL, "not allowed");



2157   assert(_late_inlines.length() > 0, "sanity");
2158 
2159   while (_late_inlines.length() > 0) {
2160     for_igvn()->clear();
2161     initial_gvn()->replace_with(&igvn);
2162 
2163     while (inline_incrementally_one()) {
2164       assert(!failing(), "inconsistent");
2165     }
2166     if (failing())  return;
2167 
2168     inline_incrementally_cleanup(igvn);
2169   }

2170 }
2171 
2172 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2173   if (_loop_opts_cnt > 0) {
2174     while (major_progress() && (_loop_opts_cnt > 0)) {
2175       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2176       PhaseIdealLoop::optimize(igvn, mode);
2177       _loop_opts_cnt--;
2178       if (failing())  return false;
2179       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2180     }
2181   }
2182   return true;
2183 }
2184 
2185 // Remove edges from "root" to each SafePoint at a backward branch.
2186 // They were inserted during parsing (see add_safepoint()) to make
2187 // infinite loops without calls or exceptions visible to root, i.e.,
2188 // useful.
2189 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2293     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2294     initial_gvn()->replace_with(&igvn);
2295     Unique_Node_List* old_worklist = for_igvn();
2296     old_worklist->clear();
2297     Unique_Node_List new_worklist(C->comp_arena());
2298     {
2299       ResourceMark rm;
2300       PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
2301     }
2302     Unique_Node_List* save_for_igvn = for_igvn();
2303     set_for_igvn(&new_worklist);
2304     igvn = PhaseIterGVN(initial_gvn());
2305     igvn.optimize();
2306     set_for_igvn(old_worklist); // new_worklist is dead beyond this point
2307   }
2308 
2309   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2310   // safepoints
2311   remove_root_to_sfpts_edges(igvn);
2312 





2313   // Perform escape analysis
2314   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2315     if (has_loops()) {
2316       // Cleanup graph (remove dead nodes).
2317       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2318       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2319       if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2320       if (failing())  return;
2321     }
2322     bool progress;
2323     do {
2324       ConnectionGraph::do_analysis(this, &igvn);
2325 
2326       if (failing())  return;
2327 
2328       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2329 
2330       // Optimize out fields loads from scalar replaceable allocations.
2331       igvn.optimize();
2332       print_method(PHASE_ITER_GVN_AFTER_EA, 2);

2406   print_method(PHASE_ITER_GVN2, 2);
2407 
2408   if (failing())  return;
2409 
2410   // Loop transforms on the ideal graph.  Range Check Elimination,
2411   // peeling, unrolling, etc.
2412   if (!optimize_loops(igvn, LoopOptsDefault)) {
2413     return;
2414   }
2415 
2416   if (failing())  return;
2417 
2418   C->clear_major_progress(); // ensure that major progress is now clear
2419 
2420   process_for_post_loop_opts_igvn(igvn);
2421 
2422 #ifdef ASSERT
2423   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2424 #endif
2425 








2426   {
2427     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2428     PhaseMacroExpand  mex(igvn);
2429     if (mex.expand_macro_nodes()) {
2430       assert(failing(), "must bail out w/ explicit message");
2431       return;
2432     }
2433     print_method(PHASE_MACRO_EXPANSION, 2);
2434   }
2435 




2436   {
2437     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2438     if (bs->expand_barriers(this, igvn)) {
2439       assert(failing(), "must bail out w/ explicit message");
2440       return;
2441     }
2442     print_method(PHASE_BARRIER_EXPANSION, 2);
2443   }
2444 
2445   if (C->max_vector_size() > 0) {
2446     C->optimize_logic_cones(igvn);
2447     igvn.optimize();
2448   }
2449 
2450   DEBUG_ONLY( _modified_nodes = NULL; )

2451 
2452   assert(igvn._worklist.size() == 0, "not empty");
2453 
2454   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2455 
2456   if (_late_inlines.length() > 0) {
2457     // More opportunities to optimize virtual and MH calls.
2458     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2459     process_late_inline_calls_no_inline(igvn);
2460   }
2461  } // (End scope of igvn; run destructor if necessary for asserts.)
2462 
2463  check_no_dead_use();
2464 
2465  process_print_inlining();
2466 
2467  // A method with only infinite loops has no edges entering loops from root
2468  {
2469    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2470    if (final_graph_reshaping()) {
2471      assert(failing(), "must bail out w/ explicit message");
2472      return;
2473    }
2474  }
2475 
2476  print_method(PHASE_OPTIMIZE_FINISHED, 2);
2477  DEBUG_ONLY(set_phase_optimize_finished();)
2478 }
2479 
2480 #ifdef ASSERT

3064             // Accumulate any precedence edges
3065             if (mem->in(i) != NULL) {
3066               n->add_prec(mem->in(i));
3067             }
3068           }
3069           // Everything above this point has been processed.
3070           done = true;
3071         }
3072         // Eliminate the previous StoreCM
3073         prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
3074         assert(mem->outcnt() == 0, "should be dead");
3075         mem->disconnect_inputs(this);
3076       } else {
3077         prev = mem;
3078       }
3079       mem = prev->in(MemNode::Memory);
3080     }
3081   }
3082 }
3083 

3084 //------------------------------final_graph_reshaping_impl----------------------
3085 // Implement items 1-5 from final_graph_reshaping below.
3086 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
3087 
3088   if ( n->outcnt() == 0 ) return; // dead node
3089   uint nop = n->Opcode();
3090 
3091   // Check for 2-input instruction with "last use" on right input.
3092   // Swap to left input.  Implements item (2).
3093   if( n->req() == 3 &&          // two-input instruction
3094       n->in(1)->outcnt() > 1 && // left use is NOT a last use
3095       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
3096       n->in(2)->outcnt() == 1 &&// right use IS a last use
3097       !n->in(2)->is_Con() ) {   // right use is not a constant
3098     // Check for commutative opcode
3099     switch( nop ) {
3100     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
3101     case Op_MaxI:  case Op_MaxL:  case Op_MaxF:  case Op_MaxD:
3102     case Op_MinI:  case Op_MinL:  case Op_MinF:  case Op_MinD:
3103     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:

3217       if (n->outcnt() > 1 &&
3218           !n->is_Proj() &&
3219           nop != Op_CreateEx &&
3220           nop != Op_CheckCastPP &&
3221           nop != Op_DecodeN &&
3222           nop != Op_DecodeNKlass &&
3223           !n->is_Mem() &&
3224           !n->is_Phi()) {
3225         Node *x = n->clone();
3226         call->set_req(TypeFunc::Parms, x);
3227       }
3228     }
3229     break;
3230   }
3231 
3232   case Op_StoreCM:
3233     {
3234       // Convert OopStore dependence into precedence edge
3235       Node* prec = n->in(MemNode::OopStore);
3236       n->del_req(MemNode::OopStore);
3237       n->add_prec(prec);















3238       eliminate_redundant_card_marks(n);
3239     }
3240 
3241     // fall through
3242 
3243   case Op_StoreB:
3244   case Op_StoreC:
3245   case Op_StoreI:
3246   case Op_StoreL:
3247   case Op_CompareAndSwapB:
3248   case Op_CompareAndSwapS:
3249   case Op_CompareAndSwapI:
3250   case Op_CompareAndSwapL:
3251   case Op_CompareAndSwapP:
3252   case Op_CompareAndSwapN:
3253   case Op_WeakCompareAndSwapB:
3254   case Op_WeakCompareAndSwapS:
3255   case Op_WeakCompareAndSwapI:
3256   case Op_WeakCompareAndSwapL:
3257   case Op_WeakCompareAndSwapP:

3827           // Replace all nodes with identical edges as m with m
3828           k->subsume_by(m, this);
3829         }
3830       }
3831     }
3832     break;
3833   }
3834   case Op_CmpUL: {
3835     if (!Matcher::has_match_rule(Op_CmpUL)) {
3836       // No support for unsigned long comparisons
3837       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
3838       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
3839       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
3840       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
3841       Node* andl = new AndLNode(orl, remove_sign_mask);
3842       Node* cmp = new CmpLNode(andl, n->in(2));
3843       n->subsume_by(cmp, this);
3844     }
3845     break;
3846   }








3847   default:
3848     assert(!n->is_Call(), "");
3849     assert(!n->is_Mem(), "");
3850     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
3851     break;
3852   }
3853 }
3854 
3855 //------------------------------final_graph_reshaping_walk---------------------
3856 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3857 // requires that the walk visits a node's inputs before visiting the node.
3858 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
3859   Unique_Node_List sfpt;
3860 
3861   frc._visited.set(root->_idx); // first, mark node as visited
3862   uint cnt = root->req();
3863   Node *n = root;
3864   uint  i = 0;
3865   while (true) {
3866     if (i < cnt) {

4174   }
4175 }
4176 
4177 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4178   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4179 }
4180 
4181 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4182   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4183 }
4184 
4185 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4186   if (holder->is_initialized()) {
4187     return false;
4188   }
4189   if (holder->is_being_initialized()) {
4190     if (accessing_method->holder() == holder) {
4191       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4192       // <init>, or a static method. In all those cases, there was an initialization
4193       // barrier on the holder klass passed.
4194       if (accessing_method->is_static_initializer() ||
4195           accessing_method->is_object_initializer() ||
4196           accessing_method->is_static()) {
4197         return false;
4198       }
4199     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4200       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4201       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4202       // child class can become fully initialized while its parent class is still being initialized.
4203       if (accessing_method->is_static_initializer()) {
4204         return false;
4205       }
4206     }
4207     ciMethod* root = method(); // the root method of compilation
4208     if (root != accessing_method) {
4209       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4210     }
4211   }
4212   return true;
4213 }
4214 
4215 #ifndef PRODUCT
4216 //------------------------------verify_graph_edges---------------------------
4217 // Walk the Graph and verify that there is a one-to-one correspondence
4218 // between Use-Def edges and Def-Use edges in the graph.
4219 void Compile::verify_graph_edges(bool no_dead_code) {
4220   if (VerifyGraphEdges) {
4221     Unique_Node_List visited;
4222     // Call recursive graph walk to check edges
4223     _root->verify_edges(visited);

4320 // (1) subklass is already limited to a subtype of superklass => always ok
4321 // (2) subklass does not overlap with superklass => always fail
4322 // (3) superklass has NO subtypes and we can check with a simple compare.
4323 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk) {
4324   if (StressReflectiveCode) {
4325     return SSC_full_test;       // Let caller generate the general case.
4326   }
4327 
4328   if (subk->is_java_subtype_of(superk)) {
4329     return SSC_always_true; // (0) and (1)  this test cannot fail
4330   }
4331 
4332   if (!subk->maybe_java_subtype_of(superk)) {
4333     return SSC_always_false; // (2) true path dead; no dynamic test needed
4334   }
4335 
4336   const Type* superelem = superk;
4337   if (superk->isa_aryklassptr()) {
4338     int ignored;
4339     superelem = superk->is_aryklassptr()->base_element_type(ignored);








4340   }
4341 
4342   if (superelem->isa_instklassptr()) {
4343     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4344     if (!ik->has_subklass()) {
4345       if (!ik->is_final()) {
4346         // Add a dependency if there is a chance of a later subclass.
4347         dependencies()->assert_leaf_type(ik);
4348       }
4349       if (!superk->maybe_java_subtype_of(subk)) {
4350         return SSC_always_false;
4351       }
4352       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
4353     }
4354   } else {
4355     // A primitive array type has no subtypes.
4356     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
4357   }
4358 
4359   return SSC_full_test;

4881       const Type* t = igvn.type_or_null(n);
4882       assert((t == NULL) || (t == t->remove_speculative()), "no more speculative types");
4883       if (n->is_Type()) {
4884         t = n->as_Type()->type();
4885         assert(t == t->remove_speculative(), "no more speculative types");
4886       }
4887       // Iterate over outs - endless loops is unreachable from below
4888       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
4889         Node *m = n->fast_out(i);
4890         if (not_a_node(m)) {
4891           continue;
4892         }
4893         worklist.push(m);
4894       }
4895     }
4896     igvn.check_no_speculative_types();
4897 #endif
4898   }
4899 }
4900 





















4901 // Auxiliary methods to support randomized stressing/fuzzing.
4902 
4903 int Compile::random() {
4904   _stress_seed = os::next_random(_stress_seed);
4905   return static_cast<int>(_stress_seed);
4906 }
4907 
4908 // This method can be called the arbitrary number of times, with current count
4909 // as the argument. The logic allows selecting a single candidate from the
4910 // running list of candidates as follows:
4911 //    int count = 0;
4912 //    Cand* selected = null;
4913 //    while(cand = cand->next()) {
4914 //      if (randomized_select(++count)) {
4915 //        selected = cand;
4916 //      }
4917 //    }
4918 //
4919 // Including count equalizes the chances any candidate is "selected".
4920 // This is useful when we don't have the complete list of candidates to choose

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

 375   // Constant node that has no out-edges and has only one in-edge from
 376   // root is usually dead. However, sometimes reshaping walk makes
 377   // it reachable by adding use edges. So, we will NOT count Con nodes
 378   // as dead to be conservative about the dead node count at any
 379   // given time.
 380   if (!dead->is_Con()) {
 381     record_dead_node(dead->_idx);
 382   }
 383   if (dead->is_macro()) {
 384     remove_macro_node(dead);
 385   }
 386   if (dead->is_expensive()) {
 387     remove_expensive_node(dead);
 388   }
 389   if (dead->Opcode() == Op_Opaque4) {
 390     remove_skeleton_predicate_opaq(dead);
 391   }
 392   if (dead->for_post_loop_opts_igvn()) {
 393     remove_from_post_loop_opts_igvn(dead);
 394   }
 395   if (dead->is_InlineTypeBase()) {
 396     remove_inline_type(dead);
 397   }
 398   if (dead->is_Call()) {
 399     remove_useless_late_inlines(                &_late_inlines, dead);
 400     remove_useless_late_inlines(         &_string_late_inlines, dead);
 401     remove_useless_late_inlines(         &_boxing_late_inlines, dead);
 402     remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
 403 
 404     if (dead->is_CallStaticJava()) {
 405       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
 406     }
 407   }
 408   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 409   bs->unregister_potential_barrier_node(dead);
 410 }
 411 
 412 // Disconnect all useless nodes by disconnecting those at the boundary.
 413 void Compile::disconnect_useless_nodes(Unique_Node_List &useful, Unique_Node_List* worklist) {
 414   uint next = 0;
 415   while (next < useful.size()) {
 416     Node *n = useful.at(next++);
 417     if (n->is_SafePoint()) {
 418       // We're done with a parsing phase. Replaced nodes are not valid
 419       // beyond that point.
 420       n->as_SafePoint()->delete_replaced_nodes();
 421     }
 422     // Use raw traversal of out edges since this code removes out edges
 423     int max = n->outcnt();
 424     for (int j = 0; j < max; ++j) {
 425       Node* child = n->raw_out(j);
 426       if (!useful.member(child)) {
 427         assert(!child->is_top() || child != top(),
 428                "If top is cached in Compile object it is in useful list");
 429         // Only need to remove this out-edge to the useless node
 430         n->raw_del_out(j);
 431         --j;
 432         --max;
 433       }
 434     }
 435     if (n->outcnt() == 1 && n->has_special_unique_user()) {
 436       worklist->push(n->unique_out());
 437     }
 438     if (n->outcnt() == 0) {
 439       worklist->push(n);
 440     }
 441   }
 442 
 443   remove_useless_nodes(_macro_nodes,        useful); // remove useless macro nodes
 444   remove_useless_nodes(_predicate_opaqs,    useful); // remove useless predicate opaque nodes
 445   remove_useless_nodes(_skeleton_predicate_opaqs, useful);
 446   remove_useless_nodes(_expensive_nodes,    useful); // remove useless expensive nodes
 447   remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
 448   remove_useless_nodes(_inline_type_nodes,  useful); // remove useless inline type nodes
 449 #ifdef ASSERT
 450   if (_modified_nodes != NULL) {
 451     _modified_nodes->remove_useless_nodes(useful.member_set());
 452   }
 453 #endif
 454   remove_useless_unstable_if_traps(useful);          // remove useless unstable_if traps
 455   remove_useless_coarsened_locks(useful);            // remove useless coarsened locks nodes
 456 #ifdef ASSERT
 457   if (_modified_nodes != NULL) {
 458     _modified_nodes->remove_useless_nodes(useful.member_set());
 459   }
 460 #endif
 461 
 462   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 463   bs->eliminate_useless_gc_barriers(useful, this);
 464   // clean up the late inline lists
 465   remove_useless_late_inlines(                &_late_inlines, useful);
 466   remove_useless_late_inlines(         &_string_late_inlines, useful);
 467   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
 468   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
 469   debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
 470 }
 471 
 472 // ============================================================================
 473 //------------------------------CompileWrapper---------------------------------

 613                   _has_reserved_stack_access(target->has_reserved_stack_access()),
 614 #ifndef PRODUCT
 615                   _igv_idx(0),
 616                   _trace_opto_output(directive->TraceOptoOutputOption),
 617 #endif
 618                   _has_method_handle_invokes(false),
 619                   _clinit_barrier_on_entry(false),
 620                   _stress_seed(0),
 621                   _comp_arena(mtCompiler),
 622                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
 623                   _env(ci_env),
 624                   _directive(directive),
 625                   _log(ci_env->log()),
 626                   _failure_reason(NULL),
 627                   _intrinsics        (comp_arena(), 0, 0, NULL),
 628                   _macro_nodes       (comp_arena(), 8, 0, NULL),
 629                   _predicate_opaqs   (comp_arena(), 8, 0, NULL),
 630                   _skeleton_predicate_opaqs (comp_arena(), 8, 0, NULL),
 631                   _expensive_nodes   (comp_arena(), 8, 0, NULL),
 632                   _for_post_loop_igvn(comp_arena(), 8, 0, NULL),
 633                   _inline_type_nodes (comp_arena(), 8, 0, NULL),
 634                   _unstable_if_traps (comp_arena(), 8, 0, NULL),
 635                   _coarsened_locks   (comp_arena(), 8, 0, NULL),
 636                   _congraph(NULL),
 637                   NOT_PRODUCT(_igv_printer(NULL) COMMA)
 638                   _dead_node_list(comp_arena()),
 639                   _dead_node_count(0),
 640                   _node_arena(mtCompiler),
 641                   _old_arena(mtCompiler),
 642                   _mach_constant_base_node(NULL),
 643                   _Compile_types(mtCompiler),
 644                   _initial_gvn(NULL),
 645                   _for_igvn(NULL),
 646                   _late_inlines(comp_arena(), 2, 0, NULL),
 647                   _string_late_inlines(comp_arena(), 2, 0, NULL),
 648                   _boxing_late_inlines(comp_arena(), 2, 0, NULL),
 649                   _vector_reboxing_late_inlines(comp_arena(), 2, 0, NULL),
 650                   _late_inlines_pos(0),
 651                   _number_of_mh_late_inlines(0),
 652                   _print_inlining_stream(NULL),
 653                   _print_inlining_list(NULL),

 719   // Node list that Iterative GVN will start with
 720   Unique_Node_List for_igvn(comp_arena());
 721   set_for_igvn(&for_igvn);
 722 
 723   // GVN that will be run immediately on new nodes
 724   uint estimated_size = method()->code_size()*4+64;
 725   estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
 726   PhaseGVN gvn(node_arena(), estimated_size);
 727   set_initial_gvn(&gvn);
 728 
 729   print_inlining_init();
 730   { // Scope for timing the parser
 731     TracePhase tp("parse", &timers[_t_parser]);
 732 
 733     // Put top into the hash table ASAP.
 734     initial_gvn()->transform_no_reclaim(top());
 735 
 736     // Set up tf(), start(), and find a CallGenerator.
 737     CallGenerator* cg = NULL;
 738     if (is_osr_compilation()) {
 739       init_tf(TypeFunc::make(method(), /* is_osr_compilation = */ true));
 740       StartNode* s = new StartOSRNode(root(), tf()->domain_sig());


 741       initial_gvn()->set_type_bottom(s);
 742       init_start(s);
 743       cg = CallGenerator::for_osr(method(), entry_bci());
 744     } else {
 745       // Normal case.
 746       init_tf(TypeFunc::make(method()));
 747       StartNode* s = new StartNode(root(), tf()->domain_cc());
 748       initial_gvn()->set_type_bottom(s);
 749       init_start(s);
 750       if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {
 751         // With java.lang.ref.reference.get() we must go through the
 752         // intrinsic - even when get() is the root
 753         // method of the compile - so that, if necessary, the value in
 754         // the referent field of the reference object gets recorded by
 755         // the pre-barrier code.
 756         cg = find_intrinsic(method(), false);
 757       }
 758       if (cg == NULL) {
 759         float past_uses = method()->interpreter_invocation_count();
 760         float expected_uses = past_uses;
 761         cg = CallGenerator::for_inline(method(), expected_uses);
 762       }
 763     }
 764     if (failing())  return;
 765     if (cg == NULL) {
 766       record_method_not_compilable("cannot parse method");
 767       return;

 846     print_ideal_ir("print_ideal");
 847   }
 848 #endif
 849 
 850 #ifdef ASSERT
 851   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 852   bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
 853 #endif
 854 
 855   // Dump compilation data to replay it.
 856   if (directive->DumpReplayOption) {
 857     env()->dump_replay_data(_compile_id);
 858   }
 859   if (directive->DumpInlineOption && (ilt() != NULL)) {
 860     env()->dump_inline_data(_compile_id);
 861   }
 862 
 863   // Now that we know the size of all the monitors we can add a fixed slot
 864   // for the original deopt pc.
 865   int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);
 866   if (needs_stack_repair()) {
 867     // One extra slot for the special stack increment value
 868     next_slot += 2;
 869   }
 870   // TODO 8284443 Only reserve extra slot if needed
 871   if (InlineTypeReturnedAsFields) {
 872     // One extra slot to hold the IsInit information for a nullable
 873     // inline type return if we run out of registers.
 874     next_slot += 2;
 875   }
 876   set_fixed_slots(next_slot);
 877 
 878   // Compute when to use implicit null checks. Used by matching trap based
 879   // nodes and NullCheck optimization.
 880   set_allowed_deopt_reasons();
 881 
 882   // Now generate code
 883   Code_Gen();
 884 }
 885 
 886 //------------------------------Compile----------------------------------------
 887 // Compile a runtime stub
 888 Compile::Compile( ciEnv* ci_env,
 889                   TypeFunc_generator generator,
 890                   address stub_function,
 891                   const char *stub_name,
 892                   int is_fancy_jump,
 893                   bool pass_tls,
 894                   bool return_pc,
 895                   DirectiveSet* directive)

1007   // Create Debug Information Recorder to record scopes, oopmaps, etc.
1008   env()->set_oop_recorder(new OopRecorder(env()->arena()));
1009   env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
1010   env()->set_dependencies(new Dependencies(env()));
1011 
1012   _fixed_slots = 0;
1013   set_has_split_ifs(false);
1014   set_has_loops(false); // first approximation
1015   set_has_stringbuilder(false);
1016   set_has_boxed_value(false);
1017   _trap_can_recompile = false;  // no traps emitted yet
1018   _major_progress = true; // start out assuming good things will happen
1019   set_has_unsafe_access(false);
1020   set_max_vector_size(0);
1021   set_clear_upper_avx(false);  //false as default for clear upper bits of ymm registers
1022   Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1023   set_decompile_count(0);
1024 
1025   set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1026   _loop_opts_cnt = LoopOptsCount;
1027   _has_flattened_accesses = false;
1028   _flattened_accesses_share_alias = true;
1029   _scalarize_in_safepoints = false;
1030 
1031   set_do_inlining(Inline);
1032   set_max_inline_size(MaxInlineSize);
1033   set_freq_inline_size(FreqInlineSize);
1034   set_do_scheduling(OptoScheduling);
1035 
1036   set_do_vector_loop(false);
1037   set_has_monitors(false);
1038 
1039   if (AllowVectorizeOnDemand) {
1040     if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
1041       set_do_vector_loop(true);
1042       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());})
1043     } else if (has_method() && method()->name() != 0 &&
1044                method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1045       set_do_vector_loop(true);
1046     }
1047   }
1048   set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1049   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());})
1050 

1314 bool Compile::allow_range_check_smearing() const {
1315   // If this method has already thrown a range-check,
1316   // assume it was because we already tried range smearing
1317   // and it failed.
1318   uint already_trapped = trap_count(Deoptimization::Reason_range_check);
1319   return !already_trapped;
1320 }
1321 
1322 
1323 //------------------------------flatten_alias_type-----------------------------
1324 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1325   int offset = tj->offset();
1326   TypePtr::PTR ptr = tj->ptr();
1327 
1328   // Known instance (scalarizable allocation) alias only with itself.
1329   bool is_known_inst = tj->isa_oopptr() != NULL &&
1330                        tj->is_oopptr()->is_known_instance();
1331 
1332   // Process weird unsafe references.
1333   if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1334     bool default_value_load = EnableValhalla && tj->is_instptr()->instance_klass() == ciEnv::current()->Class_klass();
1335     assert(InlineUnsafeOps || StressReflectiveCode || default_value_load, "indeterminate pointers come only from unsafe ops");
1336     assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1337     tj = TypeOopPtr::BOTTOM;
1338     ptr = tj->ptr();
1339     offset = tj->offset();
1340   }
1341 
1342   // Array pointers need some flattening
1343   const TypeAryPtr* ta = tj->isa_aryptr();
1344   if (ta && ta->is_stable()) {
1345     // Erase stability property for alias analysis.
1346     tj = ta = ta->cast_to_stable(false);
1347   }
1348   if (ta && ta->is_not_flat()) {
1349     // Erase not flat property for alias analysis.
1350     tj = ta = ta->cast_to_not_flat(false);
1351   }
1352   if (ta && ta->is_not_null_free()) {
1353     // Erase not null free property for alias analysis.
1354     tj = ta = ta->cast_to_not_null_free(false);
1355   }
1356 
1357   if( ta && is_known_inst ) {
1358     if ( offset != Type::OffsetBot &&
1359          offset > arrayOopDesc::length_offset_in_bytes() ) {
1360       offset = Type::OffsetBot; // Flatten constant access into array body only
1361       tj = ta = ta->
1362               remove_speculative()->
1363               cast_to_ptr_type(ptr)->
1364               with_offset(offset);
1365     }
1366   } else if( ta && _AliasLevel >= 2 ) {
1367     // For arrays indexed by constant indices, we flatten the alias
1368     // space to include all of the array body.  Only the header, klass
1369     // and array length can be accessed un-aliased.
1370     // For flattened inline type array, each field has its own slice so
1371     // we must include the field offset.
1372     if( offset != Type::OffsetBot ) {
1373       if( ta->const_oop() ) { // MethodData* or Method*
1374         offset = Type::OffsetBot;   // Flatten constant access into array body
1375         tj = ta = ta->
1376                 remove_speculative()->
1377                 cast_to_ptr_type(ptr)->
1378                 cast_to_exactness(false)->
1379                 with_offset(offset);
1380       } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1381         // range is OK as-is.
1382         tj = ta = TypeAryPtr::RANGE;
1383       } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1384         tj = TypeInstPtr::KLASS; // all klass loads look alike
1385         ta = TypeAryPtr::RANGE; // generic ignored junk
1386         ptr = TypePtr::BotPTR;
1387       } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1388         tj = TypeInstPtr::MARK;
1389         ta = TypeAryPtr::RANGE; // generic ignored junk
1390         ptr = TypePtr::BotPTR;
1391       } else {                  // Random constant offset into array body
1392         offset = Type::OffsetBot;   // Flatten constant access into array body
1393         tj = ta = ta->
1394                 remove_speculative()->
1395                 cast_to_ptr_type(ptr)->
1396                 cast_to_exactness(false)->
1397                 with_offset(offset);
1398       }
1399     }
1400     // Arrays of fixed size alias with arrays of unknown size.
1401     if (ta->size() != TypeInt::POS) {
1402       const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1403       tj = ta = ta->
1404               remove_speculative()->
1405               cast_to_ptr_type(ptr)->
1406               with_ary(tary)->
1407               cast_to_exactness(false);
1408     }
1409     // Arrays of known objects become arrays of unknown objects.
1410     if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1411       const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1412       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,Type::Offset(offset), ta->field_offset());
1413     }
1414     if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1415       const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1416       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,Type::Offset(offset), ta->field_offset());
1417     }
1418     // Initially all flattened array accesses share a single slice
1419     if (ta->is_flat() && ta->elem() != TypeInlineType::BOTTOM && _flattened_accesses_share_alias) {
1420       const TypeAry *tary = TypeAry::make(TypeInlineType::BOTTOM, ta->size());
1421       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,Type::Offset(offset), Type::Offset(Type::OffsetBot));
1422     }
1423     // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1424     // cannot be distinguished by bytecode alone.
1425     if (ta->elem() == TypeInt::BOOL) {
1426       const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1427       ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1428       tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,Type::Offset(offset), ta->field_offset());
1429     }
1430     // During the 2nd round of IterGVN, NotNull castings are removed.
1431     // Make sure the Bottom and NotNull variants alias the same.
1432     // Also, make sure exact and non-exact variants alias the same.
1433     if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != NULL) {
1434       tj = ta = ta->
1435               remove_speculative()->
1436               cast_to_ptr_type(TypePtr::BotPTR)->
1437               cast_to_exactness(false)->
1438               with_offset(offset);
1439     }
1440   }
1441 
1442   // Oop pointers need some flattening
1443   const TypeInstPtr *to = tj->isa_instptr();
1444   if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1445     ciInstanceKlass* ik = to->instance_klass();
1446     if( ptr == TypePtr::Constant ) {
1447       if (ik != ciEnv::current()->Class_klass() ||
1448           offset < ik->layout_helper_size_in_bytes()) {

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

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

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

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

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

2610     assert(has_stringbuilder(), "inconsistent");
2611     for_igvn()->clear();
2612     initial_gvn()->replace_with(&igvn);
2613 
2614     inline_string_calls(false);
2615 
2616     if (failing())  return;
2617 
2618     inline_incrementally_cleanup(igvn);
2619   }
2620 
2621   set_inlining_incrementally(false);
2622 }
2623 
2624 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2625   // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2626   // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2627   // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == NULL"
2628   // as if "inlining_incrementally() == true" were set.
2629   assert(inlining_incrementally() == false, "not allowed");
2630 #ifdef ASSERT
2631   Unique_Node_List* modified_nodes = _modified_nodes;
2632   _modified_nodes = NULL;
2633 #endif
2634   assert(_late_inlines.length() > 0, "sanity");
2635 
2636   while (_late_inlines.length() > 0) {
2637     for_igvn()->clear();
2638     initial_gvn()->replace_with(&igvn);
2639 
2640     while (inline_incrementally_one()) {
2641       assert(!failing(), "inconsistent");
2642     }
2643     if (failing())  return;
2644 
2645     inline_incrementally_cleanup(igvn);
2646   }
2647   DEBUG_ONLY( _modified_nodes = modified_nodes; )
2648 }
2649 
2650 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2651   if (_loop_opts_cnt > 0) {
2652     while (major_progress() && (_loop_opts_cnt > 0)) {
2653       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2654       PhaseIdealLoop::optimize(igvn, mode);
2655       _loop_opts_cnt--;
2656       if (failing())  return false;
2657       if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2658     }
2659   }
2660   return true;
2661 }
2662 
2663 // Remove edges from "root" to each SafePoint at a backward branch.
2664 // They were inserted during parsing (see add_safepoint()) to make
2665 // infinite loops without calls or exceptions visible to root, i.e.,
2666 // useful.
2667 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {

2771     Compile::TracePhase tp("", &timers[_t_renumberLive]);
2772     initial_gvn()->replace_with(&igvn);
2773     Unique_Node_List* old_worklist = for_igvn();
2774     old_worklist->clear();
2775     Unique_Node_List new_worklist(C->comp_arena());
2776     {
2777       ResourceMark rm;
2778       PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
2779     }
2780     Unique_Node_List* save_for_igvn = for_igvn();
2781     set_for_igvn(&new_worklist);
2782     igvn = PhaseIterGVN(initial_gvn());
2783     igvn.optimize();
2784     set_for_igvn(old_worklist); // new_worklist is dead beyond this point
2785   }
2786 
2787   // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2788   // safepoints
2789   remove_root_to_sfpts_edges(igvn);
2790 
2791   // Process inline type nodes now that all inlining is over
2792   process_inline_types(igvn);
2793 
2794   adjust_flattened_array_access_aliases(igvn);
2795 
2796   // Perform escape analysis
2797   if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2798     if (has_loops()) {
2799       // Cleanup graph (remove dead nodes).
2800       TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2801       PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2802       if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2803       if (failing())  return;
2804     }
2805     bool progress;
2806     do {
2807       ConnectionGraph::do_analysis(this, &igvn);
2808 
2809       if (failing())  return;
2810 
2811       int mcount = macro_count(); // Record number of allocations and locks before IGVN
2812 
2813       // Optimize out fields loads from scalar replaceable allocations.
2814       igvn.optimize();
2815       print_method(PHASE_ITER_GVN_AFTER_EA, 2);

2889   print_method(PHASE_ITER_GVN2, 2);
2890 
2891   if (failing())  return;
2892 
2893   // Loop transforms on the ideal graph.  Range Check Elimination,
2894   // peeling, unrolling, etc.
2895   if (!optimize_loops(igvn, LoopOptsDefault)) {
2896     return;
2897   }
2898 
2899   if (failing())  return;
2900 
2901   C->clear_major_progress(); // ensure that major progress is now clear
2902 
2903   process_for_post_loop_opts_igvn(igvn);
2904 
2905 #ifdef ASSERT
2906   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2907 #endif
2908 
2909   assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2910 
2911   if (_late_inlines.length() > 0) {
2912     // More opportunities to optimize virtual and MH calls.
2913     // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2914     process_late_inline_calls_no_inline(igvn);
2915   }
2916 
2917   {
2918     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2919     PhaseMacroExpand  mex(igvn);
2920     if (mex.expand_macro_nodes()) {
2921       assert(failing(), "must bail out w/ explicit message");
2922       return;
2923     }
2924     print_method(PHASE_MACRO_EXPANSION, 2);
2925   }
2926 
2927   // Process inline type nodes again and remove them. From here
2928   // on we don't need to keep track of field values anymore.
2929   process_inline_types(igvn, /* remove= */ true);
2930 
2931   {
2932     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2933     if (bs->expand_barriers(this, igvn)) {
2934       assert(failing(), "must bail out w/ explicit message");
2935       return;
2936     }
2937     print_method(PHASE_BARRIER_EXPANSION, 2);
2938   }
2939 
2940   if (C->max_vector_size() > 0) {
2941     C->optimize_logic_cones(igvn);
2942     igvn.optimize();
2943   }
2944 
2945   DEBUG_ONLY( _modified_nodes = NULL; )
2946   DEBUG_ONLY( _late_inlines.clear(); )
2947 
2948   assert(igvn._worklist.size() == 0, "not empty");








2949  } // (End scope of igvn; run destructor if necessary for asserts.)
2950 
2951  check_no_dead_use();
2952 
2953  process_print_inlining();
2954 
2955  // A method with only infinite loops has no edges entering loops from root
2956  {
2957    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2958    if (final_graph_reshaping()) {
2959      assert(failing(), "must bail out w/ explicit message");
2960      return;
2961    }
2962  }
2963 
2964  print_method(PHASE_OPTIMIZE_FINISHED, 2);
2965  DEBUG_ONLY(set_phase_optimize_finished();)
2966 }
2967 
2968 #ifdef ASSERT

3552             // Accumulate any precedence edges
3553             if (mem->in(i) != NULL) {
3554               n->add_prec(mem->in(i));
3555             }
3556           }
3557           // Everything above this point has been processed.
3558           done = true;
3559         }
3560         // Eliminate the previous StoreCM
3561         prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
3562         assert(mem->outcnt() == 0, "should be dead");
3563         mem->disconnect_inputs(this);
3564       } else {
3565         prev = mem;
3566       }
3567       mem = prev->in(MemNode::Memory);
3568     }
3569   }
3570 }
3571 
3572 
3573 //------------------------------final_graph_reshaping_impl----------------------
3574 // Implement items 1-5 from final_graph_reshaping below.
3575 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
3576 
3577   if ( n->outcnt() == 0 ) return; // dead node
3578   uint nop = n->Opcode();
3579 
3580   // Check for 2-input instruction with "last use" on right input.
3581   // Swap to left input.  Implements item (2).
3582   if( n->req() == 3 &&          // two-input instruction
3583       n->in(1)->outcnt() > 1 && // left use is NOT a last use
3584       (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
3585       n->in(2)->outcnt() == 1 &&// right use IS a last use
3586       !n->in(2)->is_Con() ) {   // right use is not a constant
3587     // Check for commutative opcode
3588     switch( nop ) {
3589     case Op_AddI:  case Op_AddF:  case Op_AddD:  case Op_AddL:
3590     case Op_MaxI:  case Op_MaxL:  case Op_MaxF:  case Op_MaxD:
3591     case Op_MinI:  case Op_MinL:  case Op_MinF:  case Op_MinD:
3592     case Op_MulI:  case Op_MulF:  case Op_MulD:  case Op_MulL:

3706       if (n->outcnt() > 1 &&
3707           !n->is_Proj() &&
3708           nop != Op_CreateEx &&
3709           nop != Op_CheckCastPP &&
3710           nop != Op_DecodeN &&
3711           nop != Op_DecodeNKlass &&
3712           !n->is_Mem() &&
3713           !n->is_Phi()) {
3714         Node *x = n->clone();
3715         call->set_req(TypeFunc::Parms, x);
3716       }
3717     }
3718     break;
3719   }
3720 
3721   case Op_StoreCM:
3722     {
3723       // Convert OopStore dependence into precedence edge
3724       Node* prec = n->in(MemNode::OopStore);
3725       n->del_req(MemNode::OopStore);
3726       if (prec->is_MergeMem()) {
3727         MergeMemNode* mm = prec->as_MergeMem();
3728         Node* base = mm->base_memory();
3729         for (int i = AliasIdxRaw + 1; i < num_alias_types(); i++) {
3730           const Type* adr_type = get_adr_type(i);
3731           if (adr_type->isa_aryptr() && adr_type->is_aryptr()->is_flat()) {
3732             Node* m = mm->memory_at(i);
3733             n->add_prec(m);
3734           }
3735         }
3736         if (mm->outcnt() == 0) {
3737           mm->disconnect_inputs(this);
3738         }
3739       } else {
3740         n->add_prec(prec);
3741       }
3742       eliminate_redundant_card_marks(n);
3743     }
3744 
3745     // fall through
3746 
3747   case Op_StoreB:
3748   case Op_StoreC:
3749   case Op_StoreI:
3750   case Op_StoreL:
3751   case Op_CompareAndSwapB:
3752   case Op_CompareAndSwapS:
3753   case Op_CompareAndSwapI:
3754   case Op_CompareAndSwapL:
3755   case Op_CompareAndSwapP:
3756   case Op_CompareAndSwapN:
3757   case Op_WeakCompareAndSwapB:
3758   case Op_WeakCompareAndSwapS:
3759   case Op_WeakCompareAndSwapI:
3760   case Op_WeakCompareAndSwapL:
3761   case Op_WeakCompareAndSwapP:

4331           // Replace all nodes with identical edges as m with m
4332           k->subsume_by(m, this);
4333         }
4334       }
4335     }
4336     break;
4337   }
4338   case Op_CmpUL: {
4339     if (!Matcher::has_match_rule(Op_CmpUL)) {
4340       // No support for unsigned long comparisons
4341       ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
4342       Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
4343       Node* orl = new OrLNode(n->in(1), sign_bit_mask);
4344       ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
4345       Node* andl = new AndLNode(orl, remove_sign_mask);
4346       Node* cmp = new CmpLNode(andl, n->in(2));
4347       n->subsume_by(cmp, this);
4348     }
4349     break;
4350   }
4351 #ifdef ASSERT
4352   case Op_InlineTypePtr:
4353   case Op_InlineType: {
4354     n->dump(-1);
4355     assert(false, "inline type node was not removed");
4356     break;
4357   }
4358 #endif
4359   default:
4360     assert(!n->is_Call(), "");
4361     assert(!n->is_Mem(), "");
4362     assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
4363     break;
4364   }
4365 }
4366 
4367 //------------------------------final_graph_reshaping_walk---------------------
4368 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
4369 // requires that the walk visits a node's inputs before visiting the node.
4370 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
4371   Unique_Node_List sfpt;
4372 
4373   frc._visited.set(root->_idx); // first, mark node as visited
4374   uint cnt = root->req();
4375   Node *n = root;
4376   uint  i = 0;
4377   while (true) {
4378     if (i < cnt) {

4686   }
4687 }
4688 
4689 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4690   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4691 }
4692 
4693 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4694   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4695 }
4696 
4697 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4698   if (holder->is_initialized()) {
4699     return false;
4700   }
4701   if (holder->is_being_initialized()) {
4702     if (accessing_method->holder() == holder) {
4703       // Access inside a class. The barrier can be elided when access happens in <clinit>,
4704       // <init>, or a static method. In all those cases, there was an initialization
4705       // barrier on the holder klass passed.
4706       if (accessing_method->is_class_initializer() ||
4707           accessing_method->is_object_constructor() ||
4708           accessing_method->is_static()) {
4709         return false;
4710       }
4711     } else if (accessing_method->holder()->is_subclass_of(holder)) {
4712       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4713       // In case of <init> or a static method, the barrier is on the subclass is not enough:
4714       // child class can become fully initialized while its parent class is still being initialized.
4715       if (accessing_method->is_class_initializer()) {
4716         return false;
4717       }
4718     }
4719     ciMethod* root = method(); // the root method of compilation
4720     if (root != accessing_method) {
4721       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4722     }
4723   }
4724   return true;
4725 }
4726 
4727 #ifndef PRODUCT
4728 //------------------------------verify_graph_edges---------------------------
4729 // Walk the Graph and verify that there is a one-to-one correspondence
4730 // between Use-Def edges and Def-Use edges in the graph.
4731 void Compile::verify_graph_edges(bool no_dead_code) {
4732   if (VerifyGraphEdges) {
4733     Unique_Node_List visited;
4734     // Call recursive graph walk to check edges
4735     _root->verify_edges(visited);

4832 // (1) subklass is already limited to a subtype of superklass => always ok
4833 // (2) subklass does not overlap with superklass => always fail
4834 // (3) superklass has NO subtypes and we can check with a simple compare.
4835 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk) {
4836   if (StressReflectiveCode) {
4837     return SSC_full_test;       // Let caller generate the general case.
4838   }
4839 
4840   if (subk->is_java_subtype_of(superk)) {
4841     return SSC_always_true; // (0) and (1)  this test cannot fail
4842   }
4843 
4844   if (!subk->maybe_java_subtype_of(superk)) {
4845     return SSC_always_false; // (2) true path dead; no dynamic test needed
4846   }
4847 
4848   const Type* superelem = superk;
4849   if (superk->isa_aryklassptr()) {
4850     int ignored;
4851     superelem = superk->is_aryklassptr()->base_element_type(ignored);
4852 
4853     // Do not fold the subtype check to an array klass pointer comparison for [V? arrays.
4854     // [QMyValue is a subtype of [LMyValue but the klass for [QMyValue is not equal to
4855     // the klass for [LMyValue. Perform a full test.
4856     if (!superk->is_aryklassptr()->is_null_free() && superk->is_aryklassptr()->elem()->isa_instklassptr() &&
4857         superk->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->is_inlinetype()) {
4858       return SSC_full_test;
4859     }
4860   }
4861 
4862   if (superelem->isa_instklassptr()) {
4863     ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4864     if (!ik->has_subklass()) {
4865       if (!ik->is_final()) {
4866         // Add a dependency if there is a chance of a later subclass.
4867         dependencies()->assert_leaf_type(ik);
4868       }
4869       if (!superk->maybe_java_subtype_of(subk)) {
4870         return SSC_always_false;
4871       }
4872       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
4873     }
4874   } else {
4875     // A primitive array type has no subtypes.
4876     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
4877   }
4878 
4879   return SSC_full_test;

5401       const Type* t = igvn.type_or_null(n);
5402       assert((t == NULL) || (t == t->remove_speculative()), "no more speculative types");
5403       if (n->is_Type()) {
5404         t = n->as_Type()->type();
5405         assert(t == t->remove_speculative(), "no more speculative types");
5406       }
5407       // Iterate over outs - endless loops is unreachable from below
5408       for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
5409         Node *m = n->fast_out(i);
5410         if (not_a_node(m)) {
5411           continue;
5412         }
5413         worklist.push(m);
5414       }
5415     }
5416     igvn.check_no_speculative_types();
5417 #endif
5418   }
5419 }
5420 
5421 Node* Compile::optimize_acmp(PhaseGVN* phase, Node* a, Node* b) {
5422   const TypeInstPtr* ta = phase->type(a)->isa_instptr();
5423   const TypeInstPtr* tb = phase->type(b)->isa_instptr();
5424   if (!EnableValhalla || ta == NULL || tb == NULL ||
5425       ta->is_zero_type() || tb->is_zero_type() ||
5426       !ta->can_be_inline_type() || !tb->can_be_inline_type()) {
5427     // Use old acmp if one operand is null or not an inline type
5428     return new CmpPNode(a, b);
5429   } else if (ta->is_inlinetypeptr() || tb->is_inlinetypeptr()) {
5430     // We know that one operand is an inline type. Therefore,
5431     // new acmp will only return true if both operands are NULL.
5432     // Check if both operands are null by or'ing the oops.
5433     a = phase->transform(new CastP2XNode(NULL, a));
5434     b = phase->transform(new CastP2XNode(NULL, b));
5435     a = phase->transform(new OrXNode(a, b));
5436     return new CmpXNode(a, phase->MakeConX(0));
5437   }
5438   // Use new acmp
5439   return NULL;
5440 }
5441 
5442 // Auxiliary methods to support randomized stressing/fuzzing.
5443 
5444 int Compile::random() {
5445   _stress_seed = os::next_random(_stress_seed);
5446   return static_cast<int>(_stress_seed);
5447 }
5448 
5449 // This method can be called the arbitrary number of times, with current count
5450 // as the argument. The logic allows selecting a single candidate from the
5451 // running list of candidates as follows:
5452 //    int count = 0;
5453 //    Cand* selected = null;
5454 //    while(cand = cand->next()) {
5455 //      if (randomized_select(++count)) {
5456 //        selected = cand;
5457 //      }
5458 //    }
5459 //
5460 // Including count equalizes the chances any candidate is "selected".
5461 // This is useful when we don't have the complete list of candidates to choose
< prev index next >