1 /*
2 * Copyright (c) 1999, 2023, 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 #ifndef SHARE_CI_CIFIELD_HPP
26 #define SHARE_CI_CIFIELD_HPP
27
28 #include "ci/ciClassList.hpp"
29 #include "ci/ciConstant.hpp"
30 #include "ci/ciFlags.hpp"
31 #include "ci/ciInstance.hpp"
32 #include "ci/ciUtilities.hpp"
33
34 // ciField
35 //
36 // This class represents the result of a field lookup in the VM.
37 // The lookup may not succeed, in which case the information in
38 // the ciField will be incomplete.
39 class ciField : public ArenaObj {
40 CI_PACKAGE_ACCESS
41 friend class ciEnv;
42 friend class ciInstanceKlass;
43
44 private:
45 ciFlags _flags;
46 ciInstanceKlass* _holder;
47 ciSymbol* _name;
48 ciSymbol* _signature;
49 ciType* _type;
50 int _offset;
51 bool _is_constant;
52 ciMethod* _known_to_link_with_put;
53 ciInstanceKlass* _known_to_link_with_get;
54 ciConstant _constant_value;
55
56 ciType* compute_type();
57 ciType* compute_type_impl();
58
59 ciField(ciInstanceKlass* klass, int index, Bytecodes::Code bc);
60 ciField(fieldDescriptor* fd);
61
62 // shared constructor code
63 void initialize_from(fieldDescriptor* fd);
64
65 public:
66 ciFlags flags() const { return _flags; }
67
68 // Of which klass is this field a member?
69 //
70 // Usage note: the declared holder of a field is the class
71 // referenced by name in the bytecodes. The canonical holder
72 // is the most general class which holds the field. This
73 // method returns the canonical holder. The declared holder
74 // can be accessed via a method in ciBytecodeStream.
75 //
76 // Ex.
77 // class A {
78 // public int f = 7;
79 // }
80 // class B extends A {
152 // Check for link time errors. Accessing a field from a
153 // certain method via a certain bytecode may or may not be legal.
154 // This call checks to see if an exception may be raised by
155 // an access of this field.
156 //
157 // Usage note: if the same field is accessed multiple times
158 // in the same compilation, will_link will need to be checked
159 // at each point of access.
160 bool will_link(ciMethod* accessing_method,
161 Bytecodes::Code bc);
162
163 // Java access flags
164 bool is_public () const { return flags().is_public(); }
165 bool is_private () const { return flags().is_private(); }
166 bool is_protected () const { return flags().is_protected(); }
167 bool is_static () const { return flags().is_static(); }
168 bool is_final () const { return flags().is_final(); }
169 bool is_stable () const { return flags().is_stable(); }
170 bool is_volatile () const { return flags().is_volatile(); }
171 bool is_transient () const { return flags().is_transient(); }
172 // The field is modified outside of instance initializer methods
173 // (or class/initializer methods if the field is static).
174 bool has_initialized_final_update() const { return flags().has_initialized_final_update(); }
175
176 bool is_call_site_target();
177
178 bool is_autobox_cache();
179
180 // Debugging output
181 void print();
182 void print_name_on(outputStream* st);
183 };
184
185 #endif // SHARE_CI_CIFIELD_HPP
|
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 #ifndef SHARE_CI_CIFIELD_HPP
26 #define SHARE_CI_CIFIELD_HPP
27
28 #include "ci/ciClassList.hpp"
29 #include "ci/ciConstant.hpp"
30 #include "ci/ciFlags.hpp"
31 #include "ci/ciInstance.hpp"
32 #include "ci/ciUtilities.hpp"
33 #include "oops/layoutKind.hpp"
34
35 // ciField
36 //
37 // This class represents the result of a field lookup in the VM.
38 // The lookup may not succeed, in which case the information in
39 // the ciField will be incomplete.
40 class ciField : public ArenaObj {
41 CI_PACKAGE_ACCESS
42 friend class ciEnv;
43 friend class ciInstanceKlass;
44
45 private:
46 ciFlags _flags;
47 ciInstanceKlass* _holder;
48 ciInstanceKlass* _original_holder; // For fields nested in flat fields
49 ciSymbol* _name;
50 ciSymbol* _signature;
51 ciType* _type;
52 int _offset;
53 LayoutKind _layout_kind;
54 bool _is_constant;
55 bool _is_flat;
56 bool _is_null_free;
57 int _null_marker_offset;
58 ciMethod* _known_to_link_with_put;
59 ciInstanceKlass* _known_to_link_with_get;
60 ciConstant _constant_value;
61
62 ciType* compute_type();
63 ciType* compute_type_impl();
64
65 ciField(ciInstanceKlass* klass, int index, Bytecodes::Code bc);
66 ciField(fieldDescriptor* fd);
67 ciField(ciField* declared_field, ciField* sudfield);
68 ciField(ciField* declared_field);
69
70 // shared constructor code
71 void initialize_from(fieldDescriptor* fd);
72
73 public:
74 ciFlags flags() const { return _flags; }
75
76 // Of which klass is this field a member?
77 //
78 // Usage note: the declared holder of a field is the class
79 // referenced by name in the bytecodes. The canonical holder
80 // is the most general class which holds the field. This
81 // method returns the canonical holder. The declared holder
82 // can be accessed via a method in ciBytecodeStream.
83 //
84 // Ex.
85 // class A {
86 // public int f = 7;
87 // }
88 // class B extends A {
160 // Check for link time errors. Accessing a field from a
161 // certain method via a certain bytecode may or may not be legal.
162 // This call checks to see if an exception may be raised by
163 // an access of this field.
164 //
165 // Usage note: if the same field is accessed multiple times
166 // in the same compilation, will_link will need to be checked
167 // at each point of access.
168 bool will_link(ciMethod* accessing_method,
169 Bytecodes::Code bc);
170
171 // Java access flags
172 bool is_public () const { return flags().is_public(); }
173 bool is_private () const { return flags().is_private(); }
174 bool is_protected () const { return flags().is_protected(); }
175 bool is_static () const { return flags().is_static(); }
176 bool is_final () const { return flags().is_final(); }
177 bool is_stable () const { return flags().is_stable(); }
178 bool is_volatile () const { return flags().is_volatile(); }
179 bool is_transient () const { return flags().is_transient(); }
180 bool is_strict () const { return flags().is_strict(); }
181 bool is_flat () const { return _is_flat; }
182 bool is_null_free () const { return _is_null_free; }
183 int null_marker_offset () const { return _null_marker_offset; }
184
185 // Whether this field needs to act atomically. Note that it does not actually need accessing
186 // atomically. For example, if there cannot be racy accesses to this field, then it can be
187 // accessed in a non-atomic manner. Unless this field must be in observably immutable memory,
188 // this method must not depend on the fact that the field cannot be accessed racily (e.g. it is a
189 // strict final field), as if the holder object is flattened as a field that is not strict final,
190 // this property is lost.
191 //
192 // A slice of memory is observably immutable if all stores to it must happen before all loads
193 // from it. A typical example is when the memory is a strict field and its immediate holder is
194 // not a field inside another object.
195 //
196 // For example:
197 // value class A {
198 // int x;
199 // int y;
200 // }
201 // value class AHolder {
202 // A v;
203 // }
204 // class AHolderHolder {
205 // AHolder v;
206 // }
207 // The field AHolder.v is flattened in AHolder, but AHolder cannot be flattened in AHolderHolder
208 // because we cannot access AHolderHolder.v atomically. As a result, we can say that the field is
209 // non-atomic. In this case, AHolder.v has its layout being NULLABLE_NON_ATOMIC_FLAT, this
210 // prevents its holder from being flattened in observably mutable memory.
211 //
212 // Another example:
213 // value class B {
214 // int v;
215 // }
216 // looselyconsistent value class BHolder {
217 // B v;
218 // byte b;
219 // }
220 // class BHolderHolder {
221 // null-free BHolder v;
222 // }
223 // The field BHolder.v is flattened in BHolder, and BHolder can be flattened further in
224 // BHolderHolder. In this case, while BHolder.v can be accessed in a non-atomic manner if BHolder
225 // is a standalone object, it must still be accessed atomically when it is a subfield in
226 // BHolderHolder.v. As a result, the field BHolder.v must still return true for this method, so
227 // that the compiler knows to access it correctly in all circumstances. Implementation-wise,
228 // BHolder.v has its layout being NULLABLE_ATOMIC_FLAT, which still allows its holder to be
229 // flattened in observably mutable memory.
230 bool is_atomic();
231
232 // The field is modified outside of instance initializer methods
233 // (or class/initializer methods if the field is static).
234 bool has_initialized_final_update() const { return flags().has_initialized_final_update(); }
235
236 bool is_call_site_target();
237
238 bool is_autobox_cache();
239
240 // Debugging output
241 void print() const;
242 void print_name_on(outputStream* st);
243 };
244
245 #endif // SHARE_CI_CIFIELD_HPP
|