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/ciArray.hpp"
26 #include "ci/ciArrayKlass.hpp"
27 #include "ci/ciConstant.hpp"
28 #include "ci/ciKlass.hpp"
29 #include "ci/ciUtilities.inline.hpp"
30 #include "oops/objArrayOop.inline.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "oops/typeArrayOop.inline.hpp"
33 #include "utilities/powerOfTwo.hpp"
34
35 // ciArray
36 //
37 // This class represents an arrayOop in the HotSpot virtual
38 // machine.
39 static BasicType fixup_element_type(BasicType bt) {
40 if (is_reference_type(bt)) return T_OBJECT;
41 if (bt == T_BOOLEAN) return T_BYTE;
42 return bt;
43 }
44
45 ciConstant ciArray::element_value_impl(BasicType elembt,
46 arrayOop ary,
47 int index) {
48 if (ary == nullptr)
49 return ciConstant();
50 assert(ary->is_array(), "");
51 if (index < 0 || index >= ary->length())
52 return ciConstant();
53 ArrayKlass* ak = (ArrayKlass*) ary->klass();
54 BasicType abt = ak->element_type();
55 if (fixup_element_type(elembt) !=
56 fixup_element_type(abt))
57 return ciConstant();
58 switch (elembt) {
59 case T_ARRAY:
102 return value;
103 }
104
105 // ------------------------------------------------------------------
106 // ciArray::element_value_by_offset
107 //
108 // Current value of an element at the specified offset.
109 // Returns T_ILLEGAL if there is no element at the given offset.
110 ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
111 BasicType elembt = element_basic_type();
112 intptr_t shift = exact_log2(type2aelembytes(elembt));
113 intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
114 intptr_t index = (element_offset - header) >> shift;
115 intptr_t offset = header + ((intptr_t)index << shift);
116 if (offset != element_offset || index != (jint)index || index < 0 || index >= length()) {
117 return ciConstant();
118 }
119 return element_value((jint) index);
120 }
121
122 // ------------------------------------------------------------------
123 // ciArray::print_impl
124 //
125 // Implementation of the print method.
126 void ciArray::print_impl(outputStream* st) {
127 st->print(" length=%d type=", length());
128 klass()->print(st);
129 }
|
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/ciArray.hpp"
26 #include "ci/ciArrayKlass.hpp"
27 #include "ci/ciConstant.hpp"
28 #include "ci/ciKlass.hpp"
29 #include "ci/ciUtilities.inline.hpp"
30 #include "oops/flatArrayKlass.hpp"
31 #include "oops/layoutKind.hpp"
32 #include "oops/objArrayOop.inline.hpp"
33 #include "oops/oop.inline.hpp"
34 #include "oops/typeArrayOop.inline.hpp"
35 #include "utilities/powerOfTwo.hpp"
36
37 // ciArray
38 //
39 // This class represents an arrayOop in the HotSpot virtual
40 // machine.
41 static BasicType fixup_element_type(BasicType bt) {
42 if (bt == T_FLAT_ELEMENT) return T_OBJECT;
43 if (is_reference_type(bt)) return T_OBJECT;
44 if (bt == T_BOOLEAN) return T_BYTE;
45 return bt;
46 }
47
48 ciConstant ciArray::element_value_impl(BasicType elembt,
49 arrayOop ary,
50 int index) {
51 if (ary == nullptr)
52 return ciConstant();
53 assert(ary->is_array(), "");
54 if (index < 0 || index >= ary->length())
55 return ciConstant();
56 ArrayKlass* ak = (ArrayKlass*) ary->klass();
57 BasicType abt = ak->element_type();
58 if (fixup_element_type(elembt) !=
59 fixup_element_type(abt))
60 return ciConstant();
61 switch (elembt) {
62 case T_ARRAY:
105 return value;
106 }
107
108 // ------------------------------------------------------------------
109 // ciArray::element_value_by_offset
110 //
111 // Current value of an element at the specified offset.
112 // Returns T_ILLEGAL if there is no element at the given offset.
113 ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
114 BasicType elembt = element_basic_type();
115 intptr_t shift = exact_log2(type2aelembytes(elembt));
116 intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
117 intptr_t index = (element_offset - header) >> shift;
118 intptr_t offset = header + ((intptr_t)index << shift);
119 if (offset != element_offset || index != (jint)index || index < 0 || index >= length()) {
120 return ciConstant();
121 }
122 return element_value((jint) index);
123 }
124
125 bool ciArray::is_null_free() {
126 VM_ENTRY_MARK;
127 return get_oop()->is_null_free_array();
128 }
129
130 bool ciArray::is_atomic() {
131 VM_ENTRY_MARK;
132 arrayOop oop = get_arrayOop();
133 return !oop->is_flatArray() || LayoutKindHelper::is_atomic_flat(FlatArrayKlass::cast(oop->klass())->layout_kind());
134 }
135
136 // ------------------------------------------------------------------
137 // ciArray::print_impl
138 //
139 // Implementation of the print method.
140 void ciArray::print_impl(outputStream* st) {
141 st->print(" length=%d type=", length());
142 klass()->print(st);
143 }
|