< prev index next >

src/hotspot/share/opto/graphKit.cpp

Print this page




   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 "precompiled.hpp"
  26 #include "ci/ciUtilities.hpp"
  27 #include "compiler/compileLog.hpp"
  28 #include "gc/g1/g1BarrierSet.hpp"
  29 #include "gc/g1/g1CardTable.hpp"
  30 #include "gc/g1/heapRegion.hpp"
  31 #include "gc/shared/barrierSet.hpp"
  32 #include "gc/shared/cardTable.hpp"
  33 #include "gc/shared/cardTableBarrierSet.hpp"
  34 #include "gc/shared/collectedHeap.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "opto/addnode.hpp"
  38 #include "opto/castnode.hpp"
  39 #include "opto/convertnode.hpp"
  40 #include "opto/graphKit.hpp"
  41 #include "opto/idealKit.hpp"
  42 #include "opto/intrinsicnode.hpp"
  43 #include "opto/locknode.hpp"
  44 #include "opto/machnode.hpp"
  45 #include "opto/opaquenode.hpp"
  46 #include "opto/parse.hpp"
  47 #include "opto/rootnode.hpp"
  48 #include "opto/runtime.hpp"
  49 #include "runtime/deoptimization.hpp"
  50 #include "runtime/sharedRuntime.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc/g1/g1CardTable.hpp"
  53 #include "gc/g1/g1ThreadLocalData.hpp"
  54 #include "gc/g1/heapRegion.hpp"
  55 #endif // INCLUDE_ALL_GCS
  56 
  57 //----------------------------GraphKit-----------------------------------------
  58 // Main utility constructor.
  59 GraphKit::GraphKit(JVMState* jvms)
  60   : Phase(Phase::Parser),
  61     _env(C->env()),
  62     _gvn(*C->initial_gvn())
  63 {
  64   _exceptions = jvms->map()->next_exception();
  65   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);
  66   set_jvms(jvms);
  67 }
  68 
  69 // Private constructor for parser.
  70 GraphKit::GraphKit()
  71   : Phase(Phase::Parser),


1550   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1551     record_for_igvn(st);
1552 
1553   return st;
1554 }
1555 
1556 
1557 void GraphKit::pre_barrier(bool do_load,
1558                            Node* ctl,
1559                            Node* obj,
1560                            Node* adr,
1561                            uint  adr_idx,
1562                            Node* val,
1563                            const TypeOopPtr* val_type,
1564                            Node* pre_val,
1565                            BasicType bt) {
1566 
1567   BarrierSet* bs = BarrierSet::barrier_set();
1568   set_control(ctl);
1569   switch (bs->kind()) {


1570     case BarrierSet::G1BarrierSet:
1571       g1_write_barrier_pre(do_load, obj, adr, adr_idx, val, val_type, pre_val, bt);
1572       break;

1573 
1574     case BarrierSet::CardTableBarrierSet:
1575       break;
1576 
1577     default      :
1578       ShouldNotReachHere();
1579 
1580   }
1581 }
1582 
1583 bool GraphKit::can_move_pre_barrier() const {
1584   BarrierSet* bs = BarrierSet::barrier_set();
1585   switch (bs->kind()) {


1586     case BarrierSet::G1BarrierSet:
1587       return true; // Can move it if no safepoint

1588 
1589     case BarrierSet::CardTableBarrierSet:
1590       return true; // There is no pre-barrier
1591 
1592     default      :
1593       ShouldNotReachHere();
1594   }
1595   return false;
1596 }
1597 
1598 void GraphKit::post_barrier(Node* ctl,
1599                             Node* store,
1600                             Node* obj,
1601                             Node* adr,
1602                             uint  adr_idx,
1603                             Node* val,
1604                             BasicType bt,
1605                             bool use_precise) {
1606   BarrierSet* bs = BarrierSet::barrier_set();
1607   set_control(ctl);
1608   switch (bs->kind()) {

1609     case BarrierSet::G1BarrierSet:
1610       g1_write_barrier_post(store, obj, adr, adr_idx, val, bt, use_precise);
1611       break;

1612 
1613     case BarrierSet::CardTableBarrierSet:
1614       write_barrier_post(store, obj, adr, adr_idx, val, use_precise);
1615       break;
1616 
1617     default      :
1618       ShouldNotReachHere();
1619 
1620   }
1621 }
1622 
1623 Node* GraphKit::store_oop(Node* ctl,
1624                           Node* obj,
1625                           Node* adr,
1626                           const TypePtr* adr_type,
1627                           Node* val,
1628                           const TypeOopPtr* val_type,
1629                           BasicType bt,
1630                           bool use_precise,
1631                           MemNode::MemOrd mo,


3914     // no_ctrl, but that doesn't buy much latitude.
3915     Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, bt, adr_type);
3916     __ if_then(card_val, BoolTest::ne, zero);
3917   }
3918 
3919   // Smash zero into card
3920   if( !UseConcMarkSweepGC ) {
3921     __ store(__ ctrl(), card_adr, zero, bt, adr_type, MemNode::unordered);
3922   } else {
3923     // Specialized path for CM store barrier
3924     __ storeCM(__ ctrl(), card_adr, zero, oop_store, adr_idx, bt, adr_type);
3925   }
3926 
3927   if (UseCondCardMark) {
3928     __ end_if();
3929   }
3930 
3931   // Final sync IdealKit and GraphKit.
3932   final_sync(ideal);
3933 }



