src/share/vm/opto/macro.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6775880 Sdiff src/share/vm/opto

src/share/vm/opto/macro.cpp

Print this page




  42         use->set_prec(j, newref);
  43       nreplacements++;
  44     } else if (j >= req && uin == NULL) {
  45       break;
  46     }
  47   }
  48   return nreplacements;
  49 }
  50 
  51 void PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) {
  52   // Copy debug information and adjust JVMState information
  53   uint old_dbg_start = oldcall->tf()->domain()->cnt();
  54   uint new_dbg_start = newcall->tf()->domain()->cnt();
  55   int jvms_adj  = new_dbg_start - old_dbg_start;
  56   assert (new_dbg_start == newcall->req(), "argument count mismatch");
  57 
  58   Dict* sosn_map = new Dict(cmpkey,hashkey);
  59   for (uint i = old_dbg_start; i < oldcall->req(); i++) {
  60     Node* old_in = oldcall->in(i);
  61     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
  62     if (old_in->is_SafePointScalarObject()) {
  63       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
  64       uint old_unique = C->unique();
  65       Node* new_in = old_sosn->clone(jvms_adj, sosn_map);
  66       if (old_unique != C->unique()) {
  67         new_in = transform_later(new_in); // Register new node.
  68       }
  69       old_in = new_in;
  70     }
  71     newcall->add_req(old_in);
  72   }
  73 
  74   newcall->set_jvms(oldcall->jvms());
  75   for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) {
  76     jvms->set_map(newcall);
  77     jvms->set_locoff(jvms->locoff()+jvms_adj);
  78     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
  79     jvms->set_monoff(jvms->monoff()+jvms_adj);
  80     jvms->set_scloff(jvms->scloff()+jvms_adj);
  81     jvms->set_endoff(jvms->endoff()+jvms_adj);
  82   }


1492 
1493 void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
1494   Node* length = alloc->in(AllocateNode::ALength);
1495   expand_allocate_common(alloc, length,
1496                          OptoRuntime::new_array_Type(),
1497                          OptoRuntime::new_array_Java());
1498 }
1499 
1500 
1501 // we have determined that this lock/unlock can be eliminated, we simply
1502 // eliminate the node without expanding it.
1503 //
1504 // Note:  The membar's associated with the lock/unlock are currently not
1505 //        eliminated.  This should be investigated as a future enhancement.
1506 //
1507 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
1508 
1509   if (!alock->is_eliminated()) {
1510     return false;
1511   }
1512   // Mark the box lock as eliminated if all correspondent locks are eliminated
1513   // to construct correct debug info.
1514   BoxLockNode* box = alock->box_node()->as_BoxLock();
1515   if (!box->is_eliminated()) {
1516     bool eliminate = true;
1517     for (DUIterator_Fast imax, i = box->fast_outs(imax); i < imax; i++) {
1518       Node *lck = box->fast_out(i);
1519       if (lck->is_Lock() && !lck->as_AbstractLock()->is_eliminated()) {
1520         eliminate = false;
1521         break;








1522       }












1523     }
1524     if (eliminate)
1525       box->set_eliminated();















1526   }







1527 
1528   #ifndef PRODUCT
1529   if (PrintEliminateLocks) {
1530     if (alock->is_Lock()) {
1531       tty->print_cr("++++ Eliminating: %d Lock", alock->_idx);
1532     } else {
1533       tty->print_cr("++++ Eliminating: %d Unlock", alock->_idx);
1534     }
1535   }
1536   #endif
1537 
1538   Node* mem  = alock->in(TypeFunc::Memory);
1539   Node* ctrl = alock->in(TypeFunc::Control);
1540 
1541   extract_call_projections(alock);
1542   // There are 2 projections from the lock.  The lock node will
1543   // be deleted when its last use is subsumed below.
1544   assert(alock->outcnt() == 2 &&
1545          _fallthroughproj != NULL &&
1546          _memproj_fallthrough != NULL,
1547          "Unexpected projections from Lock/Unlock");
1548 
1549   Node* fallthroughproj = _fallthroughproj;
1550   Node* memproj_fallthrough = _memproj_fallthrough;
1551 
1552   // The memory projection from a lock/unlock is RawMem
1553   // The input to a Lock is merged memory, so extract its RawMem input
1554   // (unless the MergeMem has been optimized away.)
1555   if (alock->is_Lock()) {
1556     // Seach for MemBarAcquire node and delete it also.
1557     MemBarNode* membar = fallthroughproj->unique_ctrl_out()->as_MemBar();
1558     assert(membar != NULL && membar->Opcode() == Op_MemBarAcquire, "");
1559     Node* ctrlproj = membar->proj_out(TypeFunc::Control);
1560     Node* memproj = membar->proj_out(TypeFunc::Memory);
1561     _igvn.hash_delete(ctrlproj);
1562     _igvn.subsume_node(ctrlproj, fallthroughproj);
1563     _igvn.hash_delete(memproj);
1564     _igvn.subsume_node(memproj, memproj_fallthrough);








1565   }

