< prev index next >

src/hotspot/share/ci/ciInstance.cpp

Print this page

 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.inline.hpp"
 27 #include "ci/ciConstant.hpp"
 28 #include "ci/ciField.hpp"
 29 #include "ci/ciInstance.hpp"
 30 #include "ci/ciInstanceKlass.hpp"
 31 #include "ci/ciUtilities.inline.hpp"
 32 #include "classfile/vmClasses.hpp"
 33 #include "oops/oop.inline.hpp"
 34 
 35 // ciInstance
 36 //
 37 // This class represents an instanceOop in the HotSpot virtual
 38 // machine.
 39 
 40 // ------------------------------------------------------------------
 41 // ciObject::java_mirror_type
 42 ciType* ciInstance::java_mirror_type() {
 43   VM_ENTRY_MARK;
 44   oop m = get_oop();
 45   // Return NULL if it is not java.lang.Class.
 46   if (m == NULL || m->klass() != vmClasses::Class_klass()) {
 47     return NULL;
 48   }
 49   // Return either a primitive type or a klass.
 50   if (java_lang_Class::is_primitive(m)) {
 51     return ciType::make(java_lang_Class::primitive_type(m));
 52   } else {
 53     Klass* k = java_lang_Class::as_Klass(m);
 54     assert(k != NULL, "");



 55     return CURRENT_THREAD_ENV->get_klass(k);
 56   }
 57 }
 58 
 59 // ------------------------------------------------------------------
 60 // ciInstance::field_value_impl
 61 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
 62   oop obj = get_oop();
 63   assert(obj != NULL, "bad oop");
 64   switch(field_btype) {
 65     case T_BYTE:    return ciConstant(field_btype, obj->byte_field(offset));
 66     case T_CHAR:    return ciConstant(field_btype, obj->char_field(offset));
 67     case T_SHORT:   return ciConstant(field_btype, obj->short_field(offset));
 68     case T_BOOLEAN: return ciConstant(field_btype, obj->bool_field(offset));
 69     case T_INT:     return ciConstant(field_btype, obj->int_field(offset));
 70     case T_FLOAT:   return ciConstant(obj->float_field(offset));
 71     case T_DOUBLE:  return ciConstant(obj->double_field(offset));
 72     case T_LONG:    return ciConstant(obj->long_field(offset));

 73     case T_OBJECT:  // fall through
 74     case T_ARRAY: {
 75       oop o = obj->obj_field(offset);
 76 
 77       // A field will be "constant" if it is known always to be
 78       // a non-null reference to an instance of a particular class,
 79       // or to a particular array.  This can happen even if the instance
 80       // or array is not perm.  In such a case, an "unloaded" ciArray
 81       // or ciInstance is created.  The compiler may be able to use
 82       // information about the object's class (which is exact) or length.
 83 
 84       if (o == NULL) {
 85         return ciConstant(field_btype, ciNullObject::make());
 86       } else {
 87         return ciConstant(field_btype, CURRENT_ENV->get_object(o));
 88       }
 89     }
 90     default:
 91       fatal("no field value: %s", type2name(field_btype));
 92       return ciConstant();
 93   }
 94 }
 95 
 96 // ------------------------------------------------------------------
 97 // ciInstance::field_value
 98 //
 99 // Constant value of a field.
