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