comparison src/share/vm/ci/ciArray.cpp @ 12190:edb5ab0f3fe5

8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: rbackman, twisti, kvn Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
author vlivanov
date Tue, 10 Sep 2013 14:51:48 -0700
parents f95d63e2154a
children de6a9e811145
comparison
equal deleted inserted replaced
12188:cd16d587b0fa 12190:edb5ab0f3fe5
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "ci/ciArray.hpp" 26 #include "ci/ciArray.hpp"
27 #include "ci/ciArrayKlass.hpp"
28 #include "ci/ciConstant.hpp"
27 #include "ci/ciKlass.hpp" 29 #include "ci/ciKlass.hpp"
28 #include "ci/ciUtilities.hpp" 30 #include "ci/ciUtilities.hpp"
31 #include "oops/objArrayOop.hpp"
32 #include "oops/typeArrayOop.hpp"
29 33
30 // ciArray 34 // ciArray
31 // 35 //
32 // This class represents an arrayOop in the HotSpot virtual 36 // This class represents an arrayOop in the HotSpot virtual
33 // machine. 37 // machine.
38 static BasicType fixup_element_type(BasicType bt) {
39 if (bt == T_ARRAY) return T_OBJECT;
40 if (bt == T_BOOLEAN) return T_BYTE;
41 return bt;
42 }
43
44 ciConstant ciArray::element_value_impl(BasicType elembt,
45 arrayOop ary,
46 int index) {
47 if (ary == NULL)
48 return ciConstant();
49 assert(ary->is_array(), "");
50 if (index < 0 || index >= ary->length())
51 return ciConstant();
52 ArrayKlass* ak = (ArrayKlass*) ary->klass();
53 BasicType abt = ak->element_type();
54 if (fixup_element_type(elembt) !=
55 fixup_element_type(abt))
56 return ciConstant();
57 switch (elembt) {
58 case T_ARRAY:
59 case T_OBJECT:
60 {
61 assert(ary->is_objArray(), "");
62 objArrayOop objary = (objArrayOop) ary;
63 oop elem = objary->obj_at(index);
64 ciEnv* env = CURRENT_ENV;
65 ciObject* box = env->get_object(elem);
66 return ciConstant(T_OBJECT, box);
67 }
68 }
69 assert(ary->is_typeArray(), "");
70 typeArrayOop tary = (typeArrayOop) ary;
71 jint value = 0;
72 switch (elembt) {
73 case T_LONG: return ciConstant(tary->long_at(index));
74 case T_FLOAT: return ciConstant(tary->float_at(index));
75 case T_DOUBLE: return ciConstant(tary->double_at(index));
76 default: return ciConstant();
77 case T_BYTE: value = tary->byte_at(index); break;
78 case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
79 case T_SHORT: value = tary->short_at(index); break;
80 case T_CHAR: value = tary->char_at(index); break;
81 case T_INT: value = tary->int_at(index); break;
82 }
83 return ciConstant(elembt, value);
84 }
85
86 // ------------------------------------------------------------------
87 // ciArray::element_value
88 //
89 // Current value of an element.
90 // Returns T_ILLEGAL if there is no element at the given index.
91 ciConstant ciArray::element_value(int index) {
92 BasicType elembt = element_basic_type();
93 GUARDED_VM_ENTRY(
94 return element_value_impl(elembt, get_arrayOop(), index);
95 )
96 }
97
98 // ------------------------------------------------------------------
99 // ciArray::element_value_by_offset
100 //
101 // Current value of an element at the specified offset.
102 // Returns T_ILLEGAL if there is no element at the given offset.
103 ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
104 BasicType elembt = element_basic_type();
105 intptr_t shift = exact_log2(type2aelembytes(elembt));
106 intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
107 intptr_t index = (element_offset - header) >> shift;
108 intptr_t offset = header + ((intptr_t)index << shift);
109 if (offset != element_offset || index != (jint)index)
110 return ciConstant();
111 return element_value((jint) index);
112 }
34 113
35 // ------------------------------------------------------------------ 114 // ------------------------------------------------------------------
36 // ciArray::print_impl 115 // ciArray::print_impl
37 // 116 //
38 // Implementation of the print method. 117 // Implementation of the print method.