100 ciConstant ciInstance::field_value(ciField* field) {
101   assert(is_loaded(), "invalid access - must be loaded");
102   assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
103   assert(field->is_static() || klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");

104 
105   GUARDED_VM_ENTRY(return field_value_impl(field->type()->basic_type(), field->offset());)
106 }
107 
108 // ------------------------------------------------------------------
109 // ciInstance::field_value_by_offset
110 //
111 // Constant value of a field at the specified offset.
112 ciConstant ciInstance::field_value_by_offset(int field_offset) {
113   ciInstanceKlass* ik = klass()->as_instance_klass();
114   ciField* field = ik->get_field_by_offset(field_offset, false);
115   if (field == NULL)
116     return ciConstant();  // T_ILLEGAL
117   return field_value(field);
118 }
119 
120 // ------------------------------------------------------------------
121 // ciInstance::print_impl
122 //
123 // Implementation of the print method.

 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/javaClasses.inline.hpp"
 27 #include "ci/ciConstant.hpp"
 28 #include "ci/ciField.hpp"
 29 #include "ci/ciInstance.hpp"
 30 #include "ci/ciInstanceKlass.hpp"
 31 #include "ci/ciUtilities.inline.hpp"
 32 #include "classfile/vmClasses.hpp"
 33 #include "oops/oop.inline.hpp"
 34 
 35 // ciInstance
 36 //
 37 // This class represents an instanceOop in the HotSpot virtual
 38 // machine.
 39 
 40 // ------------------------------------------------------------------
 41 // ciObject::java_mirror_type
 42 ciType* ciInstance::java_mirror_type(bool* is_val_mirror) {
 43   VM_ENTRY_MARK;
 44   oop m = get_oop();
 45   // Return NULL if it is not java.lang.Class.
 46   if (m == NULL || m->klass() != vmClasses::Class_klass()) {
 47     return NULL;
 48   }
 49   // Return either a primitive type or a klass.
 50   if (java_lang_Class::is_primitive(m)) {
 51     return ciType::make(java_lang_Class::primitive_type(m));
 52   } else {
 53     Klass* k = java_lang_Class::as_Klass(m);
 54     assert(k != NULL, "");
 55     if (is_val_mirror != NULL) {
 56       *is_val_mirror = java_lang_Class::is_secondary_mirror(m);
 57     }
 58     return CURRENT_THREAD_ENV->get_klass(k);
 59   }
 60 }
 61 
 62 // ------------------------------------------------------------------
 63 // ciInstance::field_value_impl
 64 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
 65   oop obj = get_oop();
 66   assert(obj != NULL, "bad oop");
 67   switch(field_btype) {
 68     case T_BYTE:    return ciConstant(field_btype, obj->byte_field(offset));
 69     case T_CHAR:    return ciConstant(field_btype, obj->char_field(offset));
 70     case T_SHORT:   return ciConstant(field_btype, obj->short_field(offset));
 71     case T_BOOLEAN: return ciConstant(field_btype, obj->bool_field(offset));
 72     case T_INT:     return ciConstant(field_btype, obj->int_field(offset));
 73     case T_FLOAT:   return ciConstant(obj->float_field(offset));
 74     case T_DOUBLE:  return ciConstant(obj->double_field(offset));
 75     case T_LONG:    return ciConstant(obj->long_field(offset));
 76     case T_INLINE_TYPE:  // fall through
 77     case T_OBJECT:  // fall through
 78     case T_ARRAY: {
 79       oop o = obj->obj_field(offset);
 80 
 81       // A field will be "constant" if it is known always to be
 82       // a non-null reference to an instance of a particular class,
 83       // or to a particular array.  This can happen even if the instance
 84       // or array is not perm.  In such a case, an "unloaded" ciArray
 85       // or ciInstance is created.  The compiler may be able to use
 86       // information about the object's class (which is exact) or length.
 87 
 88       if (o == NULL) {
 89         return ciConstant(field_btype, ciNullObject::make());
 90       } else {
 91         return ciConstant(field_btype, CURRENT_ENV->get_object(o));
 92       }
 93     }
 94     default:
 95       fatal("no field value: %s", type2name(field_btype));
 96       return ciConstant();
 97   }
 98 }
 99 
100 // ------------------------------------------------------------------
101 // ciInstance::field_value
102 //
103 // Constant value of a field.
104 ciConstant ciInstance::field_value(ciField* field) {
105   assert(is_loaded(), "invalid access - must be loaded");
106   assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
107   assert(field->is_static() || field->holder()->is_inlinetype() || klass()->is_subclass_of(field->holder()),
108          "invalid access - must be subclass");
109 
110   GUARDED_VM_ENTRY(return field_value_impl(field->type()->basic_type(), field->offset());)
111 }
112 
113 // ------------------------------------------------------------------
114 // ciInstance::field_value_by_offset
115 //
116 // Constant value of a field at the specified offset.
117 ciConstant ciInstance::field_value_by_offset(int field_offset) {
118   ciInstanceKlass* ik = klass()->as_instance_klass();
119   ciField* field = ik->get_field_by_offset(field_offset, false);
120   if (field == NULL)
121     return ciConstant();  // T_ILLEGAL
122   return field_value(field);
123 }
124 
125 // ------------------------------------------------------------------
126 // ciInstance::print_impl
127 //
128 // Implementation of the print method.
< prev index next >