1566 
1567   // Seach for MemBarRelease node and delete it also.
1568   if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() &&
1569       ctrl->in(0)->is_MemBar()) {
1570     MemBarNode* membar = ctrl->in(0)->as_MemBar();
1571     assert(membar->Opcode() == Op_MemBarRelease &&
1572            mem->is_Proj() && membar == mem->in(0), "");
1573     _igvn.hash_delete(fallthroughproj);
1574     _igvn.subsume_node(fallthroughproj, ctrl);
1575     _igvn.hash_delete(memproj_fallthrough);
1576     _igvn.subsume_node(memproj_fallthrough, mem);
1577     fallthroughproj = ctrl;
1578     memproj_fallthrough = mem;
1579     ctrl = membar->in(TypeFunc::Control);
1580     mem  = membar->in(TypeFunc::Memory);
1581   }
1582 
1583   _igvn.hash_delete(fallthroughproj);
1584   _igvn.subsume_node(fallthroughproj, ctrl);
1585   _igvn.hash_delete(memproj_fallthrough);


1870   _igvn.hash_delete(_fallthroughproj);
1871   _fallthroughproj->disconnect_inputs(NULL);
1872   region->init_req(1, slow_ctrl);
1873   // region inputs are now complete
1874   transform_later(region);
1875   _igvn.subsume_node(_fallthroughproj, region);
1876 
1877   Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
1878   mem_phi->init_req(1, memproj );
1879   mem_phi->init_req(2, mem);
1880   transform_later(mem_phi);
1881   _igvn.hash_delete(_memproj_fallthrough);
1882   _igvn.subsume_node(_memproj_fallthrough, mem_phi);
1883 }
1884 
1885 //------------------------------expand_macro_nodes----------------------
1886 //  Returns true if a failure occurred.
1887 bool PhaseMacroExpand::expand_macro_nodes() {
1888   if (C->macro_count() == 0)
1889     return false;
1890   // attempt to eliminate allocations
1891   bool progress = true;
1892   while (progress) {
1893     progress = false;
1894     for (int i = C->macro_count(); i > 0; i--) {
1895       Node * n = C->macro_node(i-1);
1896       bool success = false;
1897       debug_only(int old_macro_count = C->macro_count(););




















1898       switch (n->class_id()) {
1899       case Node::Class_Allocate:
1900       case Node::Class_AllocateArray:
1901         success = eliminate_allocate_node(n->as_Allocate());
1902         break;
1903       case Node::Class_Lock:
1904       case Node::Class_Unlock:
1905         success = eliminate_locking_node(n->as_AbstractLock());
1906         break;
1907       default:
1908         if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) {
1909           _igvn.add_users_to_worklist(n);
1910           _igvn.hash_delete(n);
1911           _igvn.subsume_node(n, n->in(1));
1912           success = true;
1913         } else {
1914           assert(false, "unknown node type in macro list");
1915         }
1916       }
1917       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
1918       progress = progress || success;
1919     }
1920   }
1921   // Make sure expansion will not cause node limit to be exceeded.
1922   // Worst case is a macro node gets expanded into about 50 nodes.
1923   // Allow 50% more for optimization.
1924   if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
1925     return true;
1926 
1927   // expand "macro" nodes
1928   // nodes are removed from the macro list as they are processed
1929   while (C->macro_count() > 0) {
1930     int macro_count = C->macro_count();
1931     Node * n = C->macro_node(macro_count-1);
1932     assert(n->is_macro(), "only macro nodes expected here");
1933     if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
1934       // node is unreachable, so don't try to expand it
1935       C->remove_macro_node(n);
1936       continue;




  42         use->set_prec(j, newref);
  43       nreplacements++;
  44     } else if (j >= req && uin == NULL) {
  45       break;
  46     }
  47   }
  48   return nreplacements;
  49 }
  50 
  51 void PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) {
  52   // Copy debug information and adjust JVMState information
  53   uint old_dbg_start = oldcall->tf()->domain()->cnt();
  54   uint new_dbg_start = newcall->tf()->domain()->cnt();
  55   int jvms_adj  = new_dbg_start - old_dbg_start;
  56   assert (new_dbg_start == newcall->req(), "argument count mismatch");
  57 
  58   Dict* sosn_map = new Dict(cmpkey,hashkey);
  59   for (uint i = old_dbg_start; i < oldcall->req(); i++) {
  60     Node* old_in = oldcall->in(i);
  61     // Clone old SafePointScalarObjectNodes, adjusting their field contents.
  62     if (old_in != NULL && old_in->is_SafePointScalarObject()) {
  63       SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject();
  64       uint old_unique = C->unique();
  65       Node* new_in = old_sosn->clone(jvms_adj, sosn_map);
  66       if (old_unique != C->unique()) {
  67         new_in = transform_later(new_in); // Register new node.
  68       }
  69       old_in = new_in;
  70     }
  71     newcall->add_req(old_in);
  72   }
  73 
  74   newcall->set_jvms(oldcall->jvms());
  75   for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) {
  76     jvms->set_map(newcall);
  77     jvms->set_locoff(jvms->locoff()+jvms_adj);
  78     jvms->set_stkoff(jvms->stkoff()+jvms_adj);
  79     jvms->set_monoff(jvms->monoff()+jvms_adj);
  80     jvms->set_scloff(jvms->scloff()+jvms_adj);
  81     jvms->set_endoff(jvms->endoff()+jvms_adj);
  82   }


