< prev index next >

src/share/vm/opto/parse3.cpp

Print this page




 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() &&




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


< prev index next >