25
#include "precompiled.hpp"
26
#include "ci/ciArray.hpp"
27
#include "ci/ciArrayKlass.hpp"
28
#include "ci/ciConstant.hpp"
29
#include "ci/ciKlass.hpp"
30
#include "ci/ciUtilities.inline.hpp"
31
#include "oops/objArrayOop.inline.hpp"
32
#include "oops/oop.inline.hpp"
33
#include "oops/typeArrayOop.inline.hpp"
34
#include "utilities/powerOfTwo.hpp"
40
static BasicType fixup_element_type(BasicType bt) {
41
if (is_reference_type(bt)) return T_OBJECT;
42
if (bt == T_BOOLEAN) return T_BYTE;
46
ciConstant ciArray::element_value_impl(BasicType elembt,
51
assert(ary->is_array(), "");
52
if (index < 0 || index >= ary->length())
54
ArrayKlass* ak = (ArrayKlass*) ary->klass();
55
BasicType abt = ak->element_type();
56
if (fixup_element_type(elembt) !=
57
fixup_element_type(abt))
63
assert(ary->is_objArray(), "");
64
objArrayOop objary = (objArrayOop) ary;
65
oop elem = objary->obj_at(index);
66
return ciConstant(elembt, CURRENT_ENV->get_object(elem));
71
assert(ary->is_typeArray(), "");
72
typeArrayOop tary = (typeArrayOop) ary;
75
case T_LONG: return ciConstant(tary->long_at(index));
76
case T_FLOAT: return ciConstant(tary->float_at(index));
77
case T_DOUBLE: return ciConstant(tary->double_at(index));
78
default: return ciConstant();
79
case T_BYTE: value = tary->byte_at(index); break;
80
case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
81
case T_SHORT: value = tary->short_at(index); break;
82
case T_CHAR: value = tary->char_at(index); break;
83
case T_INT: value = tary->int_at(index); break;
85
return ciConstant(elembt, value);
93
ciConstant ciArray::element_value(int index) {
94
BasicType elembt = element_basic_type();
95
ciConstant value = check_constant_value_cache(index, elembt);
96
if (value.is_valid()) {
100
value = element_value_impl(elembt, get_arrayOop(), index);
102
add_to_constant_value_cache(index, value);
111
ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
112
BasicType elembt = element_basic_type();
113
intptr_t shift = exact_log2(type2aelembytes(elembt));
114
intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
115
intptr_t index = (element_offset - header) >> shift;
116
intptr_t offset = header + ((intptr_t)index << shift);
117
if (offset != element_offset || index != (jint)index || index < 0 || index >= length()) {
120
return element_value((jint) index);
127
void ciArray::print_impl(outputStream* st) {
128
st->print(" length=%d type=", length());