1492 
1493 void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
1494   Node* length = alloc->in(AllocateNode::ALength);
1495   expand_allocate_common(alloc, length,
1496                          OptoRuntime::new_array_Type(),
1497                          OptoRuntime::new_array_Java());
1498 }
1499 
1500 
1501 // we have determined that this lock/unlock can be eliminated, we simply
1502 // eliminate the node without expanding it.
1503 //
1504 // Note:  The membar's associated with the lock/unlock are currently not
1505 //        eliminated.  This should be investigated as a future enhancement.
1506 //
1507 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
1508 
1509   if (!alock->is_eliminated()) {
1510     return false;
1511   }
1512   if (alock->is_Lock() && !alock->is_coarsened()) {
1513       // Create new "eliminated" BoxLock node and use it
1514       // in monitor debug info for the same object.
1515       BoxLockNode* oldbox = alock->box_node()->as_BoxLock();
1516       Node* obj = alock->obj_node();
1517       if (!oldbox->is_eliminated()) {
1518         BoxLockNode* newbox = oldbox->clone()->as_BoxLock();
1519         newbox->set_eliminated();
1520         transform_later(newbox);
1521         // Replace old box node with new box for all users
1522         // of the same object.
1523         for (uint i = 0; i < oldbox->outcnt();) {
1524 
1525           bool next_edge = true;
1526           Node* u = oldbox->raw_out(i);
1527           if (u == alock) {
1528             i++;
1529             continue; // It will be removed below
1530           }
1531           if (u->is_Lock() && 
1532               u->as_Lock()->obj_node() == obj &&
1533               // oldbox could be referenced in debug info also
1534               u->as_Lock()->box_node() == oldbox) {
1535             assert(u->as_Lock()->is_eliminated(), "sanity");
1536             _igvn.hash_delete(u);
1537             u->set_req(TypeFunc::Parms + 1, newbox);
1538             next_edge = false;
1539 #ifdef ASSERT
1540           } else if (u->is_Unlock() && u->as_Unlock()->obj_node() == obj) {
1541             assert(u->as_Unlock()->is_eliminated(), "sanity");
1542 #endif
1543           }
1544           // Replace old box in monitor debug info.
1545           if (u->is_SafePoint() && u->as_SafePoint()->jvms()) {
1546             SafePointNode* sfn = u->as_SafePoint();
1547             JVMState* youngest_jvms = sfn->jvms();
1548             int max_depth = youngest_jvms->depth();
1549             for (int depth = 1; depth <= max_depth; depth++) {
1550               JVMState* jvms = youngest_jvms->of_depth(depth);
1551               int num_mon  = jvms->nof_monitors();
1552               // Loop over monitors
1553               for (int idx = 0; idx < num_mon; idx++) {
1554                 Node* obj_node = sfn->monitor_obj(jvms, idx);
1555                 Node* box_node = sfn->monitor_box(jvms, idx);
1556                 if (box_node == oldbox && obj_node == obj) {
1557                   int j = jvms->monitor_box_offset(idx);
1558                   _igvn.hash_delete(u);
1559                   u->set_req(j, newbox);
1560                   next_edge = false;
1561                 }
1562               } // for (int idx = 0;
1563             } // for (int depth = 1;
1564           } // if (u->is_SafePoint()
1565           if (next_edge) i++;
1566         } // for (uint i = 0; i < oldbox->outcnt();)
1567       } // if (!oldbox->is_eliminated())
1568   } // if (alock->is_Lock() && !lock->is_coarsened())
1569 
1570   #ifndef PRODUCT
1571   if (PrintEliminateLocks) {
1572     if (alock->is_Lock()) {
1573       tty->print_cr("++++ Eliminating: %d Lock", alock->_idx);
1574     } else {
1575       tty->print_cr("++++ Eliminating: %d Unlock", alock->_idx);
1576     }
1577   }
1578   #endif
1579 
1580   Node* mem  = alock->in(TypeFunc::Memory);
1581   Node* ctrl = alock->in(TypeFunc::Control);
1582 
1583   extract_call_projections(alock);
1584   // There are 2 projections from the lock.  The lock node will
1585   // be deleted when its last use is subsumed below.
1586   assert(alock->outcnt() == 2 &&
1587          _fallthroughproj != NULL &&
1588          _memproj_fallthrough != NULL,
1589          "Unexpected projections from Lock/Unlock");
1590 
1591   Node* fallthroughproj = _fallthroughproj;
1592   Node* memproj_fallthrough = _memproj_fallthrough;
1593 
1594   // The memory projection from a lock/unlock is RawMem
1595   // The input to a Lock is merged memory, so extract its RawMem input
1596   // (unless the MergeMem has been optimized away.)
1597   if (alock->is_Lock()) {
1598     // Seach for MemBarAcquire node and delete it also.
1599     MemBarNode* membar = fallthroughproj->unique_ctrl_out()->as_MemBar();
1600     assert(membar != NULL && membar->Opcode() == Op_MemBarAcquire, "");
1601     Node* ctrlproj = membar->proj_out(TypeFunc::Control);
1602     Node* memproj = membar->proj_out(TypeFunc::Memory);
1603     _igvn.hash_delete(ctrlproj);
1604     _igvn.subsume_node(ctrlproj, fallthroughproj);
1605     _igvn.hash_delete(memproj);
1606     _igvn.subsume_node(memproj, memproj_fallthrough);
1607 
1608     // Delete FastLock node also if this Lock node is unique user
1609     // (a loop peeling may clone a Lock node).
1610     Node* flock = alock->as_Lock()->fastlock_node();
1611     if (flock->outcnt() == 1) {
1612       assert(flock->unique_out() == alock, "sanity");
1613       _igvn.hash_delete(flock);
1614       _igvn.subsume_node(flock, top());
1615     }
1616   }
1617 
1618   // Seach for MemBarRelease node and delete it also.
1619   if (alock->is_Unlock() && ctrl != NULL && ctrl->is_Proj() &&
1620       ctrl->in(0)->is_MemBar()) {
1621     MemBarNode* membar = ctrl->in(0)->as_MemBar();
1622     assert(membar->Opcode() == Op_MemBarRelease &&
1623            mem->is_Proj() && membar == mem->in(0), "");
1624     _igvn.hash_delete(fallthroughproj);
1625     _igvn.subsume_node(fallthroughproj, ctrl);
1626     _igvn.hash_delete(memproj_fallthrough);
1627     _igvn.subsume_node(memproj_fallthrough, mem);
1628     fallthroughproj = ctrl;
1629     memproj_fallthrough = mem;
1630     ctrl = membar->in(TypeFunc::Control);
1631     mem  = membar->in(TypeFunc::Memory);
1632   }
1633 
1634   _igvn.hash_delete(fallthroughproj);
1635   _igvn.subsume_node(fallthroughproj, ctrl);
1636   _igvn.hash_delete(memproj_fallthrough);