3934 /*
3935  * Determine if the G1 pre-barrier can be removed. The pre-barrier is
3936  * required by SATB to make sure all objects live at the start of the
3937  * marking are kept alive, all reference updates need to any previous
3938  * reference stored before writing.
3939  *
3940  * If the previous value is NULL there is no need to save the old value.
3941  * References that are NULL are filtered during runtime by the barrier
3942  * code to avoid unnecessary queuing.
3943  *
3944  * However in the case of newly allocated objects it might be possible to
3945  * prove that the reference about to be overwritten is NULL during compile
3946  * time and avoid adding the barrier code completely.
3947  *
3948  * The compiler needs to determine that the object in which a field is about
3949  * to be written is newly allocated, and that no prior store to the same field
3950  * has happened since the allocation.
3951  *
3952  * Returns true if the pre-barrier can be removed
3953  */


4346         } __ end_if();
4347       } __ end_if();
4348     } __ end_if();
4349   } else {
4350     // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks.
4351     // We don't need a barrier here if the destination is a newly allocated object
4352     // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden
4353     // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()).
4354     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");
4355     Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
4356     __ if_then(card_val, BoolTest::ne, young_card); {
4357       g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
4358     } __ end_if();
4359   }
4360 
4361   // Final sync IdealKit and GraphKit.
4362   final_sync(ideal);
4363 }
4364 #undef __
4365 

