< prev index next >

src/hotspot/share/ci/ciField.cpp

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciField.hpp"
 26 #include "ci/ciInstanceKlass.hpp"
 27 #include "ci/ciSymbols.hpp"
 28 #include "ci/ciUtilities.inline.hpp"
 29 #include "classfile/javaClasses.hpp"
 30 #include "classfile/vmClasses.hpp"

 31 #include "gc/shared/collectedHeap.inline.hpp"
 32 #include "interpreter/linkResolver.hpp"
 33 #include "oops/klass.inline.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "runtime/fieldDescriptor.inline.hpp"
 36 #include "runtime/handles.inline.hpp"
 37 #include "runtime/reflection.hpp"
 38 
 39 // ciField
 40 //
 41 // This class represents the result of a field lookup in the VM.
 42 // The lookup may not succeed, in which case the information in
 43 // the ciField will be incomplete.
 44 
 45 // The ciObjectFactory cannot create circular data structures in one query.
 46 // To avoid vicious circularities, we initialize ciField::_type to null
 47 // for reference types and derive it lazily from the ciField::_signature.
 48 // Primitive types are eagerly initialized, and basic layout queries
 49 // can succeed without initialization, using only the BasicType of the field.
 50 

278     }
279   }
280 }
281 
282 // ------------------------------------------------------------------
283 // ciField::constant_value
284 // Get the constant value of a this static field.
285 ciConstant ciField::constant_value() {
286   assert(is_static() && is_constant(), "illegal call to constant_value()");
287   if (!_holder->is_initialized()) {
288     return ciConstant(); // Not initialized yet
289   }
290   if (_constant_value.basic_type() == T_ILLEGAL) {
291     // Static fields are placed in mirror objects.
292     ciInstance* mirror = _holder->java_mirror();
293     _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
294   }
295   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
296     return ciConstant();
297   }



298   return _constant_value;
299 }
300 
301 // ------------------------------------------------------------------
302 // ciField::constant_value_of
303 // Get the constant value of non-static final field in the given object.
304 ciConstant ciField::constant_value_of(ciObject* object) {
305   assert(!is_static() && is_constant(), "only if field is non-static constant");
306   assert(object->is_instance(), "must be instance");
307   ciConstant field_value = object->as_instance()->field_value(this);
308   if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
309     return ciConstant();
310   }



311   return field_value;
312 }
313 
314 // ------------------------------------------------------------------
315 // ciField::compute_type
316 //
317 // Lazily compute the type, if it is an instance klass.
318 ciType* ciField::compute_type() {
319   GUARDED_VM_ENTRY(return compute_type_impl();)
320 }
321 
322 ciType* ciField::compute_type_impl() {
323   ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
324   if (!type->is_primitive_type() && is_shared()) {
325     // We must not cache a pointer to an unshared type, in a shared field.
326     bool type_is_also_shared = false;
327     if (type->is_type_array_klass()) {
328       type_is_also_shared = true;  // int[] etc. are explicitly bootstrapped
329     } else if (type->is_instance_klass()) {
330       type_is_also_shared = type->as_instance_klass()->is_shared();

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciField.hpp"
 26 #include "ci/ciInstanceKlass.hpp"
 27 #include "ci/ciSymbols.hpp"
 28 #include "ci/ciUtilities.inline.hpp"
 29 #include "classfile/javaClasses.hpp"
 30 #include "classfile/vmClasses.hpp"
 31 #include "code/aotCodeCache.hpp"
 32 #include "gc/shared/collectedHeap.inline.hpp"
 33 #include "interpreter/linkResolver.hpp"
 34 #include "oops/klass.inline.hpp"
 35 #include "oops/oop.inline.hpp"
 36 #include "runtime/fieldDescriptor.inline.hpp"
 37 #include "runtime/handles.inline.hpp"
 38 #include "runtime/reflection.hpp"
 39 
 40 // ciField
 41 //
 42 // This class represents the result of a field lookup in the VM.
 43 // The lookup may not succeed, in which case the information in
 44 // the ciField will be incomplete.
 45 
 46 // The ciObjectFactory cannot create circular data structures in one query.
 47 // To avoid vicious circularities, we initialize ciField::_type to null
 48 // for reference types and derive it lazily from the ciField::_signature.
 49 // Primitive types are eagerly initialized, and basic layout queries
 50 // can succeed without initialization, using only the BasicType of the field.
 51 

279     }
280   }
281 }
282 
283 // ------------------------------------------------------------------
284 // ciField::constant_value
285 // Get the constant value of a this static field.
286 ciConstant ciField::constant_value() {
287   assert(is_static() && is_constant(), "illegal call to constant_value()");
288   if (!_holder->is_initialized()) {
289     return ciConstant(); // Not initialized yet
290   }
291   if (_constant_value.basic_type() == T_ILLEGAL) {
292     // Static fields are placed in mirror objects.
293     ciInstance* mirror = _holder->java_mirror();
294     _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
295   }
296   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
297     return ciConstant();
298   }
299   if (!AOTCodeCache::allow_const_field(_constant_value)) {
300     return ciConstant();
301   }
302   return _constant_value;
303 }
304 
305 // ------------------------------------------------------------------
306 // ciField::constant_value_of
307 // Get the constant value of non-static final field in the given object.
308 ciConstant ciField::constant_value_of(ciObject* object) {
309   assert(!is_static() && is_constant(), "only if field is non-static constant");
310   assert(object->is_instance(), "must be instance");
311   ciConstant field_value = object->as_instance()->field_value(this);
312   if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
313     return ciConstant();
314   }
315   if (!AOTCodeCache::allow_const_field(field_value)) {
316     return ciConstant();
317   }
318   return field_value;
319 }
320 
321 // ------------------------------------------------------------------
322 // ciField::compute_type
323 //
324 // Lazily compute the type, if it is an instance klass.
325 ciType* ciField::compute_type() {
326   GUARDED_VM_ENTRY(return compute_type_impl();)
327 }
328 
329 ciType* ciField::compute_type_impl() {
330   ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
331   if (!type->is_primitive_type() && is_shared()) {
332     // We must not cache a pointer to an unshared type, in a shared field.
333     bool type_is_also_shared = false;
334     if (type->is_type_array_klass()) {
335       type_is_also_shared = true;  // int[] etc. are explicitly bootstrapped
336     } else if (type->is_instance_klass()) {
337       type_is_also_shared = type->as_instance_klass()->is_shared();
< prev index next >