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/ciNullObject.hpp"
32 #include "ci/ciUtilities.inline.hpp"
33 #include "classfile/vmClasses.hpp"
34 #include "oops/oop.inline.hpp"
35
36 // ciInstance
37 //
38 // This class represents an instanceOop in the HotSpot virtual
39 // machine.
40
41 // ------------------------------------------------------------------
42 // ciObject::java_mirror_type
43 ciType* ciInstance::java_mirror_type() {
44 VM_ENTRY_MARK;
45 oop m = get_oop();
46 // Return null if it is not java.lang.Class.
47 if (m == nullptr || m->klass() != vmClasses::Class_klass()) {
48 return nullptr;
49 }
50 // Return either a primitive type or a klass.
51 if (java_lang_Class::is_primitive(m)) {
52 return ciType::make(java_lang_Class::primitive_type(m));
53 } else {
54 Klass* k = java_lang_Class::as_Klass(m);
55 assert(k != nullptr, "");
56 return CURRENT_THREAD_ENV->get_klass(k);
57 }
58 }
59
60 // ------------------------------------------------------------------
61 // ciInstance::field_value_impl
62 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
63 ciConstant value = check_constant_value_cache(offset, field_btype);
64 if (value.is_valid()) {
65 return value;
66 }
67 VM_ENTRY_MARK;
68 oop obj = get_oop();
69 assert(obj != nullptr, "bad oop");
70 switch(field_btype) {
71 case T_BYTE: value = ciConstant(field_btype, obj->byte_field(offset)); break;
72 case T_CHAR: value = ciConstant(field_btype, obj->char_field(offset)); break;
73 case T_SHORT: value = ciConstant(field_btype, obj->short_field(offset)); break;
74 case T_BOOLEAN: value = ciConstant(field_btype, obj->bool_field(offset)); break;
75 case T_INT: value = ciConstant(field_btype, obj->int_field(offset)); break;
91 value = ciConstant(field_btype, ciNullObject::make());
92 } else {
93 value = ciConstant(field_btype, CURRENT_ENV->get_object(o));
94 }
95 break;
96 }
97 default:
98 fatal("no field value: %s", type2name(field_btype));
99 }
100 add_to_constant_value_cache(offset, value);
101 return value;
102 }
103
104 // ------------------------------------------------------------------
105 // ciInstance::field_value
106 //
107 // Constant value of a field.
108 ciConstant ciInstance::field_value(ciField* field) {
109 assert(is_loaded(), "invalid access - must be loaded");
110 assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
111 assert(field->is_static() || klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");
112 return field_value_impl(field->type()->basic_type(), field->offset_in_bytes());
113 }
114
115 // ------------------------------------------------------------------
116 // ciInstance::field_value_by_offset
117 //
118 // Constant value of a field at the specified offset.
119 ciConstant ciInstance::field_value_by_offset(int field_offset) {
120 ciInstanceKlass* ik = klass()->as_instance_klass();
121 ciField* field = ik->get_field_by_offset(field_offset, false);
122 if (field == nullptr)
123 return ciConstant(); // T_ILLEGAL
124 return field_value(field);
125 }
126
127 // ------------------------------------------------------------------
128 // ciInstance::print_impl
129 //
130 // Implementation of the print method.
131 void ciInstance::print_impl(outputStream* st) {
|
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/ciNullObject.hpp"
32 #include "ci/ciUtilities.inline.hpp"
33 #include "classfile/vmClasses.hpp"
34 #include "oops/oop.inline.hpp"
35
36 // ciInstance
37 //
38 // This class represents an instanceOop in the HotSpot virtual
39 // machine.
40
41 // ------------------------------------------------------------------
42 // ciObject::java_mirror_type
43 ciType* ciInstance::java_mirror_type(bool* is_null_free_array) {
44 VM_ENTRY_MARK;
45 oop m = get_oop();
46 // Return null if it is not java.lang.Class.
47 if (m == nullptr || m->klass() != vmClasses::Class_klass()) {
48 return nullptr;
49 }
50 // Return either a primitive type or a klass.
51 if (java_lang_Class::is_primitive(m)) {
52 return ciType::make(java_lang_Class::primitive_type(m));
53 } else {
54 Klass* k = java_lang_Class::as_Klass(m);
55 assert(k != nullptr, "");
56 if (is_null_free_array != nullptr && (k->is_flatArray_klass() || (k->is_objArray_klass() && k->is_null_free_array_klass()))) {
57 *is_null_free_array = true;
58 }
59 return CURRENT_THREAD_ENV->get_klass(k);
60 }
61 }
62
63 // ------------------------------------------------------------------
64 // ciInstance::field_value_impl
65 ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
66 ciConstant value = check_constant_value_cache(offset, field_btype);
67 if (value.is_valid()) {
68 return value;
69 }
70 VM_ENTRY_MARK;
71 oop obj = get_oop();
72 assert(obj != nullptr, "bad oop");
73 switch(field_btype) {
74 case T_BYTE: value = ciConstant(field_btype, obj->byte_field(offset)); break;
75 case T_CHAR: value = ciConstant(field_btype, obj->char_field(offset)); break;
76 case T_SHORT: value = ciConstant(field_btype, obj->short_field(offset)); break;
77 case T_BOOLEAN: value = ciConstant(field_btype, obj->bool_field(offset)); break;
78 case T_INT: value = ciConstant(field_btype, obj->int_field(offset)); break;
94 value = ciConstant(field_btype, ciNullObject::make());
95 } else {
96 value = ciConstant(field_btype, CURRENT_ENV->get_object(o));
97 }
98 break;
99 }
100 default:
101 fatal("no field value: %s", type2name(field_btype));
102 }
103 add_to_constant_value_cache(offset, value);
104 return value;
105 }
106
107 // ------------------------------------------------------------------
108 // ciInstance::field_value
109 //
110 // Constant value of a field.
111 ciConstant ciInstance::field_value(ciField* field) {
112 assert(is_loaded(), "invalid access - must be loaded");
113 assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
114 assert(field->is_static() || field->holder()->is_inlinetype() || klass()->is_subclass_of(field->holder()),
115 "invalid access - must be subclass");
116
117 return field_value_impl(field->type()->basic_type(), field->offset_in_bytes());
118 }
119
120 // ------------------------------------------------------------------
121 // ciInstance::field_value_by_offset
122 //
123 // Constant value of a field at the specified offset.
124 ciConstant ciInstance::field_value_by_offset(int field_offset) {
125 ciInstanceKlass* ik = klass()->as_instance_klass();
126 ciField* field = ik->get_field_by_offset(field_offset, false);
127 if (field == nullptr)
128 return ciConstant(); // T_ILLEGAL
129 return field_value(field);
130 }
131
132 // ------------------------------------------------------------------
133 // ciInstance::print_impl
134 //
135 // Implementation of the print method.
136 void ciInstance::print_impl(outputStream* st) {
|