src/share/vm/c1/c1_GraphBuilder.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6756768 Sdiff src/share/vm/c1

src/share/vm/c1/c1_GraphBuilder.cpp

Print this page




 659   , _jsr_xhandlers(NULL)
 660   , _caller_stack_size(-1)
 661   , _continuation(NULL)
 662   , _continuation_state(NULL)
 663   , _num_returns(0)
 664   , _cleanup_block(NULL)
 665   , _cleanup_return_prev(NULL)
 666   , _cleanup_state(NULL)
 667 {
 668   if (parent != NULL) {
 669     _max_inline_size = (intx) ((float) NestedInliningSizeRatio * (float) parent->max_inline_size() / 100.0f);
 670   } else {
 671     _max_inline_size = MaxInlineSize;
 672   }
 673   if (_max_inline_size < MaxTrivialSize) {
 674     _max_inline_size = MaxTrivialSize;
 675   }
 676 }
 677 
 678 
 679 void GraphBuilder::kill_field(ciField* field) {
 680   if (UseLocalValueNumbering) {
 681     vmap()->kill_field(field);
 682   }
 683 }
 684 
 685 
 686 void GraphBuilder::kill_array(Value value) {
 687   if (UseLocalValueNumbering) {
 688     vmap()->kill_array(value->type());
 689   }
 690   _memory->store_value(value);
 691 }
 692 
 693 
 694 void GraphBuilder::kill_all() {
 695   if (UseLocalValueNumbering) {
 696     vmap()->kill_all();
 697   }
 698   _memory->kill();
 699 }
 700 
 701 
 702 BlockBegin* GraphBuilder::ScopeData::block_at(int bci) {
 703   if (parsing_jsr()) {
 704     // It is necessary to clone all blocks associated with a
 705     // subroutine, including those for exception handlers in the scope
 706     // of the method containing the jsr (because those exception
 707     // handlers may contain ret instructions in some cases).
 708     BlockBegin* block = bci2block()->at(bci);
 709     if (block != NULL && block == parent()->bci2block()->at(bci)) {
 710       BlockBegin* new_block = new BlockBegin(block->bci());
 711 #ifndef PRODUCT
 712       if (PrintInitialBlockList) {
 713         tty->print_cr("CFG: cloned block %d (bci %d) as block %d for jsr",


 970   if (CSEArrayLength ||
 971       (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
 972       (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
 973     length = append(new ArrayLength(array, lock_stack()));
 974   }
 975   push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, lock_stack())));
 976 }
 977 
 978 
 979 void GraphBuilder::store_indexed(BasicType type) {
 980   Value value = pop(as_ValueType(type));
 981   Value index = ipop();
 982   Value array = apop();
 983   Value length = NULL;
 984   if (CSEArrayLength ||
 985       (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
 986       (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
 987     length = append(new ArrayLength(array, lock_stack()));
 988   }
 989   StoreIndexed* result = new StoreIndexed(array, index, length, type, value, lock_stack());
 990   kill_array(value); // invalidate all CSEs that are memory accesses of the same type
 991   append(result);

 992 }
 993 
 994 
 995 void GraphBuilder::stack_op(Bytecodes::Code code) {
 996   switch (code) {
 997     case Bytecodes::_pop:
 998       { state()->raw_pop();
 999       }
1000       break;
1001     case Bytecodes::_pop2:
1002       { state()->raw_pop();
1003         state()->raw_pop();
1004       }
1005       break;
1006     case Bytecodes::_dup:
1007       { Value w = state()->raw_pop();
1008         state()->raw_push(w);
1009         state()->raw_push(w);
1010       }
1011       break;


1461             constant =  new Constant(as_ValueType(field_val));
1462           }
1463           break;
1464 
1465         default:
1466           constant = new Constant(as_ValueType(field_val));
1467         }
1468       }
1469       if (constant != NULL) {
1470         push(type, append(constant));
1471         state_copy = NULL; // Not a potential deoptimization point (see set_state_before logic below)
1472       } else {
1473         push(type, append(new LoadField(append(obj), offset, field, true,
1474                                         lock_stack(), state_copy, is_loaded, is_initialized)));
1475       }
1476       break;
1477     }
1478     case Bytecodes::_putstatic:
1479       { Value val = pop(type);
1480         append(new StoreField(append(obj), offset, field, val, true, lock_stack(), state_copy, is_loaded, is_initialized));
1481         if (UseLocalValueNumbering) {
1482           vmap()->kill_field(field);   // invalidate all CSEs that are memory accesses
1483         }
1484       }
1485       break;
1486     case Bytecodes::_getfield :
1487       {
1488         LoadField* load = new LoadField(apop(), offset, field, false, lock_stack(), state_copy, is_loaded, true);
1489         Value replacement = is_loaded ? _memory->load(load) : load;
1490         if (replacement != load) {
1491           assert(replacement->bci() != -99 || replacement->as_Phi() || replacement->as_Local(),
1492                  "should already by linked");
1493           push(type, replacement);
1494         } else {
1495           push(type, append(load));
1496         }
1497         break;
1498       }
1499 
1500     case Bytecodes::_putfield :
1501       { Value val = pop(type);
1502         StoreField* store = new StoreField(apop(), offset, field, val, false, lock_stack(), state_copy, is_loaded, true);
1503         if (is_loaded) store = _memory->store(store);
1504         if (store != NULL) {
1505           append(store);
1506           kill_field(field);   // invalidate all CSEs that are accesses of this field
1507         }
1508       }
1509       break;
1510     default                   :
1511       ShouldNotReachHere();
1512       break;
1513   }
1514 }
1515 
1516 
1517 Dependencies* GraphBuilder::dependency_recorder() const {
1518   assert(DeoptC1, "need debug information");
1519   compilation()->set_needs_debug_information(true);
1520   return compilation()->dependency_recorder();
1521 }
1522 
1523 
1524 void GraphBuilder::invoke(Bytecodes::Code code) {
1525   bool will_link;
1526   ciMethod* target = stream()->get_method(will_link);


1883   return fp_value;
1884 }
1885 
1886 
1887 Instruction* GraphBuilder::append_with_bci(Instruction* instr, int bci) {
1888   Canonicalizer canon(instr, bci);
1889   Instruction* i1 = canon.canonical();
1890   if (i1->bci() != -99) {
1891     // Canonicalizer returned an instruction which was already
1892     // appended so simply return it.
1893     return i1;
1894   } else if (UseLocalValueNumbering) {
1895     // Lookup the instruction in the ValueMap and add it to the map if
1896     // it's not found.
1897     Instruction* i2 = vmap()->find_insert(i1);
1898     if (i2 != i1) {
1899       // found an entry in the value map, so just return it.
1900       assert(i2->bci() != -1, "should already be linked");
1901       return i2;
1902     }


1903   }
1904 
1905   if (i1->as_Phi() == NULL && i1->as_Local() == NULL) {
1906     // i1 was not eliminated => append it
1907     assert(i1->next() == NULL, "shouldn't already be linked");
1908     _last = _last->set_next(i1, canon.bci());
1909     if (++_instruction_count >= InstructionCountCutoff
1910         && !bailed_out()) {
1911       // set the bailout state but complete normal processing.  We
1912       // might do a little more work before noticing the bailout so we
1913       // want processing to continue normally until it's noticed.
1914       bailout("Method and/or inlining is too large");
1915     }
1916 
1917 #ifndef PRODUCT
1918     if (PrintIRDuringConstruction) {
1919       InstructionPrinter ip;
1920       ip.print_line(i1);
1921       if (Verbose) {
1922         state()->print();
1923       }
1924     }
1925 #endif
1926     assert(_last == i1, "adjust code below");
1927     StateSplit* s = i1->as_StateSplit();
1928     if (s != NULL && i1->as_BlockEnd() == NULL) {
1929       // Continue CSE across certain intrinsics
1930       Intrinsic* intrinsic = s->as_Intrinsic();
1931       if (UseLocalValueNumbering) {
1932         if (intrinsic == NULL || !intrinsic->preserves_state()) {
1933           vmap()->kill_all();      // for now, hopefully we need this only for calls eventually
1934           }
1935       }
1936       if (EliminateFieldAccess) {

1937         if (s->as_Invoke() != NULL || (intrinsic && !intrinsic->preserves_state())) {
1938           _memory->kill();
1939         }
1940       }
1941       s->set_state(state()->copy());
1942     }
1943     // set up exception handlers for this instruction if necessary
1944     if (i1->can_trap()) {
1945       assert(exception_state() != NULL || !has_handler(), "must have setup exception state");
1946       i1->set_exception_handlers(handle_exception(bci));
1947     }
1948   }
1949   return i1;
1950 }
1951 
1952 
1953 Instruction* GraphBuilder::append(Instruction* instr) {
1954   assert(instr->as_StateSplit() == NULL || instr->as_BlockEnd() != NULL, "wrong append used");
1955   return append_with_bci(instr, bci());
1956 }




 659   , _jsr_xhandlers(NULL)
 660   , _caller_stack_size(-1)
 661   , _continuation(NULL)
 662   , _continuation_state(NULL)
 663   , _num_returns(0)
 664   , _cleanup_block(NULL)
 665   , _cleanup_return_prev(NULL)
 666   , _cleanup_state(NULL)
 667 {
 668   if (parent != NULL) {
 669     _max_inline_size = (intx) ((float) NestedInliningSizeRatio * (float) parent->max_inline_size() / 100.0f);
 670   } else {
 671     _max_inline_size = MaxInlineSize;
 672   }
 673   if (_max_inline_size < MaxTrivialSize) {
 674     _max_inline_size = MaxTrivialSize;
 675   }
 676 }
 677 
 678 















 679 void GraphBuilder::kill_all() {
 680   if (UseLocalValueNumbering) {
 681     vmap()->kill_all();
 682   }
 683   _memory->kill();
 684 }
 685 
 686 
 687 BlockBegin* GraphBuilder::ScopeData::block_at(int bci) {
 688   if (parsing_jsr()) {
 689     // It is necessary to clone all blocks associated with a
 690     // subroutine, including those for exception handlers in the scope
 691     // of the method containing the jsr (because those exception
 692     // handlers may contain ret instructions in some cases).
 693     BlockBegin* block = bci2block()->at(bci);
 694     if (block != NULL && block == parent()->bci2block()->at(bci)) {
 695       BlockBegin* new_block = new BlockBegin(block->bci());
 696 #ifndef PRODUCT
 697       if (PrintInitialBlockList) {
 698         tty->print_cr("CFG: cloned block %d (bci %d) as block %d for jsr",


 955   if (CSEArrayLength ||
 956       (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
 957       (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
 958     length = append(new ArrayLength(array, lock_stack()));
 959   }
 960   push(as_ValueType(type), append(new LoadIndexed(array, index, length, type, lock_stack())));
 961 }
 962 
 963 
 964 void GraphBuilder::store_indexed(BasicType type) {
 965   Value value = pop(as_ValueType(type));
 966   Value index = ipop();
 967   Value array = apop();
 968   Value length = NULL;
 969   if (CSEArrayLength ||
 970       (array->as_AccessField() && array->as_AccessField()->field()->is_constant()) ||
 971       (array->as_NewArray() && array->as_NewArray()->length() && array->as_NewArray()->length()->type()->is_constant())) {
 972     length = append(new ArrayLength(array, lock_stack()));
 973   }
 974   StoreIndexed* result = new StoreIndexed(array, index, length, type, value, lock_stack());

 975   append(result);
 976   _memory->store_value(value);
 977 }
 978 
 979 
 980 void GraphBuilder::stack_op(Bytecodes::Code code) {
 981   switch (code) {
 982     case Bytecodes::_pop:
 983       { state()->raw_pop();
 984       }
 985       break;
 986     case Bytecodes::_pop2:
 987       { state()->raw_pop();
 988         state()->raw_pop();
 989       }
 990       break;
 991     case Bytecodes::_dup:
 992       { Value w = state()->raw_pop();
 993         state()->raw_push(w);
 994         state()->raw_push(w);
 995       }
 996       break;


1446             constant =  new Constant(as_ValueType(field_val));
1447           }
1448           break;
1449 
1450         default:
1451           constant = new Constant(as_ValueType(field_val));
1452         }
1453       }
1454       if (constant != NULL) {
1455         push(type, append(constant));
1456         state_copy = NULL; // Not a potential deoptimization point (see set_state_before logic below)
1457       } else {
1458         push(type, append(new LoadField(append(obj), offset, field, true,
1459                                         lock_stack(), state_copy, is_loaded, is_initialized)));
1460       }
1461       break;
1462     }
1463     case Bytecodes::_putstatic:
1464       { Value val = pop(type);
1465         append(new StoreField(append(obj), offset, field, val, true, lock_stack(), state_copy, is_loaded, is_initialized));


1466       }

1467       break;
1468     case Bytecodes::_getfield :
1469       {
1470         LoadField* load = new LoadField(apop(), offset, field, false, lock_stack(), state_copy, is_loaded, true);
1471         Value replacement = is_loaded ? _memory->load(load) : load;
1472         if (replacement != load) {
1473           assert(replacement->bci() != -99 || replacement->as_Phi() || replacement->as_Local(),
1474                  "should already by linked");
1475           push(type, replacement);
1476         } else {
1477           push(type, append(load));
1478         }
1479         break;
1480       }
1481 
1482     case Bytecodes::_putfield :
1483       { Value val = pop(type);
1484         StoreField* store = new StoreField(apop(), offset, field, val, false, lock_stack(), state_copy, is_loaded, true);
1485         if (is_loaded) store = _memory->store(store);
1486         if (store != NULL) {
1487           append(store);

1488         }
1489       }
1490       break;
1491     default                   :
1492       ShouldNotReachHere();
1493       break;
1494   }
1495 }
1496 
1497 
1498 Dependencies* GraphBuilder::dependency_recorder() const {
1499   assert(DeoptC1, "need debug information");
1500   compilation()->set_needs_debug_information(true);
1501   return compilation()->dependency_recorder();
1502 }
1503 
1504 
1505 void GraphBuilder::invoke(Bytecodes::Code code) {
1506   bool will_link;
1507   ciMethod* target = stream()->get_method(will_link);


1864   return fp_value;
1865 }
1866 
1867 
1868 Instruction* GraphBuilder::append_with_bci(Instruction* instr, int bci) {
1869   Canonicalizer canon(instr, bci);
1870   Instruction* i1 = canon.canonical();
1871   if (i1->bci() != -99) {
1872     // Canonicalizer returned an instruction which was already
1873     // appended so simply return it.
1874     return i1;
1875   } else if (UseLocalValueNumbering) {
1876     // Lookup the instruction in the ValueMap and add it to the map if
1877     // it's not found.
1878     Instruction* i2 = vmap()->find_insert(i1);
1879     if (i2 != i1) {
1880       // found an entry in the value map, so just return it.
1881       assert(i2->bci() != -1, "should already be linked");
1882       return i2;
1883     }
1884     ValueNumberingEffects vne(vmap());
1885     i1->visit(&vne);
1886   }
1887 
1888   if (i1->as_Phi() == NULL && i1->as_Local() == NULL) {
1889     // i1 was not eliminated => append it
1890     assert(i1->next() == NULL, "shouldn't already be linked");
1891     _last = _last->set_next(i1, canon.bci());
1892     if (++_instruction_count >= InstructionCountCutoff
1893         && !bailed_out()) {
1894       // set the bailout state but complete normal processing.  We
1895       // might do a little more work before noticing the bailout so we
1896       // want processing to continue normally until it's noticed.
1897       bailout("Method and/or inlining is too large");
1898     }
1899 
1900 #ifndef PRODUCT
1901     if (PrintIRDuringConstruction) {
1902       InstructionPrinter ip;
1903       ip.print_line(i1);
1904       if (Verbose) {
1905         state()->print();
1906       }
1907     }
1908 #endif
1909     assert(_last == i1, "adjust code below");
1910     StateSplit* s = i1->as_StateSplit();
1911     if (s != NULL && i1->as_BlockEnd() == NULL) {







1912       if (EliminateFieldAccess) {
1913         Intrinsic* intrinsic = s->as_Intrinsic();
1914         if (s->as_Invoke() != NULL || (intrinsic && !intrinsic->preserves_state())) {
1915           _memory->kill();
1916         }
1917       }
1918       s->set_state(state()->copy());
1919     }
1920     // set up exception handlers for this instruction if necessary
1921     if (i1->can_trap()) {
1922       assert(exception_state() != NULL || !has_handler(), "must have setup exception state");
1923       i1->set_exception_handlers(handle_exception(bci));
1924     }
1925   }
1926   return i1;
1927 }
1928 
1929 
1930 Instruction* GraphBuilder::append(Instruction* instr) {
1931   assert(instr->as_StateSplit() == NULL || instr->as_BlockEnd() != NULL, "wrong append used");
1932   return append_with_bci(instr, bci());
1933 }


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