src/share/vm/ci/ciField.cpp

Print this page




 160   _name = env->get_symbol(fd->name());
 161   _signature = env->get_symbol(fd->signature());
 162 
 163   BasicType field_type = fd->field_type();
 164 
 165   // If the field is a pointer type, get the klass of the
 166   // field.
 167   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 168     _type = NULL;  // must call compute_type on first access
 169   } else {
 170     _type = ciType::make(field_type);
 171   }
 172 
 173   initialize_from(fd);
 174 
 175   // Either (a) it is marked shared, or else (b) we are done bootstrapping.
 176   assert(is_shared() || ciObjectFactory::is_initialized(),
 177          "bootstrap classes must not create & cache unshared fields");
 178 }
 179 
 180 static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
 181   if (holder == NULL)
 182     return false;
 183   if (holder->name() == ciSymbol::java_lang_System())
 184     // Never trust strangely unstable finals:  System.out, etc.
 185     return false;
 186   // Even if general trusting is disabled, trust system-built closures in these packages.
 187   if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
 188     return true;
 189   // Trust VM anonymous classes. They are private API (sun.misc.Unsafe) and can't be serialized,
 190   // so there is no hacking of finals going on with them.
 191   if (holder->is_anonymous())
 192     return true;




 193   return TrustFinalNonStaticFields;
 194 }
 195 
 196 void ciField::initialize_from(fieldDescriptor* fd) {
 197   // Get the flags, offset, and canonical holder of the field.
 198   _flags = ciFlags(fd->access_flags());
 199   _offset = fd->offset();
 200   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());
 201 
 202   // Check to see if the field is constant.
 203   bool is_final = this->is_final();
 204   bool is_stable = FoldStableValues && this->is_stable();
 205   if (_holder->is_initialized() && (is_final || is_stable)) {
 206     if (!this->is_static()) {
 207       // A field can be constant if it's a final static field or if
 208       // it's a final non-static field of a trusted class (classes in
 209       // java.lang.invoke and sun.invoke packages and subpackages).
 210       if (is_stable || trust_final_non_static_fields(_holder)) {
 211         _is_constant = true;
 212         return;




 160   _name = env->get_symbol(fd->name());
 161   _signature = env->get_symbol(fd->signature());
 162 
 163   BasicType field_type = fd->field_type();
 164 
 165   // If the field is a pointer type, get the klass of the
 166   // field.
 167   if (field_type == T_OBJECT || field_type == T_ARRAY) {
 168     _type = NULL;  // must call compute_type on first access
 169   } else {
 170     _type = ciType::make(field_type);
 171   }
 172 
 173   initialize_from(fd);
 174 
 175   // Either (a) it is marked shared, or else (b) we are done bootstrapping.
 176   assert(is_shared() || ciObjectFactory::is_initialized(),
 177          "bootstrap classes must not create & cache unshared fields");
 178 }
 179 
 180 bool trust_final_non_static_fields(ciInstanceKlass* holder) {
 181   if (holder == NULL)
 182     return false;
 183   if (holder->name() == ciSymbol::java_lang_System())
 184     // Never trust strangely unstable finals:  System.out, etc.
 185     return false;
 186   // Even if general trusting is disabled, trust system-built closures in these packages.
 187   if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke"))
 188     return true;
 189   // Trust VM anonymous classes. They are private API (sun.misc.Unsafe) and can't be serialized,
 190   // so there is no hacking of finals going on with them.
 191   if (holder->is_anonymous())
 192     return true;
 193   // Trust the non-serializable classes in java/util/concurrent/atomic
 194   if (UseNewCode && holder->is_in_package("java/util/concurrent/atomic")) {
 195     return !holder->is_subtype_of(CURRENT_ENV->Serializable_klass());
 196   }
 197   return TrustFinalNonStaticFields;
 198 }
 199 
 200 void ciField::initialize_from(fieldDescriptor* fd) {
 201   // Get the flags, offset, and canonical holder of the field.
 202   _flags = ciFlags(fd->access_flags());
 203   _offset = fd->offset();
 204   _holder = CURRENT_ENV->get_instance_klass(fd->field_holder());
 205 
 206   // Check to see if the field is constant.
 207   bool is_final = this->is_final();
 208   bool is_stable = FoldStableValues && this->is_stable();
 209   if (_holder->is_initialized() && (is_final || is_stable)) {
 210     if (!this->is_static()) {
 211       // A field can be constant if it's a final static field or if
 212       // it's a final non-static field of a trusted class (classes in
 213       // java.lang.invoke and sun.invoke packages and subpackages).
 214       if (is_stable || trust_final_non_static_fields(_holder)) {
 215         _is_constant = true;
 216         return;