7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/macroAssembler.hpp"
26 #include "asm/macroAssembler.inline.hpp"
27 #include "ci/ciReplay.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "code/aotCodeCache.hpp"
30 #include "code/exceptionHandlerTable.hpp"
31 #include "code/nmethod.hpp"
32 #include "compiler/compilationFailureInfo.hpp"
33 #include "compiler/compilationMemoryStatistic.hpp"
34 #include "compiler/compileBroker.hpp"
35 #include "compiler/compileLog.hpp"
36 #include "compiler/compiler_globals.hpp"
37 #include "compiler/compilerDefinitions.hpp"
38 #include "compiler/compilerOracle.hpp"
39 #include "compiler/disassembler.hpp"
40 #include "compiler/oopMap.hpp"
41 #include "gc/shared/barrierSet.hpp"
42 #include "gc/shared/c2/barrierSetC2.hpp"
43 #include "jfr/jfrEvents.hpp"
44 #include "jvm_io.h"
45 #include "memory/allocation.hpp"
46 #include "memory/arena.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "opto/addnode.hpp"
49 #include "opto/block.hpp"
50 #include "opto/c2compiler.hpp"
51 #include "opto/callGenerator.hpp"
52 #include "opto/callnode.hpp"
53 #include "opto/castnode.hpp"
54 #include "opto/cfgnode.hpp"
55 #include "opto/chaitin.hpp"
56 #include "opto/compile.hpp"
57 #include "opto/connode.hpp"
58 #include "opto/convertnode.hpp"
59 #include "opto/divnode.hpp"
60 #include "opto/escape.hpp"
61 #include "opto/idealGraphPrinter.hpp"
62 #include "opto/locknode.hpp"
63 #include "opto/loopnode.hpp"
64 #include "opto/machnode.hpp"
65 #include "opto/macro.hpp"
66 #include "opto/matcher.hpp"
67 #include "opto/mathexactnode.hpp"
68 #include "opto/memnode.hpp"
69 #include "opto/mulnode.hpp"
70 #include "opto/narrowptrnode.hpp"
71 #include "opto/node.hpp"
72 #include "opto/opaquenode.hpp"
73 #include "opto/opcodes.hpp"
74 #include "opto/output.hpp"
75 #include "opto/parse.hpp"
76 #include "opto/phaseX.hpp"
77 #include "opto/rootnode.hpp"
78 #include "opto/runtime.hpp"
79 #include "opto/stringopts.hpp"
80 #include "opto/type.hpp"
81 #include "opto/vector.hpp"
82 #include "opto/vectornode.hpp"
83 #include "runtime/globals_extension.hpp"
84 #include "runtime/sharedRuntime.hpp"
85 #include "runtime/signature.hpp"
86 #include "runtime/stubRoutines.hpp"
87 #include "runtime/timer.hpp"
88 #include "utilities/align.hpp"
89 #include "utilities/copy.hpp"
90 #include "utilities/hashTable.hpp"
91 #include "utilities/macros.hpp"
92
93 // -------------------- Compile::mach_constant_base_node -----------------------
94 // Constant table base node singleton.
95 MachConstantBaseNode* Compile::mach_constant_base_node() {
96 if (_mach_constant_base_node == nullptr) {
97 _mach_constant_base_node = new MachConstantBaseNode();
98 _mach_constant_base_node->add_req(C->root());
99 }
100 return _mach_constant_base_node;
101 }
102
388 // as dead to be conservative about the dead node count at any
389 // given time.
390 if (!dead->is_Con()) {
391 record_dead_node(dead->_idx);
392 }
393 if (dead->is_macro()) {
394 remove_macro_node(dead);
395 }
396 if (dead->is_expensive()) {
397 remove_expensive_node(dead);
398 }
399 if (dead->is_OpaqueTemplateAssertionPredicate()) {
400 remove_template_assertion_predicate_opaque(dead->as_OpaqueTemplateAssertionPredicate());
401 }
402 if (dead->is_ParsePredicate()) {
403 remove_parse_predicate(dead->as_ParsePredicate());
404 }
405 if (dead->for_post_loop_opts_igvn()) {
406 remove_from_post_loop_opts_igvn(dead);
407 }
408 if (dead->for_merge_stores_igvn()) {
409 remove_from_merge_stores_igvn(dead);
410 }
411 if (dead->is_Call()) {
412 remove_useless_late_inlines( &_late_inlines, dead);
413 remove_useless_late_inlines( &_string_late_inlines, dead);
414 remove_useless_late_inlines( &_boxing_late_inlines, dead);
415 remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
416
417 if (dead->is_CallStaticJava()) {
418 remove_unstable_if_trap(dead->as_CallStaticJava(), false);
419 }
420 }
421 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
422 bs->unregister_potential_barrier_node(dead);
423 }
424
425 // Disconnect all useless nodes by disconnecting those at the boundary.
426 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist, const Unique_Node_List* root_and_safepoints) {
427 uint next = 0;
435 // Use raw traversal of out edges since this code removes out edges
436 int max = n->outcnt();
437 for (int j = 0; j < max; ++j) {
438 Node* child = n->raw_out(j);
439 if (!useful.member(child)) {
440 assert(!child->is_top() || child != top(),
441 "If top is cached in Compile object it is in useful list");
442 // Only need to remove this out-edge to the useless node
443 n->raw_del_out(j);
444 --j;
445 --max;
446 if (child->is_data_proj_of_pure_function(n)) {
447 worklist.push(n);
448 }
449 }
450 }
451 if (n->outcnt() == 1 && n->has_special_unique_user()) {
452 assert(useful.member(n->unique_out()), "do not push a useless node");
453 worklist.push(n->unique_out());
454 }
455 }
456
457 remove_useless_nodes(_macro_nodes, useful); // remove useless macro nodes
458 remove_useless_nodes(_parse_predicates, useful); // remove useless Parse Predicate nodes
459 // Remove useless Template Assertion Predicate opaque nodes
460 remove_useless_nodes(_template_assertion_predicate_opaques, useful);
461 remove_useless_nodes(_expensive_nodes, useful); // remove useless expensive nodes
462 remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
463 remove_useless_nodes(_for_merge_stores_igvn, useful); // remove useless node recorded for merge stores IGVN pass
464 remove_useless_unstable_if_traps(useful); // remove useless unstable_if traps
465 remove_useless_coarsened_locks(useful); // remove useless coarsened locks nodes
466 #ifdef ASSERT
467 if (_modified_nodes != nullptr) {
468 _modified_nodes->remove_useless_nodes(useful.member_set());
469 }
470 #endif
471
472 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
473 bs->eliminate_useless_gc_barriers(useful, this);
474 // clean up the late inline lists
475 remove_useless_late_inlines( &_late_inlines, useful);
476 remove_useless_late_inlines( &_string_late_inlines, useful);
477 remove_useless_late_inlines( &_boxing_late_inlines, useful);
478 remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
479 DEBUG_ONLY(verify_graph_edges(true /*check for no_dead_code*/, root_and_safepoints);)
480 }
481
482 // ============================================================================
631 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
632 Options options, DirectiveSet* directive)
633 : Phase(Compiler),
634 _compile_id(ci_env->compile_id()),
635 _options(options),
636 _method(target),
637 _entry_bci(osr_bci),
638 _ilt(nullptr),
639 _stub_function(nullptr),
640 _stub_name(nullptr),
641 _stub_id(StubId::NO_STUBID),
642 _stub_entry_point(nullptr),
643 _max_node_limit(MaxNodeLimit),
644 _post_loop_opts_phase(false),
645 _merge_stores_phase(false),
646 _allow_macro_nodes(true),
647 _inlining_progress(false),
648 _inlining_incrementally(false),
649 _do_cleanup(false),
650 _has_reserved_stack_access(target->has_reserved_stack_access()),
651 #ifndef PRODUCT
652 _igv_idx(0),
653 _trace_opto_output(directive->TraceOptoOutputOption),
654 #endif
655 _clinit_barrier_on_entry(false),
656 _stress_seed(0),
657 _comp_arena(mtCompiler, Arena::Tag::tag_comp),
658 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
659 _env(ci_env),
660 _directive(directive),
661 _log(ci_env->log()),
662 _first_failure_details(nullptr),
663 _intrinsics(comp_arena(), 0, 0, nullptr),
664 _macro_nodes(comp_arena(), 8, 0, nullptr),
665 _parse_predicates(comp_arena(), 8, 0, nullptr),
666 _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
667 _expensive_nodes(comp_arena(), 8, 0, nullptr),
668 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
669 _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
670 _unstable_if_traps(comp_arena(), 8, 0, nullptr),
671 _coarsened_locks(comp_arena(), 8, 0, nullptr),
672 _congraph(nullptr),
673 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
674 _unique(0),
675 _dead_node_count(0),
676 _dead_node_list(comp_arena()),
677 _node_arena_one(mtCompiler, Arena::Tag::tag_node),
678 _node_arena_two(mtCompiler, Arena::Tag::tag_node),
679 _node_arena(&_node_arena_one),
680 _mach_constant_base_node(nullptr),
681 _Compile_types(mtCompiler, Arena::Tag::tag_type),
682 _initial_gvn(nullptr),
683 _igvn_worklist(nullptr),
684 _types(nullptr),
685 _node_hash(nullptr),
686 _late_inlines(comp_arena(), 2, 0, nullptr),
687 _string_late_inlines(comp_arena(), 2, 0, nullptr),
688 _boxing_late_inlines(comp_arena(), 2, 0, nullptr),
757 #define MINIMUM_NODE_HASH 1023
758
759 // GVN that will be run immediately on new nodes
760 uint estimated_size = method()->code_size()*4+64;
761 estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
762 _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
763 _types = new (comp_arena()) Type_Array(comp_arena());
764 _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
765 PhaseGVN gvn;
766 set_initial_gvn(&gvn);
767
768 { // Scope for timing the parser
769 TracePhase tp(_t_parser);
770
771 // Put top into the hash table ASAP.
772 initial_gvn()->transform(top());
773
774 // Set up tf(), start(), and find a CallGenerator.
775 CallGenerator* cg = nullptr;
776 if (is_osr_compilation()) {
777 const TypeTuple *domain = StartOSRNode::osr_domain();
778 const TypeTuple *range = TypeTuple::make_range(method()->signature());
779 init_tf(TypeFunc::make(domain, range));
780 StartNode* s = new StartOSRNode(root(), domain);
781 initial_gvn()->set_type_bottom(s);
782 verify_start(s);
783 cg = CallGenerator::for_osr(method(), entry_bci());
784 } else {
785 // Normal case.
786 init_tf(TypeFunc::make(method()));
787 StartNode* s = new StartNode(root(), tf()->domain());
788 initial_gvn()->set_type_bottom(s);
789 verify_start(s);
790 float past_uses = method()->interpreter_invocation_count();
791 float expected_uses = past_uses;
792 cg = CallGenerator::for_inline(method(), expected_uses);
793 }
794 if (failing()) return;
795 if (cg == nullptr) {
796 const char* reason = InlineTree::check_can_parse(method());
797 assert(reason != nullptr, "expect reason for parse failure");
798 stringStream ss;
799 ss.print("cannot parse method: %s", reason);
800 record_method_not_compilable(ss.as_string());
801 return;
802 }
803
804 gvn.set_type(root(), root()->bottom_type());
805
806 JVMState* jvms = build_start_state(start(), tf());
807 if ((jvms = cg->generate(jvms)) == nullptr) {
868 print_ideal_ir("print_ideal");
869 }
870 #endif
871
872 #ifdef ASSERT
873 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
874 bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
875 #endif
876
877 // Dump compilation data to replay it.
878 if (directive->DumpReplayOption) {
879 env()->dump_replay_data(_compile_id);
880 }
881 if (directive->DumpInlineOption && (ilt() != nullptr)) {
882 env()->dump_inline_data(_compile_id);
883 }
884
885 // Now that we know the size of all the monitors we can add a fixed slot
886 // for the original deopt pc.
887 int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);
888 set_fixed_slots(next_slot);
889
890 // Compute when to use implicit null checks. Used by matching trap based
891 // nodes and NullCheck optimization.
892 set_allowed_deopt_reasons();
893
894 // Now generate code
895 Code_Gen();
896 }
897
898 //------------------------------Compile----------------------------------------
899 // Compile a runtime stub
900 Compile::Compile(ciEnv* ci_env,
901 TypeFunc_generator generator,
902 address stub_function,
903 const char* stub_name,
904 StubId stub_id,
905 int is_fancy_jump,
906 bool pass_tls,
907 bool return_pc,
908 DirectiveSet* directive)
909 : Phase(Compiler),
910 _compile_id(0),
911 _options(Options::for_runtime_stub()),
912 _method(nullptr),
913 _entry_bci(InvocationEntryBci),
914 _stub_function(stub_function),
915 _stub_name(stub_name),
916 _stub_id(stub_id),
917 _stub_entry_point(nullptr),
918 _max_node_limit(MaxNodeLimit),
919 _post_loop_opts_phase(false),
920 _merge_stores_phase(false),
921 _allow_macro_nodes(true),
922 _inlining_progress(false),
923 _inlining_incrementally(false),
924 _has_reserved_stack_access(false),
925 #ifndef PRODUCT
926 _igv_idx(0),
927 _trace_opto_output(directive->TraceOptoOutputOption),
928 #endif
929 _clinit_barrier_on_entry(false),
930 _stress_seed(0),
931 _comp_arena(mtCompiler, Arena::Tag::tag_comp),
932 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
933 _env(ci_env),
934 _directive(directive),
935 _log(ci_env->log()),
936 _first_failure_details(nullptr),
937 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
938 _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
939 _congraph(nullptr),
940 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
941 _unique(0),
942 _dead_node_count(0),
943 _dead_node_list(comp_arena()),
944 _node_arena_one(mtCompiler, Arena::Tag::tag_node),
1059 _fixed_slots = 0;
1060 set_has_split_ifs(false);
1061 set_has_loops(false); // first approximation
1062 set_has_stringbuilder(false);
1063 set_has_boxed_value(false);
1064 _trap_can_recompile = false; // no traps emitted yet
1065 _major_progress = true; // start out assuming good things will happen
1066 set_has_unsafe_access(false);
1067 set_max_vector_size(0);
1068 set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers
1069 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1070 set_decompile_count(0);
1071
1072 #ifndef PRODUCT
1073 _phase_counter = 0;
1074 Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1075 #endif
1076
1077 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1078 _loop_opts_cnt = LoopOptsCount;
1079 set_do_inlining(Inline);
1080 set_max_inline_size(MaxInlineSize);
1081 set_freq_inline_size(FreqInlineSize);
1082 set_do_scheduling(OptoScheduling);
1083
1084 set_do_vector_loop(false);
1085 set_has_monitors(false);
1086 set_has_scoped_access(false);
1087
1088 if (AllowVectorizeOnDemand) {
1089 if (has_method() && _directive->VectorizeOption) {
1090 set_do_vector_loop(true);
1091 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());})
1092 } else if (has_method() && method()->name() != nullptr &&
1093 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1094 set_do_vector_loop(true);
1095 }
1096 }
1097 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1098 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());})
1339 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1340 assert(do_aliasing(), "Aliasing should be enabled");
1341 int offset = tj->offset();
1342 TypePtr::PTR ptr = tj->ptr();
1343
1344 // Known instance (scalarizable allocation) alias only with itself.
1345 bool is_known_inst = tj->isa_oopptr() != nullptr &&
1346 tj->is_oopptr()->is_known_instance();
1347
1348 // Process weird unsafe references.
1349 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1350 assert(InlineUnsafeOps || StressReflectiveCode, "indeterminate pointers come only from unsafe ops");
1351 assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1352 tj = TypeOopPtr::BOTTOM;
1353 ptr = tj->ptr();
1354 offset = tj->offset();
1355 }
1356
1357 // Array pointers need some flattening
1358 const TypeAryPtr* ta = tj->isa_aryptr();
1359 if (ta && ta->is_stable()) {
1360 // Erase stability property for alias analysis.
1361 tj = ta = ta->cast_to_stable(false);
1362 }
1363 if( ta && is_known_inst ) {
1364 if ( offset != Type::OffsetBot &&
1365 offset > arrayOopDesc::length_offset_in_bytes() ) {
1366 offset = Type::OffsetBot; // Flatten constant access into array body only
1367 tj = ta = ta->
1368 remove_speculative()->
1369 cast_to_ptr_type(ptr)->
1370 with_offset(offset);
1371 }
1372 } else if (ta) {
1373 // For arrays indexed by constant indices, we flatten the alias
1374 // space to include all of the array body. Only the header, klass
1375 // and array length can be accessed un-aliased.
1376 if( offset != Type::OffsetBot ) {
1377 if( ta->const_oop() ) { // MethodData* or Method*
1378 offset = Type::OffsetBot; // Flatten constant access into array body
1379 tj = ta = ta->
1380 remove_speculative()->
1381 cast_to_ptr_type(ptr)->
1382 cast_to_exactness(false)->
1383 with_offset(offset);
1384 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1385 // range is OK as-is.
1386 tj = ta = TypeAryPtr::RANGE;
1387 } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1388 tj = TypeInstPtr::KLASS; // all klass loads look alike
1389 ta = TypeAryPtr::RANGE; // generic ignored junk
1390 ptr = TypePtr::BotPTR;
1391 } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1392 tj = TypeInstPtr::MARK;
1393 ta = TypeAryPtr::RANGE; // generic ignored junk
1394 ptr = TypePtr::BotPTR;
1395 } else { // Random constant offset into array body
1396 offset = Type::OffsetBot; // Flatten constant access into array body
1397 tj = ta = ta->
1398 remove_speculative()->
1399 cast_to_ptr_type(ptr)->
1400 cast_to_exactness(false)->
1401 with_offset(offset);
1402 }
1403 }
1404 // Arrays of fixed size alias with arrays of unknown size.
1405 if (ta->size() != TypeInt::POS) {
1406 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1407 tj = ta = ta->
1408 remove_speculative()->
1409 cast_to_ptr_type(ptr)->
1410 with_ary(tary)->
1411 cast_to_exactness(false);
1412 }
1413 // Arrays of known objects become arrays of unknown objects.
1414 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1415 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1416 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,offset);
1417 }
1418 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1419 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1420 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,nullptr,false,offset);
1421 }
1422 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1423 // cannot be distinguished by bytecode alone.
1424 if (ta->elem() == TypeInt::BOOL) {
1425 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1426 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1427 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
1428 }
1429 // During the 2nd round of IterGVN, NotNull castings are removed.
1430 // Make sure the Bottom and NotNull variants alias the same.
1431 // Also, make sure exact and non-exact variants alias the same.
1432 if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != nullptr) {
1433 tj = ta = ta->
1434 remove_speculative()->
1435 cast_to_ptr_type(TypePtr::BotPTR)->
1436 cast_to_exactness(false)->
1437 with_offset(offset);
1438 }
1439 }
1440
1441 // Oop pointers need some flattening
1442 const TypeInstPtr *to = tj->isa_instptr();
1443 if (to && to != TypeOopPtr::BOTTOM) {
1444 ciInstanceKlass* ik = to->instance_klass();
1445 if( ptr == TypePtr::Constant ) {
1446 if (ik != ciEnv::current()->Class_klass() ||
1447 offset < ik->layout_helper_size_in_bytes()) {
1448 // No constant oop pointers (such as Strings); they alias with
1449 // unknown strings.
1450 assert(!is_known_inst, "not scalarizable allocation");
1451 tj = to = to->
1452 cast_to_instance_id(TypeOopPtr::InstanceBot)->
1453 remove_speculative()->
1454 cast_to_ptr_type(TypePtr::BotPTR)->
1455 cast_to_exactness(false);
1456 }
1457 } else if( is_known_inst ) {
1458 tj = to; // Keep NotNull and klass_is_exact for instance type
1459 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1460 // During the 2nd round of IterGVN, NotNull castings are removed.
1461 // Make sure the Bottom and NotNull variants alias the same.
1462 // Also, make sure exact and non-exact variants alias the same.
1463 tj = to = to->
1464 remove_speculative()->
1465 cast_to_instance_id(TypeOopPtr::InstanceBot)->
1466 cast_to_ptr_type(TypePtr::BotPTR)->
1467 cast_to_exactness(false);
1468 }
1469 if (to->speculative() != nullptr) {
1470 tj = to = to->remove_speculative();
1471 }
1472 // Canonicalize the holder of this field
1473 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1474 // First handle header references such as a LoadKlassNode, even if the
1475 // object's klass is unloaded at compile time (4965979).
1476 if (!is_known_inst) { // Do it only for non-instance types
1477 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, nullptr, offset);
1478 }
1479 } else if (offset < 0 || offset >= ik->layout_helper_size_in_bytes()) {
1480 // Static fields are in the space above the normal instance
1481 // fields in the java.lang.Class instance.
1482 if (ik != ciEnv::current()->Class_klass()) {
1483 to = nullptr;
1484 tj = TypeOopPtr::BOTTOM;
1485 offset = tj->offset();
1486 }
1487 } else {
1488 ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
1489 assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1490 assert(tj->offset() == offset, "no change to offset expected");
1491 bool xk = to->klass_is_exact();
1492 int instance_id = to->instance_id();
1493
1494 // If the input type's class is the holder: if exact, the type only includes interfaces implemented by the holder
1495 // but if not exact, it may include extra interfaces: build new type from the holder class to make sure only
1496 // its interfaces are included.
1497 if (xk && ik->equals(canonical_holder)) {
1498 assert(tj == TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id), "exact type should be canonical type");
1499 } else {
1500 assert(xk || !is_known_inst, "Known instance should be exact type");
1501 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, offset, instance_id);
1502 }
1503 }
1504 }
1505
1506 // Klass pointers to object array klasses need some flattening
1507 const TypeKlassPtr *tk = tj->isa_klassptr();
1508 if( tk ) {
1509 // If we are referencing a field within a Klass, we need
1510 // to assume the worst case of an Object. Both exact and
1511 // inexact types must flatten to the same alias class so
1512 // use NotNull as the PTR.
1513 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1514 tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1515 env()->Object_klass(),
1516 offset);
1517 }
1518
1519 if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1520 ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1521 if (!k || !k->is_loaded()) { // Only fails for some -Xcomp runs
1522 tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), offset);
1523 } else {
1524 tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, offset);
1525 }
1526 }
1527
1528 // Check for precise loads from the primary supertype array and force them
1529 // to the supertype cache alias index. Check for generic array loads from
1530 // the primary supertype array and also force them to the supertype cache
1531 // alias index. Since the same load can reach both, we need to merge
1532 // these 2 disparate memories into the same alias class. Since the
1533 // primary supertype array is read-only, there's no chance of confusion
1534 // where we bypass an array load and an array store.
1535 int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1536 if (offset == Type::OffsetBot ||
1537 (offset >= primary_supers_offset &&
1538 offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1539 offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1540 offset = in_bytes(Klass::secondary_super_cache_offset());
1541 tj = tk = tk->with_offset(offset);
1542 }
1543 }
1544
1545 // Flatten all Raw pointers together.
1546 if (tj->base() == Type::RawPtr)
1547 tj = TypeRawPtr::BOTTOM;
1637 intptr_t key = (intptr_t) adr_type;
1638 key ^= key >> logAliasCacheSize;
1639 return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1640 }
1641
1642
1643 //-----------------------------grow_alias_types--------------------------------
1644 void Compile::grow_alias_types() {
1645 const int old_ats = _max_alias_types; // how many before?
1646 const int new_ats = old_ats; // how many more?
1647 const int grow_ats = old_ats+new_ats; // how many now?
1648 _max_alias_types = grow_ats;
1649 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1650 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1651 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1652 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
1653 }
1654
1655
1656 //--------------------------------find_alias_type------------------------------
1657 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
1658 if (!do_aliasing()) {
1659 return alias_type(AliasIdxBot);
1660 }
1661
1662 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1663 if (ace->_adr_type == adr_type) {
1664 return alias_type(ace->_index);
1665 }
1666
1667 // Handle special cases.
1668 if (adr_type == nullptr) return alias_type(AliasIdxTop);
1669 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
1670
1671 // Do it the slow way.
1672 const TypePtr* flat = flatten_alias_type(adr_type);
1673
1674 #ifdef ASSERT
1675 {
1676 ResourceMark rm;
1677 assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",
1678 Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));
1679 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",
1680 Type::str(adr_type));
1681 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1682 const TypeOopPtr* foop = flat->is_oopptr();
1683 // Scalarizable allocations have exact klass always.
1684 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
1694 if (alias_type(i)->adr_type() == flat) {
1695 idx = i;
1696 break;
1697 }
1698 }
1699
1700 if (idx == AliasIdxTop) {
1701 if (no_create) return nullptr;
1702 // Grow the array if necessary.
1703 if (_num_alias_types == _max_alias_types) grow_alias_types();
1704 // Add a new alias type.
1705 idx = _num_alias_types++;
1706 _alias_types[idx]->Init(idx, flat);
1707 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
1708 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
1709 if (flat->isa_instptr()) {
1710 if (flat->offset() == java_lang_Class::klass_offset()
1711 && flat->is_instptr()->instance_klass() == env()->Class_klass())
1712 alias_type(idx)->set_rewritable(false);
1713 }
1714 if (flat->isa_aryptr()) {
1715 #ifdef ASSERT
1716 const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1717 // (T_BYTE has the weakest alignment and size restrictions...)
1718 assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1719 #endif
1720 if (flat->offset() == TypePtr::OffsetBot) {
1721 alias_type(idx)->set_element(flat->is_aryptr()->elem());
1722 }
1723 }
1724 if (flat->isa_klassptr()) {
1725 if (UseCompactObjectHeaders) {
1726 if (flat->offset() == in_bytes(Klass::prototype_header_offset()))
1727 alias_type(idx)->set_rewritable(false);
1728 }
1729 if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1730 alias_type(idx)->set_rewritable(false);
1731 if (flat->offset() == in_bytes(Klass::misc_flags_offset()))
1732 alias_type(idx)->set_rewritable(false);
1733 if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1734 alias_type(idx)->set_rewritable(false);
1735 if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1736 alias_type(idx)->set_rewritable(false);
1737 }
1738
1739 if (flat->isa_instklassptr()) {
1740 if (flat->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
1741 alias_type(idx)->set_rewritable(false);
1742 }
1743 }
1744 // %%% (We would like to finalize JavaThread::threadObj_offset(),
1745 // but the base pointer type is not distinctive enough to identify
1746 // references into JavaThread.)
1747
1748 // Check for final fields.
1749 const TypeInstPtr* tinst = flat->isa_instptr();
1750 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1751 ciField* field;
1752 if (tinst->const_oop() != nullptr &&
1753 tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1754 tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1755 // static field
1756 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1757 field = k->get_field_by_offset(tinst->offset(), true);
1758 } else {
1759 ciInstanceKlass *k = tinst->instance_klass();
1760 field = k->get_field_by_offset(tinst->offset(), false);
1761 }
1762 assert(field == nullptr ||
1763 original_field == nullptr ||
1764 (field->holder() == original_field->holder() &&
1765 field->offset_in_bytes() == original_field->offset_in_bytes() &&
1766 field->is_static() == original_field->is_static()), "wrong field?");
1767 // Set field() and is_rewritable() attributes.
1768 if (field != nullptr) alias_type(idx)->set_field(field);
1769 }
1770 }
1771
1772 // Fill the cache for next time.
1773 ace->_adr_type = adr_type;
1774 ace->_index = idx;
1775 assert(alias_type(adr_type) == alias_type(idx), "type must be installed");
1776
1777 // Might as well try to fill the cache for the flattened version, too.
1778 AliasCacheEntry* face = probe_alias_cache(flat);
1779 if (face->_adr_type == nullptr) {
1780 face->_adr_type = flat;
1781 face->_index = idx;
1782 assert(alias_type(flat) == alias_type(idx), "flat type must work too");
1783 }
1784
1785 return alias_type(idx);
1786 }
1787
1788
1789 Compile::AliasType* Compile::alias_type(ciField* field) {
1790 const TypeOopPtr* t;
1791 if (field->is_static())
1792 t = TypeInstPtr::make(field->holder()->java_mirror());
1793 else
1794 t = TypeOopPtr::make_from_klass_raw(field->holder());
1795 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1796 assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1797 return atp;
1798 }
1799
1800
1801 //------------------------------have_alias_type--------------------------------
1802 bool Compile::have_alias_type(const TypePtr* adr_type) {
1884 assert(!C->major_progress(), "not cleared");
1885
1886 if (_for_post_loop_igvn.length() > 0) {
1887 while (_for_post_loop_igvn.length() > 0) {
1888 Node* n = _for_post_loop_igvn.pop();
1889 n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1890 igvn._worklist.push(n);
1891 }
1892 igvn.optimize();
1893 if (failing()) return;
1894 assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1895 assert(C->parse_predicate_count() == 0, "all parse predicates should have been removed now");
1896
1897 // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1898 if (C->major_progress()) {
1899 C->clear_major_progress(); // ensure that major progress is now clear
1900 }
1901 }
1902 }
1903
1904 void Compile::record_for_merge_stores_igvn(Node* n) {
1905 if (!n->for_merge_stores_igvn()) {
1906 assert(!_for_merge_stores_igvn.contains(n), "duplicate");
1907 n->add_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
1908 _for_merge_stores_igvn.append(n);
1909 }
1910 }
1911
1912 void Compile::remove_from_merge_stores_igvn(Node* n) {
1913 n->remove_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
1914 _for_merge_stores_igvn.remove(n);
1915 }
1916
1917 // We need to wait with merging stores until RangeCheck smearing has removed the RangeChecks during
1918 // the post loops IGVN phase. If we do it earlier, then there may still be some RangeChecks between
1919 // the stores, and we merge the wrong sequence of stores.
1920 // Example:
1921 // StoreI RangeCheck StoreI StoreI RangeCheck StoreI
1922 // Apply MergeStores:
1923 // StoreI RangeCheck [ StoreL ] RangeCheck StoreI
2002 assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
2003 Bytecodes::Code c = iter.cur_bc();
2004 Node* lhs = nullptr;
2005 Node* rhs = nullptr;
2006 if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
2007 lhs = unc->peek_operand(0);
2008 rhs = unc->peek_operand(1);
2009 } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
2010 lhs = unc->peek_operand(0);
2011 }
2012
2013 ResourceMark rm;
2014 const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
2015 assert(live_locals.is_valid(), "broken liveness info");
2016 int len = (int)live_locals.size();
2017
2018 for (int i = 0; i < len; i++) {
2019 Node* local = unc->local(jvms, i);
2020 // kill local using the liveness of next_bci.
2021 // give up when the local looks like an operand to secure reexecution.
2022 if (!live_locals.at(i) && !local->is_top() && local != lhs && local!= rhs) {
2023 uint idx = jvms->locoff() + i;
2024 #ifdef ASSERT
2025 if (PrintOpto && Verbose) {
2026 tty->print("[unstable_if] kill local#%d: ", idx);
2027 local->dump();
2028 tty->cr();
2029 }
2030 #endif
2031 igvn.replace_input_of(unc, idx, top());
2032 modified = true;
2033 }
2034 }
2035 }
2036
2037 // keep the mondified trap for late query
2038 if (modified) {
2039 trap->set_modified();
2040 } else {
2041 _unstable_if_traps.delete_at(i);
2042 }
2043 }
2044 igvn.optimize();
2045 }
2046
2047 // StringOpts and late inlining of string methods
2048 void Compile::inline_string_calls(bool parse_time) {
2049 {
2050 // remove useless nodes to make the usage analysis simpler
2051 ResourceMark rm;
2052 PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
2053 }
2054
2055 {
2056 ResourceMark rm;
2057 print_method(PHASE_BEFORE_STRINGOPTS, 3);
2229
2230 if (_string_late_inlines.length() > 0) {
2231 assert(has_stringbuilder(), "inconsistent");
2232
2233 inline_string_calls(false);
2234
2235 if (failing()) return;
2236
2237 inline_incrementally_cleanup(igvn);
2238 }
2239
2240 set_inlining_incrementally(false);
2241 }
2242
2243 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2244 // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2245 // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2246 // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2247 // as if "inlining_incrementally() == true" were set.
2248 assert(inlining_incrementally() == false, "not allowed");
2249 assert(_modified_nodes == nullptr, "not allowed");
2250 assert(_late_inlines.length() > 0, "sanity");
2251
2252 while (_late_inlines.length() > 0) {
2253 igvn_worklist()->ensure_empty(); // should be done with igvn
2254
2255 while (inline_incrementally_one()) {
2256 assert(!failing_internal() || failure_is_artificial(), "inconsistent");
2257 }
2258 if (failing()) return;
2259
2260 inline_incrementally_cleanup(igvn);
2261 }
2262 }
2263
2264 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2265 if (_loop_opts_cnt > 0) {
2266 while (major_progress() && (_loop_opts_cnt > 0)) {
2267 TracePhase tp(_t_idealLoop);
2268 PhaseIdealLoop::optimize(igvn, mode);
2269 _loop_opts_cnt--;
2270 if (failing()) return false;
2271 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2272 }
2273 }
2274 return true;
2275 }
2276
2277 // Remove edges from "root" to each SafePoint at a backward branch.
2278 // They were inserted during parsing (see add_safepoint()) to make
2279 // infinite loops without calls or exceptions visible to root, i.e.,
2280 // useful.
2281 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {
2385 print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2386 }
2387 assert(!has_vbox_nodes(), "sanity");
2388
2389 if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2390 Compile::TracePhase tp(_t_renumberLive);
2391 igvn_worklist()->ensure_empty(); // should be done with igvn
2392 {
2393 ResourceMark rm;
2394 PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2395 }
2396 igvn.reset();
2397 igvn.optimize();
2398 if (failing()) return;
2399 }
2400
2401 // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2402 // safepoints
2403 remove_root_to_sfpts_edges(igvn);
2404
2405 if (failing()) return;
2406
2407 if (has_loops()) {
2408 print_method(PHASE_BEFORE_LOOP_OPTS, 2);
2409 }
2410
2411 // Perform escape analysis
2412 if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2413 if (has_loops()) {
2414 // Cleanup graph (remove dead nodes).
2415 TracePhase tp(_t_idealLoop);
2416 PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2417 if (failing()) return;
2418 }
2419 bool progress;
2420 print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2421 do {
2422 ConnectionGraph::do_analysis(this, &igvn);
2423
2424 if (failing()) return;
2425
2426 int mcount = macro_count(); // Record number of allocations and locks before IGVN
2427
2428 // Optimize out fields loads from scalar replaceable allocations.
2429 igvn.optimize();
2430 print_method(PHASE_ITER_GVN_AFTER_EA, 2);
2431
2432 if (failing()) return;
2433
2434 if (congraph() != nullptr && macro_count() > 0) {
2435 TracePhase tp(_t_macroEliminate);
2436 PhaseMacroExpand mexp(igvn);
2437 mexp.eliminate_macro_nodes();
2438 if (failing()) return;
2439 print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
2440
2441 igvn.set_delay_transform(false);
2442 igvn.optimize();
2443 if (failing()) return;
2444
2445 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2446 }
2447
2448 ConnectionGraph::verify_ram_nodes(this, root());
2449 if (failing()) return;
2450
2451 progress = do_iterative_escape_analysis() &&
2452 (macro_count() < mcount) &&
2453 ConnectionGraph::has_candidates(this);
2454 // Try again if candidates exist and made progress
2455 // by removing some allocations and/or locks.
2456 } while (progress);
2457 }
2458
2459 // Loop transforms on the ideal graph. Range Check Elimination,
2460 // peeling, unrolling, etc.
2461
2462 // Set loop opts counter
2463 if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2464 {
2465 TracePhase tp(_t_idealLoop);
2466 PhaseIdealLoop::optimize(igvn, LoopOptsDefault);
2467 _loop_opts_cnt--;
2468 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
2469 if (failing()) return;
2470 }
2471 // Loop opts pass if partial peeling occurred in previous pass
2472 if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
2473 TracePhase tp(_t_idealLoop);
2474 PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
2475 _loop_opts_cnt--;
2476 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
2477 if (failing()) return;
2478 }
2515 // Loop transforms on the ideal graph. Range Check Elimination,
2516 // peeling, unrolling, etc.
2517 if (!optimize_loops(igvn, LoopOptsDefault)) {
2518 return;
2519 }
2520
2521 if (failing()) return;
2522
2523 C->clear_major_progress(); // ensure that major progress is now clear
2524
2525 process_for_post_loop_opts_igvn(igvn);
2526
2527 process_for_merge_stores_igvn(igvn);
2528
2529 if (failing()) return;
2530
2531 #ifdef ASSERT
2532 bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2533 #endif
2534
2535 {
2536 TracePhase tp(_t_macroExpand);
2537 print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);
2538 PhaseMacroExpand mex(igvn);
2539 // Do not allow new macro nodes once we start to eliminate and expand
2540 C->reset_allow_macro_nodes();
2541 // Last attempt to eliminate macro nodes before expand
2542 mex.eliminate_macro_nodes();
2543 if (failing()) {
2544 return;
2545 }
2546 mex.eliminate_opaque_looplimit_macro_nodes();
2547 if (failing()) {
2548 return;
2549 }
2550 print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
2551 if (mex.expand_macro_nodes()) {
2552 assert(failing(), "must bail out w/ explicit message");
2553 return;
2554 }
2555 print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
2556 }
2557
2558 {
2559 TracePhase tp(_t_barrierExpand);
2560 if (bs->expand_barriers(this, igvn)) {
2561 assert(failing(), "must bail out w/ explicit message");
2562 return;
2563 }
2564 print_method(PHASE_BARRIER_EXPANSION, 2);
2565 }
2566
2567 if (C->max_vector_size() > 0) {
2568 C->optimize_logic_cones(igvn);
2569 igvn.optimize();
2570 if (failing()) return;
2571 }
2572
2573 DEBUG_ONLY( _modified_nodes = nullptr; )
2574
2575 assert(igvn._worklist.size() == 0, "not empty");
2576
2577 assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
2578
2579 if (_late_inlines.length() > 0) {
2580 // More opportunities to optimize virtual and MH calls.
2581 // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2582 process_late_inline_calls_no_inline(igvn);
2583 if (failing()) return;
2584 }
2585 } // (End scope of igvn; run destructor if necessary for asserts.)
2586
2587 check_no_dead_use();
2588
2589 // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
2590 // to remove hashes to unlock nodes for modifications.
2591 C->node_hash()->clear();
2592
2593 // A method with only infinite loops has no edges entering loops from root
2594 {
2595 TracePhase tp(_t_graphReshaping);
2596 if (final_graph_reshaping()) {
2597 assert(failing(), "must bail out w/ explicit message");
2598 return;
2599 }
2600 }
2601
2602 print_method(PHASE_OPTIMIZE_FINISHED, 2);
2603 DEBUG_ONLY(set_phase_optimize_finished();)
2604 }
3310 case Op_CmpD3:
3311 case Op_StoreD:
3312 case Op_LoadD:
3313 case Op_LoadD_unaligned:
3314 frc.inc_double_count();
3315 break;
3316 case Op_Opaque1: // Remove Opaque Nodes before matching
3317 n->subsume_by(n->in(1), this);
3318 break;
3319 case Op_CallLeafPure: {
3320 // If the pure call is not supported, then lower to a CallLeaf.
3321 if (!Matcher::match_rule_supported(Op_CallLeafPure)) {
3322 CallNode* call = n->as_Call();
3323 CallNode* new_call = new CallLeafNode(call->tf(), call->entry_point(),
3324 call->_name, TypeRawPtr::BOTTOM);
3325 new_call->init_req(TypeFunc::Control, call->in(TypeFunc::Control));
3326 new_call->init_req(TypeFunc::I_O, C->top());
3327 new_call->init_req(TypeFunc::Memory, C->top());
3328 new_call->init_req(TypeFunc::ReturnAdr, C->top());
3329 new_call->init_req(TypeFunc::FramePtr, C->top());
3330 for (unsigned int i = TypeFunc::Parms; i < call->tf()->domain()->cnt(); i++) {
3331 new_call->init_req(i, call->in(i));
3332 }
3333 n->subsume_by(new_call, this);
3334 }
3335 frc.inc_call_count();
3336 break;
3337 }
3338 case Op_CallStaticJava:
3339 case Op_CallJava:
3340 case Op_CallDynamicJava:
3341 frc.inc_java_call_count(); // Count java call site;
3342 case Op_CallRuntime:
3343 case Op_CallLeaf:
3344 case Op_CallLeafVector:
3345 case Op_CallLeafNoFP: {
3346 assert (n->is_Call(), "");
3347 CallNode *call = n->as_Call();
3348 // Count call sites where the FP mode bit would have to be flipped.
3349 // Do not count uncommon runtime calls:
3350 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
3356 int nop = n->Opcode();
3357 // Clone shared simple arguments to uncommon calls, item (1).
3358 if (n->outcnt() > 1 &&
3359 !n->is_Proj() &&
3360 nop != Op_CreateEx &&
3361 nop != Op_CheckCastPP &&
3362 nop != Op_DecodeN &&
3363 nop != Op_DecodeNKlass &&
3364 !n->is_Mem() &&
3365 !n->is_Phi()) {
3366 Node *x = n->clone();
3367 call->set_req(TypeFunc::Parms, x);
3368 }
3369 }
3370 break;
3371 }
3372 case Op_StoreB:
3373 case Op_StoreC:
3374 case Op_StoreI:
3375 case Op_StoreL:
3376 case Op_CompareAndSwapB:
3377 case Op_CompareAndSwapS:
3378 case Op_CompareAndSwapI:
3379 case Op_CompareAndSwapL:
3380 case Op_CompareAndSwapP:
3381 case Op_CompareAndSwapN:
3382 case Op_WeakCompareAndSwapB:
3383 case Op_WeakCompareAndSwapS:
3384 case Op_WeakCompareAndSwapI:
3385 case Op_WeakCompareAndSwapL:
3386 case Op_WeakCompareAndSwapP:
3387 case Op_WeakCompareAndSwapN:
3388 case Op_CompareAndExchangeB:
3389 case Op_CompareAndExchangeS:
3390 case Op_CompareAndExchangeI:
3391 case Op_CompareAndExchangeL:
3392 case Op_CompareAndExchangeP:
3393 case Op_CompareAndExchangeN:
3394 case Op_GetAndAddS:
3395 case Op_GetAndAddB:
3905 k->subsume_by(m, this);
3906 }
3907 }
3908 }
3909 break;
3910 }
3911 case Op_CmpUL: {
3912 if (!Matcher::has_match_rule(Op_CmpUL)) {
3913 // No support for unsigned long comparisons
3914 ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
3915 Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
3916 Node* orl = new OrLNode(n->in(1), sign_bit_mask);
3917 ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
3918 Node* andl = new AndLNode(orl, remove_sign_mask);
3919 Node* cmp = new CmpLNode(andl, n->in(2));
3920 n->subsume_by(cmp, this);
3921 }
3922 break;
3923 }
3924 #ifdef ASSERT
3925 case Op_ConNKlass: {
3926 const TypePtr* tp = n->as_Type()->type()->make_ptr();
3927 ciKlass* klass = tp->is_klassptr()->exact_klass();
3928 assert(klass->is_in_encoding_range(), "klass cannot be compressed");
3929 break;
3930 }
3931 #endif
3932 default:
3933 assert(!n->is_Call(), "");
3934 assert(!n->is_Mem(), "");
3935 assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
3936 break;
3937 }
3938 }
3939
3940 //------------------------------final_graph_reshaping_walk---------------------
3941 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3942 // requires that the walk visits a node's inputs before visiting the node.
3943 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
3944 Unique_Node_List sfpt;
4280 }
4281 }
4282
4283 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4284 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4285 }
4286
4287 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4288 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4289 }
4290
4291 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4292 if (holder->is_initialized()) {
4293 return false;
4294 }
4295 if (holder->is_being_initialized()) {
4296 if (accessing_method->holder() == holder) {
4297 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4298 // <init>, or a static method. In all those cases, there was an initialization
4299 // barrier on the holder klass passed.
4300 if (accessing_method->is_static_initializer() ||
4301 accessing_method->is_object_initializer() ||
4302 accessing_method->is_static()) {
4303 return false;
4304 }
4305 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4306 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4307 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4308 // child class can become fully initialized while its parent class is still being initialized.
4309 if (accessing_method->is_static_initializer()) {
4310 return false;
4311 }
4312 }
4313 ciMethod* root = method(); // the root method of compilation
4314 if (root != accessing_method) {
4315 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4316 }
4317 }
4318 return true;
4319 }
4320
4321 #ifndef PRODUCT
4322 //------------------------------verify_bidirectional_edges---------------------
4323 // For each input edge to a node (ie - for each Use-Def edge), verify that
4324 // there is a corresponding Def-Use edge.
4325 void Compile::verify_bidirectional_edges(Unique_Node_List& visited, const Unique_Node_List* root_and_safepoints) const {
4326 // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4327 uint stack_size = live_nodes() >> 4;
4328 Node_List nstack(MAX2(stack_size, (uint) OptoNodeListSize));
4329 if (root_and_safepoints != nullptr) {
4359 if (in != nullptr && !in->is_top()) {
4360 // Count instances of `next`
4361 int cnt = 0;
4362 for (uint idx = 0; idx < in->_outcnt; idx++) {
4363 if (in->_out[idx] == n) {
4364 cnt++;
4365 }
4366 }
4367 assert(cnt > 0, "Failed to find Def-Use edge.");
4368 // Check for duplicate edges
4369 // walk the input array downcounting the input edges to n
4370 for (uint j = 0; j < length; j++) {
4371 if (n->in(j) == in) {
4372 cnt--;
4373 }
4374 }
4375 assert(cnt == 0, "Mismatched edge count.");
4376 } else if (in == nullptr) {
4377 assert(i == 0 || i >= n->req() ||
4378 n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||
4379 (n->is_Unlock() && i == (n->req() - 1)) ||
4380 (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4381 "only region, phi, arraycopy, unlock or membar nodes have null data edges");
4382 } else {
4383 assert(in->is_top(), "sanity");
4384 // Nothing to check.
4385 }
4386 }
4387 }
4388 }
4389
4390 //------------------------------verify_graph_edges---------------------------
4391 // Walk the Graph and verify that there is a one-to-one correspondence
4392 // between Use-Def edges and Def-Use edges in the graph.
4393 void Compile::verify_graph_edges(bool no_dead_code, const Unique_Node_List* root_and_safepoints) const {
4394 if (VerifyGraphEdges) {
4395 Unique_Node_List visited;
4396
4397 // Call graph walk to check edges
4398 verify_bidirectional_edges(visited, root_and_safepoints);
4399 if (no_dead_code) {
4400 // Now make sure that no visited node is used by an unvisited node.
4401 bool dead_nodes = false;
4512 // (1) subklass is already limited to a subtype of superklass => always ok
4513 // (2) subklass does not overlap with superklass => always fail
4514 // (3) superklass has NO subtypes and we can check with a simple compare.
4515 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
4516 if (skip) {
4517 return SSC_full_test; // Let caller generate the general case.
4518 }
4519
4520 if (subk->is_java_subtype_of(superk)) {
4521 return SSC_always_true; // (0) and (1) this test cannot fail
4522 }
4523
4524 if (!subk->maybe_java_subtype_of(superk)) {
4525 return SSC_always_false; // (2) true path dead; no dynamic test needed
4526 }
4527
4528 const Type* superelem = superk;
4529 if (superk->isa_aryklassptr()) {
4530 int ignored;
4531 superelem = superk->is_aryklassptr()->base_element_type(ignored);
4532 }
4533
4534 if (superelem->isa_instklassptr()) {
4535 ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
4536 if (!ik->has_subklass()) {
4537 if (!ik->is_final()) {
4538 // Add a dependency if there is a chance of a later subclass.
4539 dependencies()->assert_leaf_type(ik);
4540 }
4541 if (!superk->maybe_java_subtype_of(subk)) {
4542 return SSC_always_false;
4543 }
4544 return SSC_easy_test; // (3) caller can do a simple ptr comparison
4545 }
4546 } else {
4547 // A primitive array type has no subtypes.
4548 return SSC_easy_test; // (3) caller can do a simple ptr comparison
4549 }
4550
4551 return SSC_full_test;
5350 } else {
5351 _debug_network_printer->update_compiled_method(C->method());
5352 }
5353 tty->print_cr("Method printed over network stream to IGV");
5354 _debug_network_printer->print(name, C->root(), visible_nodes, fr);
5355 }
5356 #endif // !PRODUCT
5357
5358 Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {
5359 if (type != nullptr && phase->type(value)->higher_equal(type)) {
5360 return value;
5361 }
5362 Node* result = nullptr;
5363 if (bt == T_BYTE) {
5364 result = phase->transform(new LShiftINode(value, phase->intcon(24)));
5365 result = new RShiftINode(result, phase->intcon(24));
5366 } else if (bt == T_BOOLEAN) {
5367 result = new AndINode(value, phase->intcon(0xFF));
5368 } else if (bt == T_CHAR) {
5369 result = new AndINode(value,phase->intcon(0xFFFF));
5370 } else {
5371 assert(bt == T_SHORT, "unexpected narrow type");
5372 result = phase->transform(new LShiftINode(value, phase->intcon(16)));
5373 result = new RShiftINode(result, phase->intcon(16));
5374 }
5375 if (transform_res) {
5376 result = phase->transform(result);
5377 }
5378 return result;
5379 }
5380
5381 void Compile::record_method_not_compilable_oom() {
5382 record_method_not_compilable(CompilationMemoryStatistic::failure_reason_memlimit());
5383 }
5384
5385 #ifndef PRODUCT
5386 // Collects all the control inputs from nodes on the worklist and from their data dependencies
5387 static void find_candidate_control_inputs(Unique_Node_List& worklist, Unique_Node_List& candidates) {
5388 // Follow non-control edges until we reach CFG nodes
5389 for (uint i = 0; i < worklist.size(); i++) {
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/macroAssembler.hpp"
26 #include "asm/macroAssembler.inline.hpp"
27 #include "ci/ciInlineKlass.hpp"
28 #include "ci/ciReplay.hpp"
29 #include "classfile/javaClasses.hpp"
30 #include "code/aotCodeCache.hpp"
31 #include "code/exceptionHandlerTable.hpp"
32 #include "code/nmethod.hpp"
33 #include "compiler/compilationFailureInfo.hpp"
34 #include "compiler/compilationMemoryStatistic.hpp"
35 #include "compiler/compileBroker.hpp"
36 #include "compiler/compileLog.hpp"
37 #include "compiler/compiler_globals.hpp"
38 #include "compiler/compilerDefinitions.hpp"
39 #include "compiler/compilerOracle.hpp"
40 #include "compiler/disassembler.hpp"
41 #include "compiler/oopMap.hpp"
42 #include "gc/shared/barrierSet.hpp"
43 #include "gc/shared/c2/barrierSetC2.hpp"
44 #include "jfr/jfrEvents.hpp"
45 #include "jvm_io.h"
46 #include "memory/allocation.hpp"
47 #include "memory/arena.hpp"
48 #include "memory/resourceArea.hpp"
49 #include "opto/addnode.hpp"
50 #include "opto/block.hpp"
51 #include "opto/c2compiler.hpp"
52 #include "opto/callGenerator.hpp"
53 #include "opto/callnode.hpp"
54 #include "opto/castnode.hpp"
55 #include "opto/cfgnode.hpp"
56 #include "opto/chaitin.hpp"
57 #include "opto/compile.hpp"
58 #include "opto/connode.hpp"
59 #include "opto/convertnode.hpp"
60 #include "opto/divnode.hpp"
61 #include "opto/escape.hpp"
62 #include "opto/idealGraphPrinter.hpp"
63 #include "opto/inlinetypenode.hpp"
64 #include "opto/locknode.hpp"
65 #include "opto/loopnode.hpp"
66 #include "opto/machnode.hpp"
67 #include "opto/macro.hpp"
68 #include "opto/matcher.hpp"
69 #include "opto/mathexactnode.hpp"
70 #include "opto/memnode.hpp"
71 #include "opto/movenode.hpp"
72 #include "opto/mulnode.hpp"
73 #include "opto/multnode.hpp"
74 #include "opto/narrowptrnode.hpp"
75 #include "opto/node.hpp"
76 #include "opto/opaquenode.hpp"
77 #include "opto/opcodes.hpp"
78 #include "opto/output.hpp"
79 #include "opto/parse.hpp"
80 #include "opto/phaseX.hpp"
81 #include "opto/rootnode.hpp"
82 #include "opto/runtime.hpp"
83 #include "opto/stringopts.hpp"
84 #include "opto/type.hpp"
85 #include "opto/vector.hpp"
86 #include "opto/vectornode.hpp"
87 #include "runtime/arguments.hpp"
88 #include "runtime/globals_extension.hpp"
89 #include "runtime/sharedRuntime.hpp"
90 #include "runtime/signature.hpp"
91 #include "runtime/stubRoutines.hpp"
92 #include "runtime/timer.hpp"
93 #include "utilities/align.hpp"
94 #include "utilities/copy.hpp"
95 #include "utilities/hashTable.hpp"
96 #include "utilities/macros.hpp"
97
98 // -------------------- Compile::mach_constant_base_node -----------------------
99 // Constant table base node singleton.
100 MachConstantBaseNode* Compile::mach_constant_base_node() {
101 if (_mach_constant_base_node == nullptr) {
102 _mach_constant_base_node = new MachConstantBaseNode();
103 _mach_constant_base_node->add_req(C->root());
104 }
105 return _mach_constant_base_node;
106 }
107
393 // as dead to be conservative about the dead node count at any
394 // given time.
395 if (!dead->is_Con()) {
396 record_dead_node(dead->_idx);
397 }
398 if (dead->is_macro()) {
399 remove_macro_node(dead);
400 }
401 if (dead->is_expensive()) {
402 remove_expensive_node(dead);
403 }
404 if (dead->is_OpaqueTemplateAssertionPredicate()) {
405 remove_template_assertion_predicate_opaque(dead->as_OpaqueTemplateAssertionPredicate());
406 }
407 if (dead->is_ParsePredicate()) {
408 remove_parse_predicate(dead->as_ParsePredicate());
409 }
410 if (dead->for_post_loop_opts_igvn()) {
411 remove_from_post_loop_opts_igvn(dead);
412 }
413 if (dead->is_InlineType()) {
414 remove_inline_type(dead);
415 }
416 if (dead->is_LoadFlat() || dead->is_StoreFlat()) {
417 remove_flat_access(dead);
418 }
419 if (dead->for_merge_stores_igvn()) {
420 remove_from_merge_stores_igvn(dead);
421 }
422 if (dead->is_Call()) {
423 remove_useless_late_inlines( &_late_inlines, dead);
424 remove_useless_late_inlines( &_string_late_inlines, dead);
425 remove_useless_late_inlines( &_boxing_late_inlines, dead);
426 remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
427
428 if (dead->is_CallStaticJava()) {
429 remove_unstable_if_trap(dead->as_CallStaticJava(), false);
430 }
431 }
432 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
433 bs->unregister_potential_barrier_node(dead);
434 }
435
436 // Disconnect all useless nodes by disconnecting those at the boundary.
437 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist, const Unique_Node_List* root_and_safepoints) {
438 uint next = 0;
446 // Use raw traversal of out edges since this code removes out edges
447 int max = n->outcnt();
448 for (int j = 0; j < max; ++j) {
449 Node* child = n->raw_out(j);
450 if (!useful.member(child)) {
451 assert(!child->is_top() || child != top(),
452 "If top is cached in Compile object it is in useful list");
453 // Only need to remove this out-edge to the useless node
454 n->raw_del_out(j);
455 --j;
456 --max;
457 if (child->is_data_proj_of_pure_function(n)) {
458 worklist.push(n);
459 }
460 }
461 }
462 if (n->outcnt() == 1 && n->has_special_unique_user()) {
463 assert(useful.member(n->unique_out()), "do not push a useless node");
464 worklist.push(n->unique_out());
465 }
466 if (n->outcnt() == 0) {
467 worklist.push(n);
468 }
469 }
470
471 remove_useless_nodes(_macro_nodes, useful); // remove useless macro nodes
472 remove_useless_nodes(_parse_predicates, useful); // remove useless Parse Predicate nodes
473 // Remove useless Template Assertion Predicate opaque nodes
474 remove_useless_nodes(_template_assertion_predicate_opaques, useful);
475 remove_useless_nodes(_expensive_nodes, useful); // remove useless expensive nodes
476 remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
477 remove_useless_nodes(_inline_type_nodes, useful); // remove useless inline type nodes
478 remove_useless_nodes(_flat_access_nodes, useful); // remove useless flat access nodes
479 #ifdef ASSERT
480 if (_modified_nodes != nullptr) {
481 _modified_nodes->remove_useless_nodes(useful.member_set());
482 }
483 #endif
484 remove_useless_nodes(_for_merge_stores_igvn, useful); // remove useless node recorded for merge stores IGVN pass
485 remove_useless_unstable_if_traps(useful); // remove useless unstable_if traps
486 remove_useless_coarsened_locks(useful); // remove useless coarsened locks nodes
487 #ifdef ASSERT
488 if (_modified_nodes != nullptr) {
489 _modified_nodes->remove_useless_nodes(useful.member_set());
490 }
491 #endif
492
493 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
494 bs->eliminate_useless_gc_barriers(useful, this);
495 // clean up the late inline lists
496 remove_useless_late_inlines( &_late_inlines, useful);
497 remove_useless_late_inlines( &_string_late_inlines, useful);
498 remove_useless_late_inlines( &_boxing_late_inlines, useful);
499 remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
500 DEBUG_ONLY(verify_graph_edges(true /*check for no_dead_code*/, root_and_safepoints);)
501 }
502
503 // ============================================================================
652 Compile::Compile(ciEnv* ci_env, ciMethod* target, int osr_bci,
653 Options options, DirectiveSet* directive)
654 : Phase(Compiler),
655 _compile_id(ci_env->compile_id()),
656 _options(options),
657 _method(target),
658 _entry_bci(osr_bci),
659 _ilt(nullptr),
660 _stub_function(nullptr),
661 _stub_name(nullptr),
662 _stub_id(StubId::NO_STUBID),
663 _stub_entry_point(nullptr),
664 _max_node_limit(MaxNodeLimit),
665 _post_loop_opts_phase(false),
666 _merge_stores_phase(false),
667 _allow_macro_nodes(true),
668 _inlining_progress(false),
669 _inlining_incrementally(false),
670 _do_cleanup(false),
671 _has_reserved_stack_access(target->has_reserved_stack_access()),
672 _has_circular_inline_type(false),
673 #ifndef PRODUCT
674 _igv_idx(0),
675 _trace_opto_output(directive->TraceOptoOutputOption),
676 #endif
677 _clinit_barrier_on_entry(false),
678 _stress_seed(0),
679 _comp_arena(mtCompiler, Arena::Tag::tag_comp),
680 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
681 _env(ci_env),
682 _directive(directive),
683 _log(ci_env->log()),
684 _first_failure_details(nullptr),
685 _intrinsics(comp_arena(), 0, 0, nullptr),
686 _macro_nodes(comp_arena(), 8, 0, nullptr),
687 _parse_predicates(comp_arena(), 8, 0, nullptr),
688 _template_assertion_predicate_opaques(comp_arena(), 8, 0, nullptr),
689 _expensive_nodes(comp_arena(), 8, 0, nullptr),
690 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
691 _inline_type_nodes (comp_arena(), 8, 0, nullptr),
692 _flat_access_nodes(comp_arena(), 8, 0, nullptr),
693 _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
694 _unstable_if_traps(comp_arena(), 8, 0, nullptr),
695 _coarsened_locks(comp_arena(), 8, 0, nullptr),
696 _congraph(nullptr),
697 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
698 _unique(0),
699 _dead_node_count(0),
700 _dead_node_list(comp_arena()),
701 _node_arena_one(mtCompiler, Arena::Tag::tag_node),
702 _node_arena_two(mtCompiler, Arena::Tag::tag_node),
703 _node_arena(&_node_arena_one),
704 _mach_constant_base_node(nullptr),
705 _Compile_types(mtCompiler, Arena::Tag::tag_type),
706 _initial_gvn(nullptr),
707 _igvn_worklist(nullptr),
708 _types(nullptr),
709 _node_hash(nullptr),
710 _late_inlines(comp_arena(), 2, 0, nullptr),
711 _string_late_inlines(comp_arena(), 2, 0, nullptr),
712 _boxing_late_inlines(comp_arena(), 2, 0, nullptr),
781 #define MINIMUM_NODE_HASH 1023
782
783 // GVN that will be run immediately on new nodes
784 uint estimated_size = method()->code_size()*4+64;
785 estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
786 _igvn_worklist = new (comp_arena()) Unique_Node_List(comp_arena());
787 _types = new (comp_arena()) Type_Array(comp_arena());
788 _node_hash = new (comp_arena()) NodeHash(comp_arena(), estimated_size);
789 PhaseGVN gvn;
790 set_initial_gvn(&gvn);
791
792 { // Scope for timing the parser
793 TracePhase tp(_t_parser);
794
795 // Put top into the hash table ASAP.
796 initial_gvn()->transform(top());
797
798 // Set up tf(), start(), and find a CallGenerator.
799 CallGenerator* cg = nullptr;
800 if (is_osr_compilation()) {
801 init_tf(TypeFunc::make(method(), /* is_osr_compilation = */ true));
802 StartNode* s = new StartOSRNode(root(), tf()->domain_sig());
803 initial_gvn()->set_type_bottom(s);
804 verify_start(s);
805 cg = CallGenerator::for_osr(method(), entry_bci());
806 } else {
807 // Normal case.
808 init_tf(TypeFunc::make(method()));
809 StartNode* s = new StartNode(root(), tf()->domain_cc());
810 initial_gvn()->set_type_bottom(s);
811 verify_start(s);
812 float past_uses = method()->interpreter_invocation_count();
813 float expected_uses = past_uses;
814 cg = CallGenerator::for_inline(method(), expected_uses);
815 }
816 if (failing()) return;
817 if (cg == nullptr) {
818 const char* reason = InlineTree::check_can_parse(method());
819 assert(reason != nullptr, "expect reason for parse failure");
820 stringStream ss;
821 ss.print("cannot parse method: %s", reason);
822 record_method_not_compilable(ss.as_string());
823 return;
824 }
825
826 gvn.set_type(root(), root()->bottom_type());
827
828 JVMState* jvms = build_start_state(start(), tf());
829 if ((jvms = cg->generate(jvms)) == nullptr) {
890 print_ideal_ir("print_ideal");
891 }
892 #endif
893
894 #ifdef ASSERT
895 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
896 bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
897 #endif
898
899 // Dump compilation data to replay it.
900 if (directive->DumpReplayOption) {
901 env()->dump_replay_data(_compile_id);
902 }
903 if (directive->DumpInlineOption && (ilt() != nullptr)) {
904 env()->dump_inline_data(_compile_id);
905 }
906
907 // Now that we know the size of all the monitors we can add a fixed slot
908 // for the original deopt pc.
909 int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);
910 if (needs_stack_repair()) {
911 // One extra slot for the special stack increment value
912 next_slot += 2;
913 }
914 // TODO 8284443 Only reserve extra slot if needed
915 if (InlineTypeReturnedAsFields) {
916 // One extra slot to hold the null marker for a nullable
917 // inline type return if we run out of registers.
918 next_slot += 2;
919 }
920 set_fixed_slots(next_slot);
921
922 // Compute when to use implicit null checks. Used by matching trap based
923 // nodes and NullCheck optimization.
924 set_allowed_deopt_reasons();
925
926 // Now generate code
927 Code_Gen();
928 }
929
930 //------------------------------Compile----------------------------------------
931 // Compile a runtime stub
932 Compile::Compile(ciEnv* ci_env,
933 TypeFunc_generator generator,
934 address stub_function,
935 const char* stub_name,
936 StubId stub_id,
937 int is_fancy_jump,
938 bool pass_tls,
939 bool return_pc,
940 DirectiveSet* directive)
941 : Phase(Compiler),
942 _compile_id(0),
943 _options(Options::for_runtime_stub()),
944 _method(nullptr),
945 _entry_bci(InvocationEntryBci),
946 _stub_function(stub_function),
947 _stub_name(stub_name),
948 _stub_id(stub_id),
949 _stub_entry_point(nullptr),
950 _max_node_limit(MaxNodeLimit),
951 _post_loop_opts_phase(false),
952 _merge_stores_phase(false),
953 _allow_macro_nodes(true),
954 _inlining_progress(false),
955 _inlining_incrementally(false),
956 _has_reserved_stack_access(false),
957 _has_circular_inline_type(false),
958 #ifndef PRODUCT
959 _igv_idx(0),
960 _trace_opto_output(directive->TraceOptoOutputOption),
961 #endif
962 _clinit_barrier_on_entry(false),
963 _stress_seed(0),
964 _comp_arena(mtCompiler, Arena::Tag::tag_comp),
965 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
966 _env(ci_env),
967 _directive(directive),
968 _log(ci_env->log()),
969 _first_failure_details(nullptr),
970 _for_post_loop_igvn(comp_arena(), 8, 0, nullptr),
971 _for_merge_stores_igvn(comp_arena(), 8, 0, nullptr),
972 _congraph(nullptr),
973 NOT_PRODUCT(_igv_printer(nullptr) COMMA)
974 _unique(0),
975 _dead_node_count(0),
976 _dead_node_list(comp_arena()),
977 _node_arena_one(mtCompiler, Arena::Tag::tag_node),
1092 _fixed_slots = 0;
1093 set_has_split_ifs(false);
1094 set_has_loops(false); // first approximation
1095 set_has_stringbuilder(false);
1096 set_has_boxed_value(false);
1097 _trap_can_recompile = false; // no traps emitted yet
1098 _major_progress = true; // start out assuming good things will happen
1099 set_has_unsafe_access(false);
1100 set_max_vector_size(0);
1101 set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers
1102 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
1103 set_decompile_count(0);
1104
1105 #ifndef PRODUCT
1106 _phase_counter = 0;
1107 Copy::zero_to_bytes(_igv_phase_iter, sizeof(_igv_phase_iter));
1108 #endif
1109
1110 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
1111 _loop_opts_cnt = LoopOptsCount;
1112 _has_flat_accesses = false;
1113 _flat_accesses_share_alias = true;
1114 _scalarize_in_safepoints = false;
1115
1116 set_do_inlining(Inline);
1117 set_max_inline_size(MaxInlineSize);
1118 set_freq_inline_size(FreqInlineSize);
1119 set_do_scheduling(OptoScheduling);
1120
1121 set_do_vector_loop(false);
1122 set_has_monitors(false);
1123 set_has_scoped_access(false);
1124
1125 if (AllowVectorizeOnDemand) {
1126 if (has_method() && _directive->VectorizeOption) {
1127 set_do_vector_loop(true);
1128 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());})
1129 } else if (has_method() && method()->name() != nullptr &&
1130 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
1131 set_do_vector_loop(true);
1132 }
1133 }
1134 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
1135 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());})
1376 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1377 assert(do_aliasing(), "Aliasing should be enabled");
1378 int offset = tj->offset();
1379 TypePtr::PTR ptr = tj->ptr();
1380
1381 // Known instance (scalarizable allocation) alias only with itself.
1382 bool is_known_inst = tj->isa_oopptr() != nullptr &&
1383 tj->is_oopptr()->is_known_instance();
1384
1385 // Process weird unsafe references.
1386 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1387 assert(InlineUnsafeOps || StressReflectiveCode, "indeterminate pointers come only from unsafe ops");
1388 assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
1389 tj = TypeOopPtr::BOTTOM;
1390 ptr = tj->ptr();
1391 offset = tj->offset();
1392 }
1393
1394 // Array pointers need some flattening
1395 const TypeAryPtr* ta = tj->isa_aryptr();
1396 if( ta && is_known_inst ) {
1397 if ( offset != Type::OffsetBot &&
1398 offset > arrayOopDesc::length_offset_in_bytes() ) {
1399 offset = Type::OffsetBot; // Flatten constant access into array body only
1400 tj = ta = ta->
1401 remove_speculative()->
1402 cast_to_ptr_type(ptr)->
1403 with_offset(offset);
1404 }
1405 } else if (ta) {
1406 // Common slices
1407 if (offset == arrayOopDesc::length_offset_in_bytes()) {
1408 return TypeAryPtr::RANGE;
1409 } else if (offset == oopDesc::klass_offset_in_bytes()) {
1410 return TypeInstPtr::KLASS;
1411 } else if (offset == oopDesc::mark_offset_in_bytes()) {
1412 return TypeInstPtr::MARK;
1413 }
1414
1415 // Remove size and stability
1416 const TypeAry* normalized_ary = TypeAry::make(ta->elem(), TypeInt::POS, false, ta->is_flat(), ta->is_not_flat(), ta->is_not_null_free(), ta->is_atomic());
1417 // Remove ptr, const_oop, and offset
1418 if (ta->elem() == Type::BOTTOM) {
1419 // Bottom array (meet of int[] and byte[] for example), accesses to it will be done with
1420 // Unsafe. This should alias with all arrays. For now just leave it as it is (this is
1421 // incorrect, see JDK-8331133).
1422 tj = ta = TypeAryPtr::make(TypePtr::BotPTR, nullptr, normalized_ary, nullptr, false, Type::Offset::bottom);
1423 } else if (ta->elem()->make_oopptr() != nullptr) {
1424 // Object arrays, keep field_offset
1425 tj = ta = TypeAryPtr::make(TypePtr::BotPTR, nullptr, normalized_ary, nullptr, ta->klass_is_exact(), Type::Offset::bottom, Type::Offset(ta->field_offset()));
1426 } else {
1427 // Primitive arrays
1428 tj = ta = TypeAryPtr::make(TypePtr::BotPTR, nullptr, normalized_ary, ta->exact_klass(), true, Type::Offset::bottom);
1429 }
1430
1431 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1432 // cannot be distinguished by bytecode alone.
1433 if (ta->elem() == TypeInt::BOOL) {
1434 tj = ta = TypeAryPtr::BYTES;
1435 }
1436
1437 // All arrays of references share the same slice
1438 if (!ta->is_flat() && ta->elem()->make_oopptr() != nullptr) {
1439 const TypeAry* tary = TypeAry::make(TypeInstPtr::BOTTOM, TypeInt::POS, false, false, true, true, true);
1440 tj = ta = TypeAryPtr::make(TypePtr::BotPTR, nullptr, tary, nullptr, false, Type::Offset::bottom);
1441 }
1442
1443 if (ta->is_flat()) {
1444 if (_flat_accesses_share_alias) {
1445 // Initially all flattened array accesses share a single slice
1446 tj = ta = TypeAryPtr::INLINES;
1447 } else {
1448 // Flat accesses are always exact
1449 tj = ta = ta->cast_to_exactness(true);
1450 }
1451 }
1452 }
1453
1454 // Oop pointers need some flattening
1455 const TypeInstPtr *to = tj->isa_instptr();
1456 if (to && to != TypeOopPtr::BOTTOM) {
1457 ciInstanceKlass* ik = to->instance_klass();
1458 tj = to = to->cast_to_maybe_flat_in_array(); // flatten to maybe flat in array
1459 if( ptr == TypePtr::Constant ) {
1460 if (ik != ciEnv::current()->Class_klass() ||
1461 offset < ik->layout_helper_size_in_bytes()) {
1462 // No constant oop pointers (such as Strings); they alias with
1463 // unknown strings.
1464 assert(!is_known_inst, "not scalarizable allocation");
1465 tj = to = to->
1466 cast_to_instance_id(TypeOopPtr::InstanceBot)->
1467 remove_speculative()->
1468 cast_to_ptr_type(TypePtr::BotPTR)->
1469 cast_to_exactness(false);
1470 }
1471 } else if( is_known_inst ) {
1472 tj = to; // Keep NotNull and klass_is_exact for instance type
1473 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1474 // During the 2nd round of IterGVN, NotNull castings are removed.
1475 // Make sure the Bottom and NotNull variants alias the same.
1476 // Also, make sure exact and non-exact variants alias the same.
1477 tj = to = to->
1478 remove_speculative()->
1479 cast_to_instance_id(TypeOopPtr::InstanceBot)->
1480 cast_to_ptr_type(TypePtr::BotPTR)->
1481 cast_to_exactness(false);
1482 }
1483 if (to->speculative() != nullptr) {
1484 tj = to = to->remove_speculative();
1485 }
1486 // Canonicalize the holder of this field
1487 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1488 // First handle header references such as a LoadKlassNode, even if the
1489 // object's klass is unloaded at compile time (4965979).
1490 if (!is_known_inst) { // Do it only for non-instance types
1491 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, nullptr, Type::Offset(offset));
1492 }
1493 } else if (offset < 0 || offset >= ik->layout_helper_size_in_bytes()) {
1494 // Static fields are in the space above the normal instance
1495 // fields in the java.lang.Class instance.
1496 if (ik != ciEnv::current()->Class_klass()) {
1497 to = nullptr;
1498 tj = TypeOopPtr::BOTTOM;
1499 offset = tj->offset();
1500 }
1501 } else {
1502 ciInstanceKlass *canonical_holder = ik->get_canonical_holder(offset);
1503 assert(offset < canonical_holder->layout_helper_size_in_bytes(), "");
1504 assert(tj->offset() == offset, "no change to offset expected");
1505 bool xk = to->klass_is_exact();
1506 int instance_id = to->instance_id();
1507
1508 // If the input type's class is the holder: if exact, the type only includes interfaces implemented by the holder
1509 // but if not exact, it may include extra interfaces: build new type from the holder class to make sure only
1510 // its interfaces are included.
1511 if (xk && ik->equals(canonical_holder)) {
1512 assert(tj == TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, Type::Offset(offset), instance_id,
1513 TypePtr::MaybeFlat), "exact type should be canonical type");
1514 } else {
1515 assert(xk || !is_known_inst, "Known instance should be exact type");
1516 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, is_known_inst, nullptr, Type::Offset(offset), instance_id,
1517 TypePtr::MaybeFlat);
1518 }
1519 }
1520 }
1521
1522 // Klass pointers to object array klasses need some flattening
1523 const TypeKlassPtr *tk = tj->isa_klassptr();
1524 if( tk ) {
1525 // If we are referencing a field within a Klass, we need
1526 // to assume the worst case of an Object. Both exact and
1527 // inexact types must flatten to the same alias class so
1528 // use NotNull as the PTR.
1529 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1530 tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull,
1531 env()->Object_klass(),
1532 Type::Offset(offset),
1533 TypePtr::MaybeFlat);
1534 }
1535
1536 if (tk->isa_aryklassptr() && tk->is_aryklassptr()->elem()->isa_klassptr()) {
1537 ciKlass* k = ciObjArrayKlass::make(env()->Object_klass());
1538 if (!k || !k->is_loaded()) { // Only fails for some -Xcomp runs
1539 tj = tk = TypeInstKlassPtr::make(TypePtr::NotNull, env()->Object_klass(), Type::Offset(offset), TypePtr::MaybeFlat);
1540 } else {
1541 tj = tk = TypeAryKlassPtr::make(TypePtr::NotNull, tk->is_aryklassptr()->elem(), k, Type::Offset(offset), tk->is_not_flat(), tk->is_not_null_free(), tk->is_flat(), tk->is_null_free(), tk->is_atomic(), tk->is_aryklassptr()->is_refined_type());
1542 }
1543 }
1544 // Check for precise loads from the primary supertype array and force them
1545 // to the supertype cache alias index. Check for generic array loads from
1546 // the primary supertype array and also force them to the supertype cache
1547 // alias index. Since the same load can reach both, we need to merge
1548 // these 2 disparate memories into the same alias class. Since the
1549 // primary supertype array is read-only, there's no chance of confusion
1550 // where we bypass an array load and an array store.
1551 int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1552 if (offset == Type::OffsetBot ||
1553 (offset >= primary_supers_offset &&
1554 offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1555 offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1556 offset = in_bytes(Klass::secondary_super_cache_offset());
1557 tj = tk = tk->with_offset(offset);
1558 }
1559 }
1560
1561 // Flatten all Raw pointers together.
1562 if (tj->base() == Type::RawPtr)
1563 tj = TypeRawPtr::BOTTOM;
1653 intptr_t key = (intptr_t) adr_type;
1654 key ^= key >> logAliasCacheSize;
1655 return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1656 }
1657
1658
1659 //-----------------------------grow_alias_types--------------------------------
1660 void Compile::grow_alias_types() {
1661 const int old_ats = _max_alias_types; // how many before?
1662 const int new_ats = old_ats; // how many more?
1663 const int grow_ats = old_ats+new_ats; // how many now?
1664 _max_alias_types = grow_ats;
1665 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1666 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1667 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1668 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
1669 }
1670
1671
1672 //--------------------------------find_alias_type------------------------------
1673 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field, bool uncached) {
1674 if (!do_aliasing()) {
1675 return alias_type(AliasIdxBot);
1676 }
1677
1678 AliasCacheEntry* ace = nullptr;
1679 if (!uncached) {
1680 ace = probe_alias_cache(adr_type);
1681 if (ace->_adr_type == adr_type) {
1682 return alias_type(ace->_index);
1683 }
1684 }
1685
1686 // Handle special cases.
1687 if (adr_type == nullptr) return alias_type(AliasIdxTop);
1688 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
1689
1690 // Do it the slow way.
1691 const TypePtr* flat = flatten_alias_type(adr_type);
1692
1693 #ifdef ASSERT
1694 {
1695 ResourceMark rm;
1696 assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",
1697 Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)));
1698 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",
1699 Type::str(adr_type));
1700 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1701 const TypeOopPtr* foop = flat->is_oopptr();
1702 // Scalarizable allocations have exact klass always.
1703 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
1713 if (alias_type(i)->adr_type() == flat) {
1714 idx = i;
1715 break;
1716 }
1717 }
1718
1719 if (idx == AliasIdxTop) {
1720 if (no_create) return nullptr;
1721 // Grow the array if necessary.
1722 if (_num_alias_types == _max_alias_types) grow_alias_types();
1723 // Add a new alias type.
1724 idx = _num_alias_types++;
1725 _alias_types[idx]->Init(idx, flat);
1726 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
1727 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
1728 if (flat->isa_instptr()) {
1729 if (flat->offset() == java_lang_Class::klass_offset()
1730 && flat->is_instptr()->instance_klass() == env()->Class_klass())
1731 alias_type(idx)->set_rewritable(false);
1732 }
1733 ciField* field = nullptr;
1734 if (flat->isa_aryptr()) {
1735 #ifdef ASSERT
1736 const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1737 // (T_BYTE has the weakest alignment and size restrictions...)
1738 assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
1739 #endif
1740 const Type* elemtype = flat->is_aryptr()->elem();
1741 if (flat->offset() == TypePtr::OffsetBot) {
1742 alias_type(idx)->set_element(elemtype);
1743 }
1744 int field_offset = flat->is_aryptr()->field_offset().get();
1745 if (flat->is_flat() &&
1746 field_offset != Type::OffsetBot) {
1747 ciInlineKlass* vk = elemtype->inline_klass();
1748 field_offset += vk->payload_offset();
1749 field = vk->get_field_by_offset(field_offset, false);
1750 }
1751 }
1752 if (flat->isa_klassptr()) {
1753 if (UseCompactObjectHeaders) {
1754 if (flat->offset() == in_bytes(Klass::prototype_header_offset()))
1755 alias_type(idx)->set_rewritable(false);
1756 }
1757 if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1758 alias_type(idx)->set_rewritable(false);
1759 if (flat->offset() == in_bytes(Klass::misc_flags_offset()))
1760 alias_type(idx)->set_rewritable(false);
1761 if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1762 alias_type(idx)->set_rewritable(false);
1763 if (flat->offset() == in_bytes(Klass::layout_helper_offset()))
1764 alias_type(idx)->set_rewritable(false);
1765 if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1766 alias_type(idx)->set_rewritable(false);
1767 }
1768
1769 if (flat->isa_instklassptr()) {
1770 if (flat->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
1771 alias_type(idx)->set_rewritable(false);
1772 }
1773 }
1774 // %%% (We would like to finalize JavaThread::threadObj_offset(),
1775 // but the base pointer type is not distinctive enough to identify
1776 // references into JavaThread.)
1777
1778 // Check for final fields.
1779 const TypeInstPtr* tinst = flat->isa_instptr();
1780 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1781 if (tinst->const_oop() != nullptr &&
1782 tinst->instance_klass() == ciEnv::current()->Class_klass() &&
1783 tinst->offset() >= (tinst->instance_klass()->layout_helper_size_in_bytes())) {
1784 // static field
1785 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1786 field = k->get_field_by_offset(tinst->offset(), true);
1787 } else if (tinst->is_inlinetypeptr()) {
1788 // Inline type field
1789 ciInlineKlass* vk = tinst->inline_klass();
1790 field = vk->get_field_by_offset(tinst->offset(), false);
1791 } else {
1792 ciInstanceKlass *k = tinst->instance_klass();
1793 field = k->get_field_by_offset(tinst->offset(), false);
1794 }
1795 }
1796 assert(field == nullptr ||
1797 original_field == nullptr ||
1798 (field->holder() == original_field->holder() &&
1799 field->offset_in_bytes() == original_field->offset_in_bytes() &&
1800 field->is_static() == original_field->is_static()), "wrong field?");
1801 // Set field() and is_rewritable() attributes.
1802 if (field != nullptr) {
1803 alias_type(idx)->set_field(field);
1804 if (flat->isa_aryptr()) {
1805 // Fields of flat arrays are rewritable although they are declared final
1806 assert(flat->is_flat(), "must be a flat array");
1807 alias_type(idx)->set_rewritable(true);
1808 }
1809 }
1810 }
1811
1812 // Fill the cache for next time.
1813 if (!uncached) {
1814 ace->_adr_type = adr_type;
1815 ace->_index = idx;
1816 assert(alias_type(adr_type) == alias_type(idx), "type must be installed");
1817
1818 // Might as well try to fill the cache for the flattened version, too.
1819 AliasCacheEntry* face = probe_alias_cache(flat);
1820 if (face->_adr_type == nullptr) {
1821 face->_adr_type = flat;
1822 face->_index = idx;
1823 assert(alias_type(flat) == alias_type(idx), "flat type must work too");
1824 }
1825 }
1826
1827 return alias_type(idx);
1828 }
1829
1830
1831 Compile::AliasType* Compile::alias_type(ciField* field) {
1832 const TypeOopPtr* t;
1833 if (field->is_static())
1834 t = TypeInstPtr::make(field->holder()->java_mirror());
1835 else
1836 t = TypeOopPtr::make_from_klass_raw(field->holder());
1837 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1838 assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
1839 return atp;
1840 }
1841
1842
1843 //------------------------------have_alias_type--------------------------------
1844 bool Compile::have_alias_type(const TypePtr* adr_type) {
1926 assert(!C->major_progress(), "not cleared");
1927
1928 if (_for_post_loop_igvn.length() > 0) {
1929 while (_for_post_loop_igvn.length() > 0) {
1930 Node* n = _for_post_loop_igvn.pop();
1931 n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1932 igvn._worklist.push(n);
1933 }
1934 igvn.optimize();
1935 if (failing()) return;
1936 assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed");
1937 assert(C->parse_predicate_count() == 0, "all parse predicates should have been removed now");
1938
1939 // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1940 if (C->major_progress()) {
1941 C->clear_major_progress(); // ensure that major progress is now clear
1942 }
1943 }
1944 }
1945
1946 void Compile::add_inline_type(Node* n) {
1947 assert(n->is_InlineType(), "unexpected node");
1948 _inline_type_nodes.push(n);
1949 }
1950
1951 void Compile::remove_inline_type(Node* n) {
1952 assert(n->is_InlineType(), "unexpected node");
1953 if (_inline_type_nodes.contains(n)) {
1954 _inline_type_nodes.remove(n);
1955 }
1956 }
1957
1958 // Does the return value keep otherwise useless inline type allocations alive?
1959 static bool return_val_keeps_allocations_alive(Node* ret_val) {
1960 ResourceMark rm;
1961 Unique_Node_List wq;
1962 wq.push(ret_val);
1963 bool some_allocations = false;
1964 for (uint i = 0; i < wq.size(); i++) {
1965 Node* n = wq.at(i);
1966 if (n->outcnt() > 1) {
1967 // Some other use for the allocation
1968 return false;
1969 } else if (n->is_InlineType()) {
1970 wq.push(n->in(1));
1971 } else if (n->is_Phi()) {
1972 for (uint j = 1; j < n->req(); j++) {
1973 wq.push(n->in(j));
1974 }
1975 } else if (n->is_CheckCastPP() &&
1976 n->in(1)->is_Proj() &&
1977 n->in(1)->in(0)->is_Allocate()) {
1978 some_allocations = true;
1979 } else if (n->is_CheckCastPP()) {
1980 wq.push(n->in(1));
1981 }
1982 }
1983 return some_allocations;
1984 }
1985
1986 void Compile::process_inline_types(PhaseIterGVN &igvn, bool remove) {
1987 // Make sure that the return value does not keep an otherwise unused allocation alive
1988 if (tf()->returns_inline_type_as_fields()) {
1989 Node* ret = nullptr;
1990 for (uint i = 1; i < root()->req(); i++) {
1991 Node* in = root()->in(i);
1992 if (in->Opcode() == Op_Return) {
1993 assert(ret == nullptr, "only one return");
1994 ret = in;
1995 }
1996 }
1997 if (ret != nullptr) {
1998 Node* ret_val = ret->in(TypeFunc::Parms);
1999 if (igvn.type(ret_val)->isa_oopptr() &&
2000 return_val_keeps_allocations_alive(ret_val)) {
2001 igvn.replace_input_of(ret, TypeFunc::Parms, InlineTypeNode::tagged_klass(igvn.type(ret_val)->inline_klass(), igvn));
2002 assert(ret_val->outcnt() == 0, "should be dead now");
2003 igvn.remove_dead_node(ret_val);
2004 }
2005 }
2006 }
2007 if (_inline_type_nodes.length() == 0) {
2008 // keep the graph canonical
2009 igvn.optimize();
2010 return;
2011 }
2012 // Scalarize inline types in safepoint debug info.
2013 // Delay this until all inlining is over to avoid getting inconsistent debug info.
2014 set_scalarize_in_safepoints(true);
2015 for (int i = _inline_type_nodes.length()-1; i >= 0; i--) {
2016 InlineTypeNode* vt = _inline_type_nodes.at(i)->as_InlineType();
2017 vt->make_scalar_in_safepoints(&igvn);
2018 igvn.record_for_igvn(vt);
2019 }
2020 if (remove) {
2021 // Remove inline type nodes by replacing them with their oop input
2022 while (_inline_type_nodes.length() > 0) {
2023 InlineTypeNode* vt = _inline_type_nodes.pop()->as_InlineType();
2024 if (vt->outcnt() == 0) {
2025 igvn.remove_dead_node(vt);
2026 continue;
2027 }
2028 for (DUIterator i = vt->outs(); vt->has_out(i); i++) {
2029 DEBUG_ONLY(bool must_be_buffered = false);
2030 Node* u = vt->out(i);
2031 // Check if any users are blackholes. If so, rewrite them to use either the
2032 // allocated buffer, or individual components, instead of the inline type node
2033 // that goes away.
2034 if (u->is_Blackhole()) {
2035 BlackholeNode* bh = u->as_Blackhole();
2036
2037 // Unlink the old input
2038 int idx = bh->find_edge(vt);
2039 assert(idx != -1, "The edge should be there");
2040 bh->del_req(idx);
2041 --i;
2042
2043 if (vt->is_allocated(&igvn)) {
2044 // Already has the allocated instance, blackhole that
2045 bh->add_req(vt->get_oop());
2046 } else {
2047 // Not allocated yet, blackhole the components
2048 for (uint c = 0; c < vt->field_count(); c++) {
2049 bh->add_req(vt->field_value(c));
2050 }
2051 }
2052
2053 // Node modified, record for IGVN
2054 igvn.record_for_igvn(bh);
2055 }
2056 #ifdef ASSERT
2057 // Verify that inline type is buffered when replacing by oop
2058 else if (u->is_InlineType()) {
2059 // InlineType uses don't need buffering because they are about to be replaced as well
2060 } else if (u->is_Phi()) {
2061 // TODO 8302217 Remove this once InlineTypeNodes are reliably pushed through
2062 } else {
2063 must_be_buffered = true;
2064 }
2065 if (must_be_buffered && !vt->is_allocated(&igvn)) {
2066 vt->dump(0);
2067 u->dump(0);
2068 assert(false, "Should have been buffered");
2069 }
2070 #endif
2071 }
2072 igvn.replace_node(vt, vt->get_oop());
2073 }
2074 }
2075 igvn.optimize();
2076 }
2077
2078 void Compile::add_flat_access(Node* n) {
2079 assert(n != nullptr && (n->Opcode() == Op_LoadFlat || n->Opcode() == Op_StoreFlat), "unexpected node %s", n == nullptr ? "nullptr" : n->Name());
2080 assert(!_flat_access_nodes.contains(n), "duplicate insertion");
2081 _flat_access_nodes.push(n);
2082 }
2083
2084 void Compile::remove_flat_access(Node* n) {
2085 assert(n != nullptr && (n->Opcode() == Op_LoadFlat || n->Opcode() == Op_StoreFlat), "unexpected node %s", n == nullptr ? "nullptr" : n->Name());
2086 _flat_access_nodes.remove_if_existing(n);
2087 }
2088
2089 void Compile::process_flat_accesses(PhaseIterGVN& igvn) {
2090 assert(igvn._worklist.size() == 0, "should be empty");
2091 igvn.set_delay_transform(true);
2092 for (int i = _flat_access_nodes.length() - 1; i >= 0; i--) {
2093 Node* n = _flat_access_nodes.at(i);
2094 assert(n != nullptr, "unexpected nullptr");
2095 if (n->is_LoadFlat()) {
2096 n->as_LoadFlat()->expand_atomic(igvn);
2097 } else {
2098 n->as_StoreFlat()->expand_atomic(igvn);
2099 }
2100 }
2101 _flat_access_nodes.clear_and_deallocate();
2102 igvn.set_delay_transform(false);
2103 igvn.optimize();
2104 }
2105
2106 void Compile::adjust_flat_array_access_aliases(PhaseIterGVN& igvn) {
2107 DEBUG_ONLY(igvn.verify_empty_worklist(nullptr));
2108 if (!_has_flat_accesses) {
2109 return;
2110 }
2111 // Initially, all flat array accesses share the same slice to
2112 // keep dependencies with Object[] array accesses (that could be
2113 // to a flat array) correct. We're done with parsing so we
2114 // now know all flat array accesses in this compile
2115 // unit. Let's move flat array accesses to their own slice,
2116 // one per element field. This should help memory access
2117 // optimizations.
2118 ResourceMark rm;
2119 Unique_Node_List wq;
2120 wq.push(root());
2121
2122 Node_List mergememnodes;
2123 Node_List memnodes;
2124
2125 // Alias index currently shared by all flat memory accesses
2126 int index = get_alias_index(TypeAryPtr::INLINES);
2127
2128 // Find MergeMem nodes and flat array accesses
2129 for (uint i = 0; i < wq.size(); i++) {
2130 Node* n = wq.at(i);
2131 if (n->is_Mem()) {
2132 const TypePtr* adr_type = nullptr;
2133 adr_type = get_adr_type(get_alias_index(n->adr_type()));
2134 if (adr_type == TypeAryPtr::INLINES) {
2135 memnodes.push(n);
2136 }
2137 } else if (n->is_MergeMem()) {
2138 MergeMemNode* mm = n->as_MergeMem();
2139 if (mm->memory_at(index) != mm->base_memory()) {
2140 mergememnodes.push(n);
2141 }
2142 }
2143 for (uint j = 0; j < n->req(); j++) {
2144 Node* m = n->in(j);
2145 if (m != nullptr) {
2146 wq.push(m);
2147 }
2148 }
2149 }
2150
2151 if (memnodes.size() > 0) {
2152 _flat_accesses_share_alias = false;
2153
2154 // We are going to change the slice for the flat array
2155 // accesses so we need to clear the cache entries that refer to
2156 // them.
2157 for (uint i = 0; i < AliasCacheSize; i++) {
2158 AliasCacheEntry* ace = &_alias_cache[i];
2159 if (ace->_adr_type != nullptr &&
2160 ace->_adr_type->is_flat()) {
2161 ace->_adr_type = nullptr;
2162 ace->_index = (i != 0) ? 0 : AliasIdxTop; // Make sure the nullptr adr_type resolves to AliasIdxTop
2163 }
2164 }
2165
2166 // Find what aliases we are going to add
2167 int start_alias = num_alias_types()-1;
2168 int stop_alias = 0;
2169
2170 for (uint i = 0; i < memnodes.size(); i++) {
2171 Node* m = memnodes.at(i);
2172 const TypePtr* adr_type = nullptr;
2173 adr_type = m->adr_type();
2174 #ifdef ASSERT
2175 m->as_Mem()->set_adr_type(adr_type);
2176 #endif
2177 int idx = get_alias_index(adr_type);
2178 start_alias = MIN2(start_alias, idx);
2179 stop_alias = MAX2(stop_alias, idx);
2180 }
2181
2182 assert(stop_alias >= start_alias, "should have expanded aliases");
2183
2184 Node_Stack stack(0);
2185 #ifdef ASSERT
2186 VectorSet seen(Thread::current()->resource_area());
2187 #endif
2188 // Now let's fix the memory graph so each flat array access
2189 // is moved to the right slice. Start from the MergeMem nodes.
2190 uint last = unique();
2191 for (uint i = 0; i < mergememnodes.size(); i++) {
2192 MergeMemNode* current = mergememnodes.at(i)->as_MergeMem();
2193 if (current->outcnt() == 0) {
2194 // This node is killed by a previous iteration
2195 continue;
2196 }
2197
2198 Node* n = current->memory_at(index);
2199 MergeMemNode* mm = nullptr;
2200 do {
2201 // Follow memory edges through memory accesses, phis and
2202 // narrow membars and push nodes on the stack. Once we hit
2203 // bottom memory, we pop element off the stack one at a
2204 // time, in reverse order, and move them to the right slice
2205 // by changing their memory edges.
2206 if ((n->is_Phi() && n->adr_type() != TypePtr::BOTTOM) || n->is_Mem() ||
2207 (n->adr_type() == TypeAryPtr::INLINES && !n->is_NarrowMemProj())) {
2208 assert(!seen.test_set(n->_idx), "");
2209 // Uses (a load for instance) will need to be moved to the
2210 // right slice as well and will get a new memory state
2211 // that we don't know yet. The use could also be the
2212 // backedge of a loop. We put a place holder node between
2213 // the memory node and its uses. We replace that place
2214 // holder with the correct memory state once we know it,
2215 // i.e. when nodes are popped off the stack. Using the
2216 // place holder make the logic work in the presence of
2217 // loops.
2218 if (n->outcnt() > 1) {
2219 Node* place_holder = nullptr;
2220 assert(!n->has_out_with(Op_Node), "");
2221 for (DUIterator k = n->outs(); n->has_out(k); k++) {
2222 Node* u = n->out(k);
2223 if (u != current && u->_idx < last) {
2224 bool success = false;
2225 for (uint l = 0; l < u->req(); l++) {
2226 if (!stack.is_empty() && u == stack.node() && l == stack.index()) {
2227 continue;
2228 }
2229 Node* in = u->in(l);
2230 if (in == n) {
2231 if (place_holder == nullptr) {
2232 place_holder = new Node(1);
2233 place_holder->init_req(0, n);
2234 }
2235 igvn.replace_input_of(u, l, place_holder);
2236 success = true;
2237 }
2238 }
2239 if (success) {
2240 --k;
2241 }
2242 }
2243 }
2244 }
2245 if (n->is_Phi()) {
2246 stack.push(n, 1);
2247 n = n->in(1);
2248 } else if (n->is_Mem()) {
2249 stack.push(n, n->req());
2250 n = n->in(MemNode::Memory);
2251 } else {
2252 assert(n->is_Proj() && n->in(0)->Opcode() == Op_MemBarCPUOrder, "");
2253 stack.push(n, n->req());
2254 n = n->in(0)->in(TypeFunc::Memory);
2255 }
2256 } else {
2257 assert(n->adr_type() == TypePtr::BOTTOM || (n->Opcode() == Op_Node && n->_idx >= last) || n->is_NarrowMemProj(), "");
2258 // Build a new MergeMem node to carry the new memory state
2259 // as we build it. IGVN should fold extraneous MergeMem
2260 // nodes.
2261 if (n->is_NarrowMemProj()) {
2262 // We need 1 NarrowMemProj for each slice of this array
2263 InitializeNode* init = n->in(0)->as_Initialize();
2264 AllocateNode* alloc = init->allocation();
2265 Node* klass_node = alloc->in(AllocateNode::KlassNode);
2266 const TypeAryKlassPtr* klass_type = klass_node->bottom_type()->isa_aryklassptr();
2267 assert(klass_type != nullptr, "must be an array");
2268 assert(klass_type->klass_is_exact(), "must be an exact klass");
2269 ciArrayKlass* klass = klass_type->exact_klass()->as_array_klass();
2270 assert(klass->is_flat_array_klass(), "must be a flat array");
2271 ciInlineKlass* elem_klass = klass->element_klass()->as_inline_klass();
2272 const TypeAryPtr* oop_type = klass_type->as_instance_type()->is_aryptr();
2273 assert(oop_type->klass_is_exact(), "must be an exact klass");
2274
2275 Node* base = alloc->in(TypeFunc::Memory);
2276 assert(base->bottom_type() == Type::MEMORY, "the memory input of AllocateNode must be a memory");
2277 assert(base->adr_type() == TypePtr::BOTTOM, "the memory input of AllocateNode must be a bottom memory");
2278 // Must create a MergeMem with base as the base memory, do not clone if base is a
2279 // MergeMem because it may not be processed yet
2280 mm = MergeMemNode::make(nullptr);
2281 mm->set_base_memory(base);
2282 for (int j = 0; j < elem_klass->nof_nonstatic_fields(); j++) {
2283 int field_offset = elem_klass->nonstatic_field_at(j)->offset_in_bytes() - elem_klass->payload_offset();
2284 const TypeAryPtr* field_ptr = oop_type->with_offset(Type::OffsetBot)->with_field_offset(field_offset);
2285 int field_alias_idx = get_alias_index(field_ptr);
2286 assert(field_ptr == get_adr_type(field_alias_idx), "must match");
2287 Node* new_proj = new NarrowMemProjNode(init, field_ptr);
2288 igvn.register_new_node_with_optimizer(new_proj);
2289 mm->set_memory_at(field_alias_idx, new_proj);
2290 }
2291 if (!klass->is_elem_null_free()) {
2292 int nm_offset = elem_klass->null_marker_offset_in_payload();
2293 const TypeAryPtr* nm_ptr = oop_type->with_offset(Type::OffsetBot)->with_field_offset(nm_offset);
2294 int nm_alias_idx = get_alias_index(nm_ptr);
2295 assert(nm_ptr == get_adr_type(nm_alias_idx), "must match");
2296 Node* new_proj = new NarrowMemProjNode(init, nm_ptr);
2297 igvn.register_new_node_with_optimizer(new_proj);
2298 mm->set_memory_at(nm_alias_idx, new_proj);
2299 }
2300
2301 // Replace all uses of the old NarrowMemProj with the correct state
2302 MergeMemNode* new_n = MergeMemNode::make(mm);
2303 igvn.register_new_node_with_optimizer(new_n);
2304 igvn.replace_node(n, new_n);
2305 } else {
2306 // Must create a MergeMem with n as the base memory, do not clone if n is a MergeMem
2307 // because it may not be processed yet
2308 mm = MergeMemNode::make(nullptr);
2309 mm->set_base_memory(n);
2310 }
2311
2312 igvn.register_new_node_with_optimizer(mm);
2313 while (stack.size() > 0) {
2314 Node* m = stack.node();
2315 uint idx = stack.index();
2316 if (m->is_Mem()) {
2317 // Move memory node to its new slice
2318 const TypePtr* adr_type = m->adr_type();
2319 int alias = get_alias_index(adr_type);
2320 Node* prev = mm->memory_at(alias);
2321 igvn.replace_input_of(m, MemNode::Memory, prev);
2322 mm->set_memory_at(alias, m);
2323 } else if (m->is_Phi()) {
2324 // We need as many new phis as there are new aliases
2325 Node* new_phi_in = MergeMemNode::make(mm);
2326 igvn.register_new_node_with_optimizer(new_phi_in);
2327 igvn.replace_input_of(m, idx, new_phi_in);
2328 if (idx == m->req()-1) {
2329 Node* r = m->in(0);
2330 for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2331 const TypePtr* adr_type = get_adr_type(j);
2332 if (!adr_type->isa_aryptr() || !adr_type->is_flat() || j == (uint)index) {
2333 continue;
2334 }
2335 Node* phi = new PhiNode(r, Type::MEMORY, get_adr_type(j));
2336 igvn.register_new_node_with_optimizer(phi);
2337 for (uint k = 1; k < m->req(); k++) {
2338 phi->init_req(k, m->in(k)->as_MergeMem()->memory_at(j));
2339 }
2340 mm->set_memory_at(j, phi);
2341 }
2342 Node* base_phi = new PhiNode(r, Type::MEMORY, TypePtr::BOTTOM);
2343 igvn.register_new_node_with_optimizer(base_phi);
2344 for (uint k = 1; k < m->req(); k++) {
2345 base_phi->init_req(k, m->in(k)->as_MergeMem()->base_memory());
2346 }
2347 mm->set_base_memory(base_phi);
2348 }
2349 } else {
2350 // This is a MemBarCPUOrder node from
2351 // Parse::array_load()/Parse::array_store(), in the
2352 // branch that handles flat arrays hidden under
2353 // an Object[] array. We also need one new membar per
2354 // new alias to keep the unknown access that the
2355 // membars protect properly ordered with accesses to
2356 // known flat array.
2357 assert(m->is_Proj(), "projection expected");
2358 Node* ctrl = m->in(0)->in(TypeFunc::Control);
2359 igvn.replace_input_of(m->in(0), TypeFunc::Control, top());
2360 for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2361 const TypePtr* adr_type = get_adr_type(j);
2362 if (!adr_type->isa_aryptr() || !adr_type->is_flat() || j == (uint)index) {
2363 continue;
2364 }
2365 MemBarNode* mb = new MemBarCPUOrderNode(this, j, nullptr);
2366 igvn.register_new_node_with_optimizer(mb);
2367 Node* mem = mm->memory_at(j);
2368 mb->init_req(TypeFunc::Control, ctrl);
2369 mb->init_req(TypeFunc::Memory, mem);
2370 ctrl = new ProjNode(mb, TypeFunc::Control);
2371 igvn.register_new_node_with_optimizer(ctrl);
2372 mem = new ProjNode(mb, TypeFunc::Memory);
2373 igvn.register_new_node_with_optimizer(mem);
2374 mm->set_memory_at(j, mem);
2375 }
2376 igvn.replace_node(m->in(0)->as_Multi()->proj_out(TypeFunc::Control), ctrl);
2377 }
2378 if (idx < m->req()-1) {
2379 idx += 1;
2380 stack.set_index(idx);
2381 n = m->in(idx);
2382 break;
2383 }
2384 // Take care of place holder nodes
2385 if (m->has_out_with(Op_Node)) {
2386 Node* place_holder = m->find_out_with(Op_Node);
2387 if (place_holder != nullptr) {
2388 Node* mm_clone = mm->clone();
2389 igvn.register_new_node_with_optimizer(mm_clone);
2390 Node* hook = new Node(1);
2391 hook->init_req(0, mm);
2392 igvn.replace_node(place_holder, mm_clone);
2393 hook->destruct(&igvn);
2394 }
2395 assert(!m->has_out_with(Op_Node), "place holder should be gone now");
2396 }
2397 stack.pop();
2398 }
2399 }
2400 } while(stack.size() > 0);
2401 // Fix the memory state at the MergeMem we started from
2402 igvn.rehash_node_delayed(current);
2403 for (uint j = (uint)start_alias; j <= (uint)stop_alias; j++) {
2404 const TypePtr* adr_type = get_adr_type(j);
2405 if (!adr_type->isa_aryptr() || !adr_type->is_flat()) {
2406 continue;
2407 }
2408 current->set_memory_at(j, mm);
2409 }
2410 current->set_memory_at(index, current->base_memory());
2411 }
2412 igvn.optimize();
2413 }
2414 print_method(PHASE_SPLIT_INLINES_ARRAY, 2);
2415 #ifdef ASSERT
2416 if (!_flat_accesses_share_alias) {
2417 wq.clear();
2418 wq.push(root());
2419 for (uint i = 0; i < wq.size(); i++) {
2420 Node* n = wq.at(i);
2421 assert(n->adr_type() != TypeAryPtr::INLINES, "should have been removed from the graph");
2422 for (uint j = 0; j < n->req(); j++) {
2423 Node* m = n->in(j);
2424 if (m != nullptr) {
2425 wq.push(m);
2426 }
2427 }
2428 }
2429 }
2430 #endif
2431 }
2432
2433 void Compile::record_for_merge_stores_igvn(Node* n) {
2434 if (!n->for_merge_stores_igvn()) {
2435 assert(!_for_merge_stores_igvn.contains(n), "duplicate");
2436 n->add_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
2437 _for_merge_stores_igvn.append(n);
2438 }
2439 }
2440
2441 void Compile::remove_from_merge_stores_igvn(Node* n) {
2442 n->remove_flag(Node::NodeFlags::Flag_for_merge_stores_igvn);
2443 _for_merge_stores_igvn.remove(n);
2444 }
2445
2446 // We need to wait with merging stores until RangeCheck smearing has removed the RangeChecks during
2447 // the post loops IGVN phase. If we do it earlier, then there may still be some RangeChecks between
2448 // the stores, and we merge the wrong sequence of stores.
2449 // Example:
2450 // StoreI RangeCheck StoreI StoreI RangeCheck StoreI
2451 // Apply MergeStores:
2452 // StoreI RangeCheck [ StoreL ] RangeCheck StoreI
2531 assert(next_bci == iter.next_bci() || next_bci == iter.get_dest(), "wrong next_bci at unstable_if");
2532 Bytecodes::Code c = iter.cur_bc();
2533 Node* lhs = nullptr;
2534 Node* rhs = nullptr;
2535 if (c == Bytecodes::_if_acmpeq || c == Bytecodes::_if_acmpne) {
2536 lhs = unc->peek_operand(0);
2537 rhs = unc->peek_operand(1);
2538 } else if (c == Bytecodes::_ifnull || c == Bytecodes::_ifnonnull) {
2539 lhs = unc->peek_operand(0);
2540 }
2541
2542 ResourceMark rm;
2543 const MethodLivenessResult& live_locals = method->liveness_at_bci(next_bci);
2544 assert(live_locals.is_valid(), "broken liveness info");
2545 int len = (int)live_locals.size();
2546
2547 for (int i = 0; i < len; i++) {
2548 Node* local = unc->local(jvms, i);
2549 // kill local using the liveness of next_bci.
2550 // give up when the local looks like an operand to secure reexecution.
2551 if (!live_locals.at(i) && !local->is_top() && local != lhs && local != rhs) {
2552 uint idx = jvms->locoff() + i;
2553 #ifdef ASSERT
2554 if (PrintOpto && Verbose) {
2555 tty->print("[unstable_if] kill local#%d: ", idx);
2556 local->dump();
2557 tty->cr();
2558 }
2559 #endif
2560 igvn.replace_input_of(unc, idx, top());
2561 modified = true;
2562 }
2563 }
2564 }
2565
2566 // keep the modified trap for late query
2567 if (modified) {
2568 trap->set_modified();
2569 } else {
2570 _unstable_if_traps.delete_at(i);
2571 }
2572 }
2573 igvn.optimize();
2574 }
2575
2576 // StringOpts and late inlining of string methods
2577 void Compile::inline_string_calls(bool parse_time) {
2578 {
2579 // remove useless nodes to make the usage analysis simpler
2580 ResourceMark rm;
2581 PhaseRemoveUseless pru(initial_gvn(), *igvn_worklist());
2582 }
2583
2584 {
2585 ResourceMark rm;
2586 print_method(PHASE_BEFORE_STRINGOPTS, 3);
2758
2759 if (_string_late_inlines.length() > 0) {
2760 assert(has_stringbuilder(), "inconsistent");
2761
2762 inline_string_calls(false);
2763
2764 if (failing()) return;
2765
2766 inline_incrementally_cleanup(igvn);
2767 }
2768
2769 set_inlining_incrementally(false);
2770 }
2771
2772 void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
2773 // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2774 // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2775 // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == nullptr"
2776 // as if "inlining_incrementally() == true" were set.
2777 assert(inlining_incrementally() == false, "not allowed");
2778 #ifdef ASSERT
2779 Unique_Node_List* modified_nodes = _modified_nodes;
2780 _modified_nodes = nullptr;
2781 #endif
2782 assert(_late_inlines.length() > 0, "sanity");
2783
2784 while (_late_inlines.length() > 0) {
2785 igvn_worklist()->ensure_empty(); // should be done with igvn
2786
2787 while (inline_incrementally_one()) {
2788 assert(!failing_internal() || failure_is_artificial(), "inconsistent");
2789 }
2790 if (failing()) return;
2791
2792 inline_incrementally_cleanup(igvn);
2793 }
2794 DEBUG_ONLY( _modified_nodes = modified_nodes; )
2795 }
2796
2797 bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2798 if (_loop_opts_cnt > 0) {
2799 while (major_progress() && (_loop_opts_cnt > 0)) {
2800 TracePhase tp(_t_idealLoop);
2801 PhaseIdealLoop::optimize(igvn, mode);
2802 _loop_opts_cnt--;
2803 if (failing()) return false;
2804 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2805 }
2806 }
2807 return true;
2808 }
2809
2810 // Remove edges from "root" to each SafePoint at a backward branch.
2811 // They were inserted during parsing (see add_safepoint()) to make
2812 // infinite loops without calls or exceptions visible to root, i.e.,
2813 // useful.
2814 void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {
2918 print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2919 }
2920 assert(!has_vbox_nodes(), "sanity");
2921
2922 if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2923 Compile::TracePhase tp(_t_renumberLive);
2924 igvn_worklist()->ensure_empty(); // should be done with igvn
2925 {
2926 ResourceMark rm;
2927 PhaseRenumberLive prl(initial_gvn(), *igvn_worklist());
2928 }
2929 igvn.reset();
2930 igvn.optimize();
2931 if (failing()) return;
2932 }
2933
2934 // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2935 // safepoints
2936 remove_root_to_sfpts_edges(igvn);
2937
2938 // Process inline type nodes now that all inlining is over
2939 process_inline_types(igvn);
2940
2941 adjust_flat_array_access_aliases(igvn);
2942
2943 if (failing()) return;
2944
2945 if (C->macro_count() > 0) {
2946 // Eliminate some macro nodes before EA to reduce analysis pressure
2947 PhaseMacroExpand mexp(igvn);
2948 mexp.eliminate_macro_nodes(/* eliminate_locks= */ false);
2949 if (failing()) {
2950 return;
2951 }
2952 igvn.set_delay_transform(false);
2953 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2954 }
2955
2956 if (has_loops()) {
2957 print_method(PHASE_BEFORE_LOOP_OPTS, 2);
2958 }
2959
2960 // Perform escape analysis
2961 if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2962 if (has_loops()) {
2963 // Cleanup graph (remove dead nodes).
2964 TracePhase tp(_t_idealLoop);
2965 PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2966 if (failing()) {
2967 return;
2968 }
2969 print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2970 if (C->macro_count() > 0) {
2971 // Eliminate some macro nodes before EA to reduce analysis pressure
2972 PhaseMacroExpand mexp(igvn);
2973 mexp.eliminate_macro_nodes(/* eliminate_locks= */ false);
2974 if (failing()) {
2975 return;
2976 }
2977 igvn.set_delay_transform(false);
2978 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2979 }
2980 }
2981
2982 bool progress;
2983 do {
2984 ConnectionGraph::do_analysis(this, &igvn);
2985
2986 if (failing()) return;
2987
2988 int mcount = macro_count(); // Record number of allocations and locks before IGVN
2989
2990 // Optimize out fields loads from scalar replaceable allocations.
2991 igvn.optimize();
2992 print_method(PHASE_ITER_GVN_AFTER_EA, 2);
2993
2994 if (failing()) return;
2995
2996 if (congraph() != nullptr && macro_count() > 0) {
2997 TracePhase tp(_t_macroEliminate);
2998 PhaseMacroExpand mexp(igvn);
2999 mexp.eliminate_macro_nodes();
3000 if (failing()) {
3001 return;
3002 }
3003 print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
3004
3005 igvn.set_delay_transform(false);
3006 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
3007 }
3008
3009 ConnectionGraph::verify_ram_nodes(this, root());
3010 if (failing()) return;
3011
3012 progress = do_iterative_escape_analysis() &&
3013 (macro_count() < mcount) &&
3014 ConnectionGraph::has_candidates(this);
3015 // Try again if candidates exist and made progress
3016 // by removing some allocations and/or locks.
3017 } while (progress);
3018 }
3019
3020 process_flat_accesses(igvn);
3021 if (failing()) {
3022 return;
3023 }
3024
3025 // Loop transforms on the ideal graph. Range Check Elimination,
3026 // peeling, unrolling, etc.
3027
3028 // Set loop opts counter
3029 if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
3030 {
3031 TracePhase tp(_t_idealLoop);
3032 PhaseIdealLoop::optimize(igvn, LoopOptsDefault);
3033 _loop_opts_cnt--;
3034 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
3035 if (failing()) return;
3036 }
3037 // Loop opts pass if partial peeling occurred in previous pass
3038 if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
3039 TracePhase tp(_t_idealLoop);
3040 PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
3041 _loop_opts_cnt--;
3042 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
3043 if (failing()) return;
3044 }
3081 // Loop transforms on the ideal graph. Range Check Elimination,
3082 // peeling, unrolling, etc.
3083 if (!optimize_loops(igvn, LoopOptsDefault)) {
3084 return;
3085 }
3086
3087 if (failing()) return;
3088
3089 C->clear_major_progress(); // ensure that major progress is now clear
3090
3091 process_for_post_loop_opts_igvn(igvn);
3092
3093 process_for_merge_stores_igvn(igvn);
3094
3095 if (failing()) return;
3096
3097 #ifdef ASSERT
3098 bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
3099 #endif
3100
3101 assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty");
3102
3103 if (_late_inlines.length() > 0) {
3104 // More opportunities to optimize virtual and MH calls.
3105 // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
3106 process_late_inline_calls_no_inline(igvn);
3107 }
3108
3109 {
3110 TracePhase tp(_t_macroExpand);
3111 PhaseMacroExpand mex(igvn);
3112 // Last attempt to eliminate macro nodes.
3113 mex.eliminate_macro_nodes();
3114 if (failing()) {
3115 return;
3116 }
3117
3118 print_method(PHASE_BEFORE_MACRO_EXPANSION, 3);
3119 // Do not allow new macro nodes once we start to eliminate and expand
3120 C->reset_allow_macro_nodes();
3121 // Last attempt to eliminate macro nodes before expand
3122 mex.eliminate_macro_nodes();
3123 if (failing()) {
3124 return;
3125 }
3126 mex.eliminate_opaque_looplimit_macro_nodes();
3127 if (failing()) {
3128 return;
3129 }
3130 print_method(PHASE_AFTER_MACRO_ELIMINATION, 2);
3131 if (mex.expand_macro_nodes()) {
3132 assert(failing(), "must bail out w/ explicit message");
3133 return;
3134 }
3135 print_method(PHASE_AFTER_MACRO_EXPANSION, 2);
3136 }
3137
3138 // Process inline type nodes again and remove them. From here
3139 // on we don't need to keep track of field values anymore.
3140 process_inline_types(igvn, /* remove= */ true);
3141
3142 {
3143 TracePhase tp(_t_barrierExpand);
3144 if (bs->expand_barriers(this, igvn)) {
3145 assert(failing(), "must bail out w/ explicit message");
3146 return;
3147 }
3148 print_method(PHASE_BARRIER_EXPANSION, 2);
3149 }
3150
3151 if (C->max_vector_size() > 0) {
3152 C->optimize_logic_cones(igvn);
3153 igvn.optimize();
3154 if (failing()) return;
3155 }
3156
3157 DEBUG_ONLY( _modified_nodes = nullptr; )
3158 DEBUG_ONLY( _late_inlines.clear(); )
3159
3160 assert(igvn._worklist.size() == 0, "not empty");
3161 } // (End scope of igvn; run destructor if necessary for asserts.)
3162
3163 check_no_dead_use();
3164
3165 // We will never use the NodeHash table any more. Clear it so that final_graph_reshaping does not have
3166 // to remove hashes to unlock nodes for modifications.
3167 C->node_hash()->clear();
3168
3169 // A method with only infinite loops has no edges entering loops from root
3170 {
3171 TracePhase tp(_t_graphReshaping);
3172 if (final_graph_reshaping()) {
3173 assert(failing(), "must bail out w/ explicit message");
3174 return;
3175 }
3176 }
3177
3178 print_method(PHASE_OPTIMIZE_FINISHED, 2);
3179 DEBUG_ONLY(set_phase_optimize_finished();)
3180 }
3886 case Op_CmpD3:
3887 case Op_StoreD:
3888 case Op_LoadD:
3889 case Op_LoadD_unaligned:
3890 frc.inc_double_count();
3891 break;
3892 case Op_Opaque1: // Remove Opaque Nodes before matching
3893 n->subsume_by(n->in(1), this);
3894 break;
3895 case Op_CallLeafPure: {
3896 // If the pure call is not supported, then lower to a CallLeaf.
3897 if (!Matcher::match_rule_supported(Op_CallLeafPure)) {
3898 CallNode* call = n->as_Call();
3899 CallNode* new_call = new CallLeafNode(call->tf(), call->entry_point(),
3900 call->_name, TypeRawPtr::BOTTOM);
3901 new_call->init_req(TypeFunc::Control, call->in(TypeFunc::Control));
3902 new_call->init_req(TypeFunc::I_O, C->top());
3903 new_call->init_req(TypeFunc::Memory, C->top());
3904 new_call->init_req(TypeFunc::ReturnAdr, C->top());
3905 new_call->init_req(TypeFunc::FramePtr, C->top());
3906 for (unsigned int i = TypeFunc::Parms; i < call->tf()->domain_sig()->cnt(); i++) {
3907 new_call->init_req(i, call->in(i));
3908 }
3909 n->subsume_by(new_call, this);
3910 }
3911 frc.inc_call_count();
3912 break;
3913 }
3914 case Op_CallStaticJava:
3915 case Op_CallJava:
3916 case Op_CallDynamicJava:
3917 frc.inc_java_call_count(); // Count java call site;
3918 case Op_CallRuntime:
3919 case Op_CallLeaf:
3920 case Op_CallLeafVector:
3921 case Op_CallLeafNoFP: {
3922 assert (n->is_Call(), "");
3923 CallNode *call = n->as_Call();
3924 // Count call sites where the FP mode bit would have to be flipped.
3925 // Do not count uncommon runtime calls:
3926 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
3932 int nop = n->Opcode();
3933 // Clone shared simple arguments to uncommon calls, item (1).
3934 if (n->outcnt() > 1 &&
3935 !n->is_Proj() &&
3936 nop != Op_CreateEx &&
3937 nop != Op_CheckCastPP &&
3938 nop != Op_DecodeN &&
3939 nop != Op_DecodeNKlass &&
3940 !n->is_Mem() &&
3941 !n->is_Phi()) {
3942 Node *x = n->clone();
3943 call->set_req(TypeFunc::Parms, x);
3944 }
3945 }
3946 break;
3947 }
3948 case Op_StoreB:
3949 case Op_StoreC:
3950 case Op_StoreI:
3951 case Op_StoreL:
3952 case Op_StoreLSpecial:
3953 case Op_CompareAndSwapB:
3954 case Op_CompareAndSwapS:
3955 case Op_CompareAndSwapI:
3956 case Op_CompareAndSwapL:
3957 case Op_CompareAndSwapP:
3958 case Op_CompareAndSwapN:
3959 case Op_WeakCompareAndSwapB:
3960 case Op_WeakCompareAndSwapS:
3961 case Op_WeakCompareAndSwapI:
3962 case Op_WeakCompareAndSwapL:
3963 case Op_WeakCompareAndSwapP:
3964 case Op_WeakCompareAndSwapN:
3965 case Op_CompareAndExchangeB:
3966 case Op_CompareAndExchangeS:
3967 case Op_CompareAndExchangeI:
3968 case Op_CompareAndExchangeL:
3969 case Op_CompareAndExchangeP:
3970 case Op_CompareAndExchangeN:
3971 case Op_GetAndAddS:
3972 case Op_GetAndAddB:
4482 k->subsume_by(m, this);
4483 }
4484 }
4485 }
4486 break;
4487 }
4488 case Op_CmpUL: {
4489 if (!Matcher::has_match_rule(Op_CmpUL)) {
4490 // No support for unsigned long comparisons
4491 ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
4492 Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
4493 Node* orl = new OrLNode(n->in(1), sign_bit_mask);
4494 ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
4495 Node* andl = new AndLNode(orl, remove_sign_mask);
4496 Node* cmp = new CmpLNode(andl, n->in(2));
4497 n->subsume_by(cmp, this);
4498 }
4499 break;
4500 }
4501 #ifdef ASSERT
4502 case Op_InlineType: {
4503 n->dump(-1);
4504 assert(false, "inline type node was not removed");
4505 break;
4506 }
4507 case Op_ConNKlass: {
4508 const TypePtr* tp = n->as_Type()->type()->make_ptr();
4509 ciKlass* klass = tp->is_klassptr()->exact_klass();
4510 assert(klass->is_in_encoding_range(), "klass cannot be compressed");
4511 break;
4512 }
4513 #endif
4514 default:
4515 assert(!n->is_Call(), "");
4516 assert(!n->is_Mem(), "");
4517 assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN");
4518 break;
4519 }
4520 }
4521
4522 //------------------------------final_graph_reshaping_walk---------------------
4523 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
4524 // requires that the walk visits a node's inputs before visiting the node.
4525 void Compile::final_graph_reshaping_walk(Node_Stack& nstack, Node* root, Final_Reshape_Counts& frc, Unique_Node_List& dead_nodes) {
4526 Unique_Node_List sfpt;
4862 }
4863 }
4864
4865 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
4866 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
4867 }
4868
4869 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
4870 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
4871 }
4872
4873 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
4874 if (holder->is_initialized()) {
4875 return false;
4876 }
4877 if (holder->is_being_initialized()) {
4878 if (accessing_method->holder() == holder) {
4879 // Access inside a class. The barrier can be elided when access happens in <clinit>,
4880 // <init>, or a static method. In all those cases, there was an initialization
4881 // barrier on the holder klass passed.
4882 if (accessing_method->is_class_initializer() ||
4883 accessing_method->is_object_constructor() ||
4884 accessing_method->is_static()) {
4885 return false;
4886 }
4887 } else if (accessing_method->holder()->is_subclass_of(holder)) {
4888 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
4889 // In case of <init> or a static method, the barrier is on the subclass is not enough:
4890 // child class can become fully initialized while its parent class is still being initialized.
4891 if (accessing_method->is_class_initializer()) {
4892 return false;
4893 }
4894 }
4895 ciMethod* root = method(); // the root method of compilation
4896 if (root != accessing_method) {
4897 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
4898 }
4899 }
4900 return true;
4901 }
4902
4903 #ifndef PRODUCT
4904 //------------------------------verify_bidirectional_edges---------------------
4905 // For each input edge to a node (ie - for each Use-Def edge), verify that
4906 // there is a corresponding Def-Use edge.
4907 void Compile::verify_bidirectional_edges(Unique_Node_List& visited, const Unique_Node_List* root_and_safepoints) const {
4908 // Allocate stack of size C->live_nodes()/16 to avoid frequent realloc
4909 uint stack_size = live_nodes() >> 4;
4910 Node_List nstack(MAX2(stack_size, (uint) OptoNodeListSize));
4911 if (root_and_safepoints != nullptr) {
4941 if (in != nullptr && !in->is_top()) {
4942 // Count instances of `next`
4943 int cnt = 0;
4944 for (uint idx = 0; idx < in->_outcnt; idx++) {
4945 if (in->_out[idx] == n) {
4946 cnt++;
4947 }
4948 }
4949 assert(cnt > 0, "Failed to find Def-Use edge.");
4950 // Check for duplicate edges
4951 // walk the input array downcounting the input edges to n
4952 for (uint j = 0; j < length; j++) {
4953 if (n->in(j) == in) {
4954 cnt--;
4955 }
4956 }
4957 assert(cnt == 0, "Mismatched edge count.");
4958 } else if (in == nullptr) {
4959 assert(i == 0 || i >= n->req() ||
4960 n->is_Region() || n->is_Phi() || n->is_ArrayCopy() ||
4961 (n->is_Allocate() && i >= AllocateNode::InlineType) ||
4962 (n->is_Unlock() && i == (n->req() - 1)) ||
4963 (n->is_MemBar() && i == 5), // the precedence edge to a membar can be removed during macro node expansion
4964 "only region, phi, arraycopy, allocate, unlock or membar nodes have null data edges");
4965 } else {
4966 assert(in->is_top(), "sanity");
4967 // Nothing to check.
4968 }
4969 }
4970 }
4971 }
4972
4973 //------------------------------verify_graph_edges---------------------------
4974 // Walk the Graph and verify that there is a one-to-one correspondence
4975 // between Use-Def edges and Def-Use edges in the graph.
4976 void Compile::verify_graph_edges(bool no_dead_code, const Unique_Node_List* root_and_safepoints) const {
4977 if (VerifyGraphEdges) {
4978 Unique_Node_List visited;
4979
4980 // Call graph walk to check edges
4981 verify_bidirectional_edges(visited, root_and_safepoints);
4982 if (no_dead_code) {
4983 // Now make sure that no visited node is used by an unvisited node.
4984 bool dead_nodes = false;
5095 // (1) subklass is already limited to a subtype of superklass => always ok
5096 // (2) subklass does not overlap with superklass => always fail
5097 // (3) superklass has NO subtypes and we can check with a simple compare.
5098 Compile::SubTypeCheckResult Compile::static_subtype_check(const TypeKlassPtr* superk, const TypeKlassPtr* subk, bool skip) {
5099 if (skip) {
5100 return SSC_full_test; // Let caller generate the general case.
5101 }
5102
5103 if (subk->is_java_subtype_of(superk)) {
5104 return SSC_always_true; // (0) and (1) this test cannot fail
5105 }
5106
5107 if (!subk->maybe_java_subtype_of(superk)) {
5108 return SSC_always_false; // (2) true path dead; no dynamic test needed
5109 }
5110
5111 const Type* superelem = superk;
5112 if (superk->isa_aryklassptr()) {
5113 int ignored;
5114 superelem = superk->is_aryklassptr()->base_element_type(ignored);
5115
5116 // Do not fold the subtype check to an array klass pointer comparison for null-able inline type arrays
5117 // because null-free [LMyValue <: null-able [LMyValue but the klasses are different. Perform a full test.
5118 if (!superk->is_aryklassptr()->is_null_free() && superk->is_aryklassptr()->elem()->isa_instklassptr() &&
5119 superk->is_aryklassptr()->elem()->is_instklassptr()->instance_klass()->is_inlinetype()) {
5120 return SSC_full_test;
5121 }
5122 }
5123
5124 if (superelem->isa_instklassptr()) {
5125 ciInstanceKlass* ik = superelem->is_instklassptr()->instance_klass();
5126 if (!ik->has_subklass()) {
5127 if (!ik->is_final()) {
5128 // Add a dependency if there is a chance of a later subclass.
5129 dependencies()->assert_leaf_type(ik);
5130 }
5131 if (!superk->maybe_java_subtype_of(subk)) {
5132 return SSC_always_false;
5133 }
5134 return SSC_easy_test; // (3) caller can do a simple ptr comparison
5135 }
5136 } else {
5137 // A primitive array type has no subtypes.
5138 return SSC_easy_test; // (3) caller can do a simple ptr comparison
5139 }
5140
5141 return SSC_full_test;
5940 } else {
5941 _debug_network_printer->update_compiled_method(C->method());
5942 }
5943 tty->print_cr("Method printed over network stream to IGV");
5944 _debug_network_printer->print(name, C->root(), visible_nodes, fr);
5945 }
5946 #endif // !PRODUCT
5947
5948 Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {
5949 if (type != nullptr && phase->type(value)->higher_equal(type)) {
5950 return value;
5951 }
5952 Node* result = nullptr;
5953 if (bt == T_BYTE) {
5954 result = phase->transform(new LShiftINode(value, phase->intcon(24)));
5955 result = new RShiftINode(result, phase->intcon(24));
5956 } else if (bt == T_BOOLEAN) {
5957 result = new AndINode(value, phase->intcon(0xFF));
5958 } else if (bt == T_CHAR) {
5959 result = new AndINode(value,phase->intcon(0xFFFF));
5960 } else if (bt == T_FLOAT) {
5961 result = new MoveI2FNode(value);
5962 } else {
5963 assert(bt == T_SHORT, "unexpected narrow type");
5964 result = phase->transform(new LShiftINode(value, phase->intcon(16)));
5965 result = new RShiftINode(result, phase->intcon(16));
5966 }
5967 if (transform_res) {
5968 result = phase->transform(result);
5969 }
5970 return result;
5971 }
5972
5973 void Compile::record_method_not_compilable_oom() {
5974 record_method_not_compilable(CompilationMemoryStatistic::failure_reason_memlimit());
5975 }
5976
5977 #ifndef PRODUCT
5978 // Collects all the control inputs from nodes on the worklist and from their data dependencies
5979 static void find_candidate_control_inputs(Unique_Node_List& worklist, Unique_Node_List& candidates) {
5980 // Follow non-control edges until we reach CFG nodes
5981 for (uint i = 0; i < worklist.size(); i++) {
|