< prev index next >

src/hotspot/share/ci/ciField.cpp

Print this page

 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 "precompiled.hpp"
 26 #include "ci/ciField.hpp"
 27 #include "ci/ciInstanceKlass.hpp"
 28 #include "ci/ciSymbols.hpp"
 29 #include "ci/ciUtilities.inline.hpp"
 30 #include "classfile/javaClasses.hpp"
 31 #include "classfile/vmClasses.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 

300     }
301   }
302 }
303 
304 // ------------------------------------------------------------------
305 // ciField::constant_value
306 // Get the constant value of a this static field.
307 ciConstant ciField::constant_value() {
308   assert(is_static() && is_constant(), "illegal call to constant_value()");
309   if (!_holder->is_initialized()) {
310     return ciConstant(); // Not initialized yet
311   }
312   if (_constant_value.basic_type() == T_ILLEGAL) {
313     // Static fields are placed in mirror objects.
314     ciInstance* mirror = _holder->java_mirror();
315     _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
316   }
317   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
318     return ciConstant();
319   }



320   return _constant_value;
321 }
322 
323 // ------------------------------------------------------------------
324 // ciField::constant_value_of
325 // Get the constant value of non-static final field in the given object.
326 ciConstant ciField::constant_value_of(ciObject* object) {
327   assert(!is_static() && is_constant(), "only if field is non-static constant");
328   assert(object->is_instance(), "must be instance");
329   ciConstant field_value = object->as_instance()->field_value(this);
330   if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
331     return ciConstant();
332   }



333   return field_value;
334 }
335 
336 // ------------------------------------------------------------------
337 // ciField::compute_type
338 //
339 // Lazily compute the type, if it is an instance klass.
340 ciType* ciField::compute_type() {
341   GUARDED_VM_ENTRY(return compute_type_impl();)
342 }
343 
344 ciType* ciField::compute_type_impl() {
345   ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
346   if (!type->is_primitive_type() && is_shared()) {
347     // We must not cache a pointer to an unshared type, in a shared field.
348     bool type_is_also_shared = false;
349     if (type->is_type_array_klass()) {
350       type_is_also_shared = true;  // int[] etc. are explicitly bootstrapped
351     } else if (type->is_instance_klass()) {
352       type_is_also_shared = type->as_instance_klass()->is_shared();

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

301     }
302   }
303 }
304 
305 // ------------------------------------------------------------------
306 // ciField::constant_value
307 // Get the constant value of a this static field.
308 ciConstant ciField::constant_value() {
309   assert(is_static() && is_constant(), "illegal call to constant_value()");
310   if (!_holder->is_initialized()) {
311     return ciConstant(); // Not initialized yet
312   }
313   if (_constant_value.basic_type() == T_ILLEGAL) {
314     // Static fields are placed in mirror objects.
315     ciInstance* mirror = _holder->java_mirror();
316     _constant_value = mirror->field_value_impl(type()->basic_type(), offset_in_bytes());
317   }
318   if (FoldStableValues && is_stable() && _constant_value.is_null_or_zero()) {
319     return ciConstant();
320   }
321   if (!SCCache::allow_const_field(_constant_value)) {
322     return ciConstant();
323   }
324   return _constant_value;
325 }
326 
327 // ------------------------------------------------------------------
328 // ciField::constant_value_of
329 // Get the constant value of non-static final field in the given object.
330 ciConstant ciField::constant_value_of(ciObject* object) {
331   assert(!is_static() && is_constant(), "only if field is non-static constant");
332   assert(object->is_instance(), "must be instance");
333   ciConstant field_value = object->as_instance()->field_value(this);
334   if (FoldStableValues && is_stable() && field_value.is_null_or_zero()) {
335     return ciConstant();
336   }
337   if (!SCCache::allow_const_field(field_value)) {
338     return ciConstant();
339   }
340   return field_value;
341 }
342 
343 // ------------------------------------------------------------------
344 // ciField::compute_type
345 //
346 // Lazily compute the type, if it is an instance klass.
347 ciType* ciField::compute_type() {
348   GUARDED_VM_ENTRY(return compute_type_impl();)
349 }
350 
351 ciType* ciField::compute_type_impl() {
352   ciKlass* type = CURRENT_ENV->get_klass_by_name_impl(_holder, constantPoolHandle(), _signature, false);
353   if (!type->is_primitive_type() && is_shared()) {
354     // We must not cache a pointer to an unshared type, in a shared field.
355     bool type_is_also_shared = false;
356     if (type->is_type_array_klass()) {
357       type_is_also_shared = true;  // int[] etc. are explicitly bootstrapped
358     } else if (type->is_instance_klass()) {
359       type_is_also_shared = type->as_instance_klass()->is_shared();
< prev index next >