annotate src/share/vm/c1/c1_Instruction.cpp @ 8860:46f6f063b272

7153771: array bound check elimination for c1 Summary: when possible optimize out array bound checks, inserting predicates when needed. Reviewed-by: never, kvn, twisti Contributed-by: thomaswue <thomas.wuerthinger@oracle.com>
author roland
date Thu, 21 Mar 2013 09:27:54 +0100
parents 37c18711a0df
children d13d7aba8c12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1295
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
26 #include "c1/c1_IR.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
27 #include "c1/c1_Instruction.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
28 #include "c1/c1_InstructionPrinter.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
29 #include "c1/c1_ValueStack.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
30 #include "ci/ciObjArrayKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1899
diff changeset
31 #include "ci/ciTypeArrayKlass.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Implementation of Instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
37 int Instruction::dominator_depth() {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
38 int result = -1;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
39 if (block()) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
40 result = block()->dominator_depth();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
41 }
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
42 assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
43 return result;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
44 }
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
45
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 Instruction::Condition Instruction::mirror(Condition cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 case eql: return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 case neq: return neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 case lss: return gtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 case leq: return geq;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 case gtr: return lss;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 case geq: return leq;
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
54 case aeq: return beq;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
55 case beq: return aeq;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 Instruction::Condition Instruction::negate(Condition cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case eql: return neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 case neq: return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case lss: return geq;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 case leq: return gtr;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case gtr: return leq;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case geq: return lss;
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
70 case aeq: assert(false, "Above equal cannot be negated");
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
71 case beq: assert(false, "Below equal cannot be negated");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return eql;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
77 void Instruction::update_exception_state(ValueStack* state) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
78 if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
79 assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->jvmti_can_access_local_variables(), "unexpected state kind");
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
80 _exception_state = state;
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
81 } else {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
82 _exception_state = NULL;
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
83 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
84 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
85
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
86 // Prev without need to have BlockBegin
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
87 Instruction* Instruction::prev() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Instruction* p = NULL;
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
89 Instruction* q = block();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90 while (q != this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 assert(q != NULL, "this is not in the block's instruction list");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 p = q; q = q->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return p;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
98 void Instruction::state_values_do(ValueVisitor* f) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
99 if (state_before() != NULL) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
100 state_before()->values_do(f);
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
101 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
102 if (exception_state() != NULL){
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
103 exception_state()->values_do(f);
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
104 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
105 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
106
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
107
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 #ifndef PRODUCT
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
109 void Instruction::check_state(ValueStack* state) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
110 if (state != NULL) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
111 state->verify();
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
112 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
113 }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
114
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
115
0
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void Instruction::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 print(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void Instruction::print_line() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 ip.print_line(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void Instruction::print(InstructionPrinter& ip) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ip.print_head();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ip.print_line(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // perform constant and interval tests on index value
a61af66fc99e Initial load
duke
parents:
diff changeset
137 bool AccessIndexed::compute_needs_range_check() {
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
138
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
139 if (length()) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
140
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
141 Constant* clength = length()->as_Constant();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
142 Constant* cindex = index()->as_Constant();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
143 if (clength && cindex) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
144 IntConstant* l = clength->type()->as_IntConstant();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
145 IntConstant* i = cindex->type()->as_IntConstant();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
146 if (l && i && i->value() < l->value() && i->value() >= 0) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
147 return false;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
148 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
151
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
152 if (!this->check_flag(NeedsRangeCheckFlag)) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
153 return false;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
154 }
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
155
0
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159
2446
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
160 ciType* Local::exact_type() const {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
161 ciType* type = declared_type();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
162
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
163 // for primitive arrays, the declared type is the exact type
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
164 if (type->is_type_array_klass()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
165 return type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
166 } else if (type->is_instance_klass()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
167 ciInstanceKlass* ik = (ciInstanceKlass*)type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
168 if (ik->is_loaded() && ik->is_final() && !ik->is_interface()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
169 return type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
170 }
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
171 } else if (type->is_obj_array_klass()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
172 ciObjArrayKlass* oak = (ciObjArrayKlass*)type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
173 ciType* base = oak->base_element_type();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
174 if (base->is_instance_klass()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
175 ciInstanceKlass* ik = base->as_instance_klass();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
176 if (ik->is_loaded() && ik->is_final()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
177 return type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
178 }
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
179 } else if (base->is_primitive_type()) {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
180 return type;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
181 }
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
182 }
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
183 return NULL;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
184 }
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
185
6266
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
186 ciType* Constant::exact_type() const {
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
187 if (type()->is_object()) {
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
188 return type()->as_ObjectType()->exact_type();
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
189 }
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
190 return NULL;
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 3900
diff changeset
191 }
2446
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
192
0
a61af66fc99e Initial load
duke
parents:
diff changeset
193 ciType* LoadIndexed::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 ciType* array_type = array()->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (array_type == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 assert(array_type->is_array_klass(), "what else?");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 ciArrayKlass* ak = (ciArrayKlass*)array_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 if (ak->element_type()->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return ik;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ciType* LoadIndexed::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 ciType* array_type = array()->declared_type();
7995
37c18711a0df 8005114: VM is crashing in ciKlass*ciObjArrayKlass::element_klass() if metaspaces are full
roland
parents: 6725
diff changeset
213 if (array_type == NULL || !array_type->is_loaded()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 assert(array_type->is_array_klass(), "what else?");
a61af66fc99e Initial load
duke
parents:
diff changeset
217 ciArrayKlass* ak = (ciArrayKlass*)array_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 return ak->element_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 ciType* LoadField::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return field()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 ciType* LoadField::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 ciType* type = declared_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // for primitive arrays, the declared type is the exact type
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (type->is_type_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if (type->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 ciInstanceKlass* ik = (ciInstanceKlass*)type;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 ciType* NewTypeArray::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 return ciTypeArrayKlass::make(elt_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 ciType* NewObjectArray::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return ciObjArrayKlass::make(klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
2446
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
251 ciType* NewArray::declared_type() const {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
252 return exact_type();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
253 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 ciType* NewInstance::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
2446
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
259 ciType* NewInstance::declared_type() const {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
260 return exact_type();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
261 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 ciType* CheckCast::declared_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 ciType* CheckCast::exact_type() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (klass()->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 ciInstanceKlass* ik = (ciInstanceKlass*)klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 if (ik->is_loaded() && ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
271 return ik;
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // Implementation of ArithmeticOp
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279 bool ArithmeticOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 case Bytecodes::_iadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
282 case Bytecodes::_ladd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
283 case Bytecodes::_fadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
284 case Bytecodes::_dadd: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
285 case Bytecodes::_imul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
286 case Bytecodes::_lmul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
287 case Bytecodes::_fmul: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
288 case Bytecodes::_dmul: return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 bool ArithmeticOp::can_trap() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 case Bytecodes::_idiv: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
297 case Bytecodes::_ldiv: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
298 case Bytecodes::_irem: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
299 case Bytecodes::_lrem: return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Implementation of LogicOp
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 bool LogicOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
309 switch (op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 case Bytecodes::_iand: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
311 case Bytecodes::_land: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
312 case Bytecodes::_ior : // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
313 case Bytecodes::_lor : // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
314 case Bytecodes::_ixor: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
315 case Bytecodes::_lxor: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // all LogicOps are commutative
a61af66fc99e Initial load
duke
parents:
diff changeset
320 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Implementation of IfOp
a61af66fc99e Initial load
duke
parents:
diff changeset
325
a61af66fc99e Initial load
duke
parents:
diff changeset
326 bool IfOp::is_commutative() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 return cond() == eql || cond() == neq;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // Implementation of StateSplit
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 NOT_PRODUCT(bool assigned = false;)
a61af66fc99e Initial load
duke
parents:
diff changeset
335 for (int i = 0; i < list.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 BlockBegin** b = list.adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (*b == old_block) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 *b = new_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
339 NOT_PRODUCT(assigned = true;)
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 assert(assigned == true, "should have assigned at least once");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 IRScope* StateSplit::scope() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 return _state->scope();
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
351 void StateSplit::state_values_do(ValueVisitor* f) {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
352 Instruction::state_values_do(f);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
353 if (state() != NULL) state()->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
357 void BlockBegin::state_values_do(ValueVisitor* f) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
358 StateSplit::state_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 if (is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 for (int i = 0; i < number_of_exception_states(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 exception_state_at(i)->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // Implementation of Invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1295
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
372 int vtable_index, ciMethod* target, ValueStack* state_before)
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
373 : StateSplit(result_type, state_before)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
374 , _code(code)
a61af66fc99e Initial load
duke
parents:
diff changeset
375 , _recv(recv)
a61af66fc99e Initial load
duke
parents:
diff changeset
376 , _args(args)
a61af66fc99e Initial load
duke
parents:
diff changeset
377 , _vtable_index(vtable_index)
a61af66fc99e Initial load
duke
parents:
diff changeset
378 , _target(target)
a61af66fc99e Initial load
duke
parents:
diff changeset
379 {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 set_flag(TargetIsLoadedFlag, target->is_loaded());
a61af66fc99e Initial load
duke
parents:
diff changeset
381 set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());
a61af66fc99e Initial load
duke
parents:
diff changeset
382 set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 assert(args != NULL, "args must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
385 #ifdef ASSERT
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
386 AssertValues assert_value;
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
387 values_do(&assert_value);
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
388 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // provide an initial guess of signature size.
a61af66fc99e Initial load
duke
parents:
diff changeset
391 _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (has_receiver()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 _signature->append(as_BasicType(receiver()->type()));
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395 for (int i = 0; i < number_of_arguments(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 ValueType* t = argument_at(i)->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
397 BasicType bt = as_BasicType(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 _signature->append(bt);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
403 void Invoke::state_values_do(ValueVisitor* f) {
1295
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
404 StateSplit::state_values_do(f);
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
405 if (state_before() != NULL) state_before()->values_do(f);
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
406 if (state() != NULL) state()->values_do(f);
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
407 }
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
408
2446
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
409 ciType* Invoke::declared_type() const {
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
410 ciType *t = _target->signature()->return_type();
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
411 assert(t->basic_type() != T_VOID, "need return value of void method?");
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
412 return t;
13bc79b5c9c8 7033154: Improve C1 arraycopy performance
roland
parents: 1972
diff changeset
413 }
1295
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
414
0
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // Implementation of Contant
a61af66fc99e Initial load
duke
parents:
diff changeset
416 intx Constant::hash() const {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
417 if (state_before() == NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
418 switch (type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
420 return HASH2(name(), type()->as_IntConstant()->value());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
421 case addressTag:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
422 return HASH2(name(), type()->as_AddressConstant()->value());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
423 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
424 {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 jlong temp = type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
426 return HASH3(name(), high(temp), low(temp));
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 case floatTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
429 return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
430 case doubleTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
431 {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return HASH3(name(), high(temp), low(temp));
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435 case objectTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
436 assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
a61af66fc99e Initial load
duke
parents:
diff changeset
437 return HASH2(name(), type()->as_ObjectType()->constant_value());
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
438 case metaDataTag:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
439 assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
440 return HASH2(name(), type()->as_MetadataType()->constant_value());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
441 default:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
442 ShouldNotReachHere();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447
a61af66fc99e Initial load
duke
parents:
diff changeset
448 bool Constant::is_equal(Value v) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 if (v->as_Constant() == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 switch (type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
453 {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 IntConstant* t1 = type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
455 IntConstant* t2 = v->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
456 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
457 t1->value() == t2->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
460 {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 LongConstant* t1 = type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
462 LongConstant* t2 = v->type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
463 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
464 t1->value() == t2->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466 case floatTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
467 {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 FloatConstant* t1 = type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 FloatConstant* t2 = v->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
470 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
471 jint_cast(t1->value()) == jint_cast(t2->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 case doubleTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
474 {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 DoubleConstant* t1 = type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
476 DoubleConstant* t2 = v->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
477 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
478 jlong_cast(t1->value()) == jlong_cast(t2->value()));
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 case objectTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
481 {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 ObjectType* t1 = type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
483 ObjectType* t2 = v->type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
484 return (t1 != NULL && t2 != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
485 t1->is_loaded() && t2->is_loaded() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
486 t1->constant_value() == t2->constant_value());
a61af66fc99e Initial load
duke
parents:
diff changeset
487 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
488 case metaDataTag:
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
489 {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
490 MetadataType* t1 = type()->as_MetadataType();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
491 MetadataType* t2 = v->type()->as_MetadataType();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
492 return (t1 != NULL && t2 != NULL &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
493 t1->is_loaded() && t2->is_loaded() &&
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
494 t1->constant_value() == t2->constant_value());
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
495 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
500 Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
501 Constant* rc = right->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // other is not a constant
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
503 if (rc == NULL) return not_comparable;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 ValueType* lt = type();
a61af66fc99e Initial load
duke
parents:
diff changeset
506 ValueType* rt = rc->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // different types
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
508 if (lt->base() != rt->base()) return not_comparable;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
509 switch (lt->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 case intTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 int x = lt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
512 int y = rt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
513 switch (cond) {
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
514 case If::eql: return x == y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
515 case If::neq: return x != y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
516 case If::lss: return x < y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
517 case If::leq: return x <= y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
518 case If::gtr: return x > y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
519 case If::geq: return x >= y ? cond_true : cond_false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
520 }
a61af66fc99e Initial load
duke
parents:
diff changeset
521 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
522 }
a61af66fc99e Initial load
duke
parents:
diff changeset
523 case longTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 jlong x = lt->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
525 jlong y = rt->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
526 switch (cond) {
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
527 case If::eql: return x == y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
528 case If::neq: return x != y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
529 case If::lss: return x < y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
530 case If::leq: return x <= y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
531 case If::gtr: return x > y ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
532 case If::geq: return x >= y ? cond_true : cond_false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536 case objectTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 ciObject* xvalue = lt->as_ObjectType()->constant_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
538 ciObject* yvalue = rt->as_ObjectType()->constant_value();
a61af66fc99e Initial load
duke
parents:
diff changeset
539 assert(xvalue != NULL && yvalue != NULL, "not constants");
a61af66fc99e Initial load
duke
parents:
diff changeset
540 if (xvalue->is_loaded() && yvalue->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
541 switch (cond) {
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
542 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
543 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
546 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
548 case metaDataTag: {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
549 ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
550 ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
551 assert(xvalue != NULL && yvalue != NULL, "not constants");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
552 if (xvalue->is_loaded() && yvalue->is_loaded()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
553 switch (cond) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
554 case If::eql: return xvalue == yvalue ? cond_true : cond_false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
555 case If::neq: return xvalue != yvalue ? cond_true : cond_false;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
556 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
557 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
558 break;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6616
diff changeset
559 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
560 }
1899
42a10fc37986 6991577: add IfOp optimization to C1
roland
parents: 1819
diff changeset
561 return not_comparable;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
563
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // Implementation of BlockBegin
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 void BlockBegin::set_end(BlockEnd* end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 assert(end != NULL, "should not reset block end to NULL");
3900
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
569 if (end == _end) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
570 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 }
3900
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
572 clear_end();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
573
3900
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
574 // Set the new end
0
a61af66fc99e Initial load
duke
parents:
diff changeset
575 _end = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
576
a61af66fc99e Initial load
duke
parents:
diff changeset
577 _successors.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // Now reset successors list based on BlockEnd
3900
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
579 for (int i = 0; i < end->number_of_sux(); i++) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
580 BlockBegin* sux = end->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 _successors.append(sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 sux->_predecessors.append(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584 _end->set_begin(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587
3900
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
588 void BlockBegin::clear_end() {
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
589 // Must make the predecessors/successors match up with the
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
590 // BlockEnd's notion.
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
591 if (_end != NULL) {
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
592 // disconnect from the old end
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
593 _end->set_begin(NULL);
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
594
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
595 // disconnect this block from it's current successors
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
596 for (int i = 0; i < _successors.length(); i++) {
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
597 _successors.at(i)->remove_predecessor(this);
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
598 }
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
599 _end = NULL;
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
600 }
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
601 }
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
602
a32de5085326 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 3243
diff changeset
603
0
a61af66fc99e Initial load
duke
parents:
diff changeset
604 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // disconnect any edges between from and to
a61af66fc99e Initial load
duke
parents:
diff changeset
606 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
607 if (PrintIR && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
608 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
610 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
611 for (int s = 0; s < from->number_of_sux();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
612 BlockBegin* sux = from->sux_at(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
613 if (sux == to) {
a61af66fc99e Initial load
duke
parents:
diff changeset
614 int index = sux->_predecessors.index_of(from);
a61af66fc99e Initial load
duke
parents:
diff changeset
615 if (index >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
616 sux->_predecessors.remove_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
617 }
a61af66fc99e Initial load
duke
parents:
diff changeset
618 from->_successors.remove_at(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
620 s++;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 }
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
624
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 void BlockBegin::disconnect_from_graph() {
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // disconnect this block from all other blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
628 for (int p = 0; p < number_of_preds(); p++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 pred_at(p)->remove_successor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631 for (int s = 0; s < number_of_sux(); s++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 sux_at(s)->remove_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // modify predecessors before substituting successors
a61af66fc99e Initial load
duke
parents:
diff changeset
638 for (int i = 0; i < number_of_sux(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
639 if (sux_at(i) == old_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // remove old predecessor before adding new predecessor
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // otherwise there is a dead predecessor in the list
a61af66fc99e Initial load
duke
parents:
diff changeset
642 new_sux->remove_predecessor(old_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 new_sux->add_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646 old_sux->remove_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
647 end()->substitute_sux(old_sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // In general it is not possible to calculate a value for the field "depth_first_number"
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // of the inserted block, without recomputing the values of the other blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
a61af66fc99e Initial load
duke
parents:
diff changeset
655 BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
656 int bci = sux->bci();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
657 // critical edge splitting may introduce a goto after a if and array
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
658 // bound check elimination may insert a predicate between the if and
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
659 // goto. The bci of the goto can't be the one of the if otherwise
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
660 // the state and bci are inconsistent and a deoptimization triggered
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
661 // by the predicate would lead to incorrect execution/a crash.
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
662 BlockBegin* new_sux = new BlockBegin(bci);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
663
a61af66fc99e Initial load
duke
parents:
diff changeset
664 // mark this block (special treatment when block order is computed)
a61af66fc99e Initial load
duke
parents:
diff changeset
665 new_sux->set(critical_edge_split_flag);
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // This goto is not a safepoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
668 Goto* e = new Goto(sux, false);
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
669 new_sux->set_next(e, bci);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
670 new_sux->set_end(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // setup states
a61af66fc99e Initial load
duke
parents:
diff changeset
672 ValueStack* s = end()->state();
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
673 new_sux->set_state(s->copy(s->kind(), bci));
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
674 e->set_state(s->copy(s->kind(), bci));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
675 assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
676 assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
677 assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 // link predecessor to new block
a61af66fc99e Initial load
duke
parents:
diff changeset
680 end()->substitute_sux(sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
681
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // The ordering needs to be the same, so remove the link that the
a61af66fc99e Initial load
duke
parents:
diff changeset
683 // set_end call above added and substitute the new_sux for this
a61af66fc99e Initial load
duke
parents:
diff changeset
684 // block.
a61af66fc99e Initial load
duke
parents:
diff changeset
685 sux->remove_predecessor(new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
686
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // the successor could be the target of a switch so it might have
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // multiple copies of this predecessor, so substitute the new_sux
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // for the first and delete the rest.
a61af66fc99e Initial load
duke
parents:
diff changeset
690 bool assigned = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 BlockList& list = sux->_predecessors;
a61af66fc99e Initial load
duke
parents:
diff changeset
692 for (int i = 0; i < list.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 BlockBegin** b = list.adr_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
694 if (*b == this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 if (assigned) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 list.remove_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 // reprocess this index
a61af66fc99e Initial load
duke
parents:
diff changeset
698 i--;
a61af66fc99e Initial load
duke
parents:
diff changeset
699 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
700 assigned = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
701 *b = new_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
703 // link the new block back to it's predecessors.
a61af66fc99e Initial load
duke
parents:
diff changeset
704 new_sux->add_predecessor(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707 assert(assigned == true, "should have assigned at least once");
a61af66fc99e Initial load
duke
parents:
diff changeset
708 return new_sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710
a61af66fc99e Initial load
duke
parents:
diff changeset
711
a61af66fc99e Initial load
duke
parents:
diff changeset
712 void BlockBegin::remove_successor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 int idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
714 while ((idx = _successors.index_of(pred)) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 _successors.remove_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720 void BlockBegin::add_predecessor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
721 _predecessors.append(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724
a61af66fc99e Initial load
duke
parents:
diff changeset
725 void BlockBegin::remove_predecessor(BlockBegin* pred) {
a61af66fc99e Initial load
duke
parents:
diff changeset
726 int idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
727 while ((idx = _predecessors.index_of(pred)) >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
728 _predecessors.remove_at(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731
a61af66fc99e Initial load
duke
parents:
diff changeset
732
a61af66fc99e Initial load
duke
parents:
diff changeset
733 void BlockBegin::add_exception_handler(BlockBegin* b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
735 // add only if not in the list already
a61af66fc99e Initial load
duke
parents:
diff changeset
736 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 int BlockBegin::add_exception_state(ValueStack* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 assert(is_set(exception_entry_flag), "only for xhandlers");
a61af66fc99e Initial load
duke
parents:
diff changeset
741 if (_exception_states == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 _exception_states = new ValueStackStack(4);
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744 _exception_states->append(state);
a61af66fc99e Initial load
duke
parents:
diff changeset
745 return _exception_states->length() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747
a61af66fc99e Initial load
duke
parents:
diff changeset
748
a61af66fc99e Initial load
duke
parents:
diff changeset
749 void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 if (!mark.at(block_id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 mark.at_put(block_id(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
752 closure->block_do(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
a61af66fc99e Initial load
duke
parents:
diff changeset
754 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757 }
a61af66fc99e Initial load
duke
parents:
diff changeset
758
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 if (!mark.at(block_id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
762 mark.at_put(block_id(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
763 BlockEnd* e = end();
a61af66fc99e Initial load
duke
parents:
diff changeset
764 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
765 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
a61af66fc99e Initial load
duke
parents:
diff changeset
766 closure->block_do(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770
a61af66fc99e Initial load
duke
parents:
diff changeset
771 void BlockBegin::iterate_preorder(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
772 boolArray mark(number_of_blocks(), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
773 iterate_preorder(mark, closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
774 }
a61af66fc99e Initial load
duke
parents:
diff changeset
775
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 void BlockBegin::iterate_postorder(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
778 boolArray mark(number_of_blocks(), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 iterate_postorder(mark, closure);
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
783 void BlockBegin::block_values_do(ValueVisitor* f) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
784 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 #ifndef PRODUCT
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
789 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
790 #else
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
791 #define TRACE_PHI(coce)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
792 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
793
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795 bool BlockBegin::try_merge(ValueStack* new_state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
796 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // local variables used for state iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
799 int index;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 Value new_value, existing_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
801
a61af66fc99e Initial load
duke
parents:
diff changeset
802 ValueStack* existing_state = state();
a61af66fc99e Initial load
duke
parents:
diff changeset
803 if (existing_state == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
804 TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 if (is_set(BlockBegin::was_visited_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 // this actually happens for complicated jsr/ret structures
a61af66fc99e Initial load
duke
parents:
diff changeset
808 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
809 }
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 // copy state because it is altered
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
812 new_state = new_state->copy(ValueStack::BlockBeginState, bci());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
813
a61af66fc99e Initial load
duke
parents:
diff changeset
814 // Use method liveness to invalidate dead locals
a61af66fc99e Initial load
duke
parents:
diff changeset
815 MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
816 if (liveness.is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
a61af66fc99e Initial load
duke
parents:
diff changeset
818
a61af66fc99e Initial load
duke
parents:
diff changeset
819 for_each_local_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
820 if (!liveness.at(index) || new_value->type()->is_illegal()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 new_state->invalidate_local(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
822 TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
825 }
a61af66fc99e Initial load
duke
parents:
diff changeset
826
a61af66fc99e Initial load
duke
parents:
diff changeset
827 if (is_set(BlockBegin::parser_loop_header_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 for_each_stack_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 new_state->setup_phi_for_stack(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834
a61af66fc99e Initial load
duke
parents:
diff changeset
835 BitMap requires_phi_function = new_state->scope()->requires_phi_function();
a61af66fc99e Initial load
duke
parents:
diff changeset
836
a61af66fc99e Initial load
duke
parents:
diff changeset
837 for_each_local_value(new_state, index, new_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
838 bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
839 if (requires_phi || !SelectivePhiFunctions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 new_state->setup_phi_for_local(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
844 }
a61af66fc99e Initial load
duke
parents:
diff changeset
845
a61af66fc99e Initial load
duke
parents:
diff changeset
846 // initialize state of block
a61af66fc99e Initial load
duke
parents:
diff changeset
847 set_state(new_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
848
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1783
diff changeset
849 } else if (existing_state->is_same(new_state)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
850 TRACE_PHI(tty->print_cr("exisiting state found"));
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 assert(existing_state->scope() == new_state->scope(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
853 assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
854 assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
a61af66fc99e Initial load
duke
parents:
diff changeset
855
a61af66fc99e Initial load
duke
parents:
diff changeset
856 if (is_set(BlockBegin::was_visited_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
a61af66fc99e Initial load
duke
parents:
diff changeset
858
a61af66fc99e Initial load
duke
parents:
diff changeset
859 if (!is_set(BlockBegin::parser_loop_header_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 // this actually happens for complicated jsr/ret structures
a61af66fc99e Initial load
duke
parents:
diff changeset
861 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
863
a61af66fc99e Initial load
duke
parents:
diff changeset
864 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
865 Value new_value = new_state->local_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
866 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
867 // The old code invalidated the phi function here
a61af66fc99e Initial load
duke
parents:
diff changeset
868 // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out
a61af66fc99e Initial load
duke
parents:
diff changeset
869 return false; // BAILOUT in caller
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
874 // check that all necessary phi functions are present
a61af66fc99e Initial load
duke
parents:
diff changeset
875 for_each_stack_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
876 assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
879 assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
a61af66fc99e Initial load
duke
parents:
diff changeset
880 }
a61af66fc99e Initial load
duke
parents:
diff changeset
881 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
882
a61af66fc99e Initial load
duke
parents:
diff changeset
883 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 TRACE_PHI(tty->print_cr("creating phi functions on demand"));
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 // create necessary phi functions for stack
a61af66fc99e Initial load
duke
parents:
diff changeset
887 for_each_stack_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 Value new_value = new_state->stack_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
889 Phi* existing_phi = existing_value->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
890
a61af66fc99e Initial load
duke
parents:
diff changeset
891 if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
892 existing_state->setup_phi_for_stack(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
893 TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
896
a61af66fc99e Initial load
duke
parents:
diff changeset
897 // create necessary phi functions for locals
a61af66fc99e Initial load
duke
parents:
diff changeset
898 for_each_local_value(existing_state, index, existing_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
899 Value new_value = new_state->local_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
900 Phi* existing_phi = existing_value->as_Phi();
a61af66fc99e Initial load
duke
parents:
diff changeset
901
a61af66fc99e Initial load
duke
parents:
diff changeset
902 if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
903 existing_state->invalidate_local(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
904 TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
a61af66fc99e Initial load
duke
parents:
diff changeset
905 } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 existing_state->setup_phi_for_local(this, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
907 TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
a61af66fc99e Initial load
duke
parents:
diff changeset
908 }
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910 }
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
a61af66fc99e Initial load
duke
parents:
diff changeset
913
a61af66fc99e Initial load
duke
parents:
diff changeset
914 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
915 assert(false, "stack or locks not matching (invalid bytecodes)");
a61af66fc99e Initial load
duke
parents:
diff changeset
916 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
917 }
a61af66fc99e Initial load
duke
parents:
diff changeset
918
a61af66fc99e Initial load
duke
parents:
diff changeset
919 TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
a61af66fc99e Initial load
duke
parents:
diff changeset
920
a61af66fc99e Initial load
duke
parents:
diff changeset
921 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
922 }
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924
a61af66fc99e Initial load
duke
parents:
diff changeset
925 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
926 void BlockBegin::print_block() {
a61af66fc99e Initial load
duke
parents:
diff changeset
927 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
928 print_block(ip, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931
a61af66fc99e Initial load
duke
parents:
diff changeset
932 void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 ip.print_instr(this); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
934 ip.print_stack(this->state()); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
935 ip.print_inline_level(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
936 ip.print_head();
a61af66fc99e Initial load
duke
parents:
diff changeset
937 for (Instruction* n = next(); n != NULL; n = n->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
938 if (!live_only || n->is_pinned() || n->use_count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 ip.print_line(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
944 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946
a61af66fc99e Initial load
duke
parents:
diff changeset
947 // Implementation of BlockList
a61af66fc99e Initial load
duke
parents:
diff changeset
948
a61af66fc99e Initial load
duke
parents:
diff changeset
949 void BlockList::iterate_forward (BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
950 const int l = length();
a61af66fc99e Initial load
duke
parents:
diff changeset
951 for (int i = 0; i < l; i++) closure->block_do(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
952 }
a61af66fc99e Initial load
duke
parents:
diff changeset
953
a61af66fc99e Initial load
duke
parents:
diff changeset
954
a61af66fc99e Initial load
duke
parents:
diff changeset
955 void BlockList::iterate_backward(BlockClosure* closure) {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
958
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 void BlockList::blocks_do(void f(BlockBegin*)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961 for (int i = length() - 1; i >= 0; i--) f(at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963
a61af66fc99e Initial load
duke
parents:
diff changeset
964
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
965 void BlockList::values_do(ValueVisitor* f) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
966 for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
967 }
a61af66fc99e Initial load
duke
parents:
diff changeset
968
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
971 void BlockList::print(bool cfg_only, bool live_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
972 InstructionPrinter ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
973 for (int i = 0; i < length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
974 BlockBegin* block = at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
975 if (cfg_only) {
a61af66fc99e Initial load
duke
parents:
diff changeset
976 ip.print_instr(block); tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
977 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 block->print_block(ip, live_only);
a61af66fc99e Initial load
duke
parents:
diff changeset
979 }
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
982 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
983
a61af66fc99e Initial load
duke
parents:
diff changeset
984
a61af66fc99e Initial load
duke
parents:
diff changeset
985 // Implementation of BlockEnd
a61af66fc99e Initial load
duke
parents:
diff changeset
986
a61af66fc99e Initial load
duke
parents:
diff changeset
987 void BlockEnd::set_begin(BlockBegin* begin) {
a61af66fc99e Initial load
duke
parents:
diff changeset
988 BlockList* sux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
989 if (begin != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 sux = begin->successors();
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
991 } else if (this->begin() != NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
992 // copy our sux list
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
993 BlockList* sux = new BlockList(this->begin()->number_of_sux());
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
994 for (int i = 0; i < this->begin()->number_of_sux(); i++) {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
995 sux->append(this->begin()->sux_at(i));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998 _sux = sux;
a61af66fc99e Initial load
duke
parents:
diff changeset
999 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1000
a61af66fc99e Initial load
duke
parents:
diff changeset
1001
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 substitute(*_sux, old_sux, new_sux);
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1005
a61af66fc99e Initial load
duke
parents:
diff changeset
1006
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 // Implementation of Phi
a61af66fc99e Initial load
duke
parents:
diff changeset
1008
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 // Normal phi functions take their operands from the last instruction of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 // predecessor. Special handling is needed for xhanlder entries because there
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 // the state of arbitrary instructions are needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1012
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 Value Phi::operand_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 ValueStack* state;
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 if (_block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 state = _block->exception_state_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 state = _block->pred_at(i)->end()->state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 assert(state != NULL, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (is_local()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 return state->local_at(local_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 return state->stack_at(stack_index());
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1028
a61af66fc99e Initial load
duke
parents:
diff changeset
1029
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 int Phi::operand_count() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 if (_block->is_set(BlockBegin::exception_entry_flag)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 return _block->number_of_exception_states();
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 return _block->number_of_preds();
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1038 #ifdef ASSERT
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1039 // Constructor of Assert
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1040 Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1041 , _x(x)
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1042 , _cond(cond)
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1043 , _y(y)
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1044 {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1045 set_flag(UnorderedIsTrueFlag, unordered_is_true);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1046 assert(x->type()->tag() == y->type()->tag(), "types must match");
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1047 pin();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1048
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1049 stringStream strStream;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1050 Compilation::current()->method()->print_name(&strStream);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1051
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1052 stringStream strStream1;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1053 InstructionPrinter ip1(1, &strStream1);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1054 ip1.print_instr(x);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1055
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1056 stringStream strStream2;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1057 InstructionPrinter ip2(1, &strStream2);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1058 ip2.print_instr(y);
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1059
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1060 stringStream ss;
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1061 ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1062
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1063 _message = ss.as_string();
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1064 }
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1065 #endif
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1066
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1067 void RangeCheckPredicate::check_state() {
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1068 assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 7995
diff changeset
1069 }
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
1070
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
1071 void ProfileInvoke::state_values_do(ValueVisitor* f) {
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
1072 if (state() != NULL) state()->values_do(f);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
1073 }