1924 // See if already computed; if so return it
1925 if (derived_base_map[derived->_idx]) {
1926 return derived_base_map[derived->_idx];
1927 }
1928
1929 #ifdef ASSERT
1930 if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1931 // Bypass the verification node
1932 Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1933 derived_base_map[derived->_idx] = base;
1934 return base;
1935 }
1936 #endif
1937
1938 // See if this happens to be a base.
1939 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1940 // pointers derived from null! These are always along paths that
1941 // can't happen at run-time but the optimizer cannot deduce it so
1942 // we have to handle it gracefully.
1943 assert(!derived->bottom_type()->isa_narrowoop() ||
1944 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
1945 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1946 // If its an OOP with a non-zero offset, then it is derived.
1947 if( tj == nullptr || tj->_offset == 0 ) {
1948 derived_base_map[derived->_idx] = derived;
1949 return derived;
1950 }
1951 // Derived is null+offset? Base is null!
1952 if( derived->is_Con() ) {
1953 Node *base = _matcher.mach_null();
1954 assert(base != nullptr, "sanity");
1955 if (base->in(0) == nullptr) {
1956 // Initialize it once and make it shared:
1957 // set control to _root and place it into Start block
1958 // (where top() node is placed).
1959 base->init_req(0, _cfg.get_root_node());
1960 Block *startb = _cfg.get_block_for_node(C->top());
1961 uint node_pos = startb->find_node(C->top());
1962 startb->insert_node(base, node_pos);
1963 _cfg.map_node_to_block(base, startb);
1964 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1965
1966 // The loadConP0 might have projection nodes depending on architecture
1967 // Add the projection nodes to the CFG
2093 // Copies do not define a new value and so do not interfere.
2094 // Remove the copies source from the liveout set before interfering.
2095 uint idx = n->is_Copy();
2096 if (idx) {
2097 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2098 }
2099 }
2100
2101 // Found a safepoint?
2102 JVMState *jvms = n->jvms();
2103 if (jvms && !liveout.is_empty()) {
2104 // Now scan for a live derived pointer
2105 IndexSetIterator elements(&liveout);
2106 uint neighbor;
2107 while ((neighbor = elements.next()) != 0) {
2108 // Find reaching DEF for base and derived values
2109 // This works because we are still in SSA during this call.
2110 Node *derived = lrgs(neighbor)._def;
2111 const TypePtr *tj = derived->bottom_type()->isa_ptr();
2112 assert(!derived->bottom_type()->isa_narrowoop() ||
2113 derived->bottom_type()->make_ptr()->is_ptr()->_offset == 0, "sanity");
2114 // If its an OOP with a non-zero offset, then it is derived.
2115 if( tj && tj->_offset != 0 && tj->isa_oop_ptr() ) {
2116 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2117 assert(base->_idx < _lrg_map.size(), "");
2118 // Add reaching DEFs of derived pointer and base pointer as a
2119 // pair of inputs
2120 n->add_req(derived);
2121 n->add_req(base);
2122
2123 // See if the base pointer is already live to this point.
2124 // Since I'm working on the SSA form, live-ness amounts to
2125 // reaching def's. So if I find the base's live range then
2126 // I know the base's def reaches here.
2127 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2128 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2129 (_lrg_map.live_range_id(base) > 0) && // not a constant
2130 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2131 // Base pointer is not currently live. Since I stretched
2132 // the base pointer to here and it crosses basic-block
2133 // boundaries, the global live info is now incorrect.
2134 // Recompute live.
2135 must_recompute_live = true;
2385 return buf+strlen(buf);
2386 }
2387
2388 void PhaseChaitin::dump_for_spill_split_recycle() const {
2389 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2390 // Display which live ranges need to be split and the allocator's state
2391 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2392 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2393 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2394 tty->print("L%d: ", bidx);
2395 lrgs(bidx).dump();
2396 }
2397 }
2398 tty->cr();
2399 dump();
2400 }
2401 }
2402
2403 void PhaseChaitin::dump_frame() const {
2404 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2405 const TypeTuple *domain = C->tf()->domain();
2406 const int argcnt = domain->cnt() - TypeFunc::Parms;
2407
2408 // Incoming arguments in registers dump
2409 for( int k = 0; k < argcnt; k++ ) {
2410 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2411 if( OptoReg::is_reg(parmreg)) {
2412 const char *reg_name = OptoReg::regname(parmreg);
2413 tty->print("#r%3.3d %s", parmreg, reg_name);
2414 parmreg = _matcher._parm_regs[k].second();
2415 if( OptoReg::is_reg(parmreg)) {
2416 tty->print(":%s", OptoReg::regname(parmreg));
2417 }
2418 tty->print(" : parm %d: ", k);
2419 domain->field_at(k + TypeFunc::Parms)->dump();
2420 tty->cr();
2421 }
2422 }
2423
2424 // Check for un-owned padding above incoming args
2425 OptoReg::Name reg = _matcher._new_SP;
2446 if( j >= argcnt )
2447 tty->print_cr("HOLE, owned by SELF");
2448 }
2449
2450 // Old outgoing preserve area
2451 while( reg > _matcher._old_SP ) {
2452 reg = OptoReg::add(reg, -1);
2453 tty->print_cr("#r%3.3d %s+%2d: old out preserve",reg,fp,reg2offset_unchecked(reg));
2454 }
2455
2456 // Old SP
2457 tty->print_cr("# -- Old %s -- Framesize: %d --",fp,
2458 reg2offset_unchecked(OptoReg::add(_matcher._old_SP,-1)) - reg2offset_unchecked(_matcher._new_SP)+jintSize);
2459
2460 // Preserve area dump
2461 int fixed_slots = C->fixed_slots();
2462 OptoReg::Name begin_in_preserve = OptoReg::add(_matcher._old_SP, -(int)C->in_preserve_stack_slots());
2463 OptoReg::Name return_addr = _matcher.return_addr();
2464
2465 reg = OptoReg::add(reg, -1);
2466 while (OptoReg::is_stack(reg)) {
2467 tty->print("#r%3.3d %s+%2d: ",reg,fp,reg2offset_unchecked(reg));
2468 if (return_addr == reg) {
2469 tty->print_cr("return address");
2470 } else if (reg >= begin_in_preserve) {
2471 // Preserved slots are present on x86
2472 if (return_addr == OptoReg::add(reg, VMRegImpl::slots_per_word))
2473 tty->print_cr("saved fp register");
2474 else if (return_addr == OptoReg::add(reg, 2*VMRegImpl::slots_per_word) &&
2475 VerifyStackAtCalls)
2476 tty->print_cr("<Majik cookie> +VerifyStackAtCalls");
2477 else
2478 tty->print_cr("in_preserve");
2479 } else if ((int)OptoReg::reg2stack(reg) < fixed_slots) {
2480 tty->print_cr("Fixed slot %d", OptoReg::reg2stack(reg));
2481 } else {
2482 tty->print_cr("pad2, stack alignment");
2483 }
2484 reg = OptoReg::add(reg, -1);
2485 }
2486
2487 // Spill area dump
2488 reg = OptoReg::add(_matcher._new_SP, _framesize );
2489 while( reg > _matcher._out_arg_limit ) {
2490 reg = OptoReg::add(reg, -1);
2491 tty->print_cr("#r%3.3d %s+%2d: spill",reg,fp,reg2offset_unchecked(reg));
2492 }
2493
2494 // Outgoing argument area dump
2495 while( reg > OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ) {
2496 reg = OptoReg::add(reg, -1);
2497 tty->print_cr("#r%3.3d %s+%2d: outgoing argument",reg,fp,reg2offset_unchecked(reg));
2498 }
2499
2500 // Outgoing new preserve area
2594 // Check each derived/base pair
2595 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2596 Node* check = sfpt->in(idx);
2597 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2598 // search upwards through spills and spill phis for AddP
2599 worklist.clear();
2600 worklist.push(check);
2601 uint k = 0;
2602 while (k < worklist.size()) {
2603 check = worklist.at(k);
2604 assert(check, "Bad base or derived pointer");
2605 // See PhaseChaitin::find_base_for_derived() for all cases.
2606 int isc = check->is_Copy();
2607 if (isc) {
2608 worklist.push(check->in(isc));
2609 } else if (check->is_Phi()) {
2610 for (uint m = 1; m < check->req(); m++) {
2611 worklist.push(check->in(m));
2612 }
2613 } else if (check->is_Con()) {
2614 if (is_derived && check->bottom_type()->is_ptr()->_offset != 0) {
2615 // Derived is null+non-zero offset, base must be null.
2616 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2617 } else {
2618 assert(check->bottom_type()->is_ptr()->_offset == 0, "Bad base pointer");
2619 // Base either ConP(nullptr) or loadConP
2620 if (check->is_Mach()) {
2621 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2622 } else {
2623 assert(check->Opcode() == Op_ConP &&
2624 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2625 }
2626 }
2627 } else if (check->bottom_type()->is_ptr()->_offset == 0) {
2628 if (check->is_Proj() || (check->is_Mach() &&
2629 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2630 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2631 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2632 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2633 #ifdef _LP64
2634 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2635 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2636 (check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2637 #endif // _LP64
2638 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2639 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2640 // Valid nodes
2641 } else {
2642 check->dump();
2643 assert(false, "Bad base or derived pointer");
2644 }
2645 } else {
2646 assert(is_derived, "Bad base pointer");
2647 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|
1924 // See if already computed; if so return it
1925 if (derived_base_map[derived->_idx]) {
1926 return derived_base_map[derived->_idx];
1927 }
1928
1929 #ifdef ASSERT
1930 if (derived->is_Mach() && derived->as_Mach()->ideal_Opcode() == Op_VerifyVectorAlignment) {
1931 // Bypass the verification node
1932 Node* base = find_base_for_derived(derived_base_map, derived->in(1), maxlrg);
1933 derived_base_map[derived->_idx] = base;
1934 return base;
1935 }
1936 #endif
1937
1938 // See if this happens to be a base.
1939 // NOTE: we use TypePtr instead of TypeOopPtr because we can have
1940 // pointers derived from null! These are always along paths that
1941 // can't happen at run-time but the optimizer cannot deduce it so
1942 // we have to handle it gracefully.
1943 assert(!derived->bottom_type()->isa_narrowoop() ||
1944 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
1945 const TypePtr *tj = derived->bottom_type()->isa_ptr();
1946 // If its an OOP with a non-zero offset, then it is derived.
1947 if (tj == nullptr || tj->offset() == 0) {
1948 derived_base_map[derived->_idx] = derived;
1949 return derived;
1950 }
1951 // Derived is null+offset? Base is null!
1952 if( derived->is_Con() ) {
1953 Node *base = _matcher.mach_null();
1954 assert(base != nullptr, "sanity");
1955 if (base->in(0) == nullptr) {
1956 // Initialize it once and make it shared:
1957 // set control to _root and place it into Start block
1958 // (where top() node is placed).
1959 base->init_req(0, _cfg.get_root_node());
1960 Block *startb = _cfg.get_block_for_node(C->top());
1961 uint node_pos = startb->find_node(C->top());
1962 startb->insert_node(base, node_pos);
1963 _cfg.map_node_to_block(base, startb);
1964 assert(_lrg_map.live_range_id(base) == 0, "should not have LRG yet");
1965
1966 // The loadConP0 might have projection nodes depending on architecture
1967 // Add the projection nodes to the CFG
2093 // Copies do not define a new value and so do not interfere.
2094 // Remove the copies source from the liveout set before interfering.
2095 uint idx = n->is_Copy();
2096 if (idx) {
2097 liveout.remove(_lrg_map.live_range_id(n->in(idx)));
2098 }
2099 }
2100
2101 // Found a safepoint?
2102 JVMState *jvms = n->jvms();
2103 if (jvms && !liveout.is_empty()) {
2104 // Now scan for a live derived pointer
2105 IndexSetIterator elements(&liveout);
2106 uint neighbor;
2107 while ((neighbor = elements.next()) != 0) {
2108 // Find reaching DEF for base and derived values
2109 // This works because we are still in SSA during this call.
2110 Node *derived = lrgs(neighbor)._def;
2111 const TypePtr *tj = derived->bottom_type()->isa_ptr();
2112 assert(!derived->bottom_type()->isa_narrowoop() ||
2113 derived->bottom_type()->make_ptr()->is_ptr()->offset() == 0, "sanity");
2114 // If its an OOP with a non-zero offset, then it is derived.
2115 if (tj && tj->offset() != 0 && tj->isa_oop_ptr()) {
2116 Node *base = find_base_for_derived(derived_base_map, derived, maxlrg);
2117 assert(base->_idx < _lrg_map.size(), "");
2118 // Add reaching DEFs of derived pointer and base pointer as a
2119 // pair of inputs
2120 n->add_req(derived);
2121 n->add_req(base);
2122
2123 // See if the base pointer is already live to this point.
2124 // Since I'm working on the SSA form, live-ness amounts to
2125 // reaching def's. So if I find the base's live range then
2126 // I know the base's def reaches here.
2127 if ((_lrg_map.live_range_id(base) >= _lrg_map.max_lrg_id() || // (Brand new base (hence not live) or
2128 !liveout.member(_lrg_map.live_range_id(base))) && // not live) AND
2129 (_lrg_map.live_range_id(base) > 0) && // not a constant
2130 _cfg.get_block_for_node(base) != block) { // base not def'd in blk)
2131 // Base pointer is not currently live. Since I stretched
2132 // the base pointer to here and it crosses basic-block
2133 // boundaries, the global live info is now incorrect.
2134 // Recompute live.
2135 must_recompute_live = true;
2385 return buf+strlen(buf);
2386 }
2387
2388 void PhaseChaitin::dump_for_spill_split_recycle() const {
2389 if( WizardMode && (PrintCompilation || PrintOpto) ) {
2390 // Display which live ranges need to be split and the allocator's state
2391 tty->print_cr("Graph-Coloring Iteration %d will split the following live ranges", _trip_cnt);
2392 for (uint bidx = 1; bidx < _lrg_map.max_lrg_id(); bidx++) {
2393 if( lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG ) {
2394 tty->print("L%d: ", bidx);
2395 lrgs(bidx).dump();
2396 }
2397 }
2398 tty->cr();
2399 dump();
2400 }
2401 }
2402
2403 void PhaseChaitin::dump_frame() const {
2404 const char *fp = OptoReg::regname(OptoReg::c_frame_pointer);
2405 const TypeTuple *domain = C->tf()->domain_cc();
2406 const int argcnt = domain->cnt() - TypeFunc::Parms;
2407
2408 // Incoming arguments in registers dump
2409 for( int k = 0; k < argcnt; k++ ) {
2410 OptoReg::Name parmreg = _matcher._parm_regs[k].first();
2411 if( OptoReg::is_reg(parmreg)) {
2412 const char *reg_name = OptoReg::regname(parmreg);
2413 tty->print("#r%3.3d %s", parmreg, reg_name);
2414 parmreg = _matcher._parm_regs[k].second();
2415 if( OptoReg::is_reg(parmreg)) {
2416 tty->print(":%s", OptoReg::regname(parmreg));
2417 }
2418 tty->print(" : parm %d: ", k);
2419 domain->field_at(k + TypeFunc::Parms)->dump();
2420 tty->cr();
2421 }
2422 }
2423
2424 // Check for un-owned padding above incoming args
2425 OptoReg::Name reg = _matcher._new_SP;
2446 if( j >= argcnt )
2447 tty->print_cr("HOLE, owned by SELF");
2448 }
2449
2450 // Old outgoing preserve area
2451 while( reg > _matcher._old_SP ) {
2452 reg = OptoReg::add(reg, -1);
2453 tty->print_cr("#r%3.3d %s+%2d: old out preserve",reg,fp,reg2offset_unchecked(reg));
2454 }
2455
2456 // Old SP
2457 tty->print_cr("# -- Old %s -- Framesize: %d --",fp,
2458 reg2offset_unchecked(OptoReg::add(_matcher._old_SP,-1)) - reg2offset_unchecked(_matcher._new_SP)+jintSize);
2459
2460 // Preserve area dump
2461 int fixed_slots = C->fixed_slots();
2462 OptoReg::Name begin_in_preserve = OptoReg::add(_matcher._old_SP, -(int)C->in_preserve_stack_slots());
2463 OptoReg::Name return_addr = _matcher.return_addr();
2464
2465 reg = OptoReg::add(reg, -1);
2466
2467 // Special fixed slots
2468 int current_slot = fixed_slots;
2469 int stack_increment_slot = -1;
2470 int nm_slot = -1;
2471
2472 auto next_slot = [&]() {
2473 current_slot -= VMRegImpl::slots_per_word;
2474 return current_slot;
2475 };
2476
2477 if (C->needs_stack_repair()) {
2478 stack_increment_slot = next_slot();
2479 }
2480 if (C->needs_nm_slot()) {
2481 nm_slot = next_slot();
2482 }
2483 int orig_pc_slot = next_slot();
2484
2485 while (OptoReg::is_stack(reg)) {
2486 int stack_slot = (int)OptoReg::reg2stack(reg);
2487 tty->print("#r%3.3d %s+%2d: ",reg,fp,reg2offset_unchecked(reg));
2488 if (return_addr == reg) {
2489 tty->print_cr("return address");
2490 } else if (reg >= begin_in_preserve) {
2491 // Preserved slots are present on x86
2492 if (return_addr == OptoReg::add(reg, VMRegImpl::slots_per_word))
2493 tty->print_cr("saved fp register");
2494 else if (return_addr == OptoReg::add(reg, 2*VMRegImpl::slots_per_word) &&
2495 VerifyStackAtCalls)
2496 tty->print_cr("<Majik cookie> +VerifyStackAtCalls");
2497 else
2498 tty->print_cr("in_preserve");
2499 } else if (stack_slot < fixed_slots) {
2500 tty->print("Fixed slot %d", OptoReg::reg2stack(reg));
2501 if (stack_slot == stack_increment_slot) {
2502 tty->print_cr(" (stack increment)");
2503 } else if (stack_slot == nm_slot) {
2504 tty->print_cr(" (null marker)");
2505 } else if (stack_slot == orig_pc_slot) {
2506 tty->print_cr(" (original deopt pc)");
2507 } else {
2508 tty->cr();
2509 }
2510 } else {
2511 tty->print_cr("pad2, stack alignment");
2512 }
2513 reg = OptoReg::add(reg, -1);
2514 }
2515
2516 // Spill area dump
2517 reg = OptoReg::add(_matcher._new_SP, _framesize );
2518 while( reg > _matcher._out_arg_limit ) {
2519 reg = OptoReg::add(reg, -1);
2520 tty->print_cr("#r%3.3d %s+%2d: spill",reg,fp,reg2offset_unchecked(reg));
2521 }
2522
2523 // Outgoing argument area dump
2524 while( reg > OptoReg::add(_matcher._new_SP, C->out_preserve_stack_slots()) ) {
2525 reg = OptoReg::add(reg, -1);
2526 tty->print_cr("#r%3.3d %s+%2d: outgoing argument",reg,fp,reg2offset_unchecked(reg));
2527 }
2528
2529 // Outgoing new preserve area
2623 // Check each derived/base pair
2624 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
2625 Node* check = sfpt->in(idx);
2626 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
2627 // search upwards through spills and spill phis for AddP
2628 worklist.clear();
2629 worklist.push(check);
2630 uint k = 0;
2631 while (k < worklist.size()) {
2632 check = worklist.at(k);
2633 assert(check, "Bad base or derived pointer");
2634 // See PhaseChaitin::find_base_for_derived() for all cases.
2635 int isc = check->is_Copy();
2636 if (isc) {
2637 worklist.push(check->in(isc));
2638 } else if (check->is_Phi()) {
2639 for (uint m = 1; m < check->req(); m++) {
2640 worklist.push(check->in(m));
2641 }
2642 } else if (check->is_Con()) {
2643 if (is_derived && check->bottom_type()->is_ptr()->offset() != 0) {
2644 // Derived is null+non-zero offset, base must be null.
2645 assert(check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad derived pointer");
2646 } else {
2647 assert(check->bottom_type()->is_ptr()->offset() == 0, "Bad base pointer");
2648 // Base either ConP(nullptr) or loadConP
2649 if (check->is_Mach()) {
2650 assert(check->as_Mach()->ideal_Opcode() == Op_ConP, "Bad base pointer");
2651 } else {
2652 assert(check->Opcode() == Op_ConP &&
2653 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null, "Bad base pointer");
2654 }
2655 }
2656 } else if (check->bottom_type()->is_ptr()->offset() == 0) {
2657 if (check->is_Proj() || (check->is_Mach() &&
2658 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
2659 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
2660 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
2661 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
2662 #ifdef _LP64
2663 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP) ||
2664 (UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN) ||
2665 (check->as_Mach()->ideal_Opcode() == Op_DecodeNKlass) ||
2666 #endif // _LP64
2667 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
2668 check->as_Mach()->ideal_Opcode() == Op_LoadKlass))) {
2669 // Valid nodes
2670 } else {
2671 check->dump();
2672 assert(false, "Bad base or derived pointer");
2673 }
2674 } else {
2675 assert(is_derived, "Bad base pointer");
2676 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP, "Bad derived pointer");
|