forked from openjdk/valhalla
/
ciArrayKlass.cpp
150 lines (136 loc) · 4.72 KB
/
ciArrayKlass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "ci/ciArrayKlass.hpp"
#include "ci/ciFlatArrayKlass.hpp"
#include "ci/ciInlineKlass.hpp"
#include "ci/ciObjArrayKlass.hpp"
#include "ci/ciTypeArrayKlass.hpp"
#include "ci/ciUtilities.hpp"
#include "ci/ciUtilities.inline.hpp"
#include "oops/inlineKlass.inline.hpp"
// ciArrayKlass
//
// This class represents a Klass* in the HotSpot virtual machine
// whose Klass part in an ArrayKlass.
// ------------------------------------------------------------------
// ciArrayKlass::ciArrayKlass
//
// Loaded array klass.
ciArrayKlass::ciArrayKlass(Klass* k) : ciKlass(k) {
assert(get_Klass()->is_array_klass(), "wrong type");
_dimension = get_ArrayKlass()->dimension();
}
// ------------------------------------------------------------------
// ciArrayKlass::ciArrayKlass
//
// Unloaded array klass.
ciArrayKlass::ciArrayKlass(ciSymbol* name, int dimension, BasicType bt)
: ciKlass(name, bt) {
_dimension = dimension;
}
// ------------------------------------------------------------------
// ciArrayKlass::element_type
//
// What type is obtained when this array is indexed once?
ciType* ciArrayKlass::element_type() {
if (is_type_array_klass()) {
return ciType::make(as_type_array_klass()->element_type());
} else {
return element_klass()->as_klass();
}
}
// ------------------------------------------------------------------
// ciArrayKlass::base_element_type
//
// What type is obtained when this array is indexed as many times as possible?
ciType* ciArrayKlass::base_element_type() {
if (is_type_array_klass()) {
return ciType::make(as_type_array_klass()->element_type());
} else if (is_obj_array_klass()) {
ciKlass* ek = as_obj_array_klass()->base_element_klass();
if (ek->is_type_array_klass()) {
return ciType::make(ek->as_type_array_klass()->element_type());
}
return ek;
} else {
return as_flat_array_klass()->base_element_klass();
}
}
// ------------------------------------------------------------------
// ciArrayKlass::is_leaf_type
bool ciArrayKlass::is_leaf_type() {
if (is_type_array_klass()) {
return true;
} else {
return as_obj_array_klass()->base_element_klass()->is_leaf_type();
}
}
// ------------------------------------------------------------------
// ciArrayKlass::base_element_type
//
// What type is obtained when this array is indexed as many times as possible?
ciArrayKlass* ciArrayKlass::make(ciType* element_type) {
if (element_type->is_primitive_type()) {
return ciTypeArrayKlass::make(element_type->basic_type());
} else {
return make(element_type->as_klass(), element_type->is_null_free());
}
}
ciArrayKlass* ciArrayKlass::make(ciKlass* klass, bool null_free) {
if (null_free) {
if (klass->is_loaded()) {
bool is_array_flattened = false;
GUARDED_VM_ENTRY(
EXCEPTION_CONTEXT;
Klass* ak = InlineKlass::cast(klass->get_Klass())->null_free_inline_array_klass(THREAD);
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
} else {
if (ak != NULL && ak->is_flatArray_klass()) {
is_array_flattened = true;
}
}
)
if (is_array_flattened) {
return ciFlatArrayKlass::make(klass);
} else {
return ciObjArrayKlass::make(klass, true);
}
} else {
return ciEnv::unloaded_ciobjarrayklass();
}
} else {
return ciObjArrayKlass::make(klass);
}
}
int ciArrayKlass::array_header_in_bytes() {
return get_ArrayKlass()->array_header_in_bytes();
}
ciInstance* ciArrayKlass::component_mirror_instance() const {
GUARDED_VM_ENTRY(
oop component_mirror = ArrayKlass::cast(get_Klass())->component_mirror();
return CURRENT_ENV->get_instance(component_mirror);
)
}