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