< prev index next >

src/hotspot/share/ci/ciField.cpp

Print this page




 201 }
 202 
 203 // Special copy constructor used to flatten value type fields by
 204 // copying the fields of the value type to a new holder klass.
 205 ciField::ciField(ciField* field, ciInstanceKlass* holder, int offset, bool is_final) {
 206   assert(field->holder()->is_valuetype(), "should only be used for value type field flattening");
 207   // Set the is_final flag
 208   jint final = is_final ? JVM_ACC_FINAL : ~JVM_ACC_FINAL;
 209   AccessFlags flags(field->flags().as_int() & final);
 210   _flags = ciFlags(flags);
 211   _holder = holder;
 212   _offset = offset;
 213   // Copy remaining fields
 214   _name = field->_name;
 215   _signature = field->_signature;
 216   _type = field->_type;
 217   _is_constant = field->_is_constant;
 218   _known_to_link_with_put = field->_known_to_link_with_put;
 219   _known_to_link_with_get = field->_known_to_link_with_get;
 220   _constant_value = field->_constant_value;


 221 }
 222 
 223 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
 224   if (holder == NULL)
 225     return false;
 226   if (holder->name() == ciSymbol::java_lang_System())
 227     // Never trust strangely unstable finals:  System.out, etc.
 228     return false;
 229   // Even if general trusting is disabled, trust system-built closures in these packages.
 230   if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
 231     return true;
 232   // Trust VM anonymous classes. They are private API (sun.misc.Unsafe) and can't be serialized,
 233   // so there is no hacking of finals going on with them.
 234   if (holder->is_anonymous())
 235     return true;
 236   // Trust final fields in all boxed classes
 237   if (holder->is_box_klass())
 238     return true;
 239   // Trust final fields in String
 240   if (holder->name() == ciSymbol::java_lang_String())
 241     return true;
 242   // Trust Atomic*FieldUpdaters: they are very important for performance, and make up one
 243   // more reason not to use Unsafe, if their final fields are trusted. See more in JDK-8140483.
 244   if (holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicIntegerFieldUpdater_Impl() ||
 245       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_CASUpdater() ||
 246       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_LockedUpdater() ||
 247       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicReferenceFieldUpdater_Impl()) {
 248     return true;
 249   }
 250   return TrustFinalNonStaticFields;
 251 }
 252 
 253 void ciField::initialize_from(fieldDescriptor* fd) {
 254   // Get the flags, offset, and canonical holder of the field.
 255   _flags = ciFlags(fd->access_flags());
 256   _offset = fd->offset();
 257   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());


 258 
 259   // Check to see if the field is constant.
 260   Klass* k = _holder->get_Klass();
 261   bool is_stable_field = FoldStableValues && is_stable();
 262   if ((is_final() && !has_initialized_final_update()) || is_stable_field) {
 263     if (is_static()) {
 264       // This field just may be constant.  The only case where it will
 265       // not be constant is when the field is a *special* static & final field
 266       // whose value may change.  The three examples are java.lang.System.in,
 267       // java.lang.System.out, and java.lang.System.err.
 268       assert(SystemDictionary::System_klass() != NULL, "Check once per vm");
 269       if (k == SystemDictionary::System_klass()) {
 270         // Check offsets for case 2: System.in, System.out, or System.err
 271         if( _offset == java_lang_System::in_offset_in_bytes()  ||
 272             _offset == java_lang_System::out_offset_in_bytes() ||
 273             _offset == java_lang_System::err_offset_in_bytes() ) {
 274           _is_constant = false;
 275           return;
 276         }
 277       }




 201 }
 202 
 203 // Special copy constructor used to flatten value type fields by
 204 // copying the fields of the value type to a new holder klass.
 205 ciField::ciField(ciField* field, ciInstanceKlass* holder, int offset, bool is_final) {
 206   assert(field->holder()->is_valuetype(), "should only be used for value type field flattening");
 207   // Set the is_final flag
 208   jint final = is_final ? JVM_ACC_FINAL : ~JVM_ACC_FINAL;
 209   AccessFlags flags(field->flags().as_int() & final);
 210   _flags = ciFlags(flags);
 211   _holder = holder;
 212   _offset = offset;
 213   // Copy remaining fields
 214   _name = field->_name;
 215   _signature = field->_signature;
 216   _type = field->_type;
 217   _is_constant = field->_is_constant;
 218   _known_to_link_with_put = field->_known_to_link_with_put;
 219   _known_to_link_with_get = field->_known_to_link_with_get;
 220   _constant_value = field->_constant_value;
 221   assert(!field->is_flattened(), "field must not be flattened");
 222   _is_flattened = false;
 223 }
 224 
 225 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
 226   if (holder == NULL)
 227     return false;
 228   if (holder->name() == ciSymbol::java_lang_System())
 229     // Never trust strangely unstable finals:  System.out, etc.
 230     return false;
 231   // Even if general trusting is disabled, trust system-built closures in these packages.
 232   if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
 233     return true;
 234   // Trust VM anonymous classes. They are private API (sun.misc.Unsafe) and can't be serialized,
 235   // so there is no hacking of finals going on with them.
 236   if (holder->is_anonymous())
 237     return true;
 238   // Trust final fields in all boxed classes
 239   if (holder->is_box_klass())
 240     return true;
 241   // Trust final fields in String
 242   if (holder->name() == ciSymbol::java_lang_String())
 243     return true;
 244   // Trust Atomic*FieldUpdaters: they are very important for performance, and make up one
 245   // more reason not to use Unsafe, if their final fields are trusted. See more in JDK-8140483.
 246   if (holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicIntegerFieldUpdater_Impl() ||
 247       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_CASUpdater() ||
 248       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicLongFieldUpdater_LockedUpdater() ||
 249       holder->name() == ciSymbol::java_util_concurrent_atomic_AtomicReferenceFieldUpdater_Impl()) {
 250     return true;
 251   }
 252   return TrustFinalNonStaticFields;
 253 }
 254 
 255 void ciField::initialize_from(fieldDescriptor* fd) {
 256   // Get the flags, offset, and canonical holder of the field.
 257   _flags = ciFlags(fd->access_flags());
 258   _offset = fd->offset();
 259   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());
 260   _is_flattened = fd->is_flatten();
 261   assert(fd->field_type() == T_VALUETYPE || !_is_flattened, "flattening is only supported for value type fields");
 262 
 263   // Check to see if the field is constant.
 264   Klass* k = _holder->get_Klass();
 265   bool is_stable_field = FoldStableValues && is_stable();
 266   if ((is_final() && !has_initialized_final_update()) || is_stable_field) {
 267     if (is_static()) {
 268       // This field just may be constant.  The only case where it will
 269       // not be constant is when the field is a *special* static & final field
 270       // whose value may change.  The three examples are java.lang.System.in,
 271       // java.lang.System.out, and java.lang.System.err.
 272       assert(SystemDictionary::System_klass() != NULL, "Check once per vm");
 273       if (k == SystemDictionary::System_klass()) {
 274         // Check offsets for case 2: System.in, System.out, or System.err
 275         if( _offset == java_lang_System::in_offset_in_bytes()  ||
 276             _offset == java_lang_System::out_offset_in_bytes() ||
 277             _offset == java_lang_System::err_offset_in_bytes() ) {
 278           _is_constant = false;
 279           return;
 280         }
 281       }


< prev index next >