2828#include " ci/ciField.hpp"
2929#include " ci/ciInstance.hpp"
3030#include " ci/ciInstanceKlass.hpp"
31+ #include " ci/ciNullObject.hpp"
3132#include " ci/ciUtilities.inline.hpp"
3233#include " classfile/vmClasses.hpp"
3334#include " oops/oop.inline.hpp"
@@ -59,17 +60,22 @@ ciType* ciInstance::java_mirror_type() {
5960// ------------------------------------------------------------------
6061// ciInstance::field_value_impl
6162ciConstant 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;
6268 oop obj = get_oop ();
6369 assert (obj != nullptr , " bad oop" );
6470 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));
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 ;
76+ case T_FLOAT: value = ciConstant (obj->float_field (offset)); break ;
77+ case T_DOUBLE: value = ciConstant (obj->double_field (offset)); break ;
78+ case T_LONG: value = ciConstant (obj->long_field (offset)); break ;
7379 case T_OBJECT: // fall through
7480 case T_ARRAY: {
7581 oop o = obj->obj_field (offset);
@@ -82,15 +88,17 @@ ciConstant ciInstance::field_value_impl(BasicType field_btype, int offset) {
8288 // information about the object's class (which is exact) or length.
8389
8490 if (o == nullptr ) {
85- return ciConstant (field_btype, ciNullObject::make ());
91+ value = ciConstant (field_btype, ciNullObject::make ());
8692 } else {
87- return ciConstant (field_btype, CURRENT_ENV->get_object (o));
93+ value = ciConstant (field_btype, CURRENT_ENV->get_object (o));
8894 }
95+ break ;
8996 }
9097 default :
9198 fatal (" no field value: %s" , type2name (field_btype));
92- return ciConstant ();
9399 }
100+ add_to_constant_value_cache (offset, value);
101+ return value;
94102}
95103
96104// ------------------------------------------------------------------
@@ -101,8 +109,7 @@ ciConstant ciInstance::field_value(ciField* field) {
101109 assert (is_loaded (), " invalid access - must be loaded" );
102110 assert (field->holder ()->is_loaded (), " invalid access - holder must be loaded" );
103111 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 ());)
112+ return field_value_impl (field->type ()->basic_type (), field->offset ());
106113}
107114
108115// ------------------------------------------------------------------
0 commit comments