1 /*
2 * Copyright (c) 2017, 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/ciField.hpp"
26 #include "ci/ciInlineKlass.hpp"
27 #include "ci/ciUtilities.inline.hpp"
28 #include "oops/inlineKlass.inline.hpp"
29
30 // Offset of the first field in the inline type
31 int ciInlineKlass::payload_offset() const {
32 GUARDED_VM_ENTRY(return to_InlineKlass()->payload_offset();)
33 }
34
35 // Could any array containing an instance of this value class ever be flat?
36 bool ciInlineKlass::maybe_flat_in_array() const {
37 GUARDED_VM_ENTRY(return to_InlineKlass()->maybe_flat_in_array();)
38 }
39
40 // Are arrays containing an instance of this value class always flat?
41 bool ciInlineKlass::is_always_flat_in_array() const {
42 GUARDED_VM_ENTRY(return to_InlineKlass()->is_always_flat_in_array();)
43 }
44
45 // Can this inline type be passed as multiple values?
46 bool ciInlineKlass::can_be_passed_as_fields() const {
47 GUARDED_VM_ENTRY(return to_InlineKlass()->can_be_passed_as_fields();)
48 }
49
50 // Can this inline type be returned as multiple values?
51 bool ciInlineKlass::can_be_returned_as_fields() const {
52 GUARDED_VM_ENTRY(return to_InlineKlass()->can_be_returned_as_fields();)
53 }
54
55 bool ciInlineKlass::is_empty() {
56 // Do not use InlineKlass::is_empty_inline_type here because it does
57 // consider the container empty even if fields of empty inline types
58 // are not flat
59 return nof_declared_nonstatic_fields() == 0;
60 }
61
62 // When passing an inline type's fields as arguments, count the number
63 // of argument slots that are needed
64 int ciInlineKlass::inline_arg_slots() {
65 VM_ENTRY_MARK;
66 const Array<SigEntry>* sig_vk = get_InlineKlass()->extended_sig();
67 int slots = 0;
68 for (int i = 0; i < sig_vk->length(); i++) {
69 BasicType bt = sig_vk->at(i)._bt;
70 if (bt == T_METADATA || bt == T_VOID) {
71 continue;
72 }
73 slots += type2size[bt];
74 }
75 return slots;
76 }
77
78 bool ciInlineKlass::contains_oops() const {
79 GUARDED_VM_ENTRY(return get_InlineKlass()->contains_oops();)
80 }
81
82 int ciInlineKlass::oop_count() const {
83 GUARDED_VM_ENTRY(return get_InlineKlass()->nonstatic_oop_count();)
84 }
85
86 address ciInlineKlass::pack_handler() const {
87 GUARDED_VM_ENTRY(return get_InlineKlass()->pack_handler();)
88 }
89
90 address ciInlineKlass::unpack_handler() const {
91 GUARDED_VM_ENTRY(return get_InlineKlass()->unpack_handler();)
92 }
93
94 InlineKlass* ciInlineKlass::get_InlineKlass() const {
95 GUARDED_VM_ENTRY(return to_InlineKlass();)
96 }
97
98 bool ciInlineKlass::has_non_atomic_layout() const {
99 GUARDED_VM_ENTRY(return get_InlineKlass()->has_non_atomic_layout();)
100 }
101
102 bool ciInlineKlass::has_atomic_layout() const {
103 GUARDED_VM_ENTRY(return get_InlineKlass()->has_atomic_layout();)
104 }
105
106 bool ciInlineKlass::has_nullable_atomic_layout() const {
107 GUARDED_VM_ENTRY(return get_InlineKlass()->has_nullable_atomic_layout();)
108 }
109
110 int ciInlineKlass::null_marker_offset_in_payload() const {
111 GUARDED_VM_ENTRY(return get_InlineKlass()->null_marker_offset_in_payload();)
112 }
113
114 // Convert size of atomic layout in bytes to corresponding BasicType
115 BasicType ciInlineKlass::atomic_size_to_basic_type(bool null_free) const {
116 VM_ENTRY_MARK
117 InlineKlass* vk = get_InlineKlass();
118 assert(!null_free || vk->has_atomic_layout(), "No null-free atomic layout available");
119 assert( null_free || vk->has_nullable_atomic_layout(), "No nullable atomic layout available");
120 int size = null_free ? vk->atomic_size_in_bytes() : vk->nullable_atomic_size_in_bytes();
121 BasicType bt = T_ILLEGAL;
122 if (size == sizeof(jlong)) {
123 bt = T_LONG;
124 } else if (size == sizeof(jint)) {
125 bt = T_INT;
126 } else if (size == sizeof(jshort)) {
127 bt = T_SHORT;
128 } else if (size == sizeof(jbyte)) {
129 bt = T_BYTE;
130 } else {
131 assert(false, "Unsupported size: %d", size);
132 }
133 return bt;
134 }
135
136 bool ciInlineKlass::must_be_atomic() const {
137 GUARDED_VM_ENTRY(return get_InlineKlass()->must_be_atomic();)
138 }
139
140 bool ciInlineKlass::is_naturally_atomic(bool null_free) {
141 return null_free ? (nof_nonstatic_fields() <= 1) : (nof_nonstatic_fields() == 0);
142 }