annotate src/share/vm/c1/c1_Canonicalizer.cpp @ 24164:f98ea2d742a2

fixed missing exception propagation (JDK-8185790)
author Doug Simon <doug.simon@oracle.com>
date Tue, 08 Aug 2017 10:06:50 +0200
parents f13e777eb255
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
23614
32b682649973 8132051: Better byte behavior
kevinw
parents: 20491
diff changeset
2 * Copyright (c) 1999, 2016, 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: 1819
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1819
diff changeset
26 #include "c1/c1_Canonicalizer.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1819
diff changeset
27 #include "c1/c1_InstructionPrinter.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1819
diff changeset
28 #include "c1/c1_ValueStack.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1819
diff changeset
29 #include "ci/ciArray.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1819
diff changeset
30 #include "runtime/sharedRuntime.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
33 class PrintValueVisitor: public ValueVisitor {
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
34 void visit(Value* vp) {
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
35 (*vp)->print_line();
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
36 }
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
37 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 void Canonicalizer::set_canonical(Value x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 assert(x != NULL, "value must exist");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Note: we can not currently substitute root nodes which show up in
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // the instruction stream (because the instruction list is embedded
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // in the instructions).
a61af66fc99e Initial load
duke
parents:
diff changeset
44 if (canonical() != x) {
6133
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
45 #ifndef PRODUCT
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
46 if (!x->has_printable_bci()) {
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
47 x->set_printable_bci(bci());
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
48 }
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
49 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (PrintCanonicalization) {
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
51 PrintValueVisitor do_print_value;
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
52 canonical()->input_values_do(&do_print_value);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 canonical()->print_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 tty->print_cr("canonicalized to:");
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
55 x->input_values_do(&do_print_value);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 x->print_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59 assert(_canonical->type()->tag() == x->type()->tag(), "types must match");
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _canonical = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 void Canonicalizer::move_const_to_right(Op2* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (x->x()->type()->is_constant() && x->is_commutative()) x->swap_operands();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void Canonicalizer::do_Op2(Op2* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (x->x() == x->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 case Bytecodes::_isub: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 case Bytecodes::_lsub: set_constant(jlong_cast(0)); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 case Bytecodes::_iand: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
76 case Bytecodes::_land: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
77 case Bytecodes::_ior: // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case Bytecodes::_lor : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 case Bytecodes::_ixor: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 case Bytecodes::_lxor: set_constant(jlong_cast(0)); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (x->x()->type()->is_constant() && x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // do constant folding for selected operations
a61af66fc99e Initial load
duke
parents:
diff changeset
86 switch (x->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
88 { jint a = x->x()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 jint b = x->y()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case Bytecodes::_iadd: set_constant(a + b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case Bytecodes::_isub: set_constant(a - b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 case Bytecodes::_imul: set_constant(a * b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 case Bytecodes::_idiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (a == min_jint && b == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 set_constant(min_jint);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 set_constant(a / b);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 case Bytecodes::_irem:
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (a == min_jint && b == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 set_constant(a % b);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case Bytecodes::_iand: set_constant(a & b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case Bytecodes::_ior : set_constant(a | b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 case Bytecodes::_ixor: set_constant(a ^ b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
121 { jlong a = x->x()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 jlong b = x->y()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 case Bytecodes::_ladd: set_constant(a + b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 case Bytecodes::_lsub: set_constant(a - b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 case Bytecodes::_lmul: set_constant(a * b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 case Bytecodes::_ldiv:
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 set_constant(SharedRuntime::ldiv(b, a));
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 case Bytecodes::_lrem:
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (b != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 set_constant(SharedRuntime::lrem(b, a));
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 case Bytecodes::_land: set_constant(a & b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 case Bytecodes::_lor : set_constant(a | b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 case Bytecodes::_lxor: set_constant(a ^ b); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // other cases not implemented (must be extremely careful with floats & doubles!)
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // make sure constant is on the right side, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
149 move_const_to_right(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if (x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // do constant folding for selected operations
a61af66fc99e Initial load
duke
parents:
diff changeset
153 switch (x->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 case intTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
155 if (x->y()->type()->as_IntConstant()->value() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 case Bytecodes::_iadd: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 case Bytecodes::_isub: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 case Bytecodes::_imul: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Note: for div and rem, make sure that C semantics
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // corresponds to Java semantics!
a61af66fc99e Initial load
duke
parents:
diff changeset
162 case Bytecodes::_iand: set_constant(0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 case Bytecodes::_ior : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 case longTag:
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (x->y()->type()->as_LongConstant()->value() == (jlong)0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 case Bytecodes::_ladd: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 case Bytecodes::_lsub: set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 case Bytecodes::_lmul: set_constant((jlong)0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Note: for div and rem, make sure that C semantics
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // corresponds to Java semantics!
a61af66fc99e Initial load
duke
parents:
diff changeset
175 case Bytecodes::_land: set_constant((jlong)0); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 case Bytecodes::_lor : set_canonical(x->x()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 void Canonicalizer::do_Phi (Phi* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
186 void Canonicalizer::do_Constant (Constant* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void Canonicalizer::do_Local (Local* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
188 void Canonicalizer::do_LoadField (LoadField* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // checks if v is in the block that is currently processed by
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // GraphBuilder. This is the only block that has not BlockEnd yet.
a61af66fc99e Initial load
duke
parents:
diff changeset
192 static bool in_current_block(Value v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 int max_distance = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 while (max_distance > 0 && v != NULL && v->as_BlockEnd() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 v = v->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 max_distance--;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return v == NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 void Canonicalizer::do_StoreField (StoreField* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // If a value is going to be stored into a field or array some of
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // the conversions emitted by javac are unneeded because the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // are packed to their natural size.
a61af66fc99e Initial load
duke
parents:
diff changeset
205 Convert* conv = x->value()->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 Value value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 BasicType type = x->field()->type()->basic_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 case Bytecodes::_i2b: if (type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 case Bytecodes::_i2c: if (type == T_CHAR || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // limit this optimization to current block
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (value != NULL && in_current_block(conv)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
2352
425688247f3d 6965570: assert(!needs_patching && x->is_loaded(),"how do we know it's volatile if it's not loaded")
never
parents: 2166
diff changeset
217 x->state_before(), x->needs_patching()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
218 return;
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 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 void Canonicalizer::do_ArrayLength (ArrayLength* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 NewArray* array = x->array()->as_NewArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (array != NULL && array->length() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 Constant* length = array->length()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (length != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // do not use the Constant itself, but create a new Constant
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // with same value Otherwise a Constant is live over multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // blocks without being registered in a state array.
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert(length->type()->as_IntConstant() != NULL, "array length must be integer");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 set_constant(length->type()->as_IntConstant()->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 LoadField* lf = x->array()->as_LoadField();
1295
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
237 if (lf != NULL) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
238 ciField* field = lf->field();
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
239 if (field->is_constant() && field->is_static()) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
240 // final static field
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
241 ciObject* c = field->constant_value().as_object();
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
242 if (c->is_array()) {
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
243 ciArray* array = (ciArray*) c;
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
244 set_constant(array->length());
3cf667df43ef 6919934: JSR 292 needs to support x86 C1
twisti
parents: 0
diff changeset
245 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 void Canonicalizer::do_LoadIndexed (LoadIndexed* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
252 void Canonicalizer::do_StoreIndexed (StoreIndexed* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // If a value is going to be stored into a field or array some of
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // the conversions emitted by javac are unneeded because the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // are packed to their natural size.
a61af66fc99e Initial load
duke
parents:
diff changeset
256 Convert* conv = x->value()->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 Value value = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 BasicType type = x->elt_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 case Bytecodes::_i2b: if (type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 case Bytecodes::_i2c: if (type == T_CHAR || type == T_BYTE) value = conv->value(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // limit this optimization to current block
a61af66fc99e Initial load
duke
parents:
diff changeset
266 if (value != NULL && in_current_block(conv)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 set_canonical(new StoreIndexed(x->array(), x->index(), x->length(),
23614
32b682649973 8132051: Better byte behavior
kevinw
parents: 20491
diff changeset
268 x->elt_type(), value, x->state_before(),
32b682649973 8132051: Better byte behavior
kevinw
parents: 20491
diff changeset
269 x->check_boolean()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 void Canonicalizer::do_NegateOp(NegateOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 ValueType* t = x->x()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if (t->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 switch (t->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 case intTag : set_constant(-t->as_IntConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 case longTag : set_constant(-t->as_LongConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 case floatTag : set_constant(-t->as_FloatConstant ()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 case doubleTag: set_constant(-t->as_DoubleConstant()->value()); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 void Canonicalizer::do_ArithmeticOp (ArithmeticOp* x) { do_Op2(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 void Canonicalizer::do_ShiftOp (ShiftOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 ValueType* t = x->x()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
297 ValueType* t2 = x->y()->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (t->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 switch (t->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 case intTag : if (t->as_IntConstant()->value() == 0) { set_constant(0); return; } break;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 case longTag : if (t->as_LongConstant()->value() == (jlong)0) { set_constant(jlong_cast(0)); return; } break;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (t2->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (t->tag() == intTag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 int value = t->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 int shift = t2->as_IntConstant()->value() & 31;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 jint mask = ~(~0 << (32 - shift));
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (shift == 0) mask = ~0;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 case Bytecodes::_ishl: set_constant(value << shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 case Bytecodes::_ishr: set_constant(value >> shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 case Bytecodes::_iushr: set_constant((value >> shift) & mask); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 } else if (t->tag() == longTag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 jlong value = t->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
317 int shift = t2->as_IntConstant()->value() & 63;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 jlong mask = ~(~jlong_cast(0) << (64 - shift));
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (shift == 0) mask = ~jlong_cast(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
320 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 case Bytecodes::_lshl: set_constant(value << shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 case Bytecodes::_lshr: set_constant(value >> shift); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
323 case Bytecodes::_lushr: set_constant((value >> shift) & mask); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 if (t2->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 switch (t2->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
330 case intTag : if (t2->as_IntConstant()->value() == 0) set_canonical(x->x()); return;
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
331 case longTag : if (t2->as_LongConstant()->value() == (jlong)0) set_canonical(x->x()); return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
332 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 void Canonicalizer::do_LogicOp (LogicOp* x) { do_Op2(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 void Canonicalizer::do_CompareOp (CompareOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (x->x() == x->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 switch (x->x()->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 case longTag: set_constant(0); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 case floatTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 FloatConstant* fc = x->x()->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
345 if (fc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 if (g_isnan(fc->value())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 set_constant(x->op() == Bytecodes::_fcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 case doubleTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 DoubleConstant* dc = x->x()->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (dc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (g_isnan(dc->value())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 set_constant(x->op() == Bytecodes::_dcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 } else if (x->x()->type()->is_constant() && x->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 switch (x->x()->type()->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 case longTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 jlong vx = x->x()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
370 jlong vy = x->y()->type()->as_LongConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
371 if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
372 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
374 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 else
a61af66fc99e Initial load
duke
parents:
diff changeset
376 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379
a61af66fc99e Initial load
duke
parents:
diff changeset
380 case floatTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 float vx = x->x()->type()->as_FloatConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 float vy = x->y()->type()->as_FloatConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (g_isnan(vx) || g_isnan(vy))
a61af66fc99e Initial load
duke
parents:
diff changeset
384 set_constant(x->op() == Bytecodes::_fcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
385 else if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
386 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
387 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
388 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
389 else
a61af66fc99e Initial load
duke
parents:
diff changeset
390 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 case doubleTag: {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 double vx = x->x()->type()->as_DoubleConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
396 double vy = x->y()->type()->as_DoubleConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
397 if (g_isnan(vx) || g_isnan(vy))
a61af66fc99e Initial load
duke
parents:
diff changeset
398 set_constant(x->op() == Bytecodes::_dcmpl ? -1 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 else if (vx == vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
400 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 else if (vx < vy)
a61af66fc99e Initial load
duke
parents:
diff changeset
402 set_constant(-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 else
a61af66fc99e Initial load
duke
parents:
diff changeset
404 set_constant(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
405 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 void Canonicalizer::do_IfInstanceOf(IfInstanceOf* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 void Canonicalizer::do_IfOp(IfOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
416 // Caution: do not use do_Op2(x) here for now since
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // we map the condition to the op for now!
a61af66fc99e Initial load
duke
parents:
diff changeset
418 move_const_to_right(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 void Canonicalizer::do_Intrinsic (Intrinsic* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 switch (x->id()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
424 case vmIntrinsics::_floatToRawIntBits : {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 FloatConstant* c = x->argument_at(0)->type()->as_FloatConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
426 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 v.set_jfloat(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
429 set_constant(v.get_jint());
a61af66fc99e Initial load
duke
parents:
diff changeset
430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
431 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433 case vmIntrinsics::_intBitsToFloat : {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 IntConstant* c = x->argument_at(0)->type()->as_IntConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
435 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 v.set_jint(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
438 set_constant(v.get_jfloat());
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 case vmIntrinsics::_doubleToRawLongBits : {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 DoubleConstant* c = x->argument_at(0)->type()->as_DoubleConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 v.set_jdouble(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
447 set_constant(v.get_jlong());
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 case vmIntrinsics::_longBitsToDouble : {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 LongConstant* c = x->argument_at(0)->type()->as_LongConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
453 if (c != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 JavaValue v;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 v.set_jlong(c->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
456 set_constant(v.get_jdouble());
a61af66fc99e Initial load
duke
parents:
diff changeset
457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
458 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
6135
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
460 case vmIntrinsics::_isInstance : {
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
461 assert(x->number_of_arguments() == 2, "wrong type");
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
462
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
463 InstanceConstant* c = x->argument_at(0)->type()->as_InstanceConstant();
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
464 if (c != NULL && !c->value()->is_null_object()) {
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
465 // ciInstance::java_mirror_type() returns non-NULL only for Java mirrors
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
466 ciType* t = c->value()->as_instance()->java_mirror_type();
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
467 if (t->is_klass()) {
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
468 // substitute cls.isInstance(obj) of a constant Class into
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
469 // an InstantOf instruction
6136
e1635876b206 7174884: C1: failures after 7171890: assert(cur_state != NULL) failed: state_before must be set
twisti
parents: 6135
diff changeset
470 InstanceOf* i = new InstanceOf(t->as_klass(), x->argument_at(1), x->state_before());
6135
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
471 set_canonical(i);
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
472 // and try to canonicalize even further
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
473 do_InstanceOf(i);
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
474 } else {
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
475 assert(t->is_primitive_type(), "should be a primitive type");
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
476 // cls.isInstance(obj) always returns false for primitive classes
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
477 set_constant(0);
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
478 }
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
479 }
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
480 break;
8f37087fc13f 7171890: C1: add Class.isInstance intrinsic
roland
parents: 6133
diff changeset
481 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484
a61af66fc99e Initial load
duke
parents:
diff changeset
485 void Canonicalizer::do_Convert (Convert* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 if (x->value()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 case Bytecodes::_i2b: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 24) >> 24)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 case Bytecodes::_i2s: set_constant((int)((x->value()->type()->as_IntConstant()->value() << 16) >> 16)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 case Bytecodes::_i2c: set_constant((int)(x->value()->type()->as_IntConstant()->value() & ((1<<16)-1))); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 case Bytecodes::_i2l: set_constant((jlong)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
492 case Bytecodes::_i2f: set_constant((float)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
493 case Bytecodes::_i2d: set_constant((double)(x->value()->type()->as_IntConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
494 case Bytecodes::_l2i: set_constant((int)(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 case Bytecodes::_l2f: set_constant(SharedRuntime::l2f(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 case Bytecodes::_l2d: set_constant(SharedRuntime::l2d(x->value()->type()->as_LongConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
497 case Bytecodes::_f2d: set_constant((double)(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 case Bytecodes::_f2i: set_constant(SharedRuntime::f2i(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 case Bytecodes::_f2l: set_constant(SharedRuntime::f2l(x->value()->type()->as_FloatConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 case Bytecodes::_d2f: set_constant((float)(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
501 case Bytecodes::_d2i: set_constant(SharedRuntime::d2i(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 case Bytecodes::_d2l: set_constant(SharedRuntime::d2l(x->value()->type()->as_DoubleConstant()->value())); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
503 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
504 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 Value value = x->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 BasicType type = T_ILLEGAL;
a61af66fc99e Initial load
duke
parents:
diff changeset
510 LoadField* lf = value->as_LoadField();
a61af66fc99e Initial load
duke
parents:
diff changeset
511 if (lf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 type = lf->field_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
513 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 LoadIndexed* li = value->as_LoadIndexed();
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (li) {
a61af66fc99e Initial load
duke
parents:
diff changeset
516 type = li->elt_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
517 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 Convert* conv = value->as_Convert();
a61af66fc99e Initial load
duke
parents:
diff changeset
519 if (conv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 switch (conv->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 case Bytecodes::_i2b: type = T_BYTE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
522 case Bytecodes::_i2s: type = T_SHORT; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
523 case Bytecodes::_i2c: type = T_CHAR; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
524 }
a61af66fc99e Initial load
duke
parents:
diff changeset
525 }
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
a61af66fc99e Initial load
duke
parents:
diff changeset
528 if (type != T_ILLEGAL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 case Bytecodes::_i2b: if (type == T_BYTE) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 case Bytecodes::_i2s: if (type == T_SHORT || type == T_BYTE) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
532 case Bytecodes::_i2c: if (type == T_CHAR) set_canonical(x->value()); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 Op2* op2 = x->value()->as_Op2();
a61af66fc99e Initial load
duke
parents:
diff changeset
536 if (op2 && op2->op() == Bytecodes::_iand && op2->y()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 jint safebits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 jint mask = op2->y()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
539 switch (x->op()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 case Bytecodes::_i2b: safebits = 0x7f; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
541 case Bytecodes::_i2s: safebits = 0x7fff; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 case Bytecodes::_i2c: safebits = 0xffff; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // When casting a masked integer to a smaller signed type, if
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // the mask doesn't include the sign bit the cast isn't needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if (safebits && (mask & ~safebits) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 set_canonical(x->value());
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553
a61af66fc99e Initial load
duke
parents:
diff changeset
554 void Canonicalizer::do_NullCheck (NullCheck* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
555 if (x->obj()->as_NewArray() != NULL || x->obj()->as_NewInstance() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 set_canonical(x->obj());
a61af66fc99e Initial load
duke
parents:
diff changeset
557 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 Constant* con = x->obj()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 if (con) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 ObjectType* c = con->type()->as_ObjectType();
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if (c && c->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 ObjectConstant* oc = c->as_ObjectConstant();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 if (!oc || !oc->value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 set_canonical(con);
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569 }
a61af66fc99e Initial load
duke
parents:
diff changeset
570
6266
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 6136
diff changeset
571 void Canonicalizer::do_TypeCast (TypeCast* x) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
572 void Canonicalizer::do_Invoke (Invoke* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
573 void Canonicalizer::do_NewInstance (NewInstance* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
574 void Canonicalizer::do_NewTypeArray (NewTypeArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
575 void Canonicalizer::do_NewObjectArray (NewObjectArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
576 void Canonicalizer::do_NewMultiArray (NewMultiArray* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
577 void Canonicalizer::do_CheckCast (CheckCast* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 if (x->klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 Value obj = x->obj();
a61af66fc99e Initial load
duke
parents:
diff changeset
580 ciType* klass = obj->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
581 if (klass == NULL) klass = obj->declared_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
582 if (klass != NULL && klass->is_loaded() && klass->is_subtype_of(x->klass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 set_canonical(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
584 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
586 // checkcast of null returns null
a61af66fc99e Initial load
duke
parents:
diff changeset
587 if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
588 set_canonical(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592 void Canonicalizer::do_InstanceOf (InstanceOf* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 if (x->klass()->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
594 Value obj = x->obj();
a61af66fc99e Initial load
duke
parents:
diff changeset
595 ciType* exact = obj->exact_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
596 if (exact != NULL && exact->is_loaded() && (obj->as_NewInstance() || obj->as_NewArray())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 set_constant(exact->is_subtype_of(x->klass()) ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
598 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // instanceof null returns false
a61af66fc99e Initial load
duke
parents:
diff changeset
601 if (obj->as_Constant() && obj->type()->as_ObjectType()->constant_value()->is_null_object()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 set_constant(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 }
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 }
a61af66fc99e Initial load
duke
parents:
diff changeset
607 void Canonicalizer::do_MonitorEnter (MonitorEnter* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
608 void Canonicalizer::do_MonitorExit (MonitorExit* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
609 void Canonicalizer::do_BlockBegin (BlockBegin* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
610 void Canonicalizer::do_Goto (Goto* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 static bool is_true(jlong x, If::Condition cond, jlong y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
614 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 case If::eql: return x == y;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 case If::neq: return x != y;
a61af66fc99e Initial load
duke
parents:
diff changeset
617 case If::lss: return x < y;
a61af66fc99e Initial load
duke
parents:
diff changeset
618 case If::leq: return x <= y;
a61af66fc99e Initial load
duke
parents:
diff changeset
619 case If::gtr: return x > y;
a61af66fc99e Initial load
duke
parents:
diff changeset
620 case If::geq: return x >= y;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 }
a61af66fc99e Initial load
duke
parents:
diff changeset
622 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
623 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
626 static bool is_safepoint(BlockEnd* x, BlockBegin* sux) {
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
627 // An Instruction with multiple successors, x, is replaced by a Goto
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
628 // to a single successor, sux. Is a safepoint check needed = was the
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
629 // instruction being replaced a safepoint and the single remaining
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
630 // successor a back branch?
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
631 return x->is_safepoint() && (sux->bci() < x->state_before()->bci());
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
632 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 void Canonicalizer::do_If(If* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // move const to right
a61af66fc99e Initial load
duke
parents:
diff changeset
636 if (x->x()->type()->is_constant()) x->swap_operands();
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // simplify
a61af66fc99e Initial load
duke
parents:
diff changeset
638 const Value l = x->x(); ValueType* lt = l->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
639 const Value r = x->y(); ValueType* rt = r->type();
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 if (l == r && !lt->is_float_kind()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // pattern: If (a cond a) => simplify to Goto
23822
626f594dffa6 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
csahu
parents: 20491
diff changeset
643 BlockBegin* sux = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
644 switch (x->cond()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 case If::eql: sux = x->sux_for(true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
646 case If::neq: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 case If::lss: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 case If::leq: sux = x->sux_for(true); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
649 case If::gtr: sux = x->sux_for(false); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 case If::geq: sux = x->sux_for(true); break;
23822
626f594dffa6 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
csahu
parents: 20491
diff changeset
651 default: ShouldNotReachHere();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // If is a safepoint then the debug information should come from the state_before of the If.
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
654 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
655 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 if (lt->is_constant() && rt->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 if (x->x()->as_Constant() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // pattern: If (lc cond rc) => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
661 BlockBegin* sux = x->x()->as_Constant()->compare(x->cond(), x->y(),
a61af66fc99e Initial load
duke
parents:
diff changeset
662 x->sux_for(true),
a61af66fc99e Initial load
duke
parents:
diff changeset
663 x->sux_for(false));
a61af66fc99e Initial load
duke
parents:
diff changeset
664 if (sux != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // If is a safepoint then the debug information should come from the state_before of the If.
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
666 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 } else if (rt->as_IntConstant() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // pattern: If (l cond rc) => investigate further
a61af66fc99e Initial load
duke
parents:
diff changeset
671 const jint rc = rt->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
672 if (l->as_CompareOp() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // pattern: If ((a cmp b) cond rc) => simplify to: If (x cond y) or: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
674 CompareOp* cmp = l->as_CompareOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
675 bool unordered_is_less = cmp->op() == Bytecodes::_fcmpl || cmp->op() == Bytecodes::_dcmpl;
a61af66fc99e Initial load
duke
parents:
diff changeset
676 BlockBegin* lss_sux = x->sux_for(is_true(-1, x->cond(), rc)); // successor for a < b
a61af66fc99e Initial load
duke
parents:
diff changeset
677 BlockBegin* eql_sux = x->sux_for(is_true( 0, x->cond(), rc)); // successor for a = b
a61af66fc99e Initial load
duke
parents:
diff changeset
678 BlockBegin* gtr_sux = x->sux_for(is_true(+1, x->cond(), rc)); // successor for a > b
a61af66fc99e Initial load
duke
parents:
diff changeset
679 BlockBegin* nan_sux = unordered_is_less ? lss_sux : gtr_sux ; // successor for unordered
a61af66fc99e Initial load
duke
parents:
diff changeset
680 // Note: At this point all successors (lss_sux, eql_sux, gtr_sux, nan_sux) are
a61af66fc99e Initial load
duke
parents:
diff changeset
681 // equal to x->tsux() or x->fsux(). Furthermore, nan_sux equals either
a61af66fc99e Initial load
duke
parents:
diff changeset
682 // lss_sux or gtr_sux.
a61af66fc99e Initial load
duke
parents:
diff changeset
683 if (lss_sux == eql_sux && eql_sux == gtr_sux) {
a61af66fc99e Initial load
duke
parents:
diff changeset
684 // all successors identical => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
685 set_canonical(new Goto(lss_sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
686 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // two successors differ and two successors are the same => simplify to: If (x cmp y)
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // determine new condition & successors
23822
626f594dffa6 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
csahu
parents: 20491
diff changeset
689 If::Condition cond = If::eql;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
690 BlockBegin* tsux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 BlockBegin* fsux = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
692 if (lss_sux == eql_sux) { cond = If::leq; tsux = lss_sux; fsux = gtr_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
693 else if (lss_sux == gtr_sux) { cond = If::neq; tsux = lss_sux; fsux = eql_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
694 else if (eql_sux == gtr_sux) { cond = If::geq; tsux = eql_sux; fsux = lss_sux; }
a61af66fc99e Initial load
duke
parents:
diff changeset
695 else { ShouldNotReachHere(); }
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
696 If* canon = new If(cmp->x(), cond, nan_sux == tsux, cmp->y(), tsux, fsux, cmp->state_before(), x->is_safepoint());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
697 if (cmp->x() == cmp->y()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 do_If(canon);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 } else {
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
700 if (compilation()->profile_branches()) {
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
701 // TODO: If profiling, leave floating point comparisons unoptimized.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
702 // We currently do not support profiling of the unordered case.
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
703 switch(cmp->op()) {
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
704 case Bytecodes::_fcmpl: case Bytecodes::_fcmpg:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
705 case Bytecodes::_dcmpl: case Bytecodes::_dcmpg:
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
706 set_canonical(x);
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
707 return;
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
708 }
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
709 }
6133
c8289830e172 7172843: C1: fix "assert(has_printable_bci()) failed: _printable_bci should have been set"
twisti
parents: 4966
diff changeset
710 set_bci(cmp->state_before()->bci());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
711 set_canonical(canon);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714 } else if (l->as_InstanceOf() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
715 // NOTE: Code permanently disabled for now since it leaves the old InstanceOf
a61af66fc99e Initial load
duke
parents:
diff changeset
716 // instruction in the graph (it is pinned). Need to fix this at some point.
1791
3a294e483abc 6919069: client compiler needs to capture more profile information for tiered work
iveresov
parents: 1783
diff changeset
717 // It should also be left in the graph when generating a profiled method version or Goto
3a294e483abc 6919069: client compiler needs to capture more profile information for tiered work
iveresov
parents: 1783
diff changeset
718 // has to know that it was an InstanceOf.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
719 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // pattern: If ((obj instanceof klass) cond rc) => simplify to: IfInstanceOf or: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
721 InstanceOf* inst = l->as_InstanceOf();
a61af66fc99e Initial load
duke
parents:
diff changeset
722 BlockBegin* is_inst_sux = x->sux_for(is_true(1, x->cond(), rc)); // successor for instanceof == 1
a61af66fc99e Initial load
duke
parents:
diff changeset
723 BlockBegin* no_inst_sux = x->sux_for(is_true(0, x->cond(), rc)); // successor for instanceof == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
724 if (is_inst_sux == no_inst_sux && inst->is_loaded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // both successors identical and klass is loaded => simplify to: Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
726 set_canonical(new Goto(is_inst_sux, x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
727 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // successors differ => simplify to: IfInstanceOf
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1791
diff changeset
729 set_canonical(new IfInstanceOf(inst->klass(), inst->obj(), true, inst->state_before()->bci(), is_inst_sux, no_inst_sux));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
732 } else if (rt == objectNull && (l->as_NewInstance() || l->as_NewArray())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
733 if (x->cond() == Instruction::eql) {
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
734 BlockBegin* sux = x->fsux();
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
735 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
736 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 assert(x->cond() == Instruction::neq, "only other valid case");
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
738 BlockBegin* sux = x->tsux();
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
739 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
740 }
a61af66fc99e Initial load
duke
parents:
diff changeset
741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
742 }
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744
a61af66fc99e Initial load
duke
parents:
diff changeset
745 void Canonicalizer::do_TableSwitch(TableSwitch* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 if (x->tag()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 int v = x->tag()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
748 BlockBegin* sux = x->default_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (v >= x->lo_key() && v <= x->hi_key()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 sux = x->sux_at(v - x->lo_key());
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
752 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
753 } else if (x->number_of_sux() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // NOTE: Code permanently disabled for now since the switch statement's
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // tag expression may produce side-effects in which case it must
a61af66fc99e Initial load
duke
parents:
diff changeset
756 // be executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
757 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // simplify to Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
759 set_canonical(new Goto(x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
760 } else if (x->number_of_sux() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 // NOTE: Code permanently disabled for now since it produces two new nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
762 // (Constant & If) and the Canonicalizer cannot return them correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
763 // yet. For now we copied the corresponding code directly into the
a61af66fc99e Initial load
duke
parents:
diff changeset
764 // GraphBuilder (i.e., we should never reach here).
a61af66fc99e Initial load
duke
parents:
diff changeset
765 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
766 // simplify to If
a61af66fc99e Initial load
duke
parents:
diff changeset
767 assert(x->lo_key() == x->hi_key(), "keys must be the same");
a61af66fc99e Initial load
duke
parents:
diff changeset
768 Constant* key = new Constant(new IntConstant(x->lo_key()));
a61af66fc99e Initial load
duke
parents:
diff changeset
769 set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773
a61af66fc99e Initial load
duke
parents:
diff changeset
774 void Canonicalizer::do_LookupSwitch(LookupSwitch* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (x->tag()->type()->is_constant()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 int v = x->tag()->type()->as_IntConstant()->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
777 BlockBegin* sux = x->default_sux();
a61af66fc99e Initial load
duke
parents:
diff changeset
778 for (int i = 0; i < x->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 if (v == x->key_at(i)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
780 sux = x->sux_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
781 }
a61af66fc99e Initial load
duke
parents:
diff changeset
782 }
4943
80107dc493db 7126041: jdk7u4 b05 and b06 crash with RubyMine 3.2.4, works well with b04
roland
parents: 2352
diff changeset
783 set_canonical(new Goto(sux, x->state_before(), is_safepoint(x, sux)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
784 } else if (x->number_of_sux() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 // NOTE: Code permanently disabled for now since the switch statement's
a61af66fc99e Initial load
duke
parents:
diff changeset
786 // tag expression may produce side-effects in which case it must
a61af66fc99e Initial load
duke
parents:
diff changeset
787 // be executed.
a61af66fc99e Initial load
duke
parents:
diff changeset
788 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
789 // simplify to Goto
a61af66fc99e Initial load
duke
parents:
diff changeset
790 set_canonical(new Goto(x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
791 } else if (x->number_of_sux() == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // NOTE: Code permanently disabled for now since it produces two new nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
793 // (Constant & If) and the Canonicalizer cannot return them correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // yet. For now we copied the corresponding code directly into the
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // GraphBuilder (i.e., we should never reach here).
a61af66fc99e Initial load
duke
parents:
diff changeset
796 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // simplify to If
a61af66fc99e Initial load
duke
parents:
diff changeset
798 assert(x->length() == 1, "length must be the same");
a61af66fc99e Initial load
duke
parents:
diff changeset
799 Constant* key = new Constant(new IntConstant(x->key_at(0)));
a61af66fc99e Initial load
duke
parents:
diff changeset
800 set_canonical(new If(x->tag(), If::eql, true, key, x->sux_at(0), x->default_sux(), x->state_before(), x->is_safepoint()));
a61af66fc99e Initial load
duke
parents:
diff changeset
801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803
a61af66fc99e Initial load
duke
parents:
diff changeset
804
a61af66fc99e Initial load
duke
parents:
diff changeset
805 void Canonicalizer::do_Return (Return* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
806 void Canonicalizer::do_Throw (Throw* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
807 void Canonicalizer::do_Base (Base* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
808 void Canonicalizer::do_OsrEntry (OsrEntry* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
809 void Canonicalizer::do_ExceptionObject(ExceptionObject* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 static bool match_index_and_scale(Instruction* instr,
a61af66fc99e Initial load
duke
parents:
diff changeset
812 Instruction** index,
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
813 int* log2_scale) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
814 // Skip conversion ops. This works only on 32bit because of the implicit l2i that the
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
815 // unsafe performs.
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
816 #ifndef _LP64
0
a61af66fc99e Initial load
duke
parents:
diff changeset
817 Convert* convert = instr->as_Convert();
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
818 if (convert != NULL && convert->op() == Bytecodes::_i2l) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
819 assert(convert->value()->type() == intType, "invalid input type");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
820 instr = convert->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
821 }
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
822 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824 ShiftOp* shift = instr->as_ShiftOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
825 if (shift != NULL) {
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
826 if (shift->op() == Bytecodes::_lshl) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
827 assert(shift->x()->type() == longType, "invalid input type");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
828 } else {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
829 #ifndef _LP64
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
830 if (shift->op() == Bytecodes::_ishl) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
831 assert(shift->x()->type() == intType, "invalid input type");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
832 } else {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
833 return false;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
834 }
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
835 #else
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
836 return false;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
837 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
838 }
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
839
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
840
0
a61af66fc99e Initial load
duke
parents:
diff changeset
841 // Constant shift value?
a61af66fc99e Initial load
duke
parents:
diff changeset
842 Constant* con = shift->y()->as_Constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
843 if (con == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
844 // Well-known type and value?
a61af66fc99e Initial load
duke
parents:
diff changeset
845 IntConstant* val = con->type()->as_IntConstant();
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
846 assert(val != NULL, "Should be an int constant");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
847
0
a61af66fc99e Initial load
duke
parents:
diff changeset
848 *index = shift->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
849 int tmp_scale = val->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
850 if (tmp_scale >= 0 && tmp_scale < 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
851 *log2_scale = tmp_scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
852 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
853 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858 ArithmeticOp* arith = instr->as_ArithmeticOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
859 if (arith != NULL) {
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
860 // See if either arg is a known constant
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
861 Constant* con = arith->x()->as_Constant();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
862 if (con != NULL) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
863 *index = arith->y();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
864 } else {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
865 con = arith->y()->as_Constant();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
866 if (con == NULL) return false;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
867 *index = arith->x();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
869 long const_value;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
870 // Check for integer multiply
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
871 if (arith->op() == Bytecodes::_lmul) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
872 assert((*index)->type() == longType, "invalid input type");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
873 LongConstant* val = con->type()->as_LongConstant();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
874 assert(val != NULL, "expecting a long constant");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
875 const_value = val->value();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
876 } else {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
877 #ifndef _LP64
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
878 if (arith->op() == Bytecodes::_imul) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
879 assert((*index)->type() == intType, "invalid input type");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
880 IntConstant* val = con->type()->as_IntConstant();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
881 assert(val != NULL, "expecting an int constant");
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
882 const_value = val->value();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
883 } else {
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
884 return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
885 }
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
886 #else
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
887 return false;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
888 #endif
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
889 }
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
890 switch (const_value) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
891 case 1: *log2_scale = 0; return true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
892 case 2: *log2_scale = 1; return true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
893 case 4: *log2_scale = 2; return true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
894 case 8: *log2_scale = 3; return true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
895 default: return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
896 }
a61af66fc99e Initial load
duke
parents:
diff changeset
897 }
a61af66fc99e Initial load
duke
parents:
diff changeset
898
a61af66fc99e Initial load
duke
parents:
diff changeset
899 // Unknown instruction sequence; don't touch it
a61af66fc99e Initial load
duke
parents:
diff changeset
900 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903
a61af66fc99e Initial load
duke
parents:
diff changeset
904 static bool match(UnsafeRawOp* x,
a61af66fc99e Initial load
duke
parents:
diff changeset
905 Instruction** base,
a61af66fc99e Initial load
duke
parents:
diff changeset
906 Instruction** index,
a61af66fc99e Initial load
duke
parents:
diff changeset
907 int* log2_scale) {
a61af66fc99e Initial load
duke
parents:
diff changeset
908 ArithmeticOp* root = x->base()->as_ArithmeticOp();
a61af66fc99e Initial load
duke
parents:
diff changeset
909 if (root == NULL) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
910 // Limit ourselves to addition for now
a61af66fc99e Initial load
duke
parents:
diff changeset
911 if (root->op() != Bytecodes::_ladd) return false;
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
912
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
913 bool match_found = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // Try to find shift or scale op
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
915 if (match_index_and_scale(root->y(), index, log2_scale)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
916 *base = root->x();
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
917 match_found = true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
918 } else if (match_index_and_scale(root->x(), index, log2_scale)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
919 *base = root->y();
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
920 match_found = true;
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
921 } else if (NOT_LP64(root->y()->as_Convert() != NULL) LP64_ONLY(false)) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
922 // Skipping i2l works only on 32bit because of the implicit l2i that the unsafe performs.
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
923 // 64bit needs a real sign-extending conversion.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
924 Convert* convert = root->y()->as_Convert();
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
925 if (convert->op() == Bytecodes::_i2l) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
926 assert(convert->value()->type() == intType, "should be an int");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
927 // pick base and index, setting scale at 1
a61af66fc99e Initial load
duke
parents:
diff changeset
928 *base = root->x();
a61af66fc99e Initial load
duke
parents:
diff changeset
929 *index = convert->value();
a61af66fc99e Initial load
duke
parents:
diff changeset
930 *log2_scale = 0;
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
931 match_found = true;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
932 }
20491
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
933 }
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
934 // The default solution
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
935 if (!match_found) {
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
936 *base = root->x();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
937 *index = root->y();
a60a1309a03a 8058744: Crash in C1 OSRed method w/ Unsafe usage
iveresov
parents: 14223
diff changeset
938 *log2_scale = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
939 }
a61af66fc99e Initial load
duke
parents:
diff changeset
940
a61af66fc99e Initial load
duke
parents:
diff changeset
941 // If the value is pinned then it will be always be computed so
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // there's no profit to reshaping the expression.
a61af66fc99e Initial load
duke
parents:
diff changeset
943 return !root->is_pinned();
a61af66fc99e Initial load
duke
parents:
diff changeset
944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946
a61af66fc99e Initial load
duke
parents:
diff changeset
947 void Canonicalizer::do_UnsafeRawOp(UnsafeRawOp* x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
948 Instruction* base = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
949 Instruction* index = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
950 int log2_scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
951
a61af66fc99e Initial load
duke
parents:
diff changeset
952 if (match(x, &base, &index, &log2_scale)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
953 x->set_base(base);
a61af66fc99e Initial load
duke
parents:
diff changeset
954 x->set_index(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 x->set_log2_scale(log2_scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
956 if (PrintUnsafeOptimization) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 tty->print_cr("Canonicalizer: UnsafeRawOp id %d: base = id %d, index = id %d, log2_scale = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
958 x->id(), x->base()->id(), x->index()->id(), x->log2_scale());
a61af66fc99e Initial load
duke
parents:
diff changeset
959 }
a61af66fc99e Initial load
duke
parents:
diff changeset
960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
961 }
a61af66fc99e Initial load
duke
parents:
diff changeset
962
a61af66fc99e Initial load
duke
parents:
diff changeset
963 void Canonicalizer::do_RoundFP(RoundFP* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
964 void Canonicalizer::do_UnsafeGetRaw(UnsafeGetRaw* x) { if (OptimizeUnsafes) do_UnsafeRawOp(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
965 void Canonicalizer::do_UnsafePutRaw(UnsafePutRaw* x) { if (OptimizeUnsafes) do_UnsafeRawOp(x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
966 void Canonicalizer::do_UnsafeGetObject(UnsafeGetObject* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
967 void Canonicalizer::do_UnsafePutObject(UnsafePutObject* x) {}
6795
7eca5de9e0b6 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 6266
diff changeset
968 void Canonicalizer::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
969 void Canonicalizer::do_UnsafePrefetchRead (UnsafePrefetchRead* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
970 void Canonicalizer::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
971 void Canonicalizer::do_ProfileCall(ProfileCall* x) {}
12882
ce0cc25bc5e2 8026054: New type profiling points: type of return values at calls
roland
parents: 9156
diff changeset
972 void Canonicalizer::do_ProfileReturnType(ProfileReturnType* x) {}
1783
d5d065957597 6953144: Tiered compilation
iveresov
parents: 1584
diff changeset
973 void Canonicalizer::do_ProfileInvoke(ProfileInvoke* x) {}
2166
403dc4c1d7f5 6809483: hotspot:::method_entry are not correctly generated for "method()V"
never
parents: 1972
diff changeset
974 void Canonicalizer::do_RuntimeCall(RuntimeCall* x) {}
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 6842
diff changeset
975 void Canonicalizer::do_RangeCheckPredicate(RangeCheckPredicate* x) {}
9156
acadb114c818 8011648: C1: optimized build is broken after 7153771
roland
parents: 8860
diff changeset
976 #ifdef ASSERT
8860
46f6f063b272 7153771: array bound check elimination for c1
roland
parents: 6842
diff changeset
977 void Canonicalizer::do_Assert(Assert* x) {}
9156
acadb114c818 8011648: C1: optimized build is broken after 7153771
roland
parents: 8860
diff changeset
978 #endif
4966
701a83c86f28 7120481: storeStore barrier in constructor with final field
jiangli
parents: 4943
diff changeset
979 void Canonicalizer::do_MemBar(MemBar* x) {}