1921   _igvn.hash_delete(_fallthroughproj);
1922   _fallthroughproj->disconnect_inputs(NULL);
1923   region->init_req(1, slow_ctrl);
1924   // region inputs are now complete
1925   transform_later(region);
1926   _igvn.subsume_node(_fallthroughproj, region);
1927 
1928   Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
1929   mem_phi->init_req(1, memproj );
1930   mem_phi->init_req(2, mem);
1931   transform_later(mem_phi);
1932   _igvn.hash_delete(_memproj_fallthrough);
1933   _igvn.subsume_node(_memproj_fallthrough, mem_phi);
1934 }
1935 
1936 //------------------------------expand_macro_nodes----------------------
1937 //  Returns true if a failure occurred.
1938 bool PhaseMacroExpand::expand_macro_nodes() {
1939   if (C->macro_count() == 0)
1940     return false;
1941   // First, attempt to eliminate locks
1942   bool progress = true;
1943   while (progress) {
1944     progress = false;
1945     for (int i = C->macro_count(); i > 0; i--) {
1946       Node * n = C->macro_node(i-1);
1947       bool success = false;
1948       debug_only(int old_macro_count = C->macro_count(););
1949       if (n->is_AbstractLock()) {
1950         success = eliminate_locking_node(n->as_AbstractLock());
1951       } else if (n->Opcode() == Op_Opaque1 || n->Opcode() == Op_Opaque2) {
1952         _igvn.add_users_to_worklist(n);
1953         _igvn.hash_delete(n);
1954         _igvn.subsume_node(n, n->in(1));
1955         success = true;
1956       }
1957       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
1958       progress = progress || success;
1959     }
1960   }
1961   // Next, attempt to eliminate allocations
1962   progress = true;
1963   while (progress) {
1964     progress = false;
1965     for (int i = C->macro_count(); i > 0; i--) {
1966       Node * n = C->macro_node(i-1);
1967       bool success = false;
1968       debug_only(int old_macro_count = C->macro_count(););
1969       switch (n->class_id()) {
1970       case Node::Class_Allocate:
1971       case Node::Class_AllocateArray:
1972         success = eliminate_allocate_node(n->as_Allocate());
1973         break;
1974       case Node::Class_Lock:
1975       case Node::Class_Unlock:
1976         assert(!n->as_AbstractLock()->is_eliminated(), "sanity");
1977         break;
1978       default:






1979         assert(false, "unknown node type in macro list");
1980       }

1981       assert(success == (C->macro_count() < old_macro_count), "elimination reduces macro count");
1982       progress = progress || success;
1983     }
1984   }
1985   // Make sure expansion will not cause node limit to be exceeded.
1986   // Worst case is a macro node gets expanded into about 50 nodes.
1987   // Allow 50% more for optimization.
1988   if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
1989     return true;
1990 
1991   // expand "macro" nodes
1992   // nodes are removed from the macro list as they are processed
1993   while (C->macro_count() > 0) {
1994     int macro_count = C->macro_count();
1995     Node * n = C->macro_node(macro_count-1);
1996     assert(n->is_macro(), "only macro nodes expected here");
1997     if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
1998       // node is unreachable, so don't try to expand it
1999       C->remove_macro_node(n);
2000       continue;


src/share/vm/opto/macro.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File