src/share/vm/ci/ciField.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8073191-work Sdiff src/share/vm/ci

src/share/vm/ci/ciField.cpp

Print this page




 181   _name = env->get_symbol(fd->name());
 182   _signature = env->get_symbol(fd->signature());
 183 
 184   BasicType field_type = fd->field_type();
 185 
 186   // If the field is a pointer type, get the klass of the
 187   // field.
 188   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 189     _type = NULL;  // must call compute_type on first access
 190   } else {
 191     _type = ciType::make(field_type);
 192   }
 193 
 194   initialize_from(fd);
 195 
 196   // Either (a) it is marked shared, or else (b) we are done bootstrapping.
 197   assert(is_shared() || ciObjectFactory::is_initialized(),
 198          "bootstrap classes must not create & cache unshared fields");
 199 }
 200 
 201 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
 202   if (holder == NULL)
 203     return false;
 204   if (holder->name() == ciSymbol::java_lang_System())
 205     // Never trust strangely unstable finals:  System.out, etc.
 206     return false;
 207   // Even if general trusting is disabled, trust system-built closures in these packages.
 208   if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
 209     return true;
 210   // Trust VM anonymous classes. They are private API (sun.misc.Unsafe) and can't be serialized,
 211   // so there is no hacking of finals going on with them.
 212   if (holder->is_anonymous())
 213     return true;
 214   // Trust final fields in all boxed classes
 215   if (holder->is_box_klass())
 216     return true;
 217   // Trust final fields in String
 218   if (holder->name() == ciSymbol::java_lang_String())
 219     return true;
 220   // Trust Atomic*FieldUpdaters: they are very important for performance, and make up one
 221   // more reason not to use Unsafe, if their final fields are trusted. See more in JDK-8140483.
 222   if (holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicIntegerFieldUpdater_Impl() ||
 223       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_CASUpdater() ||
 224       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_LockedUpdater() ||
 225       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicReferenceFieldUpdater_Impl()) {
 226     return true;
 227   }
 228   return TrustFinalNonStaticFields;
 229 }
 230 
 231 void ciField::initialize_from(fieldDescriptor* fd) {
 232   // Get the flags, offset, and canonical holder of the field.
 233   _flags = ciFlags(fd->access_flags());
 234   _offset = fd->offset();
 235   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());
 236 
 237   // Check to see if the field is constant.
 238   Klass* k = _holder->get_Klass();
 239   bool is_stable_field = FoldStableValues && is_stable();
 240   if (is_final() || is_stable_field) {
 241     if (is_static()) {
 242       // This field just may be constant.  The only case where it will
 243       // not be constant is when the field is a *special* static & final field
 244       // whose value may change.  The three examples are java.lang.System.in,
 245       // java.lang.System.out, and java.lang.System.err.
 246       assert(SystemDictionary::System_klass() != NULL, "Check once per vm");
 247       if (k == SystemDictionary::System_klass()) {
 248         // Check offsets for case 2: System.in, System.out, or System.err
 249         if( _offset == java_lang_System::in_offset_in_bytes()  ||
 250             _offset == java_lang_System::out_offset_in_bytes() ||
 251             _offset == java_lang_System::err_offset_in_bytes() ) {
 252           _is_constant = false;
 253           return;
 254         }
 255       }
 256       _is_constant = true;
 257     } else {
 258       // An instance field can be constant if it's a final static field or if
 259       // it's a final non-static field of a trusted class (classes in
 260       // java.lang.invoke and sun.invoke packages and subpackages).
 261       _is_constant = is_stable_field || trust_final_non_static_fields(_holder);
 262     }
 263   } else {
 264     // For CallSite objects treat the target field as a compile time constant.
 265     assert(SystemDictionary::CallSite_klass() != NULL, "should be already initialized");
 266     if (k == SystemDictionary::CallSite_klass() &&
 267         _offset == java_lang_invoke_CallSite::target_offset_in_bytes()) {

 268       _is_constant = true;
 269     } else {
 270       // Non-final & non-stable fields are not constants.
 271       _is_constant = false;
 272     }
 273   }
 274 }
 275 
 276 // ------------------------------------------------------------------
 277 // ciField::constant_value
 278 // Get the constant value of a this static field.
 279 ciConstant ciField::constant_value() {
 280   assert(is_static() && is_constant(), "illegal call to constant_value()");
 281   if (!_holder->is_initialized()) {
 282     return ciConstant(); // Not initialized yet
 283   }
 284   if (_constant_value.basic_type() == T_ILLEGAL) {
 285     // Static fields are placed in mirror objects.
 286     VM_ENTRY_MARK;
 287     ciInstance* mirror = CURRENT_ENV->get_instance(_holder->get_Klass()->java_mirror());
 288     _constant_value = mirror->field_value_impl(type()->basic_type(), offset());
 289   }
 290   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
 291     return ciConstant();
 292   }
 293   return _constant_value;


 324     } else if (type->is_instance_klass()) {
 325       type_is_also_shared = type->as_instance_klass()->is_shared();
 326     } else {
 327       // Currently there is no 'shared' query for array types.
 328       type_is_also_shared = !ciObjectFactory::is_initialized();
 329     }
 330     if (!type_is_also_shared)
 331       return type;              // Bummer.
 332   }
 333   _type = type;
 334   return type;
 335 }
 336 
 337 
 338 // ------------------------------------------------------------------
 339 // ciField::will_link
 340 //
 341 // Can a specific access to this field be made without causing
 342 // link errors?
 343 bool ciField::will_link(ciInstanceKlass* accessing_klass,

 344                         Bytecodes::Code bc) {
 345   VM_ENTRY_MARK;
 346   assert(bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic ||
 347          bc == Bytecodes::_getfield  || bc == Bytecodes::_putfield,
 348          "unexpected bytecode");
 349 
 350   if (_offset == -1) {
 351     // at creation we couldn't link to our holder so we need to
 352     // maintain that stance, otherwise there's no safe way to use this
 353     // ciField.
 354     return false;
 355   }
 356 
 357   // Check for static/nonstatic mismatch
 358   bool is_static = (bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic);
 359   if (is_static != this->is_static()) {
 360     return false;
 361   }
 362 
 363   // Get and put can have different accessibility rules
 364   bool is_put    = (bc == Bytecodes::_putfield  || bc == Bytecodes::_putstatic);
 365   if (is_put) {
 366     if (_known_to_link_with_put == accessing_klass) {
 367       return true;
 368     }
 369   } else {
 370     if (_known_to_link_with_get == accessing_klass) {
 371       return true;
 372     }
 373   }
 374 
 375   LinkInfo link_info(_holder->get_instanceKlass(),
 376                      _name->get_symbol(), _signature->get_symbol(),
 377                      accessing_klass->get_Klass());
 378   fieldDescriptor result;
 379   LinkResolver::resolve_field(result, link_info, bc, false, KILL_COMPILE_ON_FATAL_(false));
 380 
 381   // update the hit-cache, unless there is a problem with memory scoping:
 382   if (accessing_klass->is_shared() || !is_shared()) {
 383     if (is_put) {
 384       _known_to_link_with_put = accessing_klass;
 385     } else {
 386       _known_to_link_with_get = accessing_klass;
 387     }
 388   }
 389 
 390   return true;
 391 }
 392 
 393 // ------------------------------------------------------------------
 394 // ciField::print
 395 void ciField::print() {
 396   tty->print("<ciField name=");
 397   _holder->print_name();




 181   _name = env->get_symbol(fd->name());
 182   _signature = env->get_symbol(fd->signature());
 183 
 184   BasicType field_type = fd->field_type();
 185 
 186   // If the field is a pointer type, get the klass of the
 187   // field.
 188   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 189     _type = NULL;  // must call compute_type on first access
 190   } else {
 191     _type = ciType::make(field_type);
 192   }
 193 
 194   initialize_from(fd);
 195 
 196   // Either (a) it is marked shared, or else (b) we are done bootstrapping.
 197   assert(is_shared() || ciObjectFactory::is_initialized(),
 198          "bootstrap classes must not create & cache unshared fields");
 199 }
 200 






























 201 void ciField::initialize_from(fieldDescriptor* fd) {
 202   // Get the flags, offset, and canonical holder of the field.
 203   _flags = ciFlags(fd->access_flags());
 204   _offset = fd->offset();
 205   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());
 206 
 207   // Check to see if the field is constant.
 208   Klass* k = _holder->get_Klass();
 209   bool is_stable_field = FoldStableValues && is_stable();

























 210   assert(SystemDictionary::CallSite_klass() != NULL, "should be already initialized");
 211   if (is_stable_field ||
 212       (k == SystemDictionary::CallSite_klass() &&
 213        _offset == java_lang_invoke_CallSite::target_offset_in_bytes())) {
 214     _is_constant = true;
 215   } else {

 216     _is_constant = false;
 217   }

 218 }
 219 
 220 // ------------------------------------------------------------------
 221 // ciField::constant_value
 222 // Get the constant value of a this static field.
 223 ciConstant ciField::constant_value() {
 224   assert(is_static() && is_constant(), "illegal call to constant_value()");
 225   if (!_holder->is_initialized()) {
 226     return ciConstant(); // Not initialized yet
 227   }
 228   if (_constant_value.basic_type() == T_ILLEGAL) {
 229     // Static fields are placed in mirror objects.
 230     VM_ENTRY_MARK;
 231     ciInstance* mirror = CURRENT_ENV->get_instance(_holder->get_Klass()->java_mirror());
 232     _constant_value = mirror->field_value_impl(type()->basic_type(), offset());
 233   }
 234   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
 235     return ciConstant();
 236   }
 237   return _constant_value;


 268     } else if (type->is_instance_klass()) {
 269       type_is_also_shared = type->as_instance_klass()->is_shared();
 270     } else {
 271       // Currently there is no 'shared' query for array types.
 272       type_is_also_shared = !ciObjectFactory::is_initialized();
 273     }
 274     if (!type_is_also_shared)
 275       return type;              // Bummer.
 276   }
 277   _type = type;
 278   return type;
 279 }
 280 
 281 
 282 // ------------------------------------------------------------------
 283 // ciField::will_link
 284 //
 285 // Can a specific access to this field be made without causing
 286 // link errors?
 287 bool ciField::will_link(ciInstanceKlass* accessing_klass,
 288                         ciMethod* accessing_method,
 289                         Bytecodes::Code bc) {
 290   VM_ENTRY_MARK;
 291   assert(bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic ||
 292          bc == Bytecodes::_getfield  || bc == Bytecodes::_putfield,
 293          "unexpected bytecode");
 294 
 295   if (_offset == -1) {
 296     // at creation we couldn't link to our holder so we need to
 297     // maintain that stance, otherwise there's no safe way to use this
 298     // ciField.
 299     return false;
 300   }
 301 
 302   // Check for static/nonstatic mismatch
 303   bool is_static = (bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic);
 304   if (is_static != this->is_static()) {
 305     return false;
 306   }
 307 
 308   // Get and put can have different accessibility rules
 309   bool is_put    = (bc == Bytecodes::_putfield  || bc == Bytecodes::_putstatic);
 310   if (is_put) {
 311     if (_known_to_link_with_put == accessing_klass) {
 312       return true;
 313     }
 314   } else {
 315     if (_known_to_link_with_get == accessing_klass) {
 316       return true;
 317     }
 318   }
 319 
 320   LinkInfo link_info(_holder->get_instanceKlass(),
 321                      _name->get_symbol(), _signature->get_symbol(),
 322                      accessing_klass->get_Klass(), accessing_method->get_Method());
 323   fieldDescriptor result;
 324   LinkResolver::resolve_field(result, link_info, bc, false, KILL_COMPILE_ON_FATAL_(false));
 325 
 326   // update the hit-cache, unless there is a problem with memory scoping:
 327   if (accessing_klass->is_shared() || !is_shared()) {
 328     if (is_put) {
 329       _known_to_link_with_put = accessing_klass;
 330     } else {
 331       _known_to_link_with_get = accessing_klass;
 332     }
 333   }
 334 
 335   return true;
 336 }
 337 
 338 // ------------------------------------------------------------------
 339 // ciField::print
 340 void ciField::print() {
 341   tty->print("<ciField name=");
 342   _holder->print_name();


src/share/vm/ci/ciField.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File