Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/ci/ciArray.cpp
40931 views
1
/*
2
* Copyright (c) 1999, 2019, 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 "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"
35
36
// ciArray
37
//
38
// This class represents an arrayOop in the HotSpot virtual
39
// machine.
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;
43
return bt;
44
}
45
46
ciConstant ciArray::element_value_impl(BasicType elembt,
47
arrayOop ary,
48
int index) {
49
if (ary == NULL)
50
return ciConstant();
51
assert(ary->is_array(), "");
52
if (index < 0 || index >= ary->length())
53
return ciConstant();
54
ArrayKlass* ak = (ArrayKlass*) ary->klass();
55
BasicType abt = ak->element_type();
56
if (fixup_element_type(elembt) !=
57
fixup_element_type(abt))
58
return ciConstant();
59
switch (elembt) {
60
case T_ARRAY:
61
case T_OBJECT:
62
{
63
assert(ary->is_objArray(), "");
64
objArrayOop objary = (objArrayOop) ary;
65
oop elem = objary->obj_at(index);
66
ciEnv* env = CURRENT_ENV;
67
ciObject* box = env->get_object(elem);
68
return ciConstant(T_OBJECT, box);
69
}
70
default:
71
break;
72
}
73
assert(ary->is_typeArray(), "");
74
typeArrayOop tary = (typeArrayOop) ary;
75
jint value = 0;
76
switch (elembt) {
77
case T_LONG: return ciConstant(tary->long_at(index));
78
case T_FLOAT: return ciConstant(tary->float_at(index));
79
case T_DOUBLE: return ciConstant(tary->double_at(index));
80
default: return ciConstant();
81
case T_BYTE: value = tary->byte_at(index); break;
82
case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
83
case T_SHORT: value = tary->short_at(index); break;
84
case T_CHAR: value = tary->char_at(index); break;
85
case T_INT: value = tary->int_at(index); break;
86
}
87
return ciConstant(elembt, value);
88
}
89
90
// ------------------------------------------------------------------
91
// ciArray::element_value
92
//
93
// Current value of an element.
94
// Returns T_ILLEGAL if there is no element at the given index.
95
ciConstant ciArray::element_value(int index) {
96
BasicType elembt = element_basic_type();
97
GUARDED_VM_ENTRY(
98
return element_value_impl(elembt, get_arrayOop(), index);
99
)
100
}
101
102
// ------------------------------------------------------------------
103
// ciArray::element_value_by_offset
104
//
105
// Current value of an element at the specified offset.
106
// Returns T_ILLEGAL if there is no element at the given offset.
107
ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
108
BasicType elembt = element_basic_type();
109
intptr_t shift = exact_log2(type2aelembytes(elembt));
110
intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
111
intptr_t index = (element_offset - header) >> shift;
112
intptr_t offset = header + ((intptr_t)index << shift);
113
if (offset != element_offset || index != (jint)index || index < 0 || index >= length()) {
114
return ciConstant();
115
}
116
return element_value((jint) index);
117
}
118
119
// ------------------------------------------------------------------
120
// ciArray::print_impl
121
//
122
// Implementation of the print method.
123
void ciArray::print_impl(outputStream* st) {
124
st->print(" length=%d type=", length());
125
klass()->print(st);
126
}
127
128