Mercurial > hg > truffle
annotate src/share/vm/c1/c1_LIRGenerator.cpp @ 1816:87b64980e2f1
6972540: sun/nio/ch/SocketChannelImpl compilation crashed when executing CompileTheWorld
Reviewed-by: kvn
author | never |
---|---|
date | Wed, 22 Sep 2010 21:10:46 -0700 |
parents | d5d065957597 |
children | f02a8bbe6ed4 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1378
diff
changeset
|
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1378
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1378
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:
1378
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_c1_LIRGenerator.cpp.incl" | |
27 | |
28 #ifdef ASSERT | |
29 #define __ gen()->lir(__FILE__, __LINE__)-> | |
30 #else | |
31 #define __ gen()->lir()-> | |
32 #endif | |
33 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
34 // TODO: ARM - Use some recognizable constant which still fits architectural constraints |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
35 #ifdef ARM |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
36 #define PATCHED_ADDR (204) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
37 #else |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
38 #define PATCHED_ADDR (max_jint) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
39 #endif |
0 | 40 |
41 void PhiResolverState::reset(int max_vregs) { | |
42 // Initialize array sizes | |
43 _virtual_operands.at_put_grow(max_vregs - 1, NULL, NULL); | |
44 _virtual_operands.trunc_to(0); | |
45 _other_operands.at_put_grow(max_vregs - 1, NULL, NULL); | |
46 _other_operands.trunc_to(0); | |
47 _vreg_table.at_put_grow(max_vregs - 1, NULL, NULL); | |
48 _vreg_table.trunc_to(0); | |
49 } | |
50 | |
51 | |
52 | |
53 //-------------------------------------------------------------- | |
54 // PhiResolver | |
55 | |
56 // Resolves cycles: | |
57 // | |
58 // r1 := r2 becomes temp := r1 | |
59 // r2 := r1 r1 := r2 | |
60 // r2 := temp | |
61 // and orders moves: | |
62 // | |
63 // r2 := r3 becomes r1 := r2 | |
64 // r1 := r2 r2 := r3 | |
65 | |
66 PhiResolver::PhiResolver(LIRGenerator* gen, int max_vregs) | |
67 : _gen(gen) | |
68 , _state(gen->resolver_state()) | |
69 , _temp(LIR_OprFact::illegalOpr) | |
70 { | |
71 // reinitialize the shared state arrays | |
72 _state.reset(max_vregs); | |
73 } | |
74 | |
75 | |
76 void PhiResolver::emit_move(LIR_Opr src, LIR_Opr dest) { | |
77 assert(src->is_valid(), ""); | |
78 assert(dest->is_valid(), ""); | |
79 __ move(src, dest); | |
80 } | |
81 | |
82 | |
83 void PhiResolver::move_temp_to(LIR_Opr dest) { | |
84 assert(_temp->is_valid(), ""); | |
85 emit_move(_temp, dest); | |
86 NOT_PRODUCT(_temp = LIR_OprFact::illegalOpr); | |
87 } | |
88 | |
89 | |
90 void PhiResolver::move_to_temp(LIR_Opr src) { | |
91 assert(_temp->is_illegal(), ""); | |
92 _temp = _gen->new_register(src->type()); | |
93 emit_move(src, _temp); | |
94 } | |
95 | |
96 | |
97 // Traverse assignment graph in depth first order and generate moves in post order | |
98 // ie. two assignments: b := c, a := b start with node c: | |
99 // Call graph: move(NULL, c) -> move(c, b) -> move(b, a) | |
100 // Generates moves in this order: move b to a and move c to b | |
101 // ie. cycle a := b, b := a start with node a | |
102 // Call graph: move(NULL, a) -> move(a, b) -> move(b, a) | |
103 // Generates moves in this order: move b to temp, move a to b, move temp to a | |
104 void PhiResolver::move(ResolveNode* src, ResolveNode* dest) { | |
105 if (!dest->visited()) { | |
106 dest->set_visited(); | |
107 for (int i = dest->no_of_destinations()-1; i >= 0; i --) { | |
108 move(dest, dest->destination_at(i)); | |
109 } | |
110 } else if (!dest->start_node()) { | |
111 // cylce in graph detected | |
112 assert(_loop == NULL, "only one loop valid!"); | |
113 _loop = dest; | |
114 move_to_temp(src->operand()); | |
115 return; | |
116 } // else dest is a start node | |
117 | |
118 if (!dest->assigned()) { | |
119 if (_loop == dest) { | |
120 move_temp_to(dest->operand()); | |
121 dest->set_assigned(); | |
122 } else if (src != NULL) { | |
123 emit_move(src->operand(), dest->operand()); | |
124 dest->set_assigned(); | |
125 } | |
126 } | |
127 } | |
128 | |
129 | |
130 PhiResolver::~PhiResolver() { | |
131 int i; | |
132 // resolve any cycles in moves from and to virtual registers | |
133 for (i = virtual_operands().length() - 1; i >= 0; i --) { | |
134 ResolveNode* node = virtual_operands()[i]; | |
135 if (!node->visited()) { | |
136 _loop = NULL; | |
137 move(NULL, node); | |
138 node->set_start_node(); | |
139 assert(_temp->is_illegal(), "move_temp_to() call missing"); | |
140 } | |
141 } | |
142 | |
143 // generate move for move from non virtual register to abitrary destination | |
144 for (i = other_operands().length() - 1; i >= 0; i --) { | |
145 ResolveNode* node = other_operands()[i]; | |
146 for (int j = node->no_of_destinations() - 1; j >= 0; j --) { | |
147 emit_move(node->operand(), node->destination_at(j)->operand()); | |
148 } | |
149 } | |
150 } | |
151 | |
152 | |
153 ResolveNode* PhiResolver::create_node(LIR_Opr opr, bool source) { | |
154 ResolveNode* node; | |
155 if (opr->is_virtual()) { | |
156 int vreg_num = opr->vreg_number(); | |
157 node = vreg_table().at_grow(vreg_num, NULL); | |
158 assert(node == NULL || node->operand() == opr, ""); | |
159 if (node == NULL) { | |
160 node = new ResolveNode(opr); | |
161 vreg_table()[vreg_num] = node; | |
162 } | |
163 // Make sure that all virtual operands show up in the list when | |
164 // they are used as the source of a move. | |
165 if (source && !virtual_operands().contains(node)) { | |
166 virtual_operands().append(node); | |
167 } | |
168 } else { | |
169 assert(source, ""); | |
170 node = new ResolveNode(opr); | |
171 other_operands().append(node); | |
172 } | |
173 return node; | |
174 } | |
175 | |
176 | |
177 void PhiResolver::move(LIR_Opr src, LIR_Opr dest) { | |
178 assert(dest->is_virtual(), ""); | |
179 // tty->print("move "); src->print(); tty->print(" to "); dest->print(); tty->cr(); | |
180 assert(src->is_valid(), ""); | |
181 assert(dest->is_valid(), ""); | |
182 ResolveNode* source = source_node(src); | |
183 source->append(destination_node(dest)); | |
184 } | |
185 | |
186 | |
187 //-------------------------------------------------------------- | |
188 // LIRItem | |
189 | |
190 void LIRItem::set_result(LIR_Opr opr) { | |
191 assert(value()->operand()->is_illegal() || value()->operand()->is_constant(), "operand should never change"); | |
192 value()->set_operand(opr); | |
193 | |
194 if (opr->is_virtual()) { | |
195 _gen->_instruction_for_operand.at_put_grow(opr->vreg_number(), value(), NULL); | |
196 } | |
197 | |
198 _result = opr; | |
199 } | |
200 | |
201 void LIRItem::load_item() { | |
202 if (result()->is_illegal()) { | |
203 // update the items result | |
204 _result = value()->operand(); | |
205 } | |
206 if (!result()->is_register()) { | |
207 LIR_Opr reg = _gen->new_register(value()->type()); | |
208 __ move(result(), reg); | |
209 if (result()->is_constant()) { | |
210 _result = reg; | |
211 } else { | |
212 set_result(reg); | |
213 } | |
214 } | |
215 } | |
216 | |
217 | |
218 void LIRItem::load_for_store(BasicType type) { | |
219 if (_gen->can_store_as_constant(value(), type)) { | |
220 _result = value()->operand(); | |
221 if (!_result->is_constant()) { | |
222 _result = LIR_OprFact::value_type(value()->type()); | |
223 } | |
224 } else if (type == T_BYTE || type == T_BOOLEAN) { | |
225 load_byte_item(); | |
226 } else { | |
227 load_item(); | |
228 } | |
229 } | |
230 | |
231 void LIRItem::load_item_force(LIR_Opr reg) { | |
232 LIR_Opr r = result(); | |
233 if (r != reg) { | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
234 #if !defined(ARM) && !defined(E500V2) |
0 | 235 if (r->type() != reg->type()) { |
236 // moves between different types need an intervening spill slot | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
237 r = _gen->force_to_spill(r, reg->type()); |
0 | 238 } |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
239 #endif |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
240 __ move(r, reg); |
0 | 241 _result = reg; |
242 } | |
243 } | |
244 | |
245 ciObject* LIRItem::get_jobject_constant() const { | |
246 ObjectType* oc = type()->as_ObjectType(); | |
247 if (oc) { | |
248 return oc->constant_value(); | |
249 } | |
250 return NULL; | |
251 } | |
252 | |
253 | |
254 jint LIRItem::get_jint_constant() const { | |
255 assert(is_constant() && value() != NULL, ""); | |
256 assert(type()->as_IntConstant() != NULL, "type check"); | |
257 return type()->as_IntConstant()->value(); | |
258 } | |
259 | |
260 | |
261 jint LIRItem::get_address_constant() const { | |
262 assert(is_constant() && value() != NULL, ""); | |
263 assert(type()->as_AddressConstant() != NULL, "type check"); | |
264 return type()->as_AddressConstant()->value(); | |
265 } | |
266 | |
267 | |
268 jfloat LIRItem::get_jfloat_constant() const { | |
269 assert(is_constant() && value() != NULL, ""); | |
270 assert(type()->as_FloatConstant() != NULL, "type check"); | |
271 return type()->as_FloatConstant()->value(); | |
272 } | |
273 | |
274 | |
275 jdouble LIRItem::get_jdouble_constant() const { | |
276 assert(is_constant() && value() != NULL, ""); | |
277 assert(type()->as_DoubleConstant() != NULL, "type check"); | |
278 return type()->as_DoubleConstant()->value(); | |
279 } | |
280 | |
281 | |
282 jlong LIRItem::get_jlong_constant() const { | |
283 assert(is_constant() && value() != NULL, ""); | |
284 assert(type()->as_LongConstant() != NULL, "type check"); | |
285 return type()->as_LongConstant()->value(); | |
286 } | |
287 | |
288 | |
289 | |
290 //-------------------------------------------------------------- | |
291 | |
292 | |
293 void LIRGenerator::init() { | |
342 | 294 _bs = Universe::heap()->barrier_set(); |
0 | 295 } |
296 | |
297 | |
298 void LIRGenerator::block_do_prolog(BlockBegin* block) { | |
299 #ifndef PRODUCT | |
300 if (PrintIRWithLIR) { | |
301 block->print(); | |
302 } | |
303 #endif | |
304 | |
305 // set up the list of LIR instructions | |
306 assert(block->lir() == NULL, "LIR list already computed for this block"); | |
307 _lir = new LIR_List(compilation(), block); | |
308 block->set_lir(_lir); | |
309 | |
310 __ branch_destination(block->label()); | |
311 | |
312 if (LIRTraceExecution && | |
1584 | 313 Compilation::current()->hir()->start()->block_id() != block->block_id() && |
0 | 314 !block->is_set(BlockBegin::exception_entry_flag)) { |
315 assert(block->lir()->instructions_list()->length() == 1, "should come right after br_dst"); | |
316 trace_block_entry(block); | |
317 } | |
318 } | |
319 | |
320 | |
321 void LIRGenerator::block_do_epilog(BlockBegin* block) { | |
322 #ifndef PRODUCT | |
323 if (PrintIRWithLIR) { | |
324 tty->cr(); | |
325 } | |
326 #endif | |
327 | |
328 // LIR_Opr for unpinned constants shouldn't be referenced by other | |
329 // blocks so clear them out after processing the block. | |
330 for (int i = 0; i < _unpinned_constants.length(); i++) { | |
331 _unpinned_constants.at(i)->clear_operand(); | |
332 } | |
333 _unpinned_constants.trunc_to(0); | |
334 | |
335 // clear our any registers for other local constants | |
336 _constants.trunc_to(0); | |
337 _reg_for_constants.trunc_to(0); | |
338 } | |
339 | |
340 | |
341 void LIRGenerator::block_do(BlockBegin* block) { | |
342 CHECK_BAILOUT(); | |
343 | |
344 block_do_prolog(block); | |
345 set_block(block); | |
346 | |
347 for (Instruction* instr = block; instr != NULL; instr = instr->next()) { | |
348 if (instr->is_pinned()) do_root(instr); | |
349 } | |
350 | |
351 set_block(NULL); | |
352 block_do_epilog(block); | |
353 } | |
354 | |
355 | |
356 //-------------------------LIRGenerator----------------------------- | |
357 | |
358 // This is where the tree-walk starts; instr must be root; | |
359 void LIRGenerator::do_root(Value instr) { | |
360 CHECK_BAILOUT(); | |
361 | |
362 InstructionMark im(compilation(), instr); | |
363 | |
364 assert(instr->is_pinned(), "use only with roots"); | |
365 assert(instr->subst() == instr, "shouldn't have missed substitution"); | |
366 | |
367 instr->visit(this); | |
368 | |
369 assert(!instr->has_uses() || instr->operand()->is_valid() || | |
370 instr->as_Constant() != NULL || bailed_out(), "invalid item set"); | |
371 } | |
372 | |
373 | |
374 // This is called for each node in tree; the walk stops if a root is reached | |
375 void LIRGenerator::walk(Value instr) { | |
376 InstructionMark im(compilation(), instr); | |
377 //stop walk when encounter a root | |
378 if (instr->is_pinned() && instr->as_Phi() == NULL || instr->operand()->is_valid()) { | |
379 assert(instr->operand() != LIR_OprFact::illegalOpr || instr->as_Constant() != NULL, "this root has not yet been visited"); | |
380 } else { | |
381 assert(instr->subst() == instr, "shouldn't have missed substitution"); | |
382 instr->visit(this); | |
383 // assert(instr->use_count() > 0 || instr->as_Phi() != NULL, "leaf instruction must have a use"); | |
384 } | |
385 } | |
386 | |
387 | |
388 CodeEmitInfo* LIRGenerator::state_for(Instruction* x, ValueStack* state, bool ignore_xhandler) { | |
389 int index; | |
390 Value value; | |
391 for_each_stack_value(state, index, value) { | |
392 assert(value->subst() == value, "missed substition"); | |
393 if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) { | |
394 walk(value); | |
395 assert(value->operand()->is_valid(), "must be evaluated now"); | |
396 } | |
397 } | |
398 ValueStack* s = state; | |
399 int bci = x->bci(); | |
400 for_each_state(s) { | |
401 IRScope* scope = s->scope(); | |
402 ciMethod* method = scope->method(); | |
403 | |
404 MethodLivenessResult liveness = method->liveness_at_bci(bci); | |
405 if (bci == SynchronizationEntryBCI) { | |
406 if (x->as_ExceptionObject() || x->as_Throw()) { | |
407 // all locals are dead on exit from the synthetic unlocker | |
408 liveness.clear(); | |
409 } else { | |
410 assert(x->as_MonitorEnter(), "only other case is MonitorEnter"); | |
411 } | |
412 } | |
413 if (!liveness.is_valid()) { | |
414 // Degenerate or breakpointed method. | |
415 bailout("Degenerate or breakpointed method"); | |
416 } else { | |
417 assert((int)liveness.size() == s->locals_size(), "error in use of liveness"); | |
418 for_each_local_value(s, index, value) { | |
419 assert(value->subst() == value, "missed substition"); | |
420 if (liveness.at(index) && !value->type()->is_illegal()) { | |
421 if (!value->is_pinned() && value->as_Constant() == NULL && value->as_Local() == NULL) { | |
422 walk(value); | |
423 assert(value->operand()->is_valid(), "must be evaluated now"); | |
424 } | |
425 } else { | |
426 // NULL out this local so that linear scan can assume that all non-NULL values are live. | |
427 s->invalidate_local(index); | |
428 } | |
429 } | |
430 } | |
431 bci = scope->caller_bci(); | |
432 } | |
433 | |
434 return new CodeEmitInfo(x->bci(), state, ignore_xhandler ? NULL : x->exception_handlers()); | |
435 } | |
436 | |
437 | |
438 CodeEmitInfo* LIRGenerator::state_for(Instruction* x) { | |
439 return state_for(x, x->lock_stack()); | |
440 } | |
441 | |
442 | |
443 void LIRGenerator::jobject2reg_with_patching(LIR_Opr r, ciObject* obj, CodeEmitInfo* info) { | |
444 if (!obj->is_loaded() || PatchALot) { | |
445 assert(info != NULL, "info must be set if class is not loaded"); | |
446 __ oop2reg_patch(NULL, r, info); | |
447 } else { | |
448 // no patching needed | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
819
diff
changeset
|
449 __ oop2reg(obj->constant_encoding(), r); |
0 | 450 } |
451 } | |
452 | |
453 | |
454 void LIRGenerator::array_range_check(LIR_Opr array, LIR_Opr index, | |
455 CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info) { | |
456 CodeStub* stub = new RangeCheckStub(range_check_info, index); | |
457 if (index->is_constant()) { | |
458 cmp_mem_int(lir_cond_belowEqual, array, arrayOopDesc::length_offset_in_bytes(), | |
459 index->as_jint(), null_check_info); | |
460 __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch | |
461 } else { | |
462 cmp_reg_mem(lir_cond_aboveEqual, index, array, | |
463 arrayOopDesc::length_offset_in_bytes(), T_INT, null_check_info); | |
464 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch | |
465 } | |
466 } | |
467 | |
468 | |
469 void LIRGenerator::nio_range_check(LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) { | |
470 CodeStub* stub = new RangeCheckStub(info, index, true); | |
471 if (index->is_constant()) { | |
472 cmp_mem_int(lir_cond_belowEqual, buffer, java_nio_Buffer::limit_offset(), index->as_jint(), info); | |
473 __ branch(lir_cond_belowEqual, T_INT, stub); // forward branch | |
474 } else { | |
475 cmp_reg_mem(lir_cond_aboveEqual, index, buffer, | |
476 java_nio_Buffer::limit_offset(), T_INT, info); | |
477 __ branch(lir_cond_aboveEqual, T_INT, stub); // forward branch | |
478 } | |
479 __ move(index, result); | |
480 } | |
481 | |
482 | |
483 | |
484 void LIRGenerator::arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp_op, CodeEmitInfo* info) { | |
485 LIR_Opr result_op = result; | |
486 LIR_Opr left_op = left; | |
487 LIR_Opr right_op = right; | |
488 | |
489 if (TwoOperandLIRForm && left_op != result_op) { | |
490 assert(right_op != result_op, "malformed"); | |
491 __ move(left_op, result_op); | |
492 left_op = result_op; | |
493 } | |
494 | |
495 switch(code) { | |
496 case Bytecodes::_dadd: | |
497 case Bytecodes::_fadd: | |
498 case Bytecodes::_ladd: | |
499 case Bytecodes::_iadd: __ add(left_op, right_op, result_op); break; | |
500 case Bytecodes::_fmul: | |
501 case Bytecodes::_lmul: __ mul(left_op, right_op, result_op); break; | |
502 | |
503 case Bytecodes::_dmul: | |
504 { | |
505 if (is_strictfp) { | |
506 __ mul_strictfp(left_op, right_op, result_op, tmp_op); break; | |
507 } else { | |
508 __ mul(left_op, right_op, result_op); break; | |
509 } | |
510 } | |
511 break; | |
512 | |
513 case Bytecodes::_imul: | |
514 { | |
515 bool did_strength_reduce = false; | |
516 | |
517 if (right->is_constant()) { | |
518 int c = right->as_jint(); | |
519 if (is_power_of_2(c)) { | |
520 // do not need tmp here | |
521 __ shift_left(left_op, exact_log2(c), result_op); | |
522 did_strength_reduce = true; | |
523 } else { | |
524 did_strength_reduce = strength_reduce_multiply(left_op, c, result_op, tmp_op); | |
525 } | |
526 } | |
527 // we couldn't strength reduce so just emit the multiply | |
528 if (!did_strength_reduce) { | |
529 __ mul(left_op, right_op, result_op); | |
530 } | |
531 } | |
532 break; | |
533 | |
534 case Bytecodes::_dsub: | |
535 case Bytecodes::_fsub: | |
536 case Bytecodes::_lsub: | |
537 case Bytecodes::_isub: __ sub(left_op, right_op, result_op); break; | |
538 | |
539 case Bytecodes::_fdiv: __ div (left_op, right_op, result_op); break; | |
540 // ldiv and lrem are implemented with a direct runtime call | |
541 | |
542 case Bytecodes::_ddiv: | |
543 { | |
544 if (is_strictfp) { | |
545 __ div_strictfp (left_op, right_op, result_op, tmp_op); break; | |
546 } else { | |
547 __ div (left_op, right_op, result_op); break; | |
548 } | |
549 } | |
550 break; | |
551 | |
552 case Bytecodes::_drem: | |
553 case Bytecodes::_frem: __ rem (left_op, right_op, result_op); break; | |
554 | |
555 default: ShouldNotReachHere(); | |
556 } | |
557 } | |
558 | |
559 | |
560 void LIRGenerator::arithmetic_op_int(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp) { | |
561 arithmetic_op(code, result, left, right, false, tmp); | |
562 } | |
563 | |
564 | |
565 void LIRGenerator::arithmetic_op_long(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) { | |
566 arithmetic_op(code, result, left, right, false, LIR_OprFact::illegalOpr, info); | |
567 } | |
568 | |
569 | |
570 void LIRGenerator::arithmetic_op_fpu(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp) { | |
571 arithmetic_op(code, result, left, right, is_strictfp, tmp); | |
572 } | |
573 | |
574 | |
575 void LIRGenerator::shift_op(Bytecodes::Code code, LIR_Opr result_op, LIR_Opr value, LIR_Opr count, LIR_Opr tmp) { | |
576 if (TwoOperandLIRForm && value != result_op) { | |
577 assert(count != result_op, "malformed"); | |
578 __ move(value, result_op); | |
579 value = result_op; | |
580 } | |
581 | |
582 assert(count->is_constant() || count->is_register(), "must be"); | |
583 switch(code) { | |
584 case Bytecodes::_ishl: | |
585 case Bytecodes::_lshl: __ shift_left(value, count, result_op, tmp); break; | |
586 case Bytecodes::_ishr: | |
587 case Bytecodes::_lshr: __ shift_right(value, count, result_op, tmp); break; | |
588 case Bytecodes::_iushr: | |
589 case Bytecodes::_lushr: __ unsigned_shift_right(value, count, result_op, tmp); break; | |
590 default: ShouldNotReachHere(); | |
591 } | |
592 } | |
593 | |
594 | |
595 void LIRGenerator::logic_op (Bytecodes::Code code, LIR_Opr result_op, LIR_Opr left_op, LIR_Opr right_op) { | |
596 if (TwoOperandLIRForm && left_op != result_op) { | |
597 assert(right_op != result_op, "malformed"); | |
598 __ move(left_op, result_op); | |
599 left_op = result_op; | |
600 } | |
601 | |
602 switch(code) { | |
603 case Bytecodes::_iand: | |
604 case Bytecodes::_land: __ logical_and(left_op, right_op, result_op); break; | |
605 | |
606 case Bytecodes::_ior: | |
607 case Bytecodes::_lor: __ logical_or(left_op, right_op, result_op); break; | |
608 | |
609 case Bytecodes::_ixor: | |
610 case Bytecodes::_lxor: __ logical_xor(left_op, right_op, result_op); break; | |
611 | |
612 default: ShouldNotReachHere(); | |
613 } | |
614 } | |
615 | |
616 | |
617 void LIRGenerator::monitor_enter(LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info) { | |
618 if (!GenerateSynchronizationCode) return; | |
619 // for slow path, use debug info for state after successful locking | |
620 CodeStub* slow_path = new MonitorEnterStub(object, lock, info); | |
621 __ load_stack_address_monitor(monitor_no, lock); | |
622 // for handling NullPointerException, use debug info representing just the lock stack before this monitorenter | |
623 __ lock_object(hdr, object, lock, scratch, slow_path, info_for_exception); | |
624 } | |
625 | |
626 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
627 void LIRGenerator::monitor_exit(LIR_Opr object, LIR_Opr lock, LIR_Opr new_hdr, LIR_Opr scratch, int monitor_no) { |
0 | 628 if (!GenerateSynchronizationCode) return; |
629 // setup registers | |
630 LIR_Opr hdr = lock; | |
631 lock = new_hdr; | |
632 CodeStub* slow_path = new MonitorExitStub(lock, UseFastLocking, monitor_no); | |
633 __ load_stack_address_monitor(monitor_no, lock); | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
634 __ unlock_object(hdr, object, lock, scratch, slow_path); |
0 | 635 } |
636 | |
637 | |
638 void LIRGenerator::new_instance(LIR_Opr dst, ciInstanceKlass* klass, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info) { | |
639 jobject2reg_with_patching(klass_reg, klass, info); | |
640 // If klass is not loaded we do not know if the klass has finalizers: | |
641 if (UseFastNewInstance && klass->is_loaded() | |
642 && !Klass::layout_helper_needs_slow_path(klass->layout_helper())) { | |
643 | |
644 Runtime1::StubID stub_id = klass->is_initialized() ? Runtime1::fast_new_instance_id : Runtime1::fast_new_instance_init_check_id; | |
645 | |
646 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, stub_id); | |
647 | |
648 assert(klass->is_loaded(), "must be loaded"); | |
649 // allocate space for instance | |
650 assert(klass->size_helper() >= 0, "illegal instance size"); | |
651 const int instance_size = align_object_size(klass->size_helper()); | |
652 __ allocate_object(dst, scratch1, scratch2, scratch3, scratch4, | |
653 oopDesc::header_size(), instance_size, klass_reg, !klass->is_initialized(), slow_path); | |
654 } else { | |
655 CodeStub* slow_path = new NewInstanceStub(klass_reg, dst, klass, info, Runtime1::new_instance_id); | |
656 __ branch(lir_cond_always, T_ILLEGAL, slow_path); | |
657 __ branch_destination(slow_path->continuation()); | |
658 } | |
659 } | |
660 | |
661 | |
662 static bool is_constant_zero(Instruction* inst) { | |
663 IntConstant* c = inst->type()->as_IntConstant(); | |
664 if (c) { | |
665 return (c->value() == 0); | |
666 } | |
667 return false; | |
668 } | |
669 | |
670 | |
671 static bool positive_constant(Instruction* inst) { | |
672 IntConstant* c = inst->type()->as_IntConstant(); | |
673 if (c) { | |
674 return (c->value() >= 0); | |
675 } | |
676 return false; | |
677 } | |
678 | |
679 | |
680 static ciArrayKlass* as_array_klass(ciType* type) { | |
681 if (type != NULL && type->is_array_klass() && type->is_loaded()) { | |
682 return (ciArrayKlass*)type; | |
683 } else { | |
684 return NULL; | |
685 } | |
686 } | |
687 | |
688 void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { | |
689 Instruction* src = x->argument_at(0); | |
690 Instruction* src_pos = x->argument_at(1); | |
691 Instruction* dst = x->argument_at(2); | |
692 Instruction* dst_pos = x->argument_at(3); | |
693 Instruction* length = x->argument_at(4); | |
694 | |
695 // first try to identify the likely type of the arrays involved | |
696 ciArrayKlass* expected_type = NULL; | |
697 bool is_exact = false; | |
698 { | |
699 ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); | |
700 ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); | |
701 ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); | |
702 ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); | |
703 if (src_exact_type != NULL && src_exact_type == dst_exact_type) { | |
704 // the types exactly match so the type is fully known | |
705 is_exact = true; | |
706 expected_type = src_exact_type; | |
707 } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) { | |
708 ciArrayKlass* dst_type = (ciArrayKlass*) dst_exact_type; | |
709 ciArrayKlass* src_type = NULL; | |
710 if (src_exact_type != NULL && src_exact_type->is_obj_array_klass()) { | |
711 src_type = (ciArrayKlass*) src_exact_type; | |
712 } else if (src_declared_type != NULL && src_declared_type->is_obj_array_klass()) { | |
713 src_type = (ciArrayKlass*) src_declared_type; | |
714 } | |
715 if (src_type != NULL) { | |
716 if (src_type->element_type()->is_subtype_of(dst_type->element_type())) { | |
717 is_exact = true; | |
718 expected_type = dst_type; | |
719 } | |
720 } | |
721 } | |
722 // at least pass along a good guess | |
723 if (expected_type == NULL) expected_type = dst_exact_type; | |
724 if (expected_type == NULL) expected_type = src_declared_type; | |
725 if (expected_type == NULL) expected_type = dst_declared_type; | |
726 } | |
727 | |
728 // if a probable array type has been identified, figure out if any | |
729 // of the required checks for a fast case can be elided. | |
730 int flags = LIR_OpArrayCopy::all_flags; | |
731 if (expected_type != NULL) { | |
732 // try to skip null checks | |
733 if (src->as_NewArray() != NULL) | |
734 flags &= ~LIR_OpArrayCopy::src_null_check; | |
735 if (dst->as_NewArray() != NULL) | |
736 flags &= ~LIR_OpArrayCopy::dst_null_check; | |
737 | |
738 // check from incoming constant values | |
739 if (positive_constant(src_pos)) | |
740 flags &= ~LIR_OpArrayCopy::src_pos_positive_check; | |
741 if (positive_constant(dst_pos)) | |
742 flags &= ~LIR_OpArrayCopy::dst_pos_positive_check; | |
743 if (positive_constant(length)) | |
744 flags &= ~LIR_OpArrayCopy::length_positive_check; | |
745 | |
746 // see if the range check can be elided, which might also imply | |
747 // that src or dst is non-null. | |
748 ArrayLength* al = length->as_ArrayLength(); | |
749 if (al != NULL) { | |
750 if (al->array() == src) { | |
751 // it's the length of the source array | |
752 flags &= ~LIR_OpArrayCopy::length_positive_check; | |
753 flags &= ~LIR_OpArrayCopy::src_null_check; | |
754 if (is_constant_zero(src_pos)) | |
755 flags &= ~LIR_OpArrayCopy::src_range_check; | |
756 } | |
757 if (al->array() == dst) { | |
758 // it's the length of the destination array | |
759 flags &= ~LIR_OpArrayCopy::length_positive_check; | |
760 flags &= ~LIR_OpArrayCopy::dst_null_check; | |
761 if (is_constant_zero(dst_pos)) | |
762 flags &= ~LIR_OpArrayCopy::dst_range_check; | |
763 } | |
764 } | |
765 if (is_exact) { | |
766 flags &= ~LIR_OpArrayCopy::type_check; | |
767 } | |
768 } | |
769 | |
770 if (src == dst) { | |
771 // moving within a single array so no type checks are needed | |
772 if (flags & LIR_OpArrayCopy::type_check) { | |
773 flags &= ~LIR_OpArrayCopy::type_check; | |
774 } | |
775 } | |
776 *flagsp = flags; | |
777 *expected_typep = (ciArrayKlass*)expected_type; | |
778 } | |
779 | |
780 | |
781 LIR_Opr LIRGenerator::round_item(LIR_Opr opr) { | |
782 assert(opr->is_register(), "why spill if item is not register?"); | |
783 | |
784 if (RoundFPResults && UseSSE < 1 && opr->is_single_fpu()) { | |
785 LIR_Opr result = new_register(T_FLOAT); | |
786 set_vreg_flag(result, must_start_in_memory); | |
787 assert(opr->is_register(), "only a register can be spilled"); | |
788 assert(opr->value_type()->is_float(), "rounding only for floats available"); | |
789 __ roundfp(opr, LIR_OprFact::illegalOpr, result); | |
790 return result; | |
791 } | |
792 return opr; | |
793 } | |
794 | |
795 | |
796 LIR_Opr LIRGenerator::force_to_spill(LIR_Opr value, BasicType t) { | |
797 assert(type2size[t] == type2size[value->type()], "size mismatch"); | |
798 if (!value->is_register()) { | |
799 // force into a register | |
800 LIR_Opr r = new_register(value->type()); | |
801 __ move(value, r); | |
802 value = r; | |
803 } | |
804 | |
805 // create a spill location | |
806 LIR_Opr tmp = new_register(t); | |
807 set_vreg_flag(tmp, LIRGenerator::must_start_in_memory); | |
808 | |
809 // move from register to spill | |
810 __ move(value, tmp); | |
811 return tmp; | |
812 } | |
813 | |
814 void LIRGenerator::profile_branch(If* if_instr, If::Condition cond) { | |
815 if (if_instr->should_profile()) { | |
816 ciMethod* method = if_instr->profiled_method(); | |
817 assert(method != NULL, "method should be set if branch is profiled"); | |
818 ciMethodData* md = method->method_data(); | |
819 if (md == NULL) { | |
820 bailout("out of memory building methodDataOop"); | |
821 return; | |
822 } | |
823 ciProfileData* data = md->bci_to_data(if_instr->profiled_bci()); | |
824 assert(data != NULL, "must have profiling data"); | |
825 assert(data->is_BranchData(), "need BranchData for two-way branches"); | |
826 int taken_count_offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); | |
827 int not_taken_count_offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); | |
1783 | 828 if (if_instr->is_swapped()) { |
829 int t = taken_count_offset; | |
830 taken_count_offset = not_taken_count_offset; | |
831 not_taken_count_offset = t; | |
832 } | |
833 | |
0 | 834 LIR_Opr md_reg = new_register(T_OBJECT); |
1783 | 835 __ oop2reg(md->constant_encoding(), md_reg); |
836 | |
837 LIR_Opr data_offset_reg = new_pointer_register(); | |
0 | 838 __ cmove(lir_cond(cond), |
1783 | 839 LIR_OprFact::intptrConst(taken_count_offset), |
840 LIR_OprFact::intptrConst(not_taken_count_offset), | |
0 | 841 data_offset_reg); |
1783 | 842 |
843 // MDO cells are intptr_t, so the data_reg width is arch-dependent. | |
844 LIR_Opr data_reg = new_pointer_register(); | |
845 LIR_Address* data_addr = new LIR_Address(md_reg, data_offset_reg, data_reg->type()); | |
0 | 846 __ move(LIR_OprFact::address(data_addr), data_reg); |
1783 | 847 // Use leal instead of add to avoid destroying condition codes on x86 |
0 | 848 LIR_Address* fake_incr_value = new LIR_Address(data_reg, DataLayout::counter_increment, T_INT); |
849 __ leal(LIR_OprFact::address(fake_incr_value), data_reg); | |
850 __ move(data_reg, LIR_OprFact::address(data_addr)); | |
851 } | |
852 } | |
853 | |
854 // Phi technique: | |
855 // This is about passing live values from one basic block to the other. | |
856 // In code generated with Java it is rather rare that more than one | |
857 // value is on the stack from one basic block to the other. | |
858 // We optimize our technique for efficient passing of one value | |
859 // (of type long, int, double..) but it can be extended. | |
860 // When entering or leaving a basic block, all registers and all spill | |
861 // slots are release and empty. We use the released registers | |
862 // and spill slots to pass the live values from one block | |
863 // to the other. The topmost value, i.e., the value on TOS of expression | |
864 // stack is passed in registers. All other values are stored in spilling | |
865 // area. Every Phi has an index which designates its spill slot | |
866 // At exit of a basic block, we fill the register(s) and spill slots. | |
867 // At entry of a basic block, the block_prolog sets up the content of phi nodes | |
868 // and locks necessary registers and spilling slots. | |
869 | |
870 | |
871 // move current value to referenced phi function | |
872 void LIRGenerator::move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val) { | |
873 Phi* phi = sux_val->as_Phi(); | |
874 // cur_val can be null without phi being null in conjunction with inlining | |
875 if (phi != NULL && cur_val != NULL && cur_val != phi && !phi->is_illegal()) { | |
876 LIR_Opr operand = cur_val->operand(); | |
877 if (cur_val->operand()->is_illegal()) { | |
878 assert(cur_val->as_Constant() != NULL || cur_val->as_Local() != NULL, | |
879 "these can be produced lazily"); | |
880 operand = operand_for_instruction(cur_val); | |
881 } | |
882 resolver->move(operand, operand_for_instruction(phi)); | |
883 } | |
884 } | |
885 | |
886 | |
887 // Moves all stack values into their PHI position | |
888 void LIRGenerator::move_to_phi(ValueStack* cur_state) { | |
889 BlockBegin* bb = block(); | |
890 if (bb->number_of_sux() == 1) { | |
891 BlockBegin* sux = bb->sux_at(0); | |
892 assert(sux->number_of_preds() > 0, "invalid CFG"); | |
893 | |
894 // a block with only one predecessor never has phi functions | |
895 if (sux->number_of_preds() > 1) { | |
896 int max_phis = cur_state->stack_size() + cur_state->locals_size(); | |
897 PhiResolver resolver(this, _virtual_register_number + max_phis * 2); | |
898 | |
899 ValueStack* sux_state = sux->state(); | |
900 Value sux_value; | |
901 int index; | |
902 | |
903 for_each_stack_value(sux_state, index, sux_value) { | |
904 move_to_phi(&resolver, cur_state->stack_at(index), sux_value); | |
905 } | |
906 | |
907 // Inlining may cause the local state not to match up, so walk up | |
908 // the caller state until we get to the same scope as the | |
909 // successor and then start processing from there. | |
910 while (cur_state->scope() != sux_state->scope()) { | |
911 cur_state = cur_state->caller_state(); | |
912 assert(cur_state != NULL, "scopes don't match up"); | |
913 } | |
914 | |
915 for_each_local_value(sux_state, index, sux_value) { | |
916 move_to_phi(&resolver, cur_state->local_at(index), sux_value); | |
917 } | |
918 | |
919 assert(cur_state->caller_state() == sux_state->caller_state(), "caller states must be equal"); | |
920 } | |
921 } | |
922 } | |
923 | |
924 | |
925 LIR_Opr LIRGenerator::new_register(BasicType type) { | |
926 int vreg = _virtual_register_number; | |
927 // add a little fudge factor for the bailout, since the bailout is | |
928 // only checked periodically. This gives a few extra registers to | |
929 // hand out before we really run out, which helps us keep from | |
930 // tripping over assertions. | |
931 if (vreg + 20 >= LIR_OprDesc::vreg_max) { | |
932 bailout("out of virtual registers"); | |
933 if (vreg + 2 >= LIR_OprDesc::vreg_max) { | |
934 // wrap it around | |
935 _virtual_register_number = LIR_OprDesc::vreg_base; | |
936 } | |
937 } | |
938 _virtual_register_number += 1; | |
939 return LIR_OprFact::virtual_register(vreg, type); | |
940 } | |
941 | |
942 | |
943 // Try to lock using register in hint | |
944 LIR_Opr LIRGenerator::rlock(Value instr) { | |
945 return new_register(instr->type()); | |
946 } | |
947 | |
948 | |
949 // does an rlock and sets result | |
950 LIR_Opr LIRGenerator::rlock_result(Value x) { | |
951 LIR_Opr reg = rlock(x); | |
952 set_result(x, reg); | |
953 return reg; | |
954 } | |
955 | |
956 | |
957 // does an rlock and sets result | |
958 LIR_Opr LIRGenerator::rlock_result(Value x, BasicType type) { | |
959 LIR_Opr reg; | |
960 switch (type) { | |
961 case T_BYTE: | |
962 case T_BOOLEAN: | |
963 reg = rlock_byte(type); | |
964 break; | |
965 default: | |
966 reg = rlock(x); | |
967 break; | |
968 } | |
969 | |
970 set_result(x, reg); | |
971 return reg; | |
972 } | |
973 | |
974 | |
975 //--------------------------------------------------------------------- | |
976 ciObject* LIRGenerator::get_jobject_constant(Value value) { | |
977 ObjectType* oc = value->type()->as_ObjectType(); | |
978 if (oc) { | |
979 return oc->constant_value(); | |
980 } | |
981 return NULL; | |
982 } | |
983 | |
984 | |
985 void LIRGenerator::do_ExceptionObject(ExceptionObject* x) { | |
986 assert(block()->is_set(BlockBegin::exception_entry_flag), "ExceptionObject only allowed in exception handler block"); | |
987 assert(block()->next() == x, "ExceptionObject must be first instruction of block"); | |
988 | |
989 // no moves are created for phi functions at the begin of exception | |
990 // handlers, so assign operands manually here | |
991 for_each_phi_fun(block(), phi, | |
992 operand_for_instruction(phi)); | |
993 | |
994 LIR_Opr thread_reg = getThreadPointer(); | |
995 __ move(new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT), | |
996 exceptionOopOpr()); | |
997 __ move(LIR_OprFact::oopConst(NULL), | |
998 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_oop_offset()), T_OBJECT)); | |
999 __ move(LIR_OprFact::oopConst(NULL), | |
1000 new LIR_Address(thread_reg, in_bytes(JavaThread::exception_pc_offset()), T_OBJECT)); | |
1001 | |
1002 LIR_Opr result = new_register(T_OBJECT); | |
1003 __ move(exceptionOopOpr(), result); | |
1004 set_result(x, result); | |
1005 } | |
1006 | |
1007 | |
1008 //---------------------------------------------------------------------- | |
1009 //---------------------------------------------------------------------- | |
1010 //---------------------------------------------------------------------- | |
1011 //---------------------------------------------------------------------- | |
1012 // visitor functions | |
1013 //---------------------------------------------------------------------- | |
1014 //---------------------------------------------------------------------- | |
1015 //---------------------------------------------------------------------- | |
1016 //---------------------------------------------------------------------- | |
1017 | |
1018 void LIRGenerator::do_Phi(Phi* x) { | |
1019 // phi functions are never visited directly | |
1020 ShouldNotReachHere(); | |
1021 } | |
1022 | |
1023 | |
1024 // Code for a constant is generated lazily unless the constant is frequently used and can't be inlined. | |
1025 void LIRGenerator::do_Constant(Constant* x) { | |
1026 if (x->state() != NULL) { | |
1027 // Any constant with a ValueStack requires patching so emit the patch here | |
1028 LIR_Opr reg = rlock_result(x); | |
1029 CodeEmitInfo* info = state_for(x, x->state()); | |
1030 __ oop2reg_patch(NULL, reg, info); | |
1031 } else if (x->use_count() > 1 && !can_inline_as_constant(x)) { | |
1032 if (!x->is_pinned()) { | |
1033 // unpinned constants are handled specially so that they can be | |
1034 // put into registers when they are used multiple times within a | |
1035 // block. After the block completes their operand will be | |
1036 // cleared so that other blocks can't refer to that register. | |
1037 set_result(x, load_constant(x)); | |
1038 } else { | |
1039 LIR_Opr res = x->operand(); | |
1040 if (!res->is_valid()) { | |
1041 res = LIR_OprFact::value_type(x->type()); | |
1042 } | |
1043 if (res->is_constant()) { | |
1044 LIR_Opr reg = rlock_result(x); | |
1045 __ move(res, reg); | |
1046 } else { | |
1047 set_result(x, res); | |
1048 } | |
1049 } | |
1050 } else { | |
1051 set_result(x, LIR_OprFact::value_type(x->type())); | |
1052 } | |
1053 } | |
1054 | |
1055 | |
1056 void LIRGenerator::do_Local(Local* x) { | |
1057 // operand_for_instruction has the side effect of setting the result | |
1058 // so there's no need to do it here. | |
1059 operand_for_instruction(x); | |
1060 } | |
1061 | |
1062 | |
1063 void LIRGenerator::do_IfInstanceOf(IfInstanceOf* x) { | |
1064 Unimplemented(); | |
1065 } | |
1066 | |
1067 | |
1068 void LIRGenerator::do_Return(Return* x) { | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
579
diff
changeset
|
1069 if (compilation()->env()->dtrace_method_probes()) { |
0 | 1070 BasicTypeList signature; |
1071 signature.append(T_INT); // thread | |
1072 signature.append(T_OBJECT); // methodOop | |
1073 LIR_OprList* args = new LIR_OprList(); | |
1074 args->append(getThreadPointer()); | |
1075 LIR_Opr meth = new_register(T_OBJECT); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
819
diff
changeset
|
1076 __ oop2reg(method()->constant_encoding(), meth); |
0 | 1077 args->append(meth); |
1078 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), voidType, NULL); | |
1079 } | |
1080 | |
1081 if (x->type()->is_void()) { | |
1082 __ return_op(LIR_OprFact::illegalOpr); | |
1083 } else { | |
1084 LIR_Opr reg = result_register_for(x->type(), /*callee=*/true); | |
1085 LIRItem result(x->result(), this); | |
1086 | |
1087 result.load_item_force(reg); | |
1088 __ return_op(result.result()); | |
1089 } | |
1090 set_no_result(x); | |
1091 } | |
1092 | |
1093 | |
1094 // Example: object.getClass () | |
1095 void LIRGenerator::do_getClass(Intrinsic* x) { | |
1096 assert(x->number_of_arguments() == 1, "wrong type"); | |
1097 | |
1098 LIRItem rcvr(x->argument_at(0), this); | |
1099 rcvr.load_item(); | |
1100 LIR_Opr result = rlock_result(x); | |
1101 | |
1102 // need to perform the null check on the rcvr | |
1103 CodeEmitInfo* info = NULL; | |
1104 if (x->needs_null_check()) { | |
1105 info = state_for(x, x->state()->copy_locks()); | |
1106 } | |
1107 __ move(new LIR_Address(rcvr.result(), oopDesc::klass_offset_in_bytes(), T_OBJECT), result, info); | |
1108 __ move(new LIR_Address(result, Klass::java_mirror_offset_in_bytes() + | |
1109 klassOopDesc::klass_part_offset_in_bytes(), T_OBJECT), result); | |
1110 } | |
1111 | |
1112 | |
1113 // Example: Thread.currentThread() | |
1114 void LIRGenerator::do_currentThread(Intrinsic* x) { | |
1115 assert(x->number_of_arguments() == 0, "wrong type"); | |
1116 LIR_Opr reg = rlock_result(x); | |
1117 __ load(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::threadObj_offset()), T_OBJECT), reg); | |
1118 } | |
1119 | |
1120 | |
1121 void LIRGenerator::do_RegisterFinalizer(Intrinsic* x) { | |
1122 assert(x->number_of_arguments() == 1, "wrong type"); | |
1123 LIRItem receiver(x->argument_at(0), this); | |
1124 | |
1125 receiver.load_item(); | |
1126 BasicTypeList signature; | |
1127 signature.append(T_OBJECT); // receiver | |
1128 LIR_OprList* args = new LIR_OprList(); | |
1129 args->append(receiver.result()); | |
1130 CodeEmitInfo* info = state_for(x, x->state()); | |
1131 call_runtime(&signature, args, | |
1132 CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::register_finalizer_id)), | |
1133 voidType, info); | |
1134 | |
1135 set_no_result(x); | |
1136 } | |
1137 | |
1138 | |
1139 //------------------------local access-------------------------------------- | |
1140 | |
1141 LIR_Opr LIRGenerator::operand_for_instruction(Instruction* x) { | |
1142 if (x->operand()->is_illegal()) { | |
1143 Constant* c = x->as_Constant(); | |
1144 if (c != NULL) { | |
1145 x->set_operand(LIR_OprFact::value_type(c->type())); | |
1146 } else { | |
1147 assert(x->as_Phi() || x->as_Local() != NULL, "only for Phi and Local"); | |
1148 // allocate a virtual register for this local or phi | |
1149 x->set_operand(rlock(x)); | |
1150 _instruction_for_operand.at_put_grow(x->operand()->vreg_number(), x, NULL); | |
1151 } | |
1152 } | |
1153 return x->operand(); | |
1154 } | |
1155 | |
1156 | |
1157 Instruction* LIRGenerator::instruction_for_opr(LIR_Opr opr) { | |
1158 if (opr->is_virtual()) { | |
1159 return instruction_for_vreg(opr->vreg_number()); | |
1160 } | |
1161 return NULL; | |
1162 } | |
1163 | |
1164 | |
1165 Instruction* LIRGenerator::instruction_for_vreg(int reg_num) { | |
1166 if (reg_num < _instruction_for_operand.length()) { | |
1167 return _instruction_for_operand.at(reg_num); | |
1168 } | |
1169 return NULL; | |
1170 } | |
1171 | |
1172 | |
1173 void LIRGenerator::set_vreg_flag(int vreg_num, VregFlag f) { | |
1174 if (_vreg_flags.size_in_bits() == 0) { | |
1175 BitMap2D temp(100, num_vreg_flags); | |
1176 temp.clear(); | |
1177 _vreg_flags = temp; | |
1178 } | |
1179 _vreg_flags.at_put_grow(vreg_num, f, true); | |
1180 } | |
1181 | |
1182 bool LIRGenerator::is_vreg_flag_set(int vreg_num, VregFlag f) { | |
1183 if (!_vreg_flags.is_valid_index(vreg_num, f)) { | |
1184 return false; | |
1185 } | |
1186 return _vreg_flags.at(vreg_num, f); | |
1187 } | |
1188 | |
1189 | |
1190 // Block local constant handling. This code is useful for keeping | |
1191 // unpinned constants and constants which aren't exposed in the IR in | |
1192 // registers. Unpinned Constant instructions have their operands | |
1193 // cleared when the block is finished so that other blocks can't end | |
1194 // up referring to their registers. | |
1195 | |
1196 LIR_Opr LIRGenerator::load_constant(Constant* x) { | |
1197 assert(!x->is_pinned(), "only for unpinned constants"); | |
1198 _unpinned_constants.append(x); | |
1199 return load_constant(LIR_OprFact::value_type(x->type())->as_constant_ptr()); | |
1200 } | |
1201 | |
1202 | |
1203 LIR_Opr LIRGenerator::load_constant(LIR_Const* c) { | |
1204 BasicType t = c->type(); | |
1205 for (int i = 0; i < _constants.length(); i++) { | |
1206 LIR_Const* other = _constants.at(i); | |
1207 if (t == other->type()) { | |
1208 switch (t) { | |
1209 case T_INT: | |
1210 case T_FLOAT: | |
1211 if (c->as_jint_bits() != other->as_jint_bits()) continue; | |
1212 break; | |
1213 case T_LONG: | |
1214 case T_DOUBLE: | |
486
a738a625039a
6757316: load_constant() produces a wrong long constant, with high a low words swapped
never
parents:
380
diff
changeset
|
1215 if (c->as_jint_hi_bits() != other->as_jint_hi_bits()) continue; |
a738a625039a
6757316: load_constant() produces a wrong long constant, with high a low words swapped
never
parents:
380
diff
changeset
|
1216 if (c->as_jint_lo_bits() != other->as_jint_lo_bits()) continue; |
0 | 1217 break; |
1218 case T_OBJECT: | |
1219 if (c->as_jobject() != other->as_jobject()) continue; | |
1220 break; | |
1221 } | |
1222 return _reg_for_constants.at(i); | |
1223 } | |
1224 } | |
1225 | |
1226 LIR_Opr result = new_register(t); | |
1227 __ move((LIR_Opr)c, result); | |
1228 _constants.append(c); | |
1229 _reg_for_constants.append(result); | |
1230 return result; | |
1231 } | |
1232 | |
1233 // Various barriers | |
1234 | |
342 | 1235 void LIRGenerator::pre_barrier(LIR_Opr addr_opr, bool patch, CodeEmitInfo* info) { |
1236 // Do the pre-write barrier, if any. | |
1237 switch (_bs->kind()) { | |
1238 #ifndef SERIALGC | |
1239 case BarrierSet::G1SATBCT: | |
1240 case BarrierSet::G1SATBCTLogging: | |
1241 G1SATBCardTableModRef_pre_barrier(addr_opr, patch, info); | |
1242 break; | |
1243 #endif // SERIALGC | |
1244 case BarrierSet::CardTableModRef: | |
1245 case BarrierSet::CardTableExtension: | |
1246 // No pre barriers | |
1247 break; | |
1248 case BarrierSet::ModRef: | |
1249 case BarrierSet::Other: | |
1250 // No pre barriers | |
1251 break; | |
1252 default : | |
1253 ShouldNotReachHere(); | |
1254 | |
1255 } | |
1256 } | |
1257 | |
0 | 1258 void LIRGenerator::post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) { |
342 | 1259 switch (_bs->kind()) { |
1260 #ifndef SERIALGC | |
1261 case BarrierSet::G1SATBCT: | |
1262 case BarrierSet::G1SATBCTLogging: | |
1263 G1SATBCardTableModRef_post_barrier(addr, new_val); | |
1264 break; | |
1265 #endif // SERIALGC | |
0 | 1266 case BarrierSet::CardTableModRef: |
1267 case BarrierSet::CardTableExtension: | |
1268 CardTableModRef_post_barrier(addr, new_val); | |
1269 break; | |
1270 case BarrierSet::ModRef: | |
1271 case BarrierSet::Other: | |
1272 // No post barriers | |
1273 break; | |
1274 default : | |
1275 ShouldNotReachHere(); | |
1276 } | |
1277 } | |
1278 | |
342 | 1279 //////////////////////////////////////////////////////////////////////// |
1280 #ifndef SERIALGC | |
1281 | |
1282 void LIRGenerator::G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, bool patch, CodeEmitInfo* info) { | |
1283 if (G1DisablePreBarrier) return; | |
1284 | |
1285 // First we test whether marking is in progress. | |
1286 BasicType flag_type; | |
1287 if (in_bytes(PtrQueue::byte_width_of_active()) == 4) { | |
1288 flag_type = T_INT; | |
1289 } else { | |
1290 guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1, | |
1291 "Assumption"); | |
1292 flag_type = T_BYTE; | |
1293 } | |
1294 LIR_Opr thrd = getThreadPointer(); | |
1295 LIR_Address* mark_active_flag_addr = | |
1296 new LIR_Address(thrd, | |
1297 in_bytes(JavaThread::satb_mark_queue_offset() + | |
1298 PtrQueue::byte_offset_of_active()), | |
1299 flag_type); | |
1300 // Read the marking-in-progress flag. | |
1301 LIR_Opr flag_val = new_register(T_INT); | |
1302 __ load(mark_active_flag_addr, flag_val); | |
1303 | |
1304 LIR_PatchCode pre_val_patch_code = | |
1305 patch ? lir_patch_normal : lir_patch_none; | |
1306 | |
1307 LIR_Opr pre_val = new_register(T_OBJECT); | |
1308 | |
1309 __ cmp(lir_cond_notEqual, flag_val, LIR_OprFact::intConst(0)); | |
1310 if (!addr_opr->is_address()) { | |
1311 assert(addr_opr->is_register(), "must be"); | |
1572 | 1312 addr_opr = LIR_OprFact::address(new LIR_Address(addr_opr, T_OBJECT)); |
342 | 1313 } |
1314 CodeStub* slow = new G1PreBarrierStub(addr_opr, pre_val, pre_val_patch_code, | |
1315 info); | |
1316 __ branch(lir_cond_notEqual, T_INT, slow); | |
1317 __ branch_destination(slow->continuation()); | |
1318 } | |
1319 | |
1320 void LIRGenerator::G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) { | |
1321 if (G1DisablePostBarrier) return; | |
1322 | |
1323 // If the "new_val" is a constant NULL, no barrier is necessary. | |
1324 if (new_val->is_constant() && | |
1325 new_val->as_constant_ptr()->as_jobject() == NULL) return; | |
1326 | |
1327 if (!new_val->is_register()) { | |
1572 | 1328 LIR_Opr new_val_reg = new_register(T_OBJECT); |
342 | 1329 if (new_val->is_constant()) { |
1330 __ move(new_val, new_val_reg); | |
1331 } else { | |
1332 __ leal(new_val, new_val_reg); | |
1333 } | |
1334 new_val = new_val_reg; | |
1335 } | |
1336 assert(new_val->is_register(), "must be a register at this point"); | |
1337 | |
1338 if (addr->is_address()) { | |
1339 LIR_Address* address = addr->as_address_ptr(); | |
1572 | 1340 LIR_Opr ptr = new_register(T_OBJECT); |
342 | 1341 if (!address->index()->is_valid() && address->disp() == 0) { |
1342 __ move(address->base(), ptr); | |
1343 } else { | |
1344 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); | |
1345 __ leal(addr, ptr); | |
1346 } | |
1347 addr = ptr; | |
1348 } | |
1349 assert(addr->is_register(), "must be a register at this point"); | |
1350 | |
1351 LIR_Opr xor_res = new_pointer_register(); | |
1352 LIR_Opr xor_shift_res = new_pointer_register(); | |
1353 if (TwoOperandLIRForm ) { | |
1354 __ move(addr, xor_res); | |
1355 __ logical_xor(xor_res, new_val, xor_res); | |
1356 __ move(xor_res, xor_shift_res); | |
1357 __ unsigned_shift_right(xor_shift_res, | |
1358 LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes), | |
1359 xor_shift_res, | |
1360 LIR_OprDesc::illegalOpr()); | |
1361 } else { | |
1362 __ logical_xor(addr, new_val, xor_res); | |
1363 __ unsigned_shift_right(xor_res, | |
1364 LIR_OprFact::intConst(HeapRegion::LogOfHRGrainBytes), | |
1365 xor_shift_res, | |
1366 LIR_OprDesc::illegalOpr()); | |
1367 } | |
1368 | |
1369 if (!new_val->is_register()) { | |
1572 | 1370 LIR_Opr new_val_reg = new_register(T_OBJECT); |
342 | 1371 __ leal(new_val, new_val_reg); |
1372 new_val = new_val_reg; | |
1373 } | |
1374 assert(new_val->is_register(), "must be a register at this point"); | |
1375 | |
1376 __ cmp(lir_cond_notEqual, xor_shift_res, LIR_OprFact::intptrConst(NULL_WORD)); | |
1377 | |
1378 CodeStub* slow = new G1PostBarrierStub(addr, new_val); | |
1572 | 1379 __ branch(lir_cond_notEqual, LP64_ONLY(T_LONG) NOT_LP64(T_INT), slow); |
342 | 1380 __ branch_destination(slow->continuation()); |
1381 } | |
1382 | |
1383 #endif // SERIALGC | |
1384 //////////////////////////////////////////////////////////////////////// | |
1385 | |
0 | 1386 void LIRGenerator::CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val) { |
1387 | |
342 | 1388 assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code"); |
1389 LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base); | |
0 | 1390 if (addr->is_address()) { |
1391 LIR_Address* address = addr->as_address_ptr(); | |
1392 LIR_Opr ptr = new_register(T_OBJECT); | |
1393 if (!address->index()->is_valid() && address->disp() == 0) { | |
1394 __ move(address->base(), ptr); | |
1395 } else { | |
1396 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); | |
1397 __ leal(addr, ptr); | |
1398 } | |
1399 addr = ptr; | |
1400 } | |
1401 assert(addr->is_register(), "must be a register at this point"); | |
1402 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1403 #ifdef ARM |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1404 // TODO: ARM - move to platform-dependent code |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1405 LIR_Opr tmp = FrameMap::R14_opr; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1406 if (VM_Version::supports_movw()) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1407 __ move((LIR_Opr)card_table_base, tmp); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1408 } else { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1409 __ move(new LIR_Address(FrameMap::Rthread_opr, in_bytes(JavaThread::card_table_base_offset()), T_ADDRESS), tmp); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1410 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1411 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1412 CardTableModRefBS* ct = (CardTableModRefBS*)_bs; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1413 LIR_Address *card_addr = new LIR_Address(tmp, addr, (LIR_Address::Scale) -CardTableModRefBS::card_shift, 0, T_BYTE); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1414 if(((int)ct->byte_map_base & 0xff) == 0) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1415 __ move(tmp, card_addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1416 } else { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1417 LIR_Opr tmp_zero = new_register(T_INT); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1418 __ move(LIR_OprFact::intConst(0), tmp_zero); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1419 __ move(tmp_zero, card_addr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1420 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1421 #else // ARM |
0 | 1422 LIR_Opr tmp = new_pointer_register(); |
1423 if (TwoOperandLIRForm) { | |
1424 __ move(addr, tmp); | |
1425 __ unsigned_shift_right(tmp, CardTableModRefBS::card_shift, tmp); | |
1426 } else { | |
1427 __ unsigned_shift_right(addr, CardTableModRefBS::card_shift, tmp); | |
1428 } | |
1429 if (can_inline_as_constant(card_table_base)) { | |
1430 __ move(LIR_OprFact::intConst(0), | |
1431 new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE)); | |
1432 } else { | |
1433 __ move(LIR_OprFact::intConst(0), | |
1434 new LIR_Address(tmp, load_constant(card_table_base), | |
1435 T_BYTE)); | |
1436 } | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1437 #endif // ARM |
0 | 1438 } |
1439 | |
1440 | |
1441 //------------------------field access-------------------------------------- | |
1442 | |
1443 // Comment copied form templateTable_i486.cpp | |
1444 // ---------------------------------------------------------------------------- | |
1445 // Volatile variables demand their effects be made known to all CPU's in | |
1446 // order. Store buffers on most chips allow reads & writes to reorder; the | |
1447 // JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of | |
1448 // memory barrier (i.e., it's not sufficient that the interpreter does not | |
1449 // reorder volatile references, the hardware also must not reorder them). | |
1450 // | |
1451 // According to the new Java Memory Model (JMM): | |
1452 // (1) All volatiles are serialized wrt to each other. | |
1453 // ALSO reads & writes act as aquire & release, so: | |
1454 // (2) A read cannot let unrelated NON-volatile memory refs that happen after | |
1455 // the read float up to before the read. It's OK for non-volatile memory refs | |
1456 // that happen before the volatile read to float down below it. | |
1457 // (3) Similar a volatile write cannot let unrelated NON-volatile memory refs | |
1458 // that happen BEFORE the write float down to after the write. It's OK for | |
1459 // non-volatile memory refs that happen after the volatile write to float up | |
1460 // before it. | |
1461 // | |
1462 // We only put in barriers around volatile refs (they are expensive), not | |
1463 // _between_ memory refs (that would require us to track the flavor of the | |
1464 // previous memory refs). Requirements (2) and (3) require some barriers | |
1465 // before volatile stores and after volatile loads. These nearly cover | |
1466 // requirement (1) but miss the volatile-store-volatile-load case. This final | |
1467 // case is placed after volatile-stores although it could just as well go | |
1468 // before volatile-loads. | |
1469 | |
1470 | |
1471 void LIRGenerator::do_StoreField(StoreField* x) { | |
1472 bool needs_patching = x->needs_patching(); | |
1473 bool is_volatile = x->field()->is_volatile(); | |
1474 BasicType field_type = x->field_type(); | |
1475 bool is_oop = (field_type == T_ARRAY || field_type == T_OBJECT); | |
1476 | |
1477 CodeEmitInfo* info = NULL; | |
1478 if (needs_patching) { | |
1479 assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access"); | |
1480 info = state_for(x, x->state_before()); | |
1481 } else if (x->needs_null_check()) { | |
1482 NullCheck* nc = x->explicit_null_check(); | |
1483 if (nc == NULL) { | |
1484 info = state_for(x, x->lock_stack()); | |
1485 } else { | |
1486 info = state_for(nc); | |
1487 } | |
1488 } | |
1489 | |
1490 | |
1491 LIRItem object(x->obj(), this); | |
1492 LIRItem value(x->value(), this); | |
1493 | |
1494 object.load_item(); | |
1495 | |
1496 if (is_volatile || needs_patching) { | |
1497 // load item if field is volatile (fewer special cases for volatiles) | |
1498 // load item if field not initialized | |
1499 // load item if field not constant | |
1500 // because of code patching we cannot inline constants | |
1501 if (field_type == T_BYTE || field_type == T_BOOLEAN) { | |
1502 value.load_byte_item(); | |
1503 } else { | |
1504 value.load_item(); | |
1505 } | |
1506 } else { | |
1507 value.load_for_store(field_type); | |
1508 } | |
1509 | |
1510 set_no_result(x); | |
1511 | |
1512 if (PrintNotLoaded && needs_patching) { | |
1513 tty->print_cr(" ###class not loaded at store_%s bci %d", | |
1514 x->is_static() ? "static" : "field", x->bci()); | |
1515 } | |
1516 | |
1517 if (x->needs_null_check() && | |
1518 (needs_patching || | |
1519 MacroAssembler::needs_explicit_null_check(x->offset()))) { | |
1520 // emit an explicit null check because the offset is too large | |
1521 __ null_check(object.result(), new CodeEmitInfo(info)); | |
1522 } | |
1523 | |
1524 LIR_Address* address; | |
1525 if (needs_patching) { | |
1526 // we need to patch the offset in the instruction so don't allow | |
1527 // generate_address to try to be smart about emitting the -1. | |
1528 // Otherwise the patching code won't know how to find the | |
1529 // instruction to patch. | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1530 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type); |
0 | 1531 } else { |
1532 address = generate_address(object.result(), x->offset(), field_type); | |
1533 } | |
1534 | |
1535 if (is_volatile && os::is_MP()) { | |
1536 __ membar_release(); | |
1537 } | |
1538 | |
342 | 1539 if (is_oop) { |
1540 // Do the pre-write barrier, if any. | |
1541 pre_barrier(LIR_OprFact::address(address), | |
1542 needs_patching, | |
1543 (info ? new CodeEmitInfo(info) : NULL)); | |
1544 } | |
1545 | |
0 | 1546 if (is_volatile) { |
1547 assert(!needs_patching && x->is_loaded(), | |
1548 "how do we know it's volatile if it's not loaded"); | |
1549 volatile_field_store(value.result(), address, info); | |
1550 } else { | |
1551 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; | |
1552 __ store(value.result(), address, info, patch_code); | |
1553 } | |
1554 | |
1555 if (is_oop) { | |
819
c6386080541b
6849574: VM crash using NonBlockingHashMap (high_scale_lib)
never
parents:
780
diff
changeset
|
1556 // Store to object so mark the card of the header |
0 | 1557 post_barrier(object.result(), value.result()); |
1558 } | |
1559 | |
1560 if (is_volatile && os::is_MP()) { | |
1561 __ membar(); | |
1562 } | |
1563 } | |
1564 | |
1565 | |
1566 void LIRGenerator::do_LoadField(LoadField* x) { | |
1567 bool needs_patching = x->needs_patching(); | |
1568 bool is_volatile = x->field()->is_volatile(); | |
1569 BasicType field_type = x->field_type(); | |
1570 | |
1571 CodeEmitInfo* info = NULL; | |
1572 if (needs_patching) { | |
1573 assert(x->explicit_null_check() == NULL, "can't fold null check into patching field access"); | |
1574 info = state_for(x, x->state_before()); | |
1575 } else if (x->needs_null_check()) { | |
1576 NullCheck* nc = x->explicit_null_check(); | |
1577 if (nc == NULL) { | |
1578 info = state_for(x, x->lock_stack()); | |
1579 } else { | |
1580 info = state_for(nc); | |
1581 } | |
1582 } | |
1583 | |
1584 LIRItem object(x->obj(), this); | |
1585 | |
1586 object.load_item(); | |
1587 | |
1588 if (PrintNotLoaded && needs_patching) { | |
1589 tty->print_cr(" ###class not loaded at load_%s bci %d", | |
1590 x->is_static() ? "static" : "field", x->bci()); | |
1591 } | |
1592 | |
1593 if (x->needs_null_check() && | |
1594 (needs_patching || | |
1595 MacroAssembler::needs_explicit_null_check(x->offset()))) { | |
1596 // emit an explicit null check because the offset is too large | |
1597 __ null_check(object.result(), new CodeEmitInfo(info)); | |
1598 } | |
1599 | |
1600 LIR_Opr reg = rlock_result(x, field_type); | |
1601 LIR_Address* address; | |
1602 if (needs_patching) { | |
1603 // we need to patch the offset in the instruction so don't allow | |
1604 // generate_address to try to be smart about emitting the -1. | |
1605 // Otherwise the patching code won't know how to find the | |
1606 // instruction to patch. | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1607 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type); |
0 | 1608 } else { |
1609 address = generate_address(object.result(), x->offset(), field_type); | |
1610 } | |
1611 | |
1612 if (is_volatile) { | |
1613 assert(!needs_patching && x->is_loaded(), | |
1614 "how do we know it's volatile if it's not loaded"); | |
1615 volatile_field_load(address, reg, info); | |
1616 } else { | |
1617 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; | |
1618 __ load(address, reg, info, patch_code); | |
1619 } | |
1620 | |
1621 if (is_volatile && os::is_MP()) { | |
1622 __ membar_acquire(); | |
1623 } | |
1624 } | |
1625 | |
1626 | |
1627 //------------------------java.nio.Buffer.checkIndex------------------------ | |
1628 | |
1629 // int java.nio.Buffer.checkIndex(int) | |
1630 void LIRGenerator::do_NIOCheckIndex(Intrinsic* x) { | |
1631 // NOTE: by the time we are in checkIndex() we are guaranteed that | |
1632 // the buffer is non-null (because checkIndex is package-private and | |
1633 // only called from within other methods in the buffer). | |
1634 assert(x->number_of_arguments() == 2, "wrong type"); | |
1635 LIRItem buf (x->argument_at(0), this); | |
1636 LIRItem index(x->argument_at(1), this); | |
1637 buf.load_item(); | |
1638 index.load_item(); | |
1639 | |
1640 LIR_Opr result = rlock_result(x); | |
1641 if (GenerateRangeChecks) { | |
1642 CodeEmitInfo* info = state_for(x); | |
1643 CodeStub* stub = new RangeCheckStub(info, index.result(), true); | |
1644 if (index.result()->is_constant()) { | |
1645 cmp_mem_int(lir_cond_belowEqual, buf.result(), java_nio_Buffer::limit_offset(), index.result()->as_jint(), info); | |
1646 __ branch(lir_cond_belowEqual, T_INT, stub); | |
1647 } else { | |
1648 cmp_reg_mem(lir_cond_aboveEqual, index.result(), buf.result(), | |
1649 java_nio_Buffer::limit_offset(), T_INT, info); | |
1650 __ branch(lir_cond_aboveEqual, T_INT, stub); | |
1651 } | |
1652 __ move(index.result(), result); | |
1653 } else { | |
1654 // Just load the index into the result register | |
1655 __ move(index.result(), result); | |
1656 } | |
1657 } | |
1658 | |
1659 | |
1660 //------------------------array access-------------------------------------- | |
1661 | |
1662 | |
1663 void LIRGenerator::do_ArrayLength(ArrayLength* x) { | |
1664 LIRItem array(x->array(), this); | |
1665 array.load_item(); | |
1666 LIR_Opr reg = rlock_result(x); | |
1667 | |
1668 CodeEmitInfo* info = NULL; | |
1669 if (x->needs_null_check()) { | |
1670 NullCheck* nc = x->explicit_null_check(); | |
1671 if (nc == NULL) { | |
1672 info = state_for(x); | |
1673 } else { | |
1674 info = state_for(nc); | |
1675 } | |
1676 } | |
1677 __ load(new LIR_Address(array.result(), arrayOopDesc::length_offset_in_bytes(), T_INT), reg, info, lir_patch_none); | |
1678 } | |
1679 | |
1680 | |
1681 void LIRGenerator::do_LoadIndexed(LoadIndexed* x) { | |
1682 bool use_length = x->length() != NULL; | |
1683 LIRItem array(x->array(), this); | |
1684 LIRItem index(x->index(), this); | |
1685 LIRItem length(this); | |
1686 bool needs_range_check = true; | |
1687 | |
1688 if (use_length) { | |
1689 needs_range_check = x->compute_needs_range_check(); | |
1690 if (needs_range_check) { | |
1691 length.set_instruction(x->length()); | |
1692 length.load_item(); | |
1693 } | |
1694 } | |
1695 | |
1696 array.load_item(); | |
1697 if (index.is_constant() && can_inline_as_constant(x->index())) { | |
1698 // let it be a constant | |
1699 index.dont_load_item(); | |
1700 } else { | |
1701 index.load_item(); | |
1702 } | |
1703 | |
1704 CodeEmitInfo* range_check_info = state_for(x); | |
1705 CodeEmitInfo* null_check_info = NULL; | |
1706 if (x->needs_null_check()) { | |
1707 NullCheck* nc = x->explicit_null_check(); | |
1708 if (nc != NULL) { | |
1709 null_check_info = state_for(nc); | |
1710 } else { | |
1711 null_check_info = range_check_info; | |
1712 } | |
1713 } | |
1714 | |
1715 // emit array address setup early so it schedules better | |
1716 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), false); | |
1717 | |
1718 if (GenerateRangeChecks && needs_range_check) { | |
1719 if (use_length) { | |
1720 // TODO: use a (modified) version of array_range_check that does not require a | |
1721 // constant length to be loaded to a register | |
1722 __ cmp(lir_cond_belowEqual, length.result(), index.result()); | |
1723 __ branch(lir_cond_belowEqual, T_INT, new RangeCheckStub(range_check_info, index.result())); | |
1724 } else { | |
1725 array_range_check(array.result(), index.result(), null_check_info, range_check_info); | |
1726 // The range check performs the null check, so clear it out for the load | |
1727 null_check_info = NULL; | |
1728 } | |
1729 } | |
1730 | |
1731 __ move(array_addr, rlock_result(x, x->elt_type()), null_check_info); | |
1732 } | |
1733 | |
1734 | |
1735 void LIRGenerator::do_NullCheck(NullCheck* x) { | |
1736 if (x->can_trap()) { | |
1737 LIRItem value(x->obj(), this); | |
1738 value.load_item(); | |
1739 CodeEmitInfo* info = state_for(x); | |
1740 __ null_check(value.result(), info); | |
1741 } | |
1742 } | |
1743 | |
1744 | |
1745 void LIRGenerator::do_Throw(Throw* x) { | |
1746 LIRItem exception(x->exception(), this); | |
1747 exception.load_item(); | |
1748 set_no_result(x); | |
1749 LIR_Opr exception_opr = exception.result(); | |
1750 CodeEmitInfo* info = state_for(x, x->state()); | |
1751 | |
1752 #ifndef PRODUCT | |
1753 if (PrintC1Statistics) { | |
1783 | 1754 increment_counter(Runtime1::throw_count_address(), T_INT); |
0 | 1755 } |
1756 #endif | |
1757 | |
1758 // check if the instruction has an xhandler in any of the nested scopes | |
1759 bool unwind = false; | |
1760 if (info->exception_handlers()->length() == 0) { | |
1761 // this throw is not inside an xhandler | |
1762 unwind = true; | |
1763 } else { | |
1764 // get some idea of the throw type | |
1765 bool type_is_exact = true; | |
1766 ciType* throw_type = x->exception()->exact_type(); | |
1767 if (throw_type == NULL) { | |
1768 type_is_exact = false; | |
1769 throw_type = x->exception()->declared_type(); | |
1770 } | |
1771 if (throw_type != NULL && throw_type->is_instance_klass()) { | |
1772 ciInstanceKlass* throw_klass = (ciInstanceKlass*)throw_type; | |
1773 unwind = !x->exception_handlers()->could_catch(throw_klass, type_is_exact); | |
1774 } | |
1775 } | |
1776 | |
1777 // do null check before moving exception oop into fixed register | |
1778 // to avoid a fixed interval with an oop during the null check. | |
1779 // Use a copy of the CodeEmitInfo because debug information is | |
1780 // different for null_check and throw. | |
1781 if (GenerateCompilerNullChecks && | |
1782 (x->exception()->as_NewInstance() == NULL && x->exception()->as_ExceptionObject() == NULL)) { | |
1783 // if the exception object wasn't created using new then it might be null. | |
1784 __ null_check(exception_opr, new CodeEmitInfo(info, true)); | |
1785 } | |
1786 | |
1378
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1304
diff
changeset
|
1787 if (compilation()->env()->jvmti_can_post_on_exceptions()) { |
0 | 1788 // we need to go through the exception lookup path to get JVMTI |
1789 // notification done | |
1790 unwind = false; | |
1791 } | |
1792 | |
1793 // move exception oop into fixed register | |
1794 __ move(exception_opr, exceptionOopOpr()); | |
1795 | |
1796 if (unwind) { | |
1378
9f5b60a14736
6939930: exception unwind changes in 6919934 hurts compilation speed
never
parents:
1304
diff
changeset
|
1797 __ unwind_exception(exceptionOopOpr()); |
0 | 1798 } else { |
1799 __ throw_exception(exceptionPcOpr(), exceptionOopOpr(), info); | |
1800 } | |
1801 } | |
1802 | |
1803 | |
1804 void LIRGenerator::do_RoundFP(RoundFP* x) { | |
1805 LIRItem input(x->input(), this); | |
1806 input.load_item(); | |
1807 LIR_Opr input_opr = input.result(); | |
1808 assert(input_opr->is_register(), "why round if value is not in a register?"); | |
1809 assert(input_opr->is_single_fpu() || input_opr->is_double_fpu(), "input should be floating-point value"); | |
1810 if (input_opr->is_single_fpu()) { | |
1811 set_result(x, round_item(input_opr)); // This code path not currently taken | |
1812 } else { | |
1813 LIR_Opr result = new_register(T_DOUBLE); | |
1814 set_vreg_flag(result, must_start_in_memory); | |
1815 __ roundfp(input_opr, LIR_OprFact::illegalOpr, result); | |
1816 set_result(x, result); | |
1817 } | |
1818 } | |
1819 | |
1820 void LIRGenerator::do_UnsafeGetRaw(UnsafeGetRaw* x) { | |
1821 LIRItem base(x->base(), this); | |
1822 LIRItem idx(this); | |
1823 | |
1824 base.load_item(); | |
1825 if (x->has_index()) { | |
1826 idx.set_instruction(x->index()); | |
1827 idx.load_nonconstant(); | |
1828 } | |
1829 | |
1830 LIR_Opr reg = rlock_result(x, x->basic_type()); | |
1831 | |
1832 int log2_scale = 0; | |
1833 if (x->has_index()) { | |
1834 assert(x->index()->type()->tag() == intTag, "should not find non-int index"); | |
1835 log2_scale = x->log2_scale(); | |
1836 } | |
1837 | |
1838 assert(!x->has_index() || idx.value() == x->index(), "should match"); | |
1839 | |
1840 LIR_Opr base_op = base.result(); | |
1841 #ifndef _LP64 | |
1842 if (x->base()->type()->tag() == longTag) { | |
1843 base_op = new_register(T_INT); | |
1844 __ convert(Bytecodes::_l2i, base.result(), base_op); | |
1845 } else { | |
1846 assert(x->base()->type()->tag() == intTag, "must be"); | |
1847 } | |
1848 #endif | |
1849 | |
1850 BasicType dst_type = x->basic_type(); | |
1851 LIR_Opr index_op = idx.result(); | |
1852 | |
1853 LIR_Address* addr; | |
1854 if (index_op->is_constant()) { | |
1855 assert(log2_scale == 0, "must not have a scale"); | |
1856 addr = new LIR_Address(base_op, index_op->as_jint(), dst_type); | |
1857 } else { | |
304 | 1858 #ifdef X86 |
1060 | 1859 #ifdef _LP64 |
1860 if (!index_op->is_illegal() && index_op->type() == T_INT) { | |
1861 LIR_Opr tmp = new_pointer_register(); | |
1862 __ convert(Bytecodes::_i2l, index_op, tmp); | |
1863 index_op = tmp; | |
1864 } | |
1865 #endif | |
0 | 1866 addr = new LIR_Address(base_op, index_op, LIR_Address::Scale(log2_scale), 0, dst_type); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1867 #elif defined(ARM) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1868 addr = generate_address(base_op, index_op, log2_scale, 0, dst_type); |
0 | 1869 #else |
1870 if (index_op->is_illegal() || log2_scale == 0) { | |
1060 | 1871 #ifdef _LP64 |
1872 if (!index_op->is_illegal() && index_op->type() == T_INT) { | |
1873 LIR_Opr tmp = new_pointer_register(); | |
1874 __ convert(Bytecodes::_i2l, index_op, tmp); | |
1875 index_op = tmp; | |
1876 } | |
1877 #endif | |
0 | 1878 addr = new LIR_Address(base_op, index_op, dst_type); |
1879 } else { | |
1060 | 1880 LIR_Opr tmp = new_pointer_register(); |
0 | 1881 __ shift_left(index_op, log2_scale, tmp); |
1882 addr = new LIR_Address(base_op, tmp, dst_type); | |
1883 } | |
1884 #endif | |
1885 } | |
1886 | |
1887 if (x->may_be_unaligned() && (dst_type == T_LONG || dst_type == T_DOUBLE)) { | |
1888 __ unaligned_move(addr, reg); | |
1889 } else { | |
1890 __ move(addr, reg); | |
1891 } | |
1892 } | |
1893 | |
1894 | |
1895 void LIRGenerator::do_UnsafePutRaw(UnsafePutRaw* x) { | |
1896 int log2_scale = 0; | |
1897 BasicType type = x->basic_type(); | |
1898 | |
1899 if (x->has_index()) { | |
1900 assert(x->index()->type()->tag() == intTag, "should not find non-int index"); | |
1901 log2_scale = x->log2_scale(); | |
1902 } | |
1903 | |
1904 LIRItem base(x->base(), this); | |
1905 LIRItem value(x->value(), this); | |
1906 LIRItem idx(this); | |
1907 | |
1908 base.load_item(); | |
1909 if (x->has_index()) { | |
1910 idx.set_instruction(x->index()); | |
1911 idx.load_item(); | |
1912 } | |
1913 | |
1914 if (type == T_BYTE || type == T_BOOLEAN) { | |
1915 value.load_byte_item(); | |
1916 } else { | |
1917 value.load_item(); | |
1918 } | |
1919 | |
1920 set_no_result(x); | |
1921 | |
1922 LIR_Opr base_op = base.result(); | |
1923 #ifndef _LP64 | |
1924 if (x->base()->type()->tag() == longTag) { | |
1925 base_op = new_register(T_INT); | |
1926 __ convert(Bytecodes::_l2i, base.result(), base_op); | |
1927 } else { | |
1928 assert(x->base()->type()->tag() == intTag, "must be"); | |
1929 } | |
1930 #endif | |
1931 | |
1932 LIR_Opr index_op = idx.result(); | |
1933 if (log2_scale != 0) { | |
1934 // temporary fix (platform dependent code without shift on Intel would be better) | |
1060 | 1935 index_op = new_pointer_register(); |
1936 #ifdef _LP64 | |
1937 if(idx.result()->type() == T_INT) { | |
1938 __ convert(Bytecodes::_i2l, idx.result(), index_op); | |
1939 } else { | |
1940 #endif | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
1941 // TODO: ARM also allows embedded shift in the address |
1060 | 1942 __ move(idx.result(), index_op); |
1943 #ifdef _LP64 | |
1944 } | |
1945 #endif | |
0 | 1946 __ shift_left(index_op, log2_scale, index_op); |
1947 } | |
1060 | 1948 #ifdef _LP64 |
1949 else if(!index_op->is_illegal() && index_op->type() == T_INT) { | |
1950 LIR_Opr tmp = new_pointer_register(); | |
1951 __ convert(Bytecodes::_i2l, index_op, tmp); | |
1952 index_op = tmp; | |
1953 } | |
1954 #endif | |
0 | 1955 |
1956 LIR_Address* addr = new LIR_Address(base_op, index_op, x->basic_type()); | |
1957 __ move(value.result(), addr); | |
1958 } | |
1959 | |
1960 | |
1961 void LIRGenerator::do_UnsafeGetObject(UnsafeGetObject* x) { | |
1962 BasicType type = x->basic_type(); | |
1963 LIRItem src(x->object(), this); | |
1964 LIRItem off(x->offset(), this); | |
1965 | |
1966 off.load_item(); | |
1967 src.load_item(); | |
1968 | |
1969 LIR_Opr reg = reg = rlock_result(x, x->basic_type()); | |
1970 | |
1971 if (x->is_volatile() && os::is_MP()) __ membar_acquire(); | |
1972 get_Object_unsafe(reg, src.result(), off.result(), type, x->is_volatile()); | |
1973 if (x->is_volatile() && os::is_MP()) __ membar(); | |
1974 } | |
1975 | |
1976 | |
1977 void LIRGenerator::do_UnsafePutObject(UnsafePutObject* x) { | |
1978 BasicType type = x->basic_type(); | |
1979 LIRItem src(x->object(), this); | |
1980 LIRItem off(x->offset(), this); | |
1981 LIRItem data(x->value(), this); | |
1982 | |
1983 src.load_item(); | |
1984 if (type == T_BOOLEAN || type == T_BYTE) { | |
1985 data.load_byte_item(); | |
1986 } else { | |
1987 data.load_item(); | |
1988 } | |
1989 off.load_item(); | |
1990 | |
1991 set_no_result(x); | |
1992 | |
1993 if (x->is_volatile() && os::is_MP()) __ membar_release(); | |
1994 put_Object_unsafe(src.result(), off.result(), data.result(), type, x->is_volatile()); | |
1995 } | |
1996 | |
1997 | |
1998 void LIRGenerator::do_UnsafePrefetch(UnsafePrefetch* x, bool is_store) { | |
1999 LIRItem src(x->object(), this); | |
2000 LIRItem off(x->offset(), this); | |
2001 | |
2002 src.load_item(); | |
2003 if (off.is_constant() && can_inline_as_constant(x->offset())) { | |
2004 // let it be a constant | |
2005 off.dont_load_item(); | |
2006 } else { | |
2007 off.load_item(); | |
2008 } | |
2009 | |
2010 set_no_result(x); | |
2011 | |
2012 LIR_Address* addr = generate_address(src.result(), off.result(), 0, 0, T_BYTE); | |
2013 __ prefetch(addr, is_store); | |
2014 } | |
2015 | |
2016 | |
2017 void LIRGenerator::do_UnsafePrefetchRead(UnsafePrefetchRead* x) { | |
2018 do_UnsafePrefetch(x, false); | |
2019 } | |
2020 | |
2021 | |
2022 void LIRGenerator::do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { | |
2023 do_UnsafePrefetch(x, true); | |
2024 } | |
2025 | |
2026 | |
2027 void LIRGenerator::do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux) { | |
2028 int lng = x->length(); | |
2029 | |
2030 for (int i = 0; i < lng; i++) { | |
2031 SwitchRange* one_range = x->at(i); | |
2032 int low_key = one_range->low_key(); | |
2033 int high_key = one_range->high_key(); | |
2034 BlockBegin* dest = one_range->sux(); | |
2035 if (low_key == high_key) { | |
2036 __ cmp(lir_cond_equal, value, low_key); | |
2037 __ branch(lir_cond_equal, T_INT, dest); | |
2038 } else if (high_key - low_key == 1) { | |
2039 __ cmp(lir_cond_equal, value, low_key); | |
2040 __ branch(lir_cond_equal, T_INT, dest); | |
2041 __ cmp(lir_cond_equal, value, high_key); | |
2042 __ branch(lir_cond_equal, T_INT, dest); | |
2043 } else { | |
2044 LabelObj* L = new LabelObj(); | |
2045 __ cmp(lir_cond_less, value, low_key); | |
2046 __ branch(lir_cond_less, L->label()); | |
2047 __ cmp(lir_cond_lessEqual, value, high_key); | |
2048 __ branch(lir_cond_lessEqual, T_INT, dest); | |
2049 __ branch_destination(L->label()); | |
2050 } | |
2051 } | |
2052 __ jump(default_sux); | |
2053 } | |
2054 | |
2055 | |
2056 SwitchRangeArray* LIRGenerator::create_lookup_ranges(TableSwitch* x) { | |
2057 SwitchRangeList* res = new SwitchRangeList(); | |
2058 int len = x->length(); | |
2059 if (len > 0) { | |
2060 BlockBegin* sux = x->sux_at(0); | |
2061 int key = x->lo_key(); | |
2062 BlockBegin* default_sux = x->default_sux(); | |
2063 SwitchRange* range = new SwitchRange(key, sux); | |
2064 for (int i = 0; i < len; i++, key++) { | |
2065 BlockBegin* new_sux = x->sux_at(i); | |
2066 if (sux == new_sux) { | |
2067 // still in same range | |
2068 range->set_high_key(key); | |
2069 } else { | |
2070 // skip tests which explicitly dispatch to the default | |
2071 if (sux != default_sux) { | |
2072 res->append(range); | |
2073 } | |
2074 range = new SwitchRange(key, new_sux); | |
2075 } | |
2076 sux = new_sux; | |
2077 } | |
2078 if (res->length() == 0 || res->last() != range) res->append(range); | |
2079 } | |
2080 return res; | |
2081 } | |
2082 | |
2083 | |
2084 // we expect the keys to be sorted by increasing value | |
2085 SwitchRangeArray* LIRGenerator::create_lookup_ranges(LookupSwitch* x) { | |
2086 SwitchRangeList* res = new SwitchRangeList(); | |
2087 int len = x->length(); | |
2088 if (len > 0) { | |
2089 BlockBegin* default_sux = x->default_sux(); | |
2090 int key = x->key_at(0); | |
2091 BlockBegin* sux = x->sux_at(0); | |
2092 SwitchRange* range = new SwitchRange(key, sux); | |
2093 for (int i = 1; i < len; i++) { | |
2094 int new_key = x->key_at(i); | |
2095 BlockBegin* new_sux = x->sux_at(i); | |
2096 if (key+1 == new_key && sux == new_sux) { | |
2097 // still in same range | |
2098 range->set_high_key(new_key); | |
2099 } else { | |
2100 // skip tests which explicitly dispatch to the default | |
2101 if (range->sux() != default_sux) { | |
2102 res->append(range); | |
2103 } | |
2104 range = new SwitchRange(new_key, new_sux); | |
2105 } | |
2106 key = new_key; | |
2107 sux = new_sux; | |
2108 } | |
2109 if (res->length() == 0 || res->last() != range) res->append(range); | |
2110 } | |
2111 return res; | |
2112 } | |
2113 | |
2114 | |
2115 void LIRGenerator::do_TableSwitch(TableSwitch* x) { | |
2116 LIRItem tag(x->tag(), this); | |
2117 tag.load_item(); | |
2118 set_no_result(x); | |
2119 | |
2120 if (x->is_safepoint()) { | |
2121 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); | |
2122 } | |
2123 | |
2124 // move values into phi locations | |
2125 move_to_phi(x->state()); | |
2126 | |
2127 int lo_key = x->lo_key(); | |
2128 int hi_key = x->hi_key(); | |
2129 int len = x->length(); | |
2130 CodeEmitInfo* info = state_for(x, x->state()); | |
2131 LIR_Opr value = tag.result(); | |
2132 if (UseTableRanges) { | |
2133 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); | |
2134 } else { | |
2135 for (int i = 0; i < len; i++) { | |
2136 __ cmp(lir_cond_equal, value, i + lo_key); | |
2137 __ branch(lir_cond_equal, T_INT, x->sux_at(i)); | |
2138 } | |
2139 __ jump(x->default_sux()); | |
2140 } | |
2141 } | |
2142 | |
2143 | |
2144 void LIRGenerator::do_LookupSwitch(LookupSwitch* x) { | |
2145 LIRItem tag(x->tag(), this); | |
2146 tag.load_item(); | |
2147 set_no_result(x); | |
2148 | |
2149 if (x->is_safepoint()) { | |
2150 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before())); | |
2151 } | |
2152 | |
2153 // move values into phi locations | |
2154 move_to_phi(x->state()); | |
2155 | |
2156 LIR_Opr value = tag.result(); | |
2157 if (UseTableRanges) { | |
2158 do_SwitchRanges(create_lookup_ranges(x), value, x->default_sux()); | |
2159 } else { | |
2160 int len = x->length(); | |
2161 for (int i = 0; i < len; i++) { | |
2162 __ cmp(lir_cond_equal, value, x->key_at(i)); | |
2163 __ branch(lir_cond_equal, T_INT, x->sux_at(i)); | |
2164 } | |
2165 __ jump(x->default_sux()); | |
2166 } | |
2167 } | |
2168 | |
2169 | |
2170 void LIRGenerator::do_Goto(Goto* x) { | |
2171 set_no_result(x); | |
2172 | |
2173 if (block()->next()->as_OsrEntry()) { | |
2174 // need to free up storage used for OSR entry point | |
2175 LIR_Opr osrBuffer = block()->next()->operand(); | |
2176 BasicTypeList signature; | |
2177 signature.append(T_INT); | |
2178 CallingConvention* cc = frame_map()->c_calling_convention(&signature); | |
2179 __ move(osrBuffer, cc->args()->at(0)); | |
2180 __ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end), | |
2181 getThreadTemp(), LIR_OprFact::illegalOpr, cc->args()); | |
2182 } | |
2183 | |
2184 if (x->is_safepoint()) { | |
2185 ValueStack* state = x->state_before() ? x->state_before() : x->state(); | |
2186 | |
2187 // increment backedge counter if needed | |
1783 | 2188 CodeEmitInfo* info = state_for(x, state); |
2189 increment_backedge_counter(info, info->bci()); | |
0 | 2190 CodeEmitInfo* safepoint_info = state_for(x, state); |
2191 __ safepoint(safepoint_poll_register(), safepoint_info); | |
2192 } | |
2193 | |
1783 | 2194 // Gotos can be folded Ifs, handle this case. |
2195 if (x->should_profile()) { | |
2196 ciMethod* method = x->profiled_method(); | |
2197 assert(method != NULL, "method should be set if branch is profiled"); | |
2198 ciMethodData* md = method->method_data(); | |
2199 if (md == NULL) { | |
2200 bailout("out of memory building methodDataOop"); | |
2201 return; | |
2202 } | |
2203 ciProfileData* data = md->bci_to_data(x->profiled_bci()); | |
2204 assert(data != NULL, "must have profiling data"); | |
2205 int offset; | |
2206 if (x->direction() == Goto::taken) { | |
2207 assert(data->is_BranchData(), "need BranchData for two-way branches"); | |
2208 offset = md->byte_offset_of_slot(data, BranchData::taken_offset()); | |
2209 } else if (x->direction() == Goto::not_taken) { | |
2210 assert(data->is_BranchData(), "need BranchData for two-way branches"); | |
2211 offset = md->byte_offset_of_slot(data, BranchData::not_taken_offset()); | |
2212 } else { | |
2213 assert(data->is_JumpData(), "need JumpData for branches"); | |
2214 offset = md->byte_offset_of_slot(data, JumpData::taken_offset()); | |
2215 } | |
2216 LIR_Opr md_reg = new_register(T_OBJECT); | |
2217 __ oop2reg(md->constant_encoding(), md_reg); | |
2218 | |
2219 increment_counter(new LIR_Address(md_reg, offset, | |
2220 NOT_LP64(T_INT) LP64_ONLY(T_LONG)), DataLayout::counter_increment); | |
2221 } | |
2222 | |
0 | 2223 // emit phi-instruction move after safepoint since this simplifies |
2224 // describing the state as the safepoint. | |
2225 move_to_phi(x->state()); | |
2226 | |
2227 __ jump(x->default_sux()); | |
2228 } | |
2229 | |
2230 | |
2231 void LIRGenerator::do_Base(Base* x) { | |
2232 __ std_entry(LIR_OprFact::illegalOpr); | |
2233 // Emit moves from physical registers / stack slots to virtual registers | |
2234 CallingConvention* args = compilation()->frame_map()->incoming_arguments(); | |
2235 IRScope* irScope = compilation()->hir()->top_scope(); | |
2236 int java_index = 0; | |
2237 for (int i = 0; i < args->length(); i++) { | |
2238 LIR_Opr src = args->at(i); | |
2239 assert(!src->is_illegal(), "check"); | |
2240 BasicType t = src->type(); | |
2241 | |
2242 // Types which are smaller than int are passed as int, so | |
2243 // correct the type which passed. | |
2244 switch (t) { | |
2245 case T_BYTE: | |
2246 case T_BOOLEAN: | |
2247 case T_SHORT: | |
2248 case T_CHAR: | |
2249 t = T_INT; | |
2250 break; | |
2251 } | |
2252 | |
2253 LIR_Opr dest = new_register(t); | |
2254 __ move(src, dest); | |
2255 | |
2256 // Assign new location to Local instruction for this local | |
2257 Local* local = x->state()->local_at(java_index)->as_Local(); | |
2258 assert(local != NULL, "Locals for incoming arguments must have been created"); | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
2259 #ifndef __SOFTFP__ |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
2260 // The java calling convention passes double as long and float as int. |
0 | 2261 assert(as_ValueType(t)->tag() == local->type()->tag(), "check"); |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1584
diff
changeset
|
2262 #endif // __SOFTFP__ |
0 | 2263 local->set_operand(dest); |
2264 _instruction_for_operand.at_put_grow(dest->vreg_number(), local, NULL); | |
2265 java_index += type2size[t]; | |
2266 } | |
2267 | |
780
c96bf21b756f
6788527: Server vm intermittently fails with assertion "live value must not be garbage" with fastdebug bits
kvn
parents:
579
diff
changeset
|
2268 if (compilation()->env()->dtrace_method_probes()) { |
0 | 2269 BasicTypeList signature; |
2270 signature.append(T_INT); // thread | |
2271 signature.append(T_OBJECT); // methodOop | |
2272 LIR_OprList* args = new LIR_OprList(); | |
2273 args->append(getThreadPointer()); | |
2274 LIR_Opr meth = new_register(T_OBJECT); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
819
diff
changeset
|
2275 __ oop2reg(method()->constant_encoding(), meth); |
0 | 2276 args->append(meth); |
2277 call_runtime(&signature, args, CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), voidType, NULL); | |
2278 } | |
2279 | |
2280 if (method()->is_synchronized()) { | |
2281 LIR_Opr obj; | |
2282 if (method()->is_static()) { | |
2283 obj = new_register(T_OBJECT); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
819
diff
changeset
|
2284 __ oop2reg(method()->holder()->java_mirror()->constant_encoding(), obj); |
0 | 2285 } else { |
2286 Local* receiver = x->state()->local_at(0)->as_Local(); | |
2287 assert(receiver != NULL, "must already exist"); | |
2288 obj = receiver->operand(); | |
2289 } | |
2290 assert(obj->is_valid(), "must be valid"); | |
2291 | |
2292 if (method()->is_synchronized() && GenerateSynchronizationCode) { | |
2293 LIR_Opr lock = new_register(T_INT); | |
2294 __ load_stack_address_monitor(0, lock); | |
2295 | |
2296 CodeEmitInfo* info = new CodeEmitInfo(SynchronizationEntryBCI, scope()->start()->state(), NULL); | |
2297 CodeStub* slow_path = new MonitorEnterStub(obj, lock, info); | |
2298 | |
2299 // receiver is guaranteed non-NULL so don't need CodeEmitInfo | |
2300 __ lock_object(syncTempOpr(), obj, lock, new_register(T_OBJECT), slow_path, NULL); | |
2301 } | |
2302 } | |
2303 | |
2304 // increment invocation counters if needed | |
1783 | 2305 if (!method()->is_accessor()) { // Accessors do not have MDOs, so no counting. |
2306 CodeEmitInfo* info = new CodeEmitInfo(InvocationEntryBci, scope()->start()->state(), NULL); | |
2307 increment_invocation_counter(info); | |
2308 } | |
0 | 2309 |
2310 // all blocks with a successor must end with an unconditional jump | |
2311 // to the successor even if they are consecutive | |
2312 __ jump(x->default_sux()); | |
2313 } | |
2314 | |
2315 | |
2316 void LIRGenerator::do_OsrEntry(OsrEntry* x) { | |
2317 // construct our frame and model the production of incoming pointer | |
2318 // to the OSR buffer. | |
2319 __ osr_entry(LIR_Assembler::osrBufferPointer()); | |
2320 LIR_Opr result = rlock_result(x); | |
2321 __ move(LIR_Assembler::osrBufferPointer(), result); | |
2322 } | |
2323 | |
2324 | |
2325 void LIRGenerator::invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list) { | |
1295 | 2326 int i = (x->has_receiver() || x->is_invokedynamic()) ? 1 : 0; |
0 | 2327 for (; i < args->length(); i++) { |
2328 LIRItem* param = args->at(i); | |
2329 LIR_Opr loc = arg_list->at(i); | |
2330 if (loc->is_register()) { | |
2331 param->load_item_force(loc); | |
2332 } else { | |
2333 LIR_Address* addr = loc->as_address_ptr(); | |
2334 param->load_for_store(addr->type()); | |
2335 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { | |
2336 __ unaligned_move(param->result(), addr); | |
2337 } else { | |
2338 __ move(param->result(), addr); | |
2339 } | |
2340 } | |
2341 } | |
2342 | |
2343 if (x->has_receiver()) { | |
2344 LIRItem* receiver = args->at(0); | |
2345 LIR_Opr loc = arg_list->at(0); | |
2346 if (loc->is_register()) { | |
2347 receiver->load_item_force(loc); | |
2348 } else { | |
2349 assert(loc->is_address(), "just checking"); | |
2350 receiver->load_for_store(T_OBJECT); | |
2351 __ move(receiver->result(), loc); | |
2352 } | |
2353 } | |
2354 } | |
2355 | |
2356 | |
2357 // Visits all arguments, returns appropriate items without loading them | |
2358 LIRItemList* LIRGenerator::invoke_visit_arguments(Invoke* x) { | |
2359 LIRItemList* argument_items = new LIRItemList(); | |
2360 if (x->has_receiver()) { | |
2361 LIRItem* receiver = new LIRItem(x->receiver(), this); | |
2362 argument_items->append(receiver); | |
2363 } | |
1295 | 2364 if (x->is_invokedynamic()) { |
2365 // Insert a dummy for the synthetic MethodHandle argument. | |
2366 argument_items->append(NULL); | |
2367 } | |
0 | 2368 int idx = x->has_receiver() ? 1 : 0; |
2369 for (int i = 0; i < x->number_of_arguments(); i++) { | |
2370 LIRItem* param = new LIRItem(x->argument_at(i), this); | |
2371 argument_items->append(param); | |
2372 idx += (param->type()->is_double_word() ? 2 : 1); | |
2373 } | |
2374 return argument_items; | |
2375 } | |
2376 | |
2377 | |
2378 // The invoke with receiver has following phases: | |
2379 // a) traverse and load/lock receiver; | |
2380 // b) traverse all arguments -> item-array (invoke_visit_argument) | |
2381 // c) push receiver on stack | |
2382 // d) load each of the items and push on stack | |
2383 // e) unlock receiver | |
2384 // f) move receiver into receiver-register %o0 | |
2385 // g) lock result registers and emit call operation | |
2386 // | |
2387 // Before issuing a call, we must spill-save all values on stack | |
2388 // that are in caller-save register. "spill-save" moves thos registers | |
2389 // either in a free callee-save register or spills them if no free | |
2390 // callee save register is available. | |
2391 // | |
2392 // The problem is where to invoke spill-save. | |
2393 // - if invoked between e) and f), we may lock callee save | |
2394 // register in "spill-save" that destroys the receiver register | |
2395 // before f) is executed | |
2396 // - if we rearange the f) to be earlier, by loading %o0, it | |
2397 // may destroy a value on the stack that is currently in %o0 | |
2398 // and is waiting to be spilled | |
2399 // - if we keep the receiver locked while doing spill-save, | |
2400 // we cannot spill it as it is spill-locked | |
2401 // | |
2402 void LIRGenerator::do_Invoke(Invoke* x) { | |
2403 CallingConvention* cc = frame_map()->java_calling_convention(x->signature(), true); | |
2404 | |
2405 LIR_OprList* arg_list = cc->args(); | |
2406 LIRItemList* args = invoke_visit_arguments(x); | |
2407 LIR_Opr receiver = LIR_OprFact::illegalOpr; | |
2408 | |
2409 // setup result register | |
2410 LIR_Opr result_register = LIR_OprFact::illegalOpr; | |
2411 if (x->type() != voidType) { | |
2412 result_register = result_register_for(x->type()); | |
2413 } | |
2414 | |
2415 CodeEmitInfo* info = state_for(x, x->state()); | |
2416 | |
1295 | 2417 // invokedynamics can deoptimize. |
1304 | 2418 CodeEmitInfo* deopt_info = x->is_invokedynamic() ? state_for(x, x->state_before()) : NULL; |
1295 | 2419 |
0 | 2420 invoke_load_arguments(x, args, arg_list); |
2421 | |
2422 if (x->has_receiver()) { | |
2423 args->at(0)->load_item_force(LIR_Assembler::receiverOpr()); | |
2424 receiver = args->at(0)->result(); | |
2425 } | |
2426 | |
2427 // emit invoke code | |
2428 bool optimized = x->target_is_loaded() && x->target_is_final(); | |
2429 assert(receiver->is_illegal() || receiver->is_equal(LIR_Assembler::receiverOpr()), "must match"); | |
2430 | |
1564 | 2431 // JSR 292 |
2432 // Preserve the SP over MethodHandle call sites. | |
2433 ciMethod* target = x->target(); | |
2434 if (target->is_method_handle_invoke()) { | |
2435 info->set_is_method_handle_invoke(true); | |
2436 __ move(FrameMap::stack_pointer(), FrameMap::method_handle_invoke_SP_save_opr()); | |
2437 } | |
2438 | |
0 | 2439 switch (x->code()) { |
2440 case Bytecodes::_invokestatic: | |
1564 | 2441 __ call_static(target, result_register, |
0 | 2442 SharedRuntime::get_resolve_static_call_stub(), |
2443 arg_list, info); | |
2444 break; | |
2445 case Bytecodes::_invokespecial: | |
2446 case Bytecodes::_invokevirtual: | |
2447 case Bytecodes::_invokeinterface: | |
2448 // for final target we still produce an inline cache, in order | |
2449 // to be able to call mixed mode | |
2450 if (x->code() == Bytecodes::_invokespecial || optimized) { | |
1564 | 2451 __ call_opt_virtual(target, receiver, result_register, |
0 | 2452 SharedRuntime::get_resolve_opt_virtual_call_stub(), |
2453 arg_list, info); | |
2454 } else if (x->vtable_index() < 0) { | |
1564 | 2455 __ call_icvirtual(target, receiver, result_register, |
0 | 2456 SharedRuntime::get_resolve_virtual_call_stub(), |
2457 arg_list, info); | |
2458 } else { | |
2459 int entry_offset = instanceKlass::vtable_start_offset() + x->vtable_index() * vtableEntry::size(); | |
2460 int vtable_offset = entry_offset * wordSize + vtableEntry::method_offset_in_bytes(); | |
1564 | 2461 __ call_virtual(target, receiver, result_register, vtable_offset, arg_list, info); |
0 | 2462 } |
2463 break; | |
1295 | 2464 case Bytecodes::_invokedynamic: { |
2465 ciBytecodeStream bcs(x->scope()->method()); | |
2466 bcs.force_bci(x->bci()); | |
2467 assert(bcs.cur_bc() == Bytecodes::_invokedynamic, "wrong stream"); | |
2468 ciCPCache* cpcache = bcs.get_cpcache(); | |
2469 | |
2470 // Get CallSite offset from constant pool cache pointer. | |
2471 int index = bcs.get_method_index(); | |
2472 size_t call_site_offset = cpcache->get_f1_offset(index); | |
2473 | |
2474 // If this invokedynamic call site hasn't been executed yet in | |
2475 // the interpreter, the CallSite object in the constant pool | |
2476 // cache is still null and we need to deoptimize. | |
2477 if (cpcache->is_f1_null_at(index)) { | |
2478 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so | |
2479 // clone all handlers. This is handled transparently in other | |
2480 // places by the CodeEmitInfo cloning logic but is handled | |
2481 // specially here because a stub isn't being used. | |
2482 x->set_exception_handlers(new XHandlers(x->exception_handlers())); | |
2483 | |
2484 DeoptimizeStub* deopt_stub = new DeoptimizeStub(deopt_info); | |
2485 __ jump(deopt_stub); | |
2486 } | |
2487 | |
2488 // Use the receiver register for the synthetic MethodHandle | |
2489 // argument. | |
2490 receiver = LIR_Assembler::receiverOpr(); | |
2491 LIR_Opr tmp = new_register(objectType); | |
2492 | |
2493 // Load CallSite object from constant pool cache. | |
2494 __ oop2reg(cpcache->constant_encoding(), tmp); | |
2495 __ load(new LIR_Address(tmp, call_site_offset, T_OBJECT), tmp); | |
2496 | |
2497 // Load target MethodHandle from CallSite object. | |
2498 __ load(new LIR_Address(tmp, java_dyn_CallSite::target_offset_in_bytes(), T_OBJECT), receiver); | |
2499 | |
1564 | 2500 __ call_dynamic(target, receiver, result_register, |
1295 | 2501 SharedRuntime::get_resolve_opt_virtual_call_stub(), |
2502 arg_list, info); | |
2503 break; | |
2504 } | |
0 | 2505 default: |
2506 ShouldNotReachHere(); | |
2507 break; | |
2508 } | |
2509 | |
1564 | 2510 // JSR 292 |
2511 // Restore the SP after MethodHandle call sites. | |
2512 if (target->is_method_handle_invoke()) { | |
2513 __ move(FrameMap::method_handle_invoke_SP_save_opr(), FrameMap::stack_pointer()); | |
2514 } | |
2515 | |
0 | 2516 if (x->type()->is_float() || x->type()->is_double()) { |
2517 // Force rounding of results from non-strictfp when in strictfp | |
2518 // scope (or when we don't know the strictness of the callee, to | |
2519 // be safe.) | |
2520 if (method()->is_strict()) { | |
2521 if (!x->target_is_loaded() || !x->target_is_strictfp()) { | |
2522 result_register = round_item(result_register); | |
2523 } | |
2524 } | |
2525 } | |
2526 | |
2527 if (result_register->is_valid()) { | |
2528 LIR_Opr result = rlock_result(x); | |
2529 __ move(result_register, result); | |
2530 } | |
2531 } | |
2532 | |
2533 | |
2534 void LIRGenerator::do_FPIntrinsics(Intrinsic* x) { | |
2535 assert(x->number_of_arguments() == 1, "wrong type"); | |
2536 LIRItem value (x->argument_at(0), this); | |
2537 LIR_Opr reg = rlock_result(x); | |
2538 value.load_item(); | |
2539 LIR_Opr tmp = force_to_spill(value.result(), as_BasicType(x->type())); | |
2540 __ move(tmp, reg); | |
2541 } | |
2542 | |
2543 | |
2544 | |
2545 // Code for : x->x() {x->cond()} x->y() ? x->tval() : x->fval() | |
2546 void LIRGenerator::do_IfOp(IfOp* x) { | |
2547 #ifdef ASSERT | |
2548 { | |
2549 ValueTag xtag = x->x()->type()->tag(); | |
2550 ValueTag ttag = x->tval()->type()->tag(); | |
2551 assert(xtag == intTag || xtag == objectTag, "cannot handle others"); | |
2552 assert(ttag == addressTag || ttag == intTag || ttag == objectTag || ttag == longTag, "cannot handle others"); | |
2553 assert(ttag == x->fval()->type()->tag(), "cannot handle others"); | |
2554 } | |
2555 #endif | |
2556 | |
2557 LIRItem left(x->x(), this); | |
2558 LIRItem right(x->y(), this); | |
2559 left.load_item(); | |
2560 if (can_inline_as_constant(right.value())) { | |
2561 right.dont_load_item(); | |
2562 } else { | |
2563 right.load_item(); | |
2564 } | |
2565 | |
2566 LIRItem t_val(x->tval(), this); | |
2567 LIRItem f_val(x->fval(), this); | |
2568 t_val.dont_load_item(); | |
2569 f_val.dont_load_item(); | |
2570 LIR_Opr reg = rlock_result(x); | |
2571 | |
2572 __ cmp(lir_cond(x->cond()), left.result(), right.result()); | |
2573 __ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg); | |
2574 } | |
2575 | |
2576 | |
2577 void LIRGenerator::do_Intrinsic(Intrinsic* x) { | |
2578 switch (x->id()) { | |
2579 case vmIntrinsics::_intBitsToFloat : | |
2580 case vmIntrinsics::_doubleToRawLongBits : | |
2581 case vmIntrinsics::_longBitsToDouble : | |
2582 case vmIntrinsics::_floatToRawIntBits : { | |
2583 do_FPIntrinsics(x); | |
2584 break; | |
2585 } | |
2586 | |
2587 case vmIntrinsics::_currentTimeMillis: { | |
2588 assert(x->number_of_arguments() == 0, "wrong type"); | |
2589 LIR_Opr reg = result_register_for(x->type()); | |
2590 __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeMillis), getThreadTemp(), | |
2591 reg, new LIR_OprList()); | |
2592 LIR_Opr result = rlock_result(x); | |
2593 __ move(reg, result); | |
2594 break; | |
2595 } | |
2596 | |
2597 case vmIntrinsics::_nanoTime: { | |
2598 assert(x->number_of_arguments() == 0, "wrong type"); | |
2599 LIR_Opr reg = result_register_for(x->type()); | |
2600 __ call_runtime_leaf(CAST_FROM_FN_PTR(address, os::javaTimeNanos), getThreadTemp(), | |
2601 reg, new LIR_OprList()); | |
2602 LIR_Opr result = rlock_result(x); | |
2603 __ move(reg, result); | |
2604 break; | |
2605 } | |
2606 | |
2607 case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break; | |
2608 case vmIntrinsics::_getClass: do_getClass(x); break; | |
2609 case vmIntrinsics::_currentThread: do_currentThread(x); break; | |
2610 | |
2611 case vmIntrinsics::_dlog: // fall through | |
2612 case vmIntrinsics::_dlog10: // fall through | |
2613 case vmIntrinsics::_dabs: // fall through | |
2614 case vmIntrinsics::_dsqrt: // fall through | |
2615 case vmIntrinsics::_dtan: // fall through | |
2616 case vmIntrinsics::_dsin : // fall through | |
2617 case vmIntrinsics::_dcos : do_MathIntrinsic(x); break; | |
2618 case vmIntrinsics::_arraycopy: do_ArrayCopy(x); break; | |
2619 | |
2620 // java.nio.Buffer.checkIndex | |
2621 case vmIntrinsics::_checkIndex: do_NIOCheckIndex(x); break; | |
2622 | |
2623 case vmIntrinsics::_compareAndSwapObject: | |
2624 do_CompareAndSwap(x, objectType); | |
2625 break; | |
2626 case vmIntrinsics::_compareAndSwapInt: | |
2627 do_CompareAndSwap(x, intType); | |
2628 break; | |
2629 case vmIntrinsics::_compareAndSwapLong: | |
2630 do_CompareAndSwap(x, longType); | |
2631 break; | |
2632 | |
2633 // sun.misc.AtomicLongCSImpl.attemptUpdate | |
2634 case vmIntrinsics::_attemptUpdate: | |
2635 do_AttemptUpdate(x); | |
2636 break; | |
2637 | |
2638 default: ShouldNotReachHere(); break; | |
2639 } | |
2640 } | |
2641 | |
2642 void LIRGenerator::do_ProfileCall(ProfileCall* x) { | |
2643 // Need recv in a temporary register so it interferes with the other temporaries | |
2644 LIR_Opr recv = LIR_OprFact::illegalOpr; | |
2645 LIR_Opr mdo = new_register(T_OBJECT); | |
1783 | 2646 // tmp is used to hold the counters on SPARC |
2647 LIR_Opr tmp = new_pointer_register(); | |
0 | 2648 if (x->recv() != NULL) { |
2649 LIRItem value(x->recv(), this); | |
2650 value.load_item(); | |
2651 recv = new_register(T_OBJECT); | |
2652 __ move(value.result(), recv); | |
2653 } | |
2654 __ profile_call(x->method(), x->bci_of_invoke(), mdo, recv, tmp, x->known_holder()); | |
2655 } | |
2656 | |
1783 | 2657 void LIRGenerator::do_ProfileInvoke(ProfileInvoke* x) { |
2658 // We can safely ignore accessors here, since c2 will inline them anyway, | |
2659 // accessors are also always mature. | |
2660 if (!x->inlinee()->is_accessor()) { | |
2661 CodeEmitInfo* info = state_for(x, x->state(), true); | |
2662 // Increment invocation counter, don't notify the runtime, because we don't inline loops, | |
2663 increment_event_counter_impl(info, x->inlinee(), 0, InvocationEntryBci, false, false); | |
2664 } | |
2665 } | |
2666 | |
2667 void LIRGenerator::increment_event_counter(CodeEmitInfo* info, int bci, bool backedge) { | |
2668 int freq_log; | |
2669 int level = compilation()->env()->comp_level(); | |
2670 if (level == CompLevel_limited_profile) { | |
2671 freq_log = (backedge ? Tier2BackedgeNotifyFreqLog : Tier2InvokeNotifyFreqLog); | |
2672 } else if (level == CompLevel_full_profile) { | |
2673 freq_log = (backedge ? Tier3BackedgeNotifyFreqLog : Tier3InvokeNotifyFreqLog); | |
2674 } else { | |
2675 ShouldNotReachHere(); | |
2676 } | |
2677 // Increment the appropriate invocation/backedge counter and notify the runtime. | |
2678 increment_event_counter_impl(info, info->scope()->method(), (1 << freq_log) - 1, bci, backedge, true); | |
0 | 2679 } |
2680 | |
1783 | 2681 void LIRGenerator::increment_event_counter_impl(CodeEmitInfo* info, |
2682 ciMethod *method, int frequency, | |
2683 int bci, bool backedge, bool notify) { | |
2684 assert(frequency == 0 || is_power_of_2(frequency + 1), "Frequency must be x^2 - 1 or 0"); | |
2685 int level = _compilation->env()->comp_level(); | |
2686 assert(level > CompLevel_simple, "Shouldn't be here"); | |
2687 | |
2688 int offset = -1; | |
2689 LIR_Opr counter_holder = new_register(T_OBJECT); | |
2690 LIR_Opr meth; | |
2691 if (level == CompLevel_limited_profile) { | |
2692 offset = in_bytes(backedge ? methodOopDesc::backedge_counter_offset() : | |
2693 methodOopDesc::invocation_counter_offset()); | |
2694 __ oop2reg(method->constant_encoding(), counter_holder); | |
2695 meth = counter_holder; | |
2696 } else if (level == CompLevel_full_profile) { | |
2697 offset = in_bytes(backedge ? methodDataOopDesc::backedge_counter_offset() : | |
2698 methodDataOopDesc::invocation_counter_offset()); | |
2699 __ oop2reg(method->method_data()->constant_encoding(), counter_holder); | |
2700 meth = new_register(T_OBJECT); | |
2701 __ oop2reg(method->constant_encoding(), meth); | |
2702 } else { | |
2703 ShouldNotReachHere(); | |
2704 } | |
2705 LIR_Address* counter = new LIR_Address(counter_holder, offset, T_INT); | |
2706 LIR_Opr result = new_register(T_INT); | |
2707 __ load(counter, result); | |
2708 __ add(result, LIR_OprFact::intConst(InvocationCounter::count_increment), result); | |
2709 __ store(result, counter); | |
2710 if (notify) { | |
2711 LIR_Opr mask = load_immediate(frequency << InvocationCounter::count_shift, T_INT); | |
2712 __ logical_and(result, mask, result); | |
2713 __ cmp(lir_cond_equal, result, LIR_OprFact::intConst(0)); | |
2714 // The bci for info can point to cmp for if's we want the if bci | |
2715 CodeStub* overflow = new CounterOverflowStub(info, bci, meth); | |
2716 __ branch(lir_cond_equal, T_INT, overflow); | |
2717 __ branch_destination(overflow->continuation()); | |
2718 } | |
2719 } | |
0 | 2720 |
2721 LIR_Opr LIRGenerator::call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info) { | |
2722 LIRItemList args(1); | |
2723 LIRItem value(arg1, this); | |
2724 args.append(&value); | |
2725 BasicTypeList signature; | |
2726 signature.append(as_BasicType(arg1->type())); | |
2727 | |
2728 return call_runtime(&signature, &args, entry, result_type, info); | |
2729 } | |
2730 | |
2731 | |
2732 LIR_Opr LIRGenerator::call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info) { | |
2733 LIRItemList args(2); | |
2734 LIRItem value1(arg1, this); | |
2735 LIRItem value2(arg2, this); | |
2736 args.append(&value1); | |
2737 args.append(&value2); | |
2738 BasicTypeList signature; | |
2739 signature.append(as_BasicType(arg1->type())); | |
2740 signature.append(as_BasicType(arg2->type())); | |
2741 | |
2742 return call_runtime(&signature, &args, entry, result_type, info); | |
2743 } | |
2744 | |
2745 | |
2746 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIR_OprList* args, | |
2747 address entry, ValueType* result_type, CodeEmitInfo* info) { | |
2748 // get a result register | |
2749 LIR_Opr phys_reg = LIR_OprFact::illegalOpr; | |
2750 LIR_Opr result = LIR_OprFact::illegalOpr; | |
2751 if (result_type->tag() != voidTag) { | |
2752 result = new_register(result_type); | |
2753 phys_reg = result_register_for(result_type); | |
2754 } | |
2755 | |
2756 // move the arguments into the correct location | |
2757 CallingConvention* cc = frame_map()->c_calling_convention(signature); | |
2758 assert(cc->length() == args->length(), "argument mismatch"); | |
2759 for (int i = 0; i < args->length(); i++) { | |
2760 LIR_Opr arg = args->at(i); | |
2761 LIR_Opr loc = cc->at(i); | |
2762 if (loc->is_register()) { | |
2763 __ move(arg, loc); | |
2764 } else { | |
2765 LIR_Address* addr = loc->as_address_ptr(); | |
2766 // if (!can_store_as_constant(arg)) { | |
2767 // LIR_Opr tmp = new_register(arg->type()); | |
2768 // __ move(arg, tmp); | |
2769 // arg = tmp; | |
2770 // } | |
2771 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { | |
2772 __ unaligned_move(arg, addr); | |
2773 } else { | |
2774 __ move(arg, addr); | |
2775 } | |
2776 } | |
2777 } | |
2778 | |
2779 if (info) { | |
2780 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); | |
2781 } else { | |
2782 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); | |
2783 } | |
2784 if (result->is_valid()) { | |
2785 __ move(phys_reg, result); | |
2786 } | |
2787 return result; | |
2788 } | |
2789 | |
2790 | |
2791 LIR_Opr LIRGenerator::call_runtime(BasicTypeArray* signature, LIRItemList* args, | |
2792 address entry, ValueType* result_type, CodeEmitInfo* info) { | |
2793 // get a result register | |
2794 LIR_Opr phys_reg = LIR_OprFact::illegalOpr; | |
2795 LIR_Opr result = LIR_OprFact::illegalOpr; | |
2796 if (result_type->tag() != voidTag) { | |
2797 result = new_register(result_type); | |
2798 phys_reg = result_register_for(result_type); | |
2799 } | |
2800 | |
2801 // move the arguments into the correct location | |
2802 CallingConvention* cc = frame_map()->c_calling_convention(signature); | |
2803 | |
2804 assert(cc->length() == args->length(), "argument mismatch"); | |
2805 for (int i = 0; i < args->length(); i++) { | |
2806 LIRItem* arg = args->at(i); | |
2807 LIR_Opr loc = cc->at(i); | |
2808 if (loc->is_register()) { | |
2809 arg->load_item_force(loc); | |
2810 } else { | |
2811 LIR_Address* addr = loc->as_address_ptr(); | |
2812 arg->load_for_store(addr->type()); | |
2813 if (addr->type() == T_LONG || addr->type() == T_DOUBLE) { | |
2814 __ unaligned_move(arg->result(), addr); | |
2815 } else { | |
2816 __ move(arg->result(), addr); | |
2817 } | |
2818 } | |
2819 } | |
2820 | |
2821 if (info) { | |
2822 __ call_runtime(entry, getThreadTemp(), phys_reg, cc->args(), info); | |
2823 } else { | |
2824 __ call_runtime_leaf(entry, getThreadTemp(), phys_reg, cc->args()); | |
2825 } | |
2826 if (result->is_valid()) { | |
2827 __ move(phys_reg, result); | |
2828 } | |
2829 return result; | |
2830 } |