4366 
4367 Node* GraphKit::load_String_length(Node* ctrl, Node* str) {
4368   Node* len = load_array_length(load_String_value(ctrl, str));
4369   Node* coder = load_String_coder(ctrl, str);
4370   // Divide length by 2 if coder is UTF16
4371   return _gvn.transform(new RShiftINode(len, coder));
4372 }
4373 
4374 Node* GraphKit::load_String_value(Node* ctrl, Node* str) {
4375   int value_offset = java_lang_String::value_offset_in_bytes();
4376   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4377                                                      false, NULL, 0);
4378   const TypePtr* value_field_type = string_type->add_offset(value_offset);
4379   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,
4380                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS),
4381                                                   ciTypeArrayKlass::make(T_BYTE), true, 0);
4382   int value_field_idx = C->get_alias_index(value_field_type);
4383   Node* load = make_load(ctrl, basic_plus_adr(str, str, value_offset),
4384                          value_type, T_OBJECT, value_field_idx, MemNode::unordered);
4385   // String.value field is known to be @Stable.




   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 "precompiled.hpp"
  26 #include "ci/ciUtilities.hpp"
  27 #include "compiler/compileLog.hpp"



  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/cardTable.hpp"
  30 #include "gc/shared/cardTableBarrierSet.hpp"
  31 #include "gc/shared/collectedHeap.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "opto/addnode.hpp"
  35 #include "opto/castnode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/graphKit.hpp"
  38 #include "opto/idealKit.hpp"
  39 #include "opto/intrinsicnode.hpp"
  40 #include "opto/locknode.hpp"
  41 #include "opto/machnode.hpp"
  42 #include "opto/opaquenode.hpp"
  43 #include "opto/parse.hpp"
  44 #include "opto/rootnode.hpp"
  45 #include "opto/runtime.hpp"
  46 #include "runtime/deoptimization.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #if INCLUDE_G1GC
  49 #include "gc/g1/g1CardTable.hpp"
  50 #include "gc/g1/g1ThreadLocalData.hpp"
  51 #include "gc/g1/heapRegion.hpp"
  52 #endif // INCLUDE_ALL_GCS
  53 
  54 //----------------------------GraphKit-----------------------------------------
  55 // Main utility constructor.
  56 GraphKit::GraphKit(JVMState* jvms)
  57   : Phase(Phase::Parser),
  58     _env(C->env()),
  59     _gvn(*C->initial_gvn())
  60 {
  61   _exceptions = jvms->map()->next_exception();
  62   if (_exceptions != NULL)  jvms->map()->set_next_exception(NULL);
  63   set_jvms(jvms);
  64 }
  65 
  66 // Private constructor for parser.
  67 GraphKit::GraphKit()
  68   : Phase(Phase::Parser),


1547   if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1548     record_for_igvn(st);
1549 
1550   return st;
1551 }
1552 
1553 
1554 void GraphKit::pre_barrier(bool do_load,
1555                            Node* ctl,
1556                            Node* obj,
1557                            Node* adr,
1558                            uint  adr_idx,
1559                            Node* val,
1560                            const TypeOopPtr* val_type,
1561                            Node* pre_val,
1562                            BasicType bt) {
1563 
1564   BarrierSet* bs = BarrierSet::barrier_set();
1565   set_control(ctl);
1566   switch (bs->kind()) {
1567 
1568 #if INCLUDE_G1GC
1569     case BarrierSet::G1BarrierSet:
1570       g1_write_barrier_pre(do_load, obj, adr, adr_idx, val, val_type, pre_val, bt);
1571       break;
1572 #endif
1573 
1574     case BarrierSet::CardTableBarrierSet:
1575       break;
1576 
1577     default      :
1578       ShouldNotReachHere();
1579 
1580   }
1581 }
1582 
1583 bool GraphKit::can_move_pre_barrier() const {
1584   BarrierSet* bs = BarrierSet::barrier_set();
1585   switch (bs->kind()) {
1586 
1587 #if INCLUDE_G1GC
1588     case BarrierSet::G1BarrierSet:
1589       return true; // Can move it if no safepoint
1590 #endif
1591 
1592     case BarrierSet::CardTableBarrierSet:
1593       return true; // There is no pre-barrier
1594 
1595     default      :
1596       ShouldNotReachHere();
1597   }
1598   return false;
1599 }
1600 
1601 void GraphKit::post_barrier(Node* ctl,
1602                             Node* store,
1603                             Node* obj,
1604                             Node* adr,
1605                             uint  adr_idx,
1606                             Node* val,
1607                             BasicType bt,
1608                             bool use_precise) {
1609   BarrierSet* bs = BarrierSet::barrier_set();
1610   set_control(ctl);
1611   switch (bs->kind()) {
1612 #if INCLUDE_G1GC
1613     case BarrierSet::G1BarrierSet:
1614       g1_write_barrier_post(store, obj, adr, adr_idx, val, bt, use_precise);
1615       break;
1616 #endif
1617 
1618     case BarrierSet::CardTableBarrierSet:
1619       write_barrier_post(store, obj, adr, adr_idx, val, use_precise);
1620       break;
1621 
1622     default      :
1623       ShouldNotReachHere();
1624 
1625   }
1626 }
1627 
1628 Node* GraphKit::store_oop(Node* ctl,
1629                           Node* obj,
1630                           Node* adr,
1631                           const TypePtr* adr_type,
1632                           Node* val,
1633                           const TypeOopPtr* val_type,
1634                           BasicType bt,
1635                           bool use_precise,
1636                           MemNode::MemOrd mo,


3919     // no_ctrl, but that doesn't buy much latitude.
3920     Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, bt, adr_type);
3921     __ if_then(card_val, BoolTest::ne, zero);
3922   }
3923 
3924   // Smash zero into card
3925   if( !UseConcMarkSweepGC ) {
3926     __ store(__ ctrl(), card_adr, zero, bt, adr_type, MemNode::unordered);
3927   } else {
3928     // Specialized path for CM store barrier
3929     __ storeCM(__ ctrl(), card_adr, zero, oop_store, adr_idx, bt, adr_type);
3930   }
3931 
3932   if (UseCondCardMark) {
3933     __ end_if();
3934   }
3935 
3936   // Final sync IdealKit and GraphKit.
3937   final_sync(ideal);
3938 }
3939 
3940 #if INCLUDE_G1GC
3941 
3942 /*
3943  * Determine if the G1 pre-barrier can be removed. The pre-barrier is
3944  * required by SATB to make sure all objects live at the start of the
3945  * marking are kept alive, all reference updates need to any previous
3946  * reference stored before writing.
3947  *
3948  * If the previous value is NULL there is no need to save the old value.
3949  * References that are NULL are filtered during runtime by the barrier
3950  * code to avoid unnecessary queuing.
3951  *
3952  * However in the case of newly allocated objects it might be possible to
3953  * prove that the reference about to be overwritten is NULL during compile
3954  * time and avoid adding the barrier code completely.
3955  *
3956  * The compiler needs to determine that the object in which a field is about
3957  * to be written is newly allocated, and that no prior store to the same field
3958  * has happened since the allocation.
3959  *
3960  * Returns true if the pre-barrier can be removed
3961  */


