< prev index next >

src/share/vm/opto/parse3.cpp

Print this page




  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 "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/universe.inline.hpp"
  29 #include "oops/objArrayKlass.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/memnode.hpp"
  32 #include "opto/parse.hpp"
  33 #include "opto/rootnode.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/subnode.hpp"
  36 #include "runtime/deoptimization.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 




  39 //=============================================================================
  40 // Helper methods for _get* and _put* bytecodes
  41 //=============================================================================
  42 bool Parse::static_field_ok_in_clinit(ciField *field, ciMethod *method) {
  43   // Could be the field_holder's <clinit> method, or <clinit> for a subklass.
  44   // Better to check now than to Deoptimize as soon as we execute
  45   assert( field->is_static(), "Only check if field is static");
  46   // is_being_initialized() is too generous.  It allows access to statics
  47   // by threads that are not running the <clinit> before the <clinit> finishes.
  48   // return field->holder()->is_being_initialized();
  49 
  50   // The following restriction is correct but conservative.
  51   // It is also desirable to allow compilation of methods called from <clinit>
  52   // but this generated code will need to be made safe for execution by
  53   // other threads, or the transition from interpreted to compiled code would
  54   // need to be guarded.
  55   ciInstanceKlass *field_holder = field->holder();
  56 
  57   bool access_OK = false;
  58   if (method->holder()->is_subclass_of(field_holder)) {


 179         return;
 180     } else {
 181       // final or stable non-static field
 182       // Treat final non-static fields of trusted classes (classes in
 183       // java.lang.invoke and sun.invoke packages and subpackages) as
 184       // compile time constants.
 185       if (obj->is_Con()) {
 186         const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
 187         ciObject* constant_oop = oop_ptr->const_oop();
 188         ciConstant constant = field->constant_value_of(constant_oop);
 189         if (FoldStableValues && field->is_stable() && constant.is_null_or_zero()) {
 190           // fall through to field load; the field is not yet initialized
 191         } else {
 192           if (push_constant(constant, true, false, stable_type))
 193             return;
 194         }
 195       }
 196     }
 197   }
 198 

 199   ciType* field_klass = field->type();
 200   bool is_vol = field->is_volatile();
 201 
 202   // Compute address and memory type.
 203   int offset = field->offset_in_bytes();
 204   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 205   Node *adr = basic_plus_adr(obj, obj, offset);
 206   BasicType bt = field->layout_type();
 207 
 208   // Build the resultant type of the load
 209   const Type *type;
 210 
 211   bool must_assert_null = false;
 212 
 213   if( bt == T_OBJECT ) {
 214     if (!field->type()->is_loaded()) {
 215       type = TypeInstPtr::BOTTOM;
 216       must_assert_null = true;
 217     } else if (field->is_constant() && field->is_static()) {
 218       // This can happen if the constant oop is non-perm.
 219       ciObject* con = field->constant_value().as_object();
 220       // Do not "join" in the previous type; it doesn't add value,
 221       // and may yield a vacuous result if the field is of interface type.
 222       type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
 223       assert(type != NULL, "field singleton type must be consistent");
 224     } else {
 225       type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 226     }
 227   } else {
 228     type = Type::get_const_basic_type(bt);
 229   }
 230   if (support_IRIW_for_not_multiple_copy_atomic_cpu && field->is_volatile()) {
 231     insert_mem_bar(Op_MemBarVolatile);   // StoreLoad barrier
 232   }
 233   // Build the load.
 234   //
 235   MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered;
 236   Node* ld = make_load(NULL, adr, type, bt, adr_type, mo, LoadNode::DependsOnlyOnTest, is_vol);
 237 







 238   // Adjust Java stack
 239   if (type2size[bt] == 1)
 240     push(ld);
 241   else
 242     push_pair(ld);
 243 
 244   if (must_assert_null) {
 245     // Do not take a trap here.  It's possible that the program
 246     // will never load the field's class, and will happily see
 247     // null values in this field forever.  Don't stumble into a
 248     // trap for such a program, or we might get a long series
 249     // of useless recompilations.  (Or, we might load a class
 250     // which should not be loaded.)  If we ever see a non-null
 251     // value, we will then trap and recompile.  (The trap will
 252     // not need to mention the class index, since the class will
 253     // already have been loaded if we ever see a non-null value.)
 254     // uncommon_trap(iter().get_field_signature_index());
 255 #ifndef PRODUCT
 256     if (PrintOpto && (Verbose || WizardMode)) {
 257       method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
 258     }
 259 #endif
 260     if (C->log() != NULL) {
 261       C->log()->elem("assert_null reason='field' klass='%d'",
 262                      C->log()->identify(field->type()));
 263     }
 264     // If there is going to be a trap, put it at the next bytecode:
 265     set_bci(iter().next_bci());
 266     null_assert(peek());
 267     set_bci(iter().cur_bci()); // put it back
 268   }
 269 
 270   // If reference is volatile, prevent following memory ops from
 271   // floating up past the volatile read.  Also prevents commoning
 272   // another volatile read.
 273   if (field->is_volatile()) {
 274     // Memory barrier includes bogus read of value to force load BEFORE membar
 275     insert_mem_bar(Op_MemBarAcquire, ld);


 276   }
 277 }
 278 
 279 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {

 280   bool is_vol = field->is_volatile();
 281   // If reference is volatile, prevent following memory ops from
 282   // floating down past the volatile write.  Also prevents commoning
 283   // another volatile read.
 284   if (is_vol)  insert_mem_bar(Op_MemBarRelease);


 285 
 286   // Compute address and memory type.
 287   int offset = field->offset_in_bytes();
 288   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 289   Node* adr = basic_plus_adr(obj, obj, offset);
 290   BasicType bt = field->layout_type();
 291   // Value to be stored
 292   Node* val = type2size[bt] == 1 ? pop() : pop_pair();
 293   // Round doubles before storing
 294   if (bt == T_DOUBLE)  val = dstore_rounding(val);
 295 
 296   // Conservatively release stores of object references.
 297   const MemNode::MemOrd mo =
 298     is_vol ?
 299     // Volatile fields need releasing stores.
 300     MemNode::release :
 301     // Non-volatile fields also need releasing stores if they hold an
 302     // object reference, because the object reference might point to
 303     // a freshly created object.
 304     StoreNode::release_if_reference(bt);
 305 
 306   // Store the value.
 307   Node* store;
 308   if (bt == T_OBJECT) {
 309     const TypeOopPtr* field_type;
 310     if (!field->type()->is_loaded()) {
 311       field_type = TypeInstPtr::BOTTOM;
 312     } else {
 313       field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
 314     }
 315     store = store_oop_to_object(control(), obj, adr, adr_type, val, field_type, bt, mo);
 316   } else {
 317     store = store_to_memory(control(), adr, val, bt, adr_type, mo, is_vol);
 318   }
 319 
 320   // If reference is volatile, prevent following volatiles ops from
 321   // floating up before the volatile write.
 322   if (is_vol) {
 323     // If not multiple copy atomic, we do the MemBarVolatile before the load.
 324     if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
 325       insert_mem_bar(Op_MemBarVolatile); // Use fat membar

 326     }
 327     // Remember we wrote a volatile field.
 328     // For not multiple copy atomic cpu (ppc64) a barrier should be issued
 329     // in constructors which have such stores. See do_exits() in parse1.cpp.
 330     if (is_field) {
 331       set_wrote_volatile(true);
 332     }
 333   }
 334 
 335   // If the field is final, the rules of Java say we are in <init> or <clinit>.
 336   // Note the presence of writes to final non-static fields, so that we
 337   // can insert a memory barrier later on to keep the writes from floating
 338   // out of the constructor.
 339   // Any method can write a @Stable field; insert memory barriers after those also.
 340   if (is_field && (field->is_final() || field->is_stable())) {
 341     set_wrote_final(true);
 342     // Preserve allocation ptr to create precedent edge to it in membar
 343     // generated on exit from constructor.
 344     if (C->eliminate_boxing() &&
 345         adr_type->isa_oopptr() && adr_type->is_oopptr()->is_ptr_to_boxed_value() &&




  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 "compiler/compileLog.hpp"
  27 #include "interpreter/linkResolver.hpp"
  28 #include "memory/universe.inline.hpp"
  29 #include "oops/objArrayKlass.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/memnode.hpp"
  32 #include "opto/parse.hpp"
  33 #include "opto/rootnode.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/subnode.hpp"
  36 #include "runtime/deoptimization.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 
  39 #if INCLUDE_ALL_GCS
  40 #include "gc_implementation/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  41 #endif
  42 
  43 //=============================================================================
  44 // Helper methods for _get* and _put* bytecodes
  45 //=============================================================================
  46 bool Parse::static_field_ok_in_clinit(ciField *field, ciMethod *method) {
  47   // Could be the field_holder's <clinit> method, or <clinit> for a subklass.
  48   // Better to check now than to Deoptimize as soon as we execute
  49   assert( field->is_static(), "Only check if field is static");
  50   // is_being_initialized() is too generous.  It allows access to statics
  51   // by threads that are not running the <clinit> before the <clinit> finishes.
  52   // return field->holder()->is_being_initialized();
  53 
  54   // The following restriction is correct but conservative.
  55   // It is also desirable to allow compilation of methods called from <clinit>
  56   // but this generated code will need to be made safe for execution by
  57   // other threads, or the transition from interpreted to compiled code would
  58   // need to be guarded.
  59   ciInstanceKlass *field_holder = field->holder();
  60 
  61   bool access_OK = false;
  62   if (method->holder()->is_subclass_of(field_holder)) {


 183         return;
 184     } else {
 185       // final or stable non-static field
 186       // Treat final non-static fields of trusted classes (classes in
 187       // java.lang.invoke and sun.invoke packages and subpackages) as
 188       // compile time constants.
 189       if (obj->is_Con()) {
 190         const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
 191         ciObject* constant_oop = oop_ptr->const_oop();
 192         ciConstant constant = field->constant_value_of(constant_oop);
 193         if (FoldStableValues && field->is_stable() && constant.is_null_or_zero()) {
 194           // fall through to field load; the field is not yet initialized
 195         } else {
 196           if (push_constant(constant, true, false, stable_type))
 197             return;
 198         }
 199       }
 200     }
 201   }
 202 
 203   Node* leading_membar = NULL;
 204   ciType* field_klass = field->type();
 205   bool is_vol = field->is_volatile();
 206 
 207   // Compute address and memory type.
 208   int offset = field->offset_in_bytes();
 209   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 210   Node *adr = basic_plus_adr(obj, obj, offset);
 211   BasicType bt = field->layout_type();
 212 
 213   // Build the resultant type of the load
 214   const Type *type;
 215 
 216   bool must_assert_null = false;
 217 
 218   if( bt == T_OBJECT ) {
 219     if (!field->type()->is_loaded()) {
 220       type = TypeInstPtr::BOTTOM;
 221       must_assert_null = true;
 222     } else if (field->is_constant() && field->is_static()) {
 223       // This can happen if the constant oop is non-perm.
 224       ciObject* con = field->constant_value().as_object();
 225       // Do not "join" in the previous type; it doesn't add value,
 226       // and may yield a vacuous result if the field is of interface type.
 227       type = TypeOopPtr::make_from_constant(con)->isa_oopptr();
 228       assert(type != NULL, "field singleton type must be consistent");
 229     } else {
 230       type = TypeOopPtr::make_from_klass(field_klass->as_klass());
 231     }
 232   } else {
 233     type = Type::get_const_basic_type(bt);
 234   }
 235   if (support_IRIW_for_not_multiple_copy_atomic_cpu && field->is_volatile()) {
 236     leading_membar = insert_mem_bar(Op_MemBarVolatile);   // StoreLoad barrier
 237   }
 238   // Build the load.
 239   //
 240   MemNode::MemOrd mo = is_vol ? MemNode::acquire : MemNode::unordered;
 241   Node* ld = make_load(NULL, adr, type, bt, adr_type, mo, LoadNode::DependsOnlyOnTest, is_vol);
 242 
 243   Node* load = ld;
 244 #if INCLUDE_ALL_GCS
 245   if (UseShenandoahGC && (bt == T_OBJECT || bt == T_ARRAY)) {
 246     ld = ShenandoahBarrierSetC2::bsc2()->load_reference_barrier(this, ld);
 247   }
 248 #endif
 249 
 250   // Adjust Java stack
 251   if (type2size[bt] == 1)
 252     push(ld);
 253   else
 254     push_pair(ld);
 255 
 256   if (must_assert_null) {
 257     // Do not take a trap here.  It's possible that the program
 258     // will never load the field's class, and will happily see
 259     // null values in this field forever.  Don't stumble into a
 260     // trap for such a program, or we might get a long series
 261     // of useless recompilations.  (Or, we might load a class
 262     // which should not be loaded.)  If we ever see a non-null
 263     // value, we will then trap and recompile.  (The trap will
 264     // not need to mention the class index, since the class will
 265     // already have been loaded if we ever see a non-null value.)
 266     // uncommon_trap(iter().get_field_signature_index());
 267 #ifndef PRODUCT
 268     if (PrintOpto && (Verbose || WizardMode)) {
 269       method()->print_name(); tty->print_cr(" asserting nullness of field at bci: %d", bci());
 270     }
 271 #endif
 272     if (C->log() != NULL) {
 273       C->log()->elem("assert_null reason='field' klass='%d'",
 274                      C->log()->identify(field->type()));
 275     }
 276     // If there is going to be a trap, put it at the next bytecode:
 277     set_bci(iter().next_bci());
 278     null_assert(peek());
 279     set_bci(iter().cur_bci()); // put it back
 280   }
 281 
 282   // If reference is volatile, prevent following memory ops from
 283   // floating up past the volatile read.  Also prevents commoning
 284   // another volatile read.
 285   if (field->is_volatile()) {
 286     // Memory barrier includes bogus read of value to force load BEFORE membar
 287     assert(leading_membar == NULL || support_IRIW_for_not_multiple_copy_atomic_cpu, "no leading membar expected");
 288     Node* mb = insert_mem_bar(Op_MemBarAcquire, load);
 289     mb->as_MemBar()->set_trailing_load();
 290   }
 291 }
 292 
 293 void Parse::do_put_xxx(Node* obj, ciField* field, bool is_field) {
 294   Node* leading_membar = NULL;
 295   bool is_vol = field->is_volatile();
 296   // If reference is volatile, prevent following memory ops from
 297   // floating down past the volatile write.  Also prevents commoning
 298   // another volatile read.
 299   if (is_vol) {
 300     leading_membar = insert_mem_bar(Op_MemBarRelease);
 301   }
 302 
 303   // Compute address and memory type.
 304   int offset = field->offset_in_bytes();
 305   const TypePtr* adr_type = C->alias_type(field)->adr_type();
 306   Node* adr = basic_plus_adr(obj, obj, offset);
 307   BasicType bt = field->layout_type();
 308   // Value to be stored
 309   Node* val = type2size[bt] == 1 ? pop() : pop_pair();
 310   // Round doubles before storing
 311   if (bt == T_DOUBLE)  val = dstore_rounding(val);
 312 
 313   // Conservatively release stores of object references.
 314   const MemNode::MemOrd mo =
 315     is_vol ?
 316     // Volatile fields need releasing stores.
 317     MemNode::release :
 318     // Non-volatile fields also need releasing stores if they hold an
 319     // object reference, because the object reference might point to
 320     // a freshly created object.
 321     StoreNode::release_if_reference(bt);
 322 
 323   // Store the value.
 324   Node* store;
 325   if (bt == T_OBJECT) {
 326     const TypeOopPtr* field_type;
 327     if (!field->type()->is_loaded()) {
 328       field_type = TypeInstPtr::BOTTOM;
 329     } else {
 330       field_type = TypeOopPtr::make_from_klass(field->type()->as_klass());
 331     }
 332     store = store_oop_to_object(control(), obj, adr, adr_type, val, field_type, bt, mo);
 333   } else {
 334     store = store_to_memory(control(), adr, val, bt, adr_type, mo, is_vol);
 335   }
 336 
 337   // If reference is volatile, prevent following volatiles ops from
 338   // floating up before the volatile write.
 339   if (is_vol) {
 340     // If not multiple copy atomic, we do the MemBarVolatile before the load.
 341     if (!support_IRIW_for_not_multiple_copy_atomic_cpu) {
 342       Node* mb = insert_mem_bar(Op_MemBarVolatile, store); // Use fat membar
 343       MemBarNode::set_store_pair(leading_membar->as_MemBar(), mb->as_MemBar());
 344     }
 345     // Remember we wrote a volatile field.
 346     // For not multiple copy atomic cpu (ppc64) a barrier should be issued
 347     // in constructors which have such stores. See do_exits() in parse1.cpp.
 348     if (is_field) {
 349       set_wrote_volatile(true);
 350     }
 351   }
 352 
 353   // If the field is final, the rules of Java say we are in <init> or <clinit>.
 354   // Note the presence of writes to final non-static fields, so that we
 355   // can insert a memory barrier later on to keep the writes from floating
 356   // out of the constructor.
 357   // Any method can write a @Stable field; insert memory barriers after those also.
 358   if (is_field && (field->is_final() || field->is_stable())) {
 359     set_wrote_final(true);
 360     // Preserve allocation ptr to create precedent edge to it in membar
 361     // generated on exit from constructor.
 362     if (C->eliminate_boxing() &&
 363         adr_type->isa_oopptr() && adr_type->is_oopptr()->is_ptr_to_boxed_value() &&


< prev index next >