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/ciArrayKlass.hpp"
26 #include "ci/ciFlatArrayKlass.hpp"
27 #include "ci/ciInlineKlass.hpp"
28 #include "ci/ciObjArrayKlass.hpp"
29 #include "ci/ciTypeArrayKlass.hpp"
30 #include "ci/ciUtilities.inline.hpp"
31 #include "memory/universe.hpp"
32 #include "oops/arrayKlass.hpp"
33 #include "oops/inlineKlass.inline.hpp"
34
35 // ciArrayKlass
36 //
37 // This class represents a Klass* in the HotSpot virtual machine
38 // whose Klass part in an ArrayKlass.
39
40 // ------------------------------------------------------------------
41 // ciArrayKlass::ciArrayKlass
42 //
43 // Loaded array klass.
44 ciArrayKlass::ciArrayKlass(Klass* k) : ciKlass(k) {
45 assert(get_Klass()->is_array_klass(), "wrong type");
46 _dimension = get_ArrayKlass()->dimension();
47 }
48
49 // ------------------------------------------------------------------
50 // ciArrayKlass::ciArrayKlass
51 //
52 // Unloaded array klass.
53 ciArrayKlass::ciArrayKlass(ciSymbol* name, int dimension, BasicType bt)
54 : ciKlass(name, bt) {
55 _dimension = dimension;
56 }
57
58 // ------------------------------------------------------------------
59 // ciArrayKlass::element_type
60 //
61 // What type is obtained when this array is indexed once?
62 ciType* ciArrayKlass::element_type() {
63 if (is_type_array_klass()) {
64 return ciType::make(as_type_array_klass()->element_type());
65 } else {
66 return element_klass()->as_klass();
67 }
68 }
69
70
71 // ------------------------------------------------------------------
72 // ciArrayKlass::base_element_type
73 //
74 // What type is obtained when this array is indexed as many times as possible?
75 ciType* ciArrayKlass::base_element_type() {
76 if (is_type_array_klass()) {
77 return ciType::make(as_type_array_klass()->element_type());
78 } else {
79 ciKlass* ek = as_obj_array_klass()->base_element_klass();
80 if (ek->is_type_array_klass()) {
81 return ciType::make(ek->as_type_array_klass()->element_type());
82 }
83 return ek;
84 }
85 }
86
87
88 // ------------------------------------------------------------------
89 // ciArrayKlass::is_leaf_type
90 bool ciArrayKlass::is_leaf_type() {
91 if (is_type_array_klass()) {
92 return true;
93 } else {
94 return as_obj_array_klass()->base_element_klass()->is_leaf_type();
95 }
96 }
97
98
99 // ------------------------------------------------------------------
100 // ciArrayKlass::make
101 //
102 // Make an array klass of the specified element type.
103 ciArrayKlass* ciArrayKlass::make(ciType* element_type, bool null_free, bool atomic, bool refined_type) {
104 if (element_type->is_primitive_type()) {
105 return ciTypeArrayKlass::make(element_type->basic_type());
106 } else {
107 return ciObjArrayKlass::make(element_type->as_klass(), refined_type, null_free, atomic);
108 }
109 }
110
111 int ciArrayKlass::array_header_in_bytes() {
112 return get_ArrayKlass()->array_header_in_bytes();
113 }
114
115 ciInstance* ciArrayKlass::component_mirror_instance() const {
116 GUARDED_VM_ENTRY(
117 oop component_mirror = ArrayKlass::cast(get_Klass())->component_mirror();
118 return CURRENT_ENV->get_instance(component_mirror);
119 )
120 }
121
122 bool ciArrayKlass::is_elem_null_free() const {
123 ArrayKlass::ArrayProperties props = properties();
124 assert(props != ArrayKlass::INVALID, "meaningless");
125 return ArrayKlass::is_null_restricted(props);
126 }
127
128 bool ciArrayKlass::is_elem_atomic() const {
129 ArrayKlass::ArrayProperties props = properties();
130 assert(props != ArrayKlass::INVALID, "meaningless");
131 return !ArrayKlass::is_non_atomic(props);
132 }
133
134 ArrayKlass::ArrayProperties ciArrayKlass::properties() const {
135 GUARDED_VM_ENTRY(return ArrayKlass::cast(get_Klass())->properties();)
136 }