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