< prev index next >

src/hotspot/share/ci/ciInstance.cpp

Print this page

  1 /*
  2  * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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/ciConstant.hpp"
 26 #include "ci/ciField.hpp"

 27 #include "ci/ciInstance.hpp"
 28 #include "ci/ciInstanceKlass.hpp"
 29 #include "ci/ciNullObject.hpp"
 30 #include "ci/ciUtilities.inline.hpp"
 31 #include "classfile/javaClasses.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 == nullptr || m->klass() != vmClasses::Class_klass()) {

 83       // a non-null reference to an instance of a particular class,
 84       // or to a particular array.  This can happen even if the instance
 85       // or array is not perm.  In such a case, an "unloaded" ciArray
 86       // or ciInstance is created.  The compiler may be able to use
 87       // information about the object's class (which is exact) or length.
 88 
 89       if (o == nullptr) {
 90         value = ciConstant(field_btype, ciNullObject::make());
 91       } else {
 92         value = ciConstant(field_btype, CURRENT_ENV->get_object(o));
 93       }
 94       break;
 95     }
 96     default:
 97       fatal("no field value: %s", type2name(field_btype));
 98   }
 99   add_to_constant_value_cache(offset, value);
100   return value;
101 }
102 









103 // ------------------------------------------------------------------
104 // ciInstance::field_value
105 //
106 // Constant value of a field.
107 ciConstant ciInstance::field_value(ciField* field) {
108   assert(is_loaded(), "invalid access - must be loaded");
109   assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
110   assert(field->is_static() || klass()->is_subclass_of(field->holder()), "invalid access - must be subclass");


111   return field_value_impl(field->type()->basic_type(), field->offset_in_bytes());
112 }
113 
114 // ------------------------------------------------------------------
115 // ciInstance::field_value_by_offset
116 //
117 // Constant value of a field at the specified offset.
118 ciConstant ciInstance::field_value_by_offset(int field_offset) {
119   ciInstanceKlass* ik = klass()->as_instance_klass();
120   ciField* field = ik->get_field_by_offset(field_offset, false);
121   if (field == nullptr)
122     return ciConstant();  // T_ILLEGAL
123   return field_value(field);
124 }
125 
126 // ------------------------------------------------------------------
127 // ciInstance::print_impl
128 //
129 // Implementation of the print method.
130 void ciInstance::print_impl(outputStream* st) {

  1 /*
  2  * Copyright (c) 1999, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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/ciConstant.hpp"
 26 #include "ci/ciField.hpp"
 27 #include "ci/ciInlineKlass.hpp"
 28 #include "ci/ciInstance.hpp"
 29 #include "ci/ciInstanceKlass.hpp"
 30 #include "ci/ciNullObject.hpp"
 31 #include "ci/ciUtilities.inline.hpp"
 32 #include "classfile/javaClasses.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()) {

 84       // a non-null reference to an instance of a particular class,
 85       // or to a particular array.  This can happen even if the instance
 86       // or array is not perm.  In such a case, an "unloaded" ciArray
 87       // or ciInstance is created.  The compiler may be able to use
 88       // information about the object's class (which is exact) or length.
 89 
 90       if (o == nullptr) {
 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 // Constant value of the null marker.
105 ciConstant ciInstance::null_marker_value() {
106   if (!klass()->is_inlinetype()) {
107     return ciConstant();
108   }
109   ciInlineKlass* ik = klass()->as_inline_klass();
110   return field_value_impl(T_BOOLEAN, ik->null_marker_offset_in_payload() + ik->payload_offset());
111 }
112 
113 // ------------------------------------------------------------------
114 // ciInstance::field_value
115 //
116 // Constant value of a field.
117 ciConstant ciInstance::field_value(ciField* field) {
118   assert(is_loaded(), "invalid access - must be loaded");
119   assert(field->holder()->is_loaded(), "invalid access - holder must be loaded");
120   assert(field->is_static() || field->holder()->is_inlinetype() || klass()->is_subclass_of(field->holder()),
121          "invalid access - must be subclass");
122 
123   return field_value_impl(field->type()->basic_type(), field->offset_in_bytes());
124 }
125 
126 // ------------------------------------------------------------------
127 // ciInstance::field_value_by_offset
128 //
129 // Constant value of a field at the specified offset.
130 ciConstant ciInstance::field_value_by_offset(int field_offset) {
131   ciInstanceKlass* ik = klass()->as_instance_klass();
132   ciField* field = ik->get_field_by_offset(field_offset, false);
133   if (field == nullptr)
134     return ciConstant();  // T_ILLEGAL
135   return field_value(field);
136 }
137 
138 // ------------------------------------------------------------------
139 // ciInstance::print_impl
140 //
141 // Implementation of the print method.
142 void ciInstance::print_impl(outputStream* st) {
< prev index next >