4354         } __ end_if();
4355       } __ end_if();
4356     } __ end_if();
4357   } else {
4358     // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks.
4359     // We don't need a barrier here if the destination is a newly allocated object
4360     // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden
4361     // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()).
4362     assert(!use_ReduceInitialCardMarks(), "can only happen with card marking");
4363     Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
4364     __ if_then(card_val, BoolTest::ne, young_card); {
4365       g1_mark_card(ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf);
4366     } __ end_if();
4367   }
4368 
4369   // Final sync IdealKit and GraphKit.
4370   final_sync(ideal);
4371 }
4372 #undef __
4373 
4374 #endif // INCLUDE_G1GC
4375 
4376 Node* GraphKit::load_String_length(Node* ctrl, Node* str) {
4377   Node* len = load_array_length(load_String_value(ctrl, str));
4378   Node* coder = load_String_coder(ctrl, str);
4379   // Divide length by 2 if coder is UTF16
4380   return _gvn.transform(new RShiftINode(len, coder));
4381 }
4382 
4383 Node* GraphKit::load_String_value(Node* ctrl, Node* str) {
4384   int value_offset = java_lang_String::value_offset_in_bytes();
4385   const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(),
4386                                                      false, NULL, 0);
4387   const TypePtr* value_field_type = string_type->add_offset(value_offset);
4388   const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull,
4389                                                   TypeAry::make(TypeInt::BYTE, TypeInt::POS),
4390                                                   ciTypeArrayKlass::make(T_BYTE), true, 0);
4391   int value_field_idx = C->get_alias_index(value_field_type);
4392   Node* load = make_load(ctrl, basic_plus_adr(str, str, value_offset),
4393                          value_type, T_OBJECT, value_field_idx, MemNode::unordered);
4394   // String.value field is known to be @Stable.


< prev index next >