Tue, 09 Mar 2010 20:16:19 +0100
6919934: JSR 292 needs to support x86 C1
Summary: This implements JSR 292 support for C1 x86.
Reviewed-by: never, jrose, kvn
1 /*
2 * Copyright 1998-2010 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_parse2.cpp.incl"
28 extern int explicit_null_checks_inserted,
29 explicit_null_checks_elided;
31 //---------------------------------array_load----------------------------------
32 void Parse::array_load(BasicType elem_type) {
33 const Type* elem = Type::TOP;
34 Node* adr = array_addressing(elem_type, 0, &elem);
35 if (stopped()) return; // guaranteed null or range check
36 _sp -= 2; // Pop array and index
37 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
38 Node* ld = make_load(control(), adr, elem, elem_type, adr_type);
39 push(ld);
40 }
43 //--------------------------------array_store----------------------------------
44 void Parse::array_store(BasicType elem_type) {
45 Node* adr = array_addressing(elem_type, 1);
46 if (stopped()) return; // guaranteed null or range check
47 Node* val = pop();
48 _sp -= 2; // Pop array and index
49 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
50 store_to_memory(control(), adr, val, elem_type, adr_type);
51 }
54 //------------------------------array_addressing-------------------------------
55 // Pull array and index from the stack. Compute pointer-to-element.
56 Node* Parse::array_addressing(BasicType type, int vals, const Type* *result2) {
57 Node *idx = peek(0+vals); // Get from stack without popping
58 Node *ary = peek(1+vals); // in case of exception
60 // Null check the array base, with correct stack contents
61 ary = do_null_check(ary, T_ARRAY);
62 // Compile-time detect of null-exception?
63 if (stopped()) return top();
65 const TypeAryPtr* arytype = _gvn.type(ary)->is_aryptr();
66 const TypeInt* sizetype = arytype->size();
67 const Type* elemtype = arytype->elem();
69 if (UseUniqueSubclasses && result2 != NULL) {
70 const Type* el = elemtype->make_ptr();
71 if (el && el->isa_instptr()) {
72 const TypeInstPtr* toop = el->is_instptr();
73 if (toop->klass()->as_instance_klass()->unique_concrete_subklass()) {
74 // If we load from "AbstractClass[]" we must see "ConcreteSubClass".
75 const Type* subklass = Type::get_const_type(toop->klass());
76 elemtype = subklass->join(el);
77 }
78 }
79 }
81 // Check for big class initializers with all constant offsets
82 // feeding into a known-size array.
83 const TypeInt* idxtype = _gvn.type(idx)->is_int();
84 // See if the highest idx value is less than the lowest array bound,
85 // and if the idx value cannot be negative:
86 bool need_range_check = true;
87 if (idxtype->_hi < sizetype->_lo && idxtype->_lo >= 0) {
88 need_range_check = false;
89 if (C->log() != NULL) C->log()->elem("observe that='!need_range_check'");
90 }
92 if (!arytype->klass()->is_loaded()) {
93 // Only fails for some -Xcomp runs
94 // The class is unloaded. We have to run this bytecode in the interpreter.
95 uncommon_trap(Deoptimization::Reason_unloaded,
96 Deoptimization::Action_reinterpret,
97 arytype->klass(), "!loaded array");
98 return top();
99 }
101 // Do the range check
102 if (GenerateRangeChecks && need_range_check) {
103 Node* tst;
104 if (sizetype->_hi <= 0) {
105 // The greatest array bound is negative, so we can conclude that we're
106 // compiling unreachable code, but the unsigned compare trick used below
107 // only works with non-negative lengths. Instead, hack "tst" to be zero so
108 // the uncommon_trap path will always be taken.
109 tst = _gvn.intcon(0);
110 } else {
111 // Range is constant in array-oop, so we can use the original state of mem
112 Node* len = load_array_length(ary);
114 // Test length vs index (standard trick using unsigned compare)
115 Node* chk = _gvn.transform( new (C, 3) CmpUNode(idx, len) );
116 BoolTest::mask btest = BoolTest::lt;
117 tst = _gvn.transform( new (C, 2) BoolNode(chk, btest) );
118 }
119 // Branch to failure if out of bounds
120 { BuildCutout unless(this, tst, PROB_MAX);
121 if (C->allow_range_check_smearing()) {
122 // Do not use builtin_throw, since range checks are sometimes
123 // made more stringent by an optimistic transformation.
124 // This creates "tentative" range checks at this point,
125 // which are not guaranteed to throw exceptions.
126 // See IfNode::Ideal, is_range_check, adjust_check.
127 uncommon_trap(Deoptimization::Reason_range_check,
128 Deoptimization::Action_make_not_entrant,
129 NULL, "range_check");
130 } else {
131 // If we have already recompiled with the range-check-widening
132 // heroic optimization turned off, then we must really be throwing
133 // range check exceptions.
134 builtin_throw(Deoptimization::Reason_range_check, idx);
135 }
136 }
137 }
138 // Check for always knowing you are throwing a range-check exception
139 if (stopped()) return top();
141 Node* ptr = array_element_address(ary, idx, type, sizetype);
143 if (result2 != NULL) *result2 = elemtype;
145 assert(ptr != top(), "top should go hand-in-hand with stopped");
147 return ptr;
148 }
151 // returns IfNode
152 IfNode* Parse::jump_if_fork_int(Node* a, Node* b, BoolTest::mask mask) {
153 Node *cmp = _gvn.transform( new (C, 3) CmpINode( a, b)); // two cases: shiftcount > 32 and shiftcount <= 32
154 Node *tst = _gvn.transform( new (C, 2) BoolNode( cmp, mask));
155 IfNode *iff = create_and_map_if( control(), tst, ((mask == BoolTest::eq) ? PROB_STATIC_INFREQUENT : PROB_FAIR), COUNT_UNKNOWN );
156 return iff;
157 }
159 // return Region node
160 Node* Parse::jump_if_join(Node* iffalse, Node* iftrue) {
161 Node *region = new (C, 3) RegionNode(3); // 2 results
162 record_for_igvn(region);
163 region->init_req(1, iffalse);
164 region->init_req(2, iftrue );
165 _gvn.set_type(region, Type::CONTROL);
166 region = _gvn.transform(region);
167 set_control (region);
168 return region;
169 }
172 //------------------------------helper for tableswitch-------------------------
173 void Parse::jump_if_true_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) {
174 // True branch, use existing map info
175 { PreserveJVMState pjvms(this);
176 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode (iff) );
177 set_control( iftrue );
178 profile_switch_case(prof_table_index);
179 merge_new_path(dest_bci_if_true);
180 }
182 // False branch
183 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff) );
184 set_control( iffalse );
185 }
187 void Parse::jump_if_false_fork(IfNode *iff, int dest_bci_if_true, int prof_table_index) {
188 // True branch, use existing map info
189 { PreserveJVMState pjvms(this);
190 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode (iff) );
191 set_control( iffalse );
192 profile_switch_case(prof_table_index);
193 merge_new_path(dest_bci_if_true);
194 }
196 // False branch
197 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff) );
198 set_control( iftrue );
199 }
201 void Parse::jump_if_always_fork(int dest_bci, int prof_table_index) {
202 // False branch, use existing map and control()
203 profile_switch_case(prof_table_index);
204 merge_new_path(dest_bci);
205 }
208 extern "C" {
209 static int jint_cmp(const void *i, const void *j) {
210 int a = *(jint *)i;
211 int b = *(jint *)j;
212 return a > b ? 1 : a < b ? -1 : 0;
213 }
214 }
217 // Default value for methodData switch indexing. Must be a negative value to avoid
218 // conflict with any legal switch index.
219 #define NullTableIndex -1
221 class SwitchRange : public StackObj {
222 // a range of integers coupled with a bci destination
223 jint _lo; // inclusive lower limit
224 jint _hi; // inclusive upper limit
225 int _dest;
226 int _table_index; // index into method data table
228 public:
229 jint lo() const { return _lo; }
230 jint hi() const { return _hi; }
231 int dest() const { return _dest; }
232 int table_index() const { return _table_index; }
233 bool is_singleton() const { return _lo == _hi; }
235 void setRange(jint lo, jint hi, int dest, int table_index) {
236 assert(lo <= hi, "must be a non-empty range");
237 _lo = lo, _hi = hi; _dest = dest; _table_index = table_index;
238 }
239 bool adjoinRange(jint lo, jint hi, int dest, int table_index) {
240 assert(lo <= hi, "must be a non-empty range");
241 if (lo == _hi+1 && dest == _dest && table_index == _table_index) {
242 _hi = hi;
243 return true;
244 }
245 return false;
246 }
248 void set (jint value, int dest, int table_index) {
249 setRange(value, value, dest, table_index);
250 }
251 bool adjoin(jint value, int dest, int table_index) {
252 return adjoinRange(value, value, dest, table_index);
253 }
255 void print(ciEnv* env) {
256 if (is_singleton())
257 tty->print(" {%d}=>%d", lo(), dest());
258 else if (lo() == min_jint)
259 tty->print(" {..%d}=>%d", hi(), dest());
260 else if (hi() == max_jint)
261 tty->print(" {%d..}=>%d", lo(), dest());
262 else
263 tty->print(" {%d..%d}=>%d", lo(), hi(), dest());
264 }
265 };
268 //-------------------------------do_tableswitch--------------------------------
269 void Parse::do_tableswitch() {
270 Node* lookup = pop();
272 // Get information about tableswitch
273 int default_dest = iter().get_dest_table(0);
274 int lo_index = iter().get_int_table(1);
275 int hi_index = iter().get_int_table(2);
276 int len = hi_index - lo_index + 1;
278 if (len < 1) {
279 // If this is a backward branch, add safepoint
280 maybe_add_safepoint(default_dest);
281 if (should_add_predicate(default_dest)){
282 _sp += 1; // set original stack for use by uncommon_trap
283 add_predicate();
284 _sp -= 1;
285 }
286 merge(default_dest);
287 return;
288 }
290 // generate decision tree, using trichotomy when possible
291 int rnum = len+2;
292 bool makes_backward_branch = false;
293 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
294 int rp = -1;
295 if (lo_index != min_jint) {
296 ranges[++rp].setRange(min_jint, lo_index-1, default_dest, NullTableIndex);
297 }
298 for (int j = 0; j < len; j++) {
299 jint match_int = lo_index+j;
300 int dest = iter().get_dest_table(j+3);
301 makes_backward_branch |= (dest <= bci());
302 int table_index = method_data_update() ? j : NullTableIndex;
303 if (rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index)) {
304 ranges[++rp].set(match_int, dest, table_index);
305 }
306 }
307 jint highest = lo_index+(len-1);
308 assert(ranges[rp].hi() == highest, "");
309 if (highest != max_jint
310 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex)) {
311 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex);
312 }
313 assert(rp < len+2, "not too many ranges");
315 // Safepoint in case if backward branch observed
316 if( makes_backward_branch && UseLoopSafepoints )
317 add_safepoint();
319 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
320 }
323 //------------------------------do_lookupswitch--------------------------------
324 void Parse::do_lookupswitch() {
325 Node *lookup = pop(); // lookup value
326 // Get information about lookupswitch
327 int default_dest = iter().get_dest_table(0);
328 int len = iter().get_int_table(1);
330 if (len < 1) { // If this is a backward branch, add safepoint
331 maybe_add_safepoint(default_dest);
332 if (should_add_predicate(default_dest)){
333 _sp += 1; // set original stack for use by uncommon_trap
334 add_predicate();
335 _sp -= 1;
336 }
337 merge(default_dest);
338 return;
339 }
341 // generate decision tree, using trichotomy when possible
342 jint* table = NEW_RESOURCE_ARRAY(jint, len*2);
343 {
344 for( int j = 0; j < len; j++ ) {
345 table[j+j+0] = iter().get_int_table(2+j+j);
346 table[j+j+1] = iter().get_dest_table(2+j+j+1);
347 }
348 qsort( table, len, 2*sizeof(table[0]), jint_cmp );
349 }
351 int rnum = len*2+1;
352 bool makes_backward_branch = false;
353 SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
354 int rp = -1;
355 for( int j = 0; j < len; j++ ) {
356 jint match_int = table[j+j+0];
357 int dest = table[j+j+1];
358 int next_lo = rp < 0 ? min_jint : ranges[rp].hi()+1;
359 int table_index = method_data_update() ? j : NullTableIndex;
360 makes_backward_branch |= (dest <= bci());
361 if( match_int != next_lo ) {
362 ranges[++rp].setRange(next_lo, match_int-1, default_dest, NullTableIndex);
363 }
364 if( rp < 0 || !ranges[rp].adjoin(match_int, dest, table_index) ) {
365 ranges[++rp].set(match_int, dest, table_index);
366 }
367 }
368 jint highest = table[2*(len-1)];
369 assert(ranges[rp].hi() == highest, "");
370 if( highest != max_jint
371 && !ranges[rp].adjoinRange(highest+1, max_jint, default_dest, NullTableIndex) ) {
372 ranges[++rp].setRange(highest+1, max_jint, default_dest, NullTableIndex);
373 }
374 assert(rp < rnum, "not too many ranges");
376 // Safepoint in case backward branch observed
377 if( makes_backward_branch && UseLoopSafepoints )
378 add_safepoint();
380 jump_switch_ranges(lookup, &ranges[0], &ranges[rp]);
381 }
383 //----------------------------create_jump_tables-------------------------------
384 bool Parse::create_jump_tables(Node* key_val, SwitchRange* lo, SwitchRange* hi) {
385 // Are jumptables enabled
386 if (!UseJumpTables) return false;
388 // Are jumptables supported
389 if (!Matcher::has_match_rule(Op_Jump)) return false;
391 // Don't make jump table if profiling
392 if (method_data_update()) return false;
394 // Decide if a guard is needed to lop off big ranges at either (or
395 // both) end(s) of the input set. We'll call this the default target
396 // even though we can't be sure that it is the true "default".
398 bool needs_guard = false;
399 int default_dest;
400 int64 total_outlier_size = 0;
401 int64 hi_size = ((int64)hi->hi()) - ((int64)hi->lo()) + 1;
402 int64 lo_size = ((int64)lo->hi()) - ((int64)lo->lo()) + 1;
404 if (lo->dest() == hi->dest()) {
405 total_outlier_size = hi_size + lo_size;
406 default_dest = lo->dest();
407 } else if (lo_size > hi_size) {
408 total_outlier_size = lo_size;
409 default_dest = lo->dest();
410 } else {
411 total_outlier_size = hi_size;
412 default_dest = hi->dest();
413 }
415 // If a guard test will eliminate very sparse end ranges, then
416 // it is worth the cost of an extra jump.
417 if (total_outlier_size > (MaxJumpTableSparseness * 4)) {
418 needs_guard = true;
419 if (default_dest == lo->dest()) lo++;
420 if (default_dest == hi->dest()) hi--;
421 }
423 // Find the total number of cases and ranges
424 int64 num_cases = ((int64)hi->hi()) - ((int64)lo->lo()) + 1;
425 int num_range = hi - lo + 1;
427 // Don't create table if: too large, too small, or too sparse.
428 if (num_cases < MinJumpTableSize || num_cases > MaxJumpTableSize)
429 return false;
430 if (num_cases > (MaxJumpTableSparseness * num_range))
431 return false;
433 // Normalize table lookups to zero
434 int lowval = lo->lo();
435 key_val = _gvn.transform( new (C, 3) SubINode(key_val, _gvn.intcon(lowval)) );
437 // Generate a guard to protect against input keyvals that aren't
438 // in the switch domain.
439 if (needs_guard) {
440 Node* size = _gvn.intcon(num_cases);
441 Node* cmp = _gvn.transform( new (C, 3) CmpUNode(key_val, size) );
442 Node* tst = _gvn.transform( new (C, 2) BoolNode(cmp, BoolTest::ge) );
443 IfNode* iff = create_and_map_if( control(), tst, PROB_FAIR, COUNT_UNKNOWN);
444 jump_if_true_fork(iff, default_dest, NullTableIndex);
445 }
447 // Create an ideal node JumpTable that has projections
448 // of all possible ranges for a switch statement
449 // The key_val input must be converted to a pointer offset and scaled.
450 // Compare Parse::array_addressing above.
451 #ifdef _LP64
452 // Clean the 32-bit int into a real 64-bit offset.
453 // Otherwise, the jint value 0 might turn into an offset of 0x0800000000.
454 const TypeLong* lkeytype = TypeLong::make(CONST64(0), num_cases-1, Type::WidenMin);
455 key_val = _gvn.transform( new (C, 2) ConvI2LNode(key_val, lkeytype) );
456 #endif
457 // Shift the value by wordsize so we have an index into the table, rather
458 // than a switch value
459 Node *shiftWord = _gvn.MakeConX(wordSize);
460 key_val = _gvn.transform( new (C, 3) MulXNode( key_val, shiftWord));
462 // Create the JumpNode
463 Node* jtn = _gvn.transform( new (C, 2) JumpNode(control(), key_val, num_cases) );
465 // These are the switch destinations hanging off the jumpnode
466 int i = 0;
467 for (SwitchRange* r = lo; r <= hi; r++) {
468 for (int j = r->lo(); j <= r->hi(); j++, i++) {
469 Node* input = _gvn.transform(new (C, 1) JumpProjNode(jtn, i, r->dest(), j - lowval));
470 {
471 PreserveJVMState pjvms(this);
472 set_control(input);
473 jump_if_always_fork(r->dest(), r->table_index());
474 }
475 }
476 }
477 assert(i == num_cases, "miscount of cases");
478 stop_and_kill_map(); // no more uses for this JVMS
479 return true;
480 }
482 //----------------------------jump_switch_ranges-------------------------------
483 void Parse::jump_switch_ranges(Node* key_val, SwitchRange *lo, SwitchRange *hi, int switch_depth) {
484 Block* switch_block = block();
486 if (switch_depth == 0) {
487 // Do special processing for the top-level call.
488 assert(lo->lo() == min_jint, "initial range must exhaust Type::INT");
489 assert(hi->hi() == max_jint, "initial range must exhaust Type::INT");
491 // Decrement pred-numbers for the unique set of nodes.
492 #ifdef ASSERT
493 // Ensure that the block's successors are a (duplicate-free) set.
494 int successors_counted = 0; // block occurrences in [hi..lo]
495 int unique_successors = switch_block->num_successors();
496 for (int i = 0; i < unique_successors; i++) {
497 Block* target = switch_block->successor_at(i);
499 // Check that the set of successors is the same in both places.
500 int successors_found = 0;
501 for (SwitchRange* p = lo; p <= hi; p++) {
502 if (p->dest() == target->start()) successors_found++;
503 }
504 assert(successors_found > 0, "successor must be known");
505 successors_counted += successors_found;
506 }
507 assert(successors_counted == (hi-lo)+1, "no unexpected successors");
508 #endif
510 // Maybe prune the inputs, based on the type of key_val.
511 jint min_val = min_jint;
512 jint max_val = max_jint;
513 const TypeInt* ti = key_val->bottom_type()->isa_int();
514 if (ti != NULL) {
515 min_val = ti->_lo;
516 max_val = ti->_hi;
517 assert(min_val <= max_val, "invalid int type");
518 }
519 while (lo->hi() < min_val) lo++;
520 if (lo->lo() < min_val) lo->setRange(min_val, lo->hi(), lo->dest(), lo->table_index());
521 while (hi->lo() > max_val) hi--;
522 if (hi->hi() > max_val) hi->setRange(hi->lo(), max_val, hi->dest(), hi->table_index());
523 }
525 #ifndef PRODUCT
526 if (switch_depth == 0) {
527 _max_switch_depth = 0;
528 _est_switch_depth = log2_intptr((hi-lo+1)-1)+1;
529 }
530 #endif
532 assert(lo <= hi, "must be a non-empty set of ranges");
533 if (lo == hi) {
534 jump_if_always_fork(lo->dest(), lo->table_index());
535 } else {
536 assert(lo->hi() == (lo+1)->lo()-1, "contiguous ranges");
537 assert(hi->lo() == (hi-1)->hi()+1, "contiguous ranges");
539 if (create_jump_tables(key_val, lo, hi)) return;
541 int nr = hi - lo + 1;
543 SwitchRange* mid = lo + nr/2;
544 // if there is an easy choice, pivot at a singleton:
545 if (nr > 3 && !mid->is_singleton() && (mid-1)->is_singleton()) mid--;
547 assert(lo < mid && mid <= hi, "good pivot choice");
548 assert(nr != 2 || mid == hi, "should pick higher of 2");
549 assert(nr != 3 || mid == hi-1, "should pick middle of 3");
551 Node *test_val = _gvn.intcon(mid->lo());
553 if (mid->is_singleton()) {
554 IfNode *iff_ne = jump_if_fork_int(key_val, test_val, BoolTest::ne);
555 jump_if_false_fork(iff_ne, mid->dest(), mid->table_index());
557 // Special Case: If there are exactly three ranges, and the high
558 // and low range each go to the same place, omit the "gt" test,
559 // since it will not discriminate anything.
560 bool eq_test_only = (hi == lo+2 && hi->dest() == lo->dest());
561 if (eq_test_only) {
562 assert(mid == hi-1, "");
563 }
565 // if there is a higher range, test for it and process it:
566 if (mid < hi && !eq_test_only) {
567 // two comparisons of same values--should enable 1 test for 2 branches
568 // Use BoolTest::le instead of BoolTest::gt
569 IfNode *iff_le = jump_if_fork_int(key_val, test_val, BoolTest::le);
570 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff_le) );
571 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff_le) );
572 { PreserveJVMState pjvms(this);
573 set_control(iffalse);
574 jump_switch_ranges(key_val, mid+1, hi, switch_depth+1);
575 }
576 set_control(iftrue);
577 }
579 } else {
580 // mid is a range, not a singleton, so treat mid..hi as a unit
581 IfNode *iff_ge = jump_if_fork_int(key_val, test_val, BoolTest::ge);
583 // if there is a higher range, test for it and process it:
584 if (mid == hi) {
585 jump_if_true_fork(iff_ge, mid->dest(), mid->table_index());
586 } else {
587 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(iff_ge) );
588 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff_ge) );
589 { PreserveJVMState pjvms(this);
590 set_control(iftrue);
591 jump_switch_ranges(key_val, mid, hi, switch_depth+1);
592 }
593 set_control(iffalse);
594 }
595 }
597 // in any case, process the lower range
598 jump_switch_ranges(key_val, lo, mid-1, switch_depth+1);
599 }
601 // Decrease pred_count for each successor after all is done.
602 if (switch_depth == 0) {
603 int unique_successors = switch_block->num_successors();
604 for (int i = 0; i < unique_successors; i++) {
605 Block* target = switch_block->successor_at(i);
606 // Throw away the pre-allocated path for each unique successor.
607 target->next_path_num();
608 }
609 }
611 #ifndef PRODUCT
612 _max_switch_depth = MAX2(switch_depth, _max_switch_depth);
613 if (TraceOptoParse && Verbose && WizardMode && switch_depth == 0) {
614 SwitchRange* r;
615 int nsing = 0;
616 for( r = lo; r <= hi; r++ ) {
617 if( r->is_singleton() ) nsing++;
618 }
619 tty->print(">>> ");
620 _method->print_short_name();
621 tty->print_cr(" switch decision tree");
622 tty->print_cr(" %d ranges (%d singletons), max_depth=%d, est_depth=%d",
623 hi-lo+1, nsing, _max_switch_depth, _est_switch_depth);
624 if (_max_switch_depth > _est_switch_depth) {
625 tty->print_cr("******** BAD SWITCH DEPTH ********");
626 }
627 tty->print(" ");
628 for( r = lo; r <= hi; r++ ) {
629 r->print(env());
630 }
631 tty->print_cr("");
632 }
633 #endif
634 }
636 void Parse::modf() {
637 Node *f2 = pop();
638 Node *f1 = pop();
639 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::modf_Type(),
640 CAST_FROM_FN_PTR(address, SharedRuntime::frem),
641 "frem", NULL, //no memory effects
642 f1, f2);
643 Node* res = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
645 push(res);
646 }
648 void Parse::modd() {
649 Node *d2 = pop_pair();
650 Node *d1 = pop_pair();
651 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::Math_DD_D_Type(),
652 CAST_FROM_FN_PTR(address, SharedRuntime::drem),
653 "drem", NULL, //no memory effects
654 d1, top(), d2, top());
655 Node* res_d = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
657 #ifdef ASSERT
658 Node* res_top = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 1));
659 assert(res_top == top(), "second value must be top");
660 #endif
662 push_pair(res_d);
663 }
665 void Parse::l2f() {
666 Node* f2 = pop();
667 Node* f1 = pop();
668 Node* c = make_runtime_call(RC_LEAF, OptoRuntime::l2f_Type(),
669 CAST_FROM_FN_PTR(address, SharedRuntime::l2f),
670 "l2f", NULL, //no memory effects
671 f1, f2);
672 Node* res = _gvn.transform(new (C, 1) ProjNode(c, TypeFunc::Parms + 0));
674 push(res);
675 }
677 void Parse::do_irem() {
678 // Must keep both values on the expression-stack during null-check
679 do_null_check(peek(), T_INT);
680 // Compile-time detect of null-exception?
681 if (stopped()) return;
683 Node* b = pop();
684 Node* a = pop();
686 const Type *t = _gvn.type(b);
687 if (t != Type::TOP) {
688 const TypeInt *ti = t->is_int();
689 if (ti->is_con()) {
690 int divisor = ti->get_con();
691 // check for positive power of 2
692 if (divisor > 0 &&
693 (divisor & ~(divisor-1)) == divisor) {
694 // yes !
695 Node *mask = _gvn.intcon((divisor - 1));
696 // Sigh, must handle negative dividends
697 Node *zero = _gvn.intcon(0);
698 IfNode *ifff = jump_if_fork_int(a, zero, BoolTest::lt);
699 Node *iff = _gvn.transform( new (C, 1) IfFalseNode(ifff) );
700 Node *ift = _gvn.transform( new (C, 1) IfTrueNode (ifff) );
701 Node *reg = jump_if_join(ift, iff);
702 Node *phi = PhiNode::make(reg, NULL, TypeInt::INT);
703 // Negative path; negate/and/negate
704 Node *neg = _gvn.transform( new (C, 3) SubINode(zero, a) );
705 Node *andn= _gvn.transform( new (C, 3) AndINode(neg, mask) );
706 Node *negn= _gvn.transform( new (C, 3) SubINode(zero, andn) );
707 phi->init_req(1, negn);
708 // Fast positive case
709 Node *andx = _gvn.transform( new (C, 3) AndINode(a, mask) );
710 phi->init_req(2, andx);
711 // Push the merge
712 push( _gvn.transform(phi) );
713 return;
714 }
715 }
716 }
717 // Default case
718 push( _gvn.transform( new (C, 3) ModINode(control(),a,b) ) );
719 }
721 // Handle jsr and jsr_w bytecode
722 void Parse::do_jsr() {
723 assert(bc() == Bytecodes::_jsr || bc() == Bytecodes::_jsr_w, "wrong bytecode");
725 // Store information about current state, tagged with new _jsr_bci
726 int return_bci = iter().next_bci();
727 int jsr_bci = (bc() == Bytecodes::_jsr) ? iter().get_dest() : iter().get_far_dest();
729 // Update method data
730 profile_taken_branch(jsr_bci);
732 // The way we do things now, there is only one successor block
733 // for the jsr, because the target code is cloned by ciTypeFlow.
734 Block* target = successor_for_bci(jsr_bci);
736 // What got pushed?
737 const Type* ret_addr = target->peek();
738 assert(ret_addr->singleton(), "must be a constant (cloned jsr body)");
740 // Effect on jsr on stack
741 push(_gvn.makecon(ret_addr));
743 // Flow to the jsr.
744 if (should_add_predicate(jsr_bci)){
745 add_predicate();
746 }
747 merge(jsr_bci);
748 }
750 // Handle ret bytecode
751 void Parse::do_ret() {
752 // Find to whom we return.
753 #if 0 // %%%% MAKE THIS WORK
754 Node* con = local();
755 const TypePtr* tp = con->bottom_type()->isa_ptr();
756 assert(tp && tp->singleton(), "");
757 int return_bci = (int) tp->get_con();
758 merge(return_bci);
759 #else
760 assert(block()->num_successors() == 1, "a ret can only go one place now");
761 Block* target = block()->successor_at(0);
762 assert(!target->is_ready(), "our arrival must be expected");
763 profile_ret(target->flow()->start());
764 int pnum = target->next_path_num();
765 merge_common(target, pnum);
766 #endif
767 }
769 //--------------------------dynamic_branch_prediction--------------------------
770 // Try to gather dynamic branch prediction behavior. Return a probability
771 // of the branch being taken and set the "cnt" field. Returns a -1.0
772 // if we need to use static prediction for some reason.
773 float Parse::dynamic_branch_prediction(float &cnt) {
774 ResourceMark rm;
776 cnt = COUNT_UNKNOWN;
778 // Use MethodData information if it is available
779 // FIXME: free the ProfileData structure
780 ciMethodData* methodData = method()->method_data();
781 if (!methodData->is_mature()) return PROB_UNKNOWN;
782 ciProfileData* data = methodData->bci_to_data(bci());
783 if (!data->is_JumpData()) return PROB_UNKNOWN;
785 // get taken and not taken values
786 int taken = data->as_JumpData()->taken();
787 int not_taken = 0;
788 if (data->is_BranchData()) {
789 not_taken = data->as_BranchData()->not_taken();
790 }
792 // scale the counts to be commensurate with invocation counts:
793 taken = method()->scale_count(taken);
794 not_taken = method()->scale_count(not_taken);
796 // Give up if too few counts to be meaningful
797 if (taken + not_taken < 40) {
798 if (C->log() != NULL) {
799 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
800 }
801 return PROB_UNKNOWN;
802 }
804 // Compute frequency that we arrive here
805 int sum = taken + not_taken;
806 // Adjust, if this block is a cloned private block but the
807 // Jump counts are shared. Taken the private counts for
808 // just this path instead of the shared counts.
809 if( block()->count() > 0 )
810 sum = block()->count();
811 cnt = (float)sum / (float)FreqCountInvocations;
813 // Pin probability to sane limits
814 float prob;
815 if( !taken )
816 prob = (0+PROB_MIN) / 2;
817 else if( !not_taken )
818 prob = (1+PROB_MAX) / 2;
819 else { // Compute probability of true path
820 prob = (float)taken / (float)(taken + not_taken);
821 if (prob > PROB_MAX) prob = PROB_MAX;
822 if (prob < PROB_MIN) prob = PROB_MIN;
823 }
825 assert((cnt > 0.0f) && (prob > 0.0f),
826 "Bad frequency assignment in if");
828 if (C->log() != NULL) {
829 const char* prob_str = NULL;
830 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
831 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
832 char prob_str_buf[30];
833 if (prob_str == NULL) {
834 sprintf(prob_str_buf, "%g", prob);
835 prob_str = prob_str_buf;
836 }
837 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
838 iter().get_dest(), taken, not_taken, cnt, prob_str);
839 }
840 return prob;
841 }
843 //-----------------------------branch_prediction-------------------------------
844 float Parse::branch_prediction(float& cnt,
845 BoolTest::mask btest,
846 int target_bci) {
847 float prob = dynamic_branch_prediction(cnt);
848 // If prob is unknown, switch to static prediction
849 if (prob != PROB_UNKNOWN) return prob;
851 prob = PROB_FAIR; // Set default value
852 if (btest == BoolTest::eq) // Exactly equal test?
853 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
854 else if (btest == BoolTest::ne)
855 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent
857 // If this is a conditional test guarding a backwards branch,
858 // assume its a loop-back edge. Make it a likely taken branch.
859 if (target_bci < bci()) {
860 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt
861 // Since it's an OSR, we probably have profile data, but since
862 // branch_prediction returned PROB_UNKNOWN, the counts are too small.
863 // Let's make a special check here for completely zero counts.
864 ciMethodData* methodData = method()->method_data();
865 if (!methodData->is_empty()) {
866 ciProfileData* data = methodData->bci_to_data(bci());
867 // Only stop for truly zero counts, which mean an unknown part
868 // of the OSR-ed method, and we want to deopt to gather more stats.
869 // If you have ANY counts, then this loop is simply 'cold' relative
870 // to the OSR loop.
871 if (data->as_BranchData()->taken() +
872 data->as_BranchData()->not_taken() == 0 ) {
873 // This is the only way to return PROB_UNKNOWN:
874 return PROB_UNKNOWN;
875 }
876 }
877 }
878 prob = PROB_STATIC_FREQUENT; // Likely to take backwards branch
879 }
881 assert(prob != PROB_UNKNOWN, "must have some guess at this point");
882 return prob;
883 }
885 // The magic constants are chosen so as to match the output of
886 // branch_prediction() when the profile reports a zero taken count.
887 // It is important to distinguish zero counts unambiguously, because
888 // some branches (e.g., _213_javac.Assembler.eliminate) validly produce
889 // very small but nonzero probabilities, which if confused with zero
890 // counts would keep the program recompiling indefinitely.
891 bool Parse::seems_never_taken(float prob) {
892 return prob < PROB_MIN;
893 }
895 //-------------------------------repush_if_args--------------------------------
896 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
897 inline int Parse::repush_if_args() {
898 #ifndef PRODUCT
899 if (PrintOpto && WizardMode) {
900 tty->print("defending against excessive implicit null exceptions on %s @%d in ",
901 Bytecodes::name(iter().cur_bc()), iter().cur_bci());
902 method()->print_name(); tty->cr();
903 }
904 #endif
905 int bc_depth = - Bytecodes::depth(iter().cur_bc());
906 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
907 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
908 assert(argument(0) != NULL, "must exist");
909 assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
910 _sp += bc_depth;
911 return bc_depth;
912 }
914 //----------------------------------do_ifnull----------------------------------
915 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
916 int target_bci = iter().get_dest();
918 Block* branch_block = successor_for_bci(target_bci);
919 Block* next_block = successor_for_bci(iter().next_bci());
921 float cnt;
922 float prob = branch_prediction(cnt, btest, target_bci);
923 if (prob == PROB_UNKNOWN) {
924 // (An earlier version of do_ifnull omitted this trap for OSR methods.)
925 #ifndef PRODUCT
926 if (PrintOpto && Verbose)
927 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
928 #endif
929 repush_if_args(); // to gather stats on loop
930 // We need to mark this branch as taken so that if we recompile we will
931 // see that it is possible. In the tiered system the interpreter doesn't
932 // do profiling and by the time we get to the lower tier from the interpreter
933 // the path may be cold again. Make sure it doesn't look untaken
934 profile_taken_branch(target_bci, !ProfileInterpreter);
935 uncommon_trap(Deoptimization::Reason_unreached,
936 Deoptimization::Action_reinterpret,
937 NULL, "cold");
938 if (EliminateAutoBox) {
939 // Mark the successor blocks as parsed
940 branch_block->next_path_num();
941 next_block->next_path_num();
942 }
943 return;
944 }
946 explicit_null_checks_inserted++;
948 // Generate real control flow
949 Node *tst = _gvn.transform( new (C, 2) BoolNode( c, btest ) );
951 // Sanity check the probability value
952 assert(prob > 0.0f,"Bad probability in Parser");
953 // Need xform to put node in hash table
954 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt );
955 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
956 // True branch
957 { PreserveJVMState pjvms(this);
958 Node* iftrue = _gvn.transform( new (C, 1) IfTrueNode (iff) );
959 set_control(iftrue);
961 if (stopped()) { // Path is dead?
962 explicit_null_checks_elided++;
963 if (EliminateAutoBox) {
964 // Mark the successor block as parsed
965 branch_block->next_path_num();
966 }
967 } else { // Path is live.
968 // Update method data
969 profile_taken_branch(target_bci);
970 adjust_map_after_if(btest, c, prob, branch_block, next_block);
971 if (!stopped()) {
972 if (should_add_predicate(target_bci)){ // add a predicate if it branches to a loop
973 int nargs = repush_if_args(); // set original stack for uncommon_trap
974 add_predicate();
975 _sp -= nargs;
976 }
977 merge(target_bci);
978 }
979 }
980 }
982 // False branch
983 Node* iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff) );
984 set_control(iffalse);
986 if (stopped()) { // Path is dead?
987 explicit_null_checks_elided++;
988 if (EliminateAutoBox) {
989 // Mark the successor block as parsed
990 next_block->next_path_num();
991 }
992 } else { // Path is live.
993 // Update method data
994 profile_not_taken_branch();
995 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
996 next_block, branch_block);
997 }
998 }
1000 //------------------------------------do_if------------------------------------
1001 void Parse::do_if(BoolTest::mask btest, Node* c) {
1002 int target_bci = iter().get_dest();
1004 Block* branch_block = successor_for_bci(target_bci);
1005 Block* next_block = successor_for_bci(iter().next_bci());
1007 float cnt;
1008 float prob = branch_prediction(cnt, btest, target_bci);
1009 float untaken_prob = 1.0 - prob;
1011 if (prob == PROB_UNKNOWN) {
1012 #ifndef PRODUCT
1013 if (PrintOpto && Verbose)
1014 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
1015 #endif
1016 repush_if_args(); // to gather stats on loop
1017 // We need to mark this branch as taken so that if we recompile we will
1018 // see that it is possible. In the tiered system the interpreter doesn't
1019 // do profiling and by the time we get to the lower tier from the interpreter
1020 // the path may be cold again. Make sure it doesn't look untaken
1021 profile_taken_branch(target_bci, !ProfileInterpreter);
1022 uncommon_trap(Deoptimization::Reason_unreached,
1023 Deoptimization::Action_reinterpret,
1024 NULL, "cold");
1025 if (EliminateAutoBox) {
1026 // Mark the successor blocks as parsed
1027 branch_block->next_path_num();
1028 next_block->next_path_num();
1029 }
1030 return;
1031 }
1033 // Sanity check the probability value
1034 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser");
1036 bool taken_if_true = true;
1037 // Convert BoolTest to canonical form:
1038 if (!BoolTest(btest).is_canonical()) {
1039 btest = BoolTest(btest).negate();
1040 taken_if_true = false;
1041 // prob is NOT updated here; it remains the probability of the taken
1042 // path (as opposed to the prob of the path guarded by an 'IfTrueNode').
1043 }
1044 assert(btest != BoolTest::eq, "!= is the only canonical exact test");
1046 Node* tst0 = new (C, 2) BoolNode(c, btest);
1047 Node* tst = _gvn.transform(tst0);
1048 BoolTest::mask taken_btest = BoolTest::illegal;
1049 BoolTest::mask untaken_btest = BoolTest::illegal;
1051 if (tst->is_Bool()) {
1052 // Refresh c from the transformed bool node, since it may be
1053 // simpler than the original c. Also re-canonicalize btest.
1054 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)).
1055 // That can arise from statements like: if (x instanceof C) ...
1056 if (tst != tst0) {
1057 // Canonicalize one more time since transform can change it.
1058 btest = tst->as_Bool()->_test._test;
1059 if (!BoolTest(btest).is_canonical()) {
1060 // Reverse edges one more time...
1061 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) );
1062 btest = tst->as_Bool()->_test._test;
1063 assert(BoolTest(btest).is_canonical(), "sanity");
1064 taken_if_true = !taken_if_true;
1065 }
1066 c = tst->in(1);
1067 }
1068 BoolTest::mask neg_btest = BoolTest(btest).negate();
1069 taken_btest = taken_if_true ? btest : neg_btest;
1070 untaken_btest = taken_if_true ? neg_btest : btest;
1071 }
1073 // Generate real control flow
1074 float true_prob = (taken_if_true ? prob : untaken_prob);
1075 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1076 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1077 Node* taken_branch = new (C, 1) IfTrueNode(iff);
1078 Node* untaken_branch = new (C, 1) IfFalseNode(iff);
1079 if (!taken_if_true) { // Finish conversion to canonical form
1080 Node* tmp = taken_branch;
1081 taken_branch = untaken_branch;
1082 untaken_branch = tmp;
1083 }
1085 // Branch is taken:
1086 { PreserveJVMState pjvms(this);
1087 taken_branch = _gvn.transform(taken_branch);
1088 set_control(taken_branch);
1090 if (stopped()) {
1091 if (EliminateAutoBox) {
1092 // Mark the successor block as parsed
1093 branch_block->next_path_num();
1094 }
1095 } else {
1096 // Update method data
1097 profile_taken_branch(target_bci);
1098 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block);
1099 if (!stopped()) {
1100 if (should_add_predicate(target_bci)){ // add a predicate if it branches to a loop
1101 int nargs = repush_if_args(); // set original stack for the uncommon_trap
1102 add_predicate();
1103 _sp -= nargs;
1104 }
1105 merge(target_bci);
1106 }
1107 }
1108 }
1110 untaken_branch = _gvn.transform(untaken_branch);
1111 set_control(untaken_branch);
1113 // Branch not taken.
1114 if (stopped()) {
1115 if (EliminateAutoBox) {
1116 // Mark the successor block as parsed
1117 next_block->next_path_num();
1118 }
1119 } else {
1120 // Update method data
1121 profile_not_taken_branch();
1122 adjust_map_after_if(untaken_btest, c, untaken_prob,
1123 next_block, branch_block);
1124 }
1125 }
1127 //----------------------------adjust_map_after_if------------------------------
1128 // Adjust the JVM state to reflect the result of taking this path.
1129 // Basically, it means inspecting the CmpNode controlling this
1130 // branch, seeing how it constrains a tested value, and then
1131 // deciding if it's worth our while to encode this constraint
1132 // as graph nodes in the current abstract interpretation map.
1133 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob,
1134 Block* path, Block* other_path) {
1135 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal)
1136 return; // nothing to do
1138 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
1140 int cop = c->Opcode();
1141 if (seems_never_taken(prob) && cop == Op_CmpP && btest == BoolTest::eq) {
1142 // (An earlier version of do_if omitted '&& btest == BoolTest::eq'.)
1143 //
1144 // If this might possibly turn into an implicit null check,
1145 // and the null has never yet been seen, we need to generate
1146 // an uncommon trap, so as to recompile instead of suffering
1147 // with very slow branches. (We'll get the slow branches if
1148 // the program ever changes phase and starts seeing nulls here.)
1149 //
1150 // The tests we worry about are of the form (p == null).
1151 // We do not simply inspect for a null constant, since a node may
1152 // optimize to 'null' later on.
1153 repush_if_args();
1154 // We need to mark this branch as taken so that if we recompile we will
1155 // see that it is possible. In the tiered system the interpreter doesn't
1156 // do profiling and by the time we get to the lower tier from the interpreter
1157 // the path may be cold again. Make sure it doesn't look untaken
1158 if (is_fallthrough) {
1159 profile_not_taken_branch(!ProfileInterpreter);
1160 } else {
1161 profile_taken_branch(iter().get_dest(), !ProfileInterpreter);
1162 }
1163 uncommon_trap(Deoptimization::Reason_unreached,
1164 Deoptimization::Action_reinterpret,
1165 NULL,
1166 (is_fallthrough ? "taken always" : "taken never"));
1167 return;
1168 }
1170 Node* val = c->in(1);
1171 Node* con = c->in(2);
1172 const Type* tcon = _gvn.type(con);
1173 const Type* tval = _gvn.type(val);
1174 bool have_con = tcon->singleton();
1175 if (tval->singleton()) {
1176 if (!have_con) {
1177 // Swap, so constant is in con.
1178 con = val;
1179 tcon = tval;
1180 val = c->in(2);
1181 tval = _gvn.type(val);
1182 btest = BoolTest(btest).commute();
1183 have_con = true;
1184 } else {
1185 // Do we have two constants? Then leave well enough alone.
1186 have_con = false;
1187 }
1188 }
1189 if (!have_con) // remaining adjustments need a con
1190 return;
1193 int val_in_map = map()->find_edge(val);
1194 if (val_in_map < 0) return; // replace_in_map would be useless
1195 {
1196 JVMState* jvms = this->jvms();
1197 if (!(jvms->is_loc(val_in_map) ||
1198 jvms->is_stk(val_in_map)))
1199 return; // again, it would be useless
1200 }
1202 // Check for a comparison to a constant, and "know" that the compared
1203 // value is constrained on this path.
1204 assert(tcon->singleton(), "");
1205 ConstraintCastNode* ccast = NULL;
1206 Node* cast = NULL;
1208 switch (btest) {
1209 case BoolTest::eq: // Constant test?
1210 {
1211 const Type* tboth = tcon->join(tval);
1212 if (tboth == tval) break; // Nothing to gain.
1213 if (tcon->isa_int()) {
1214 ccast = new (C, 2) CastIINode(val, tboth);
1215 } else if (tcon == TypePtr::NULL_PTR) {
1216 // Cast to null, but keep the pointer identity temporarily live.
1217 ccast = new (C, 2) CastPPNode(val, tboth);
1218 } else {
1219 const TypeF* tf = tcon->isa_float_constant();
1220 const TypeD* td = tcon->isa_double_constant();
1221 // Exclude tests vs float/double 0 as these could be
1222 // either +0 or -0. Just because you are equal to +0
1223 // doesn't mean you ARE +0!
1224 if ((!tf || tf->_f != 0.0) &&
1225 (!td || td->_d != 0.0))
1226 cast = con; // Replace non-constant val by con.
1227 }
1228 }
1229 break;
1231 case BoolTest::ne:
1232 if (tcon == TypePtr::NULL_PTR) {
1233 cast = cast_not_null(val, false);
1234 }
1235 break;
1237 default:
1238 // (At this point we could record int range types with CastII.)
1239 break;
1240 }
1242 if (ccast != NULL) {
1243 const Type* tcc = ccast->as_Type()->type();
1244 assert(tcc != tval && tcc->higher_equal(tval), "must improve");
1245 // Delay transform() call to allow recovery of pre-cast value
1246 // at the control merge.
1247 ccast->set_req(0, control());
1248 _gvn.set_type_bottom(ccast);
1249 record_for_igvn(ccast);
1250 cast = ccast;
1251 }
1253 if (cast != NULL) { // Here's the payoff.
1254 replace_in_map(val, cast);
1255 }
1256 }
1259 //------------------------------do_one_bytecode--------------------------------
1260 // Parse this bytecode, and alter the Parsers JVM->Node mapping
1261 void Parse::do_one_bytecode() {
1262 Node *a, *b, *c, *d; // Handy temps
1263 BoolTest::mask btest;
1264 int i;
1266 assert(!has_exceptions(), "bytecode entry state must be clear of throws");
1268 if (C->check_node_count(NodeLimitFudgeFactor * 5,
1269 "out of nodes parsing method")) {
1270 return;
1271 }
1273 #ifdef ASSERT
1274 // for setting breakpoints
1275 if (TraceOptoParse) {
1276 tty->print(" @");
1277 dump_bci(bci());
1278 }
1279 #endif
1281 switch (bc()) {
1282 case Bytecodes::_nop:
1283 // do nothing
1284 break;
1285 case Bytecodes::_lconst_0:
1286 push_pair(longcon(0));
1287 break;
1289 case Bytecodes::_lconst_1:
1290 push_pair(longcon(1));
1291 break;
1293 case Bytecodes::_fconst_0:
1294 push(zerocon(T_FLOAT));
1295 break;
1297 case Bytecodes::_fconst_1:
1298 push(makecon(TypeF::ONE));
1299 break;
1301 case Bytecodes::_fconst_2:
1302 push(makecon(TypeF::make(2.0f)));
1303 break;
1305 case Bytecodes::_dconst_0:
1306 push_pair(zerocon(T_DOUBLE));
1307 break;
1309 case Bytecodes::_dconst_1:
1310 push_pair(makecon(TypeD::ONE));
1311 break;
1313 case Bytecodes::_iconst_m1:push(intcon(-1)); break;
1314 case Bytecodes::_iconst_0: push(intcon( 0)); break;
1315 case Bytecodes::_iconst_1: push(intcon( 1)); break;
1316 case Bytecodes::_iconst_2: push(intcon( 2)); break;
1317 case Bytecodes::_iconst_3: push(intcon( 3)); break;
1318 case Bytecodes::_iconst_4: push(intcon( 4)); break;
1319 case Bytecodes::_iconst_5: push(intcon( 5)); break;
1320 case Bytecodes::_bipush: push(intcon( iter().get_byte())); break;
1321 case Bytecodes::_sipush: push(intcon( iter().get_short())); break;
1322 case Bytecodes::_aconst_null: push(null()); break;
1323 case Bytecodes::_ldc:
1324 case Bytecodes::_ldc_w:
1325 case Bytecodes::_ldc2_w:
1326 // If the constant is unresolved, run this BC once in the interpreter.
1327 if (iter().is_unresolved_string()) {
1328 uncommon_trap(Deoptimization::make_trap_request
1329 (Deoptimization::Reason_unloaded,
1330 Deoptimization::Action_reinterpret,
1331 iter().get_constant_index()),
1332 NULL, "unresolved_string");
1333 break;
1334 } else {
1335 ciConstant constant = iter().get_constant();
1336 if (constant.basic_type() == T_OBJECT) {
1337 ciObject* c = constant.as_object();
1338 if (c->is_klass()) {
1339 // The constant returned for a klass is the ciKlass for the
1340 // entry. We want the java_mirror so get it.
1341 ciKlass* klass = c->as_klass();
1342 if (klass->is_loaded()) {
1343 constant = ciConstant(T_OBJECT, klass->java_mirror());
1344 } else {
1345 uncommon_trap(Deoptimization::make_trap_request
1346 (Deoptimization::Reason_unloaded,
1347 Deoptimization::Action_reinterpret,
1348 iter().get_constant_index()),
1349 NULL, "unresolved_klass");
1350 break;
1351 }
1352 }
1353 }
1354 bool pushed = push_constant(constant, true);
1355 guarantee(pushed, "must be possible to push this constant");
1356 }
1358 break;
1360 case Bytecodes::_aload_0:
1361 push( local(0) );
1362 break;
1363 case Bytecodes::_aload_1:
1364 push( local(1) );
1365 break;
1366 case Bytecodes::_aload_2:
1367 push( local(2) );
1368 break;
1369 case Bytecodes::_aload_3:
1370 push( local(3) );
1371 break;
1372 case Bytecodes::_aload:
1373 push( local(iter().get_index()) );
1374 break;
1376 case Bytecodes::_fload_0:
1377 case Bytecodes::_iload_0:
1378 push( local(0) );
1379 break;
1380 case Bytecodes::_fload_1:
1381 case Bytecodes::_iload_1:
1382 push( local(1) );
1383 break;
1384 case Bytecodes::_fload_2:
1385 case Bytecodes::_iload_2:
1386 push( local(2) );
1387 break;
1388 case Bytecodes::_fload_3:
1389 case Bytecodes::_iload_3:
1390 push( local(3) );
1391 break;
1392 case Bytecodes::_fload:
1393 case Bytecodes::_iload:
1394 push( local(iter().get_index()) );
1395 break;
1396 case Bytecodes::_lload_0:
1397 push_pair_local( 0 );
1398 break;
1399 case Bytecodes::_lload_1:
1400 push_pair_local( 1 );
1401 break;
1402 case Bytecodes::_lload_2:
1403 push_pair_local( 2 );
1404 break;
1405 case Bytecodes::_lload_3:
1406 push_pair_local( 3 );
1407 break;
1408 case Bytecodes::_lload:
1409 push_pair_local( iter().get_index() );
1410 break;
1412 case Bytecodes::_dload_0:
1413 push_pair_local(0);
1414 break;
1415 case Bytecodes::_dload_1:
1416 push_pair_local(1);
1417 break;
1418 case Bytecodes::_dload_2:
1419 push_pair_local(2);
1420 break;
1421 case Bytecodes::_dload_3:
1422 push_pair_local(3);
1423 break;
1424 case Bytecodes::_dload:
1425 push_pair_local(iter().get_index());
1426 break;
1427 case Bytecodes::_fstore_0:
1428 case Bytecodes::_istore_0:
1429 case Bytecodes::_astore_0:
1430 set_local( 0, pop() );
1431 break;
1432 case Bytecodes::_fstore_1:
1433 case Bytecodes::_istore_1:
1434 case Bytecodes::_astore_1:
1435 set_local( 1, pop() );
1436 break;
1437 case Bytecodes::_fstore_2:
1438 case Bytecodes::_istore_2:
1439 case Bytecodes::_astore_2:
1440 set_local( 2, pop() );
1441 break;
1442 case Bytecodes::_fstore_3:
1443 case Bytecodes::_istore_3:
1444 case Bytecodes::_astore_3:
1445 set_local( 3, pop() );
1446 break;
1447 case Bytecodes::_fstore:
1448 case Bytecodes::_istore:
1449 case Bytecodes::_astore:
1450 set_local( iter().get_index(), pop() );
1451 break;
1452 // long stores
1453 case Bytecodes::_lstore_0:
1454 set_pair_local( 0, pop_pair() );
1455 break;
1456 case Bytecodes::_lstore_1:
1457 set_pair_local( 1, pop_pair() );
1458 break;
1459 case Bytecodes::_lstore_2:
1460 set_pair_local( 2, pop_pair() );
1461 break;
1462 case Bytecodes::_lstore_3:
1463 set_pair_local( 3, pop_pair() );
1464 break;
1465 case Bytecodes::_lstore:
1466 set_pair_local( iter().get_index(), pop_pair() );
1467 break;
1469 // double stores
1470 case Bytecodes::_dstore_0:
1471 set_pair_local( 0, dstore_rounding(pop_pair()) );
1472 break;
1473 case Bytecodes::_dstore_1:
1474 set_pair_local( 1, dstore_rounding(pop_pair()) );
1475 break;
1476 case Bytecodes::_dstore_2:
1477 set_pair_local( 2, dstore_rounding(pop_pair()) );
1478 break;
1479 case Bytecodes::_dstore_3:
1480 set_pair_local( 3, dstore_rounding(pop_pair()) );
1481 break;
1482 case Bytecodes::_dstore:
1483 set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) );
1484 break;
1486 case Bytecodes::_pop: _sp -= 1; break;
1487 case Bytecodes::_pop2: _sp -= 2; break;
1488 case Bytecodes::_swap:
1489 a = pop();
1490 b = pop();
1491 push(a);
1492 push(b);
1493 break;
1494 case Bytecodes::_dup:
1495 a = pop();
1496 push(a);
1497 push(a);
1498 break;
1499 case Bytecodes::_dup_x1:
1500 a = pop();
1501 b = pop();
1502 push( a );
1503 push( b );
1504 push( a );
1505 break;
1506 case Bytecodes::_dup_x2:
1507 a = pop();
1508 b = pop();
1509 c = pop();
1510 push( a );
1511 push( c );
1512 push( b );
1513 push( a );
1514 break;
1515 case Bytecodes::_dup2:
1516 a = pop();
1517 b = pop();
1518 push( b );
1519 push( a );
1520 push( b );
1521 push( a );
1522 break;
1524 case Bytecodes::_dup2_x1:
1525 // before: .. c, b, a
1526 // after: .. b, a, c, b, a
1527 // not tested
1528 a = pop();
1529 b = pop();
1530 c = pop();
1531 push( b );
1532 push( a );
1533 push( c );
1534 push( b );
1535 push( a );
1536 break;
1537 case Bytecodes::_dup2_x2:
1538 // before: .. d, c, b, a
1539 // after: .. b, a, d, c, b, a
1540 // not tested
1541 a = pop();
1542 b = pop();
1543 c = pop();
1544 d = pop();
1545 push( b );
1546 push( a );
1547 push( d );
1548 push( c );
1549 push( b );
1550 push( a );
1551 break;
1553 case Bytecodes::_arraylength: {
1554 // Must do null-check with value on expression stack
1555 Node *ary = do_null_check(peek(), T_ARRAY);
1556 // Compile-time detect of null-exception?
1557 if (stopped()) return;
1558 a = pop();
1559 push(load_array_length(a));
1560 break;
1561 }
1563 case Bytecodes::_baload: array_load(T_BYTE); break;
1564 case Bytecodes::_caload: array_load(T_CHAR); break;
1565 case Bytecodes::_iaload: array_load(T_INT); break;
1566 case Bytecodes::_saload: array_load(T_SHORT); break;
1567 case Bytecodes::_faload: array_load(T_FLOAT); break;
1568 case Bytecodes::_aaload: array_load(T_OBJECT); break;
1569 case Bytecodes::_laload: {
1570 a = array_addressing(T_LONG, 0);
1571 if (stopped()) return; // guaranteed null or range check
1572 _sp -= 2; // Pop array and index
1573 push_pair( make_load(control(), a, TypeLong::LONG, T_LONG, TypeAryPtr::LONGS));
1574 break;
1575 }
1576 case Bytecodes::_daload: {
1577 a = array_addressing(T_DOUBLE, 0);
1578 if (stopped()) return; // guaranteed null or range check
1579 _sp -= 2; // Pop array and index
1580 push_pair( make_load(control(), a, Type::DOUBLE, T_DOUBLE, TypeAryPtr::DOUBLES));
1581 break;
1582 }
1583 case Bytecodes::_bastore: array_store(T_BYTE); break;
1584 case Bytecodes::_castore: array_store(T_CHAR); break;
1585 case Bytecodes::_iastore: array_store(T_INT); break;
1586 case Bytecodes::_sastore: array_store(T_SHORT); break;
1587 case Bytecodes::_fastore: array_store(T_FLOAT); break;
1588 case Bytecodes::_aastore: {
1589 d = array_addressing(T_OBJECT, 1);
1590 if (stopped()) return; // guaranteed null or range check
1591 array_store_check();
1592 c = pop(); // Oop to store
1593 b = pop(); // index (already used)
1594 a = pop(); // the array itself
1595 const TypeOopPtr* elemtype = _gvn.type(a)->is_aryptr()->elem()->make_oopptr();
1596 const TypeAryPtr* adr_type = TypeAryPtr::OOPS;
1597 Node* store = store_oop_to_array(control(), a, d, adr_type, c, elemtype, T_OBJECT);
1598 break;
1599 }
1600 case Bytecodes::_lastore: {
1601 a = array_addressing(T_LONG, 2);
1602 if (stopped()) return; // guaranteed null or range check
1603 c = pop_pair();
1604 _sp -= 2; // Pop array and index
1605 store_to_memory(control(), a, c, T_LONG, TypeAryPtr::LONGS);
1606 break;
1607 }
1608 case Bytecodes::_dastore: {
1609 a = array_addressing(T_DOUBLE, 2);
1610 if (stopped()) return; // guaranteed null or range check
1611 c = pop_pair();
1612 _sp -= 2; // Pop array and index
1613 c = dstore_rounding(c);
1614 store_to_memory(control(), a, c, T_DOUBLE, TypeAryPtr::DOUBLES);
1615 break;
1616 }
1617 case Bytecodes::_getfield:
1618 do_getfield();
1619 break;
1621 case Bytecodes::_getstatic:
1622 do_getstatic();
1623 break;
1625 case Bytecodes::_putfield:
1626 do_putfield();
1627 break;
1629 case Bytecodes::_putstatic:
1630 do_putstatic();
1631 break;
1633 case Bytecodes::_irem:
1634 do_irem();
1635 break;
1636 case Bytecodes::_idiv:
1637 // Must keep both values on the expression-stack during null-check
1638 do_null_check(peek(), T_INT);
1639 // Compile-time detect of null-exception?
1640 if (stopped()) return;
1641 b = pop();
1642 a = pop();
1643 push( _gvn.transform( new (C, 3) DivINode(control(),a,b) ) );
1644 break;
1645 case Bytecodes::_imul:
1646 b = pop(); a = pop();
1647 push( _gvn.transform( new (C, 3) MulINode(a,b) ) );
1648 break;
1649 case Bytecodes::_iadd:
1650 b = pop(); a = pop();
1651 push( _gvn.transform( new (C, 3) AddINode(a,b) ) );
1652 break;
1653 case Bytecodes::_ineg:
1654 a = pop();
1655 push( _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),a)) );
1656 break;
1657 case Bytecodes::_isub:
1658 b = pop(); a = pop();
1659 push( _gvn.transform( new (C, 3) SubINode(a,b) ) );
1660 break;
1661 case Bytecodes::_iand:
1662 b = pop(); a = pop();
1663 push( _gvn.transform( new (C, 3) AndINode(a,b) ) );
1664 break;
1665 case Bytecodes::_ior:
1666 b = pop(); a = pop();
1667 push( _gvn.transform( new (C, 3) OrINode(a,b) ) );
1668 break;
1669 case Bytecodes::_ixor:
1670 b = pop(); a = pop();
1671 push( _gvn.transform( new (C, 3) XorINode(a,b) ) );
1672 break;
1673 case Bytecodes::_ishl:
1674 b = pop(); a = pop();
1675 push( _gvn.transform( new (C, 3) LShiftINode(a,b) ) );
1676 break;
1677 case Bytecodes::_ishr:
1678 b = pop(); a = pop();
1679 push( _gvn.transform( new (C, 3) RShiftINode(a,b) ) );
1680 break;
1681 case Bytecodes::_iushr:
1682 b = pop(); a = pop();
1683 push( _gvn.transform( new (C, 3) URShiftINode(a,b) ) );
1684 break;
1686 case Bytecodes::_fneg:
1687 a = pop();
1688 b = _gvn.transform(new (C, 2) NegFNode (a));
1689 push(b);
1690 break;
1692 case Bytecodes::_fsub:
1693 b = pop();
1694 a = pop();
1695 c = _gvn.transform( new (C, 3) SubFNode(a,b) );
1696 d = precision_rounding(c);
1697 push( d );
1698 break;
1700 case Bytecodes::_fadd:
1701 b = pop();
1702 a = pop();
1703 c = _gvn.transform( new (C, 3) AddFNode(a,b) );
1704 d = precision_rounding(c);
1705 push( d );
1706 break;
1708 case Bytecodes::_fmul:
1709 b = pop();
1710 a = pop();
1711 c = _gvn.transform( new (C, 3) MulFNode(a,b) );
1712 d = precision_rounding(c);
1713 push( d );
1714 break;
1716 case Bytecodes::_fdiv:
1717 b = pop();
1718 a = pop();
1719 c = _gvn.transform( new (C, 3) DivFNode(0,a,b) );
1720 d = precision_rounding(c);
1721 push( d );
1722 break;
1724 case Bytecodes::_frem:
1725 if (Matcher::has_match_rule(Op_ModF)) {
1726 // Generate a ModF node.
1727 b = pop();
1728 a = pop();
1729 c = _gvn.transform( new (C, 3) ModFNode(0,a,b) );
1730 d = precision_rounding(c);
1731 push( d );
1732 }
1733 else {
1734 // Generate a call.
1735 modf();
1736 }
1737 break;
1739 case Bytecodes::_fcmpl:
1740 b = pop();
1741 a = pop();
1742 c = _gvn.transform( new (C, 3) CmpF3Node( a, b));
1743 push(c);
1744 break;
1745 case Bytecodes::_fcmpg:
1746 b = pop();
1747 a = pop();
1749 // Same as fcmpl but need to flip the unordered case. Swap the inputs,
1750 // which negates the result sign except for unordered. Flip the unordered
1751 // as well by using CmpF3 which implements unordered-lesser instead of
1752 // unordered-greater semantics. Finally, commute the result bits. Result
1753 // is same as using a CmpF3Greater except we did it with CmpF3 alone.
1754 c = _gvn.transform( new (C, 3) CmpF3Node( b, a));
1755 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
1756 push(c);
1757 break;
1759 case Bytecodes::_f2i:
1760 a = pop();
1761 push(_gvn.transform(new (C, 2) ConvF2INode(a)));
1762 break;
1764 case Bytecodes::_d2i:
1765 a = pop_pair();
1766 b = _gvn.transform(new (C, 2) ConvD2INode(a));
1767 push( b );
1768 break;
1770 case Bytecodes::_f2d:
1771 a = pop();
1772 b = _gvn.transform( new (C, 2) ConvF2DNode(a));
1773 push_pair( b );
1774 break;
1776 case Bytecodes::_d2f:
1777 a = pop_pair();
1778 b = _gvn.transform( new (C, 2) ConvD2FNode(a));
1779 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed)
1780 //b = _gvn.transform(new (C, 2) RoundFloatNode(0, b) );
1781 push( b );
1782 break;
1784 case Bytecodes::_l2f:
1785 if (Matcher::convL2FSupported()) {
1786 a = pop_pair();
1787 b = _gvn.transform( new (C, 2) ConvL2FNode(a));
1788 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits.
1789 // Rather than storing the result into an FP register then pushing
1790 // out to memory to round, the machine instruction that implements
1791 // ConvL2D is responsible for rounding.
1792 // c = precision_rounding(b);
1793 c = _gvn.transform(b);
1794 push(c);
1795 } else {
1796 l2f();
1797 }
1798 break;
1800 case Bytecodes::_l2d:
1801 a = pop_pair();
1802 b = _gvn.transform( new (C, 2) ConvL2DNode(a));
1803 // For i486.ad, rounding is always necessary (see _l2f above).
1804 // c = dprecision_rounding(b);
1805 c = _gvn.transform(b);
1806 push_pair(c);
1807 break;
1809 case Bytecodes::_f2l:
1810 a = pop();
1811 b = _gvn.transform( new (C, 2) ConvF2LNode(a));
1812 push_pair(b);
1813 break;
1815 case Bytecodes::_d2l:
1816 a = pop_pair();
1817 b = _gvn.transform( new (C, 2) ConvD2LNode(a));
1818 push_pair(b);
1819 break;
1821 case Bytecodes::_dsub:
1822 b = pop_pair();
1823 a = pop_pair();
1824 c = _gvn.transform( new (C, 3) SubDNode(a,b) );
1825 d = dprecision_rounding(c);
1826 push_pair( d );
1827 break;
1829 case Bytecodes::_dadd:
1830 b = pop_pair();
1831 a = pop_pair();
1832 c = _gvn.transform( new (C, 3) AddDNode(a,b) );
1833 d = dprecision_rounding(c);
1834 push_pair( d );
1835 break;
1837 case Bytecodes::_dmul:
1838 b = pop_pair();
1839 a = pop_pair();
1840 c = _gvn.transform( new (C, 3) MulDNode(a,b) );
1841 d = dprecision_rounding(c);
1842 push_pair( d );
1843 break;
1845 case Bytecodes::_ddiv:
1846 b = pop_pair();
1847 a = pop_pair();
1848 c = _gvn.transform( new (C, 3) DivDNode(0,a,b) );
1849 d = dprecision_rounding(c);
1850 push_pair( d );
1851 break;
1853 case Bytecodes::_dneg:
1854 a = pop_pair();
1855 b = _gvn.transform(new (C, 2) NegDNode (a));
1856 push_pair(b);
1857 break;
1859 case Bytecodes::_drem:
1860 if (Matcher::has_match_rule(Op_ModD)) {
1861 // Generate a ModD node.
1862 b = pop_pair();
1863 a = pop_pair();
1864 // a % b
1866 c = _gvn.transform( new (C, 3) ModDNode(0,a,b) );
1867 d = dprecision_rounding(c);
1868 push_pair( d );
1869 }
1870 else {
1871 // Generate a call.
1872 modd();
1873 }
1874 break;
1876 case Bytecodes::_dcmpl:
1877 b = pop_pair();
1878 a = pop_pair();
1879 c = _gvn.transform( new (C, 3) CmpD3Node( a, b));
1880 push(c);
1881 break;
1883 case Bytecodes::_dcmpg:
1884 b = pop_pair();
1885 a = pop_pair();
1886 // Same as dcmpl but need to flip the unordered case.
1887 // Commute the inputs, which negates the result sign except for unordered.
1888 // Flip the unordered as well by using CmpD3 which implements
1889 // unordered-lesser instead of unordered-greater semantics.
1890 // Finally, negate the result bits. Result is same as using a
1891 // CmpD3Greater except we did it with CmpD3 alone.
1892 c = _gvn.transform( new (C, 3) CmpD3Node( b, a));
1893 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
1894 push(c);
1895 break;
1898 // Note for longs -> lo word is on TOS, hi word is on TOS - 1
1899 case Bytecodes::_land:
1900 b = pop_pair();
1901 a = pop_pair();
1902 c = _gvn.transform( new (C, 3) AndLNode(a,b) );
1903 push_pair(c);
1904 break;
1905 case Bytecodes::_lor:
1906 b = pop_pair();
1907 a = pop_pair();
1908 c = _gvn.transform( new (C, 3) OrLNode(a,b) );
1909 push_pair(c);
1910 break;
1911 case Bytecodes::_lxor:
1912 b = pop_pair();
1913 a = pop_pair();
1914 c = _gvn.transform( new (C, 3) XorLNode(a,b) );
1915 push_pair(c);
1916 break;
1918 case Bytecodes::_lshl:
1919 b = pop(); // the shift count
1920 a = pop_pair(); // value to be shifted
1921 c = _gvn.transform( new (C, 3) LShiftLNode(a,b) );
1922 push_pair(c);
1923 break;
1924 case Bytecodes::_lshr:
1925 b = pop(); // the shift count
1926 a = pop_pair(); // value to be shifted
1927 c = _gvn.transform( new (C, 3) RShiftLNode(a,b) );
1928 push_pair(c);
1929 break;
1930 case Bytecodes::_lushr:
1931 b = pop(); // the shift count
1932 a = pop_pair(); // value to be shifted
1933 c = _gvn.transform( new (C, 3) URShiftLNode(a,b) );
1934 push_pair(c);
1935 break;
1936 case Bytecodes::_lmul:
1937 b = pop_pair();
1938 a = pop_pair();
1939 c = _gvn.transform( new (C, 3) MulLNode(a,b) );
1940 push_pair(c);
1941 break;
1943 case Bytecodes::_lrem:
1944 // Must keep both values on the expression-stack during null-check
1945 assert(peek(0) == top(), "long word order");
1946 do_null_check(peek(1), T_LONG);
1947 // Compile-time detect of null-exception?
1948 if (stopped()) return;
1949 b = pop_pair();
1950 a = pop_pair();
1951 c = _gvn.transform( new (C, 3) ModLNode(control(),a,b) );
1952 push_pair(c);
1953 break;
1955 case Bytecodes::_ldiv:
1956 // Must keep both values on the expression-stack during null-check
1957 assert(peek(0) == top(), "long word order");
1958 do_null_check(peek(1), T_LONG);
1959 // Compile-time detect of null-exception?
1960 if (stopped()) return;
1961 b = pop_pair();
1962 a = pop_pair();
1963 c = _gvn.transform( new (C, 3) DivLNode(control(),a,b) );
1964 push_pair(c);
1965 break;
1967 case Bytecodes::_ladd:
1968 b = pop_pair();
1969 a = pop_pair();
1970 c = _gvn.transform( new (C, 3) AddLNode(a,b) );
1971 push_pair(c);
1972 break;
1973 case Bytecodes::_lsub:
1974 b = pop_pair();
1975 a = pop_pair();
1976 c = _gvn.transform( new (C, 3) SubLNode(a,b) );
1977 push_pair(c);
1978 break;
1979 case Bytecodes::_lcmp:
1980 // Safepoints are now inserted _before_ branches. The long-compare
1981 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a
1982 // slew of control flow. These are usually followed by a CmpI vs zero and
1983 // a branch; this pattern then optimizes to the obvious long-compare and
1984 // branch. However, if the branch is backwards there's a Safepoint
1985 // inserted. The inserted Safepoint captures the JVM state at the
1986 // pre-branch point, i.e. it captures the 3-way value. Thus if a
1987 // long-compare is used to control a loop the debug info will force
1988 // computation of the 3-way value, even though the generated code uses a
1989 // long-compare and branch. We try to rectify the situation by inserting
1990 // a SafePoint here and have it dominate and kill the safepoint added at a
1991 // following backwards branch. At this point the JVM state merely holds 2
1992 // longs but not the 3-way value.
1993 if( UseLoopSafepoints ) {
1994 switch( iter().next_bc() ) {
1995 case Bytecodes::_ifgt:
1996 case Bytecodes::_iflt:
1997 case Bytecodes::_ifge:
1998 case Bytecodes::_ifle:
1999 case Bytecodes::_ifne:
2000 case Bytecodes::_ifeq:
2001 // If this is a backwards branch in the bytecodes, add Safepoint
2002 maybe_add_safepoint(iter().next_get_dest());
2003 }
2004 }
2005 b = pop_pair();
2006 a = pop_pair();
2007 c = _gvn.transform( new (C, 3) CmpL3Node( a, b ));
2008 push(c);
2009 break;
2011 case Bytecodes::_lneg:
2012 a = pop_pair();
2013 b = _gvn.transform( new (C, 3) SubLNode(longcon(0),a));
2014 push_pair(b);
2015 break;
2016 case Bytecodes::_l2i:
2017 a = pop_pair();
2018 push( _gvn.transform( new (C, 2) ConvL2INode(a)));
2019 break;
2020 case Bytecodes::_i2l:
2021 a = pop();
2022 b = _gvn.transform( new (C, 2) ConvI2LNode(a));
2023 push_pair(b);
2024 break;
2025 case Bytecodes::_i2b:
2026 // Sign extend
2027 a = pop();
2028 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(24)) );
2029 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(24)) );
2030 push( a );
2031 break;
2032 case Bytecodes::_i2s:
2033 a = pop();
2034 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(16)) );
2035 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(16)) );
2036 push( a );
2037 break;
2038 case Bytecodes::_i2c:
2039 a = pop();
2040 push( _gvn.transform( new (C, 3) AndINode(a,_gvn.intcon(0xFFFF)) ) );
2041 break;
2043 case Bytecodes::_i2f:
2044 a = pop();
2045 b = _gvn.transform( new (C, 2) ConvI2FNode(a) ) ;
2046 c = precision_rounding(b);
2047 push (b);
2048 break;
2050 case Bytecodes::_i2d:
2051 a = pop();
2052 b = _gvn.transform( new (C, 2) ConvI2DNode(a));
2053 push_pair(b);
2054 break;
2056 case Bytecodes::_iinc: // Increment local
2057 i = iter().get_index(); // Get local index
2058 set_local( i, _gvn.transform( new (C, 3) AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
2059 break;
2061 // Exit points of synchronized methods must have an unlock node
2062 case Bytecodes::_return:
2063 return_current(NULL);
2064 break;
2066 case Bytecodes::_ireturn:
2067 case Bytecodes::_areturn:
2068 case Bytecodes::_freturn:
2069 return_current(pop());
2070 break;
2071 case Bytecodes::_lreturn:
2072 return_current(pop_pair());
2073 break;
2074 case Bytecodes::_dreturn:
2075 return_current(pop_pair());
2076 break;
2078 case Bytecodes::_athrow:
2079 // null exception oop throws NULL pointer exception
2080 do_null_check(peek(), T_OBJECT);
2081 if (stopped()) return;
2082 // Hook the thrown exception directly to subsequent handlers.
2083 if (BailoutToInterpreterForThrows) {
2084 // Keep method interpreted from now on.
2085 uncommon_trap(Deoptimization::Reason_unhandled,
2086 Deoptimization::Action_make_not_compilable);
2087 return;
2088 }
2089 if (env()->jvmti_can_post_on_exceptions()) {
2090 // check if we must post exception events, take uncommon trap if so (with must_throw = false)
2091 uncommon_trap_if_should_post_on_exceptions(Deoptimization::Reason_unhandled, false);
2092 }
2093 // Here if either can_post_on_exceptions or should_post_on_exceptions is false
2094 add_exception_state(make_exception_state(peek()));
2095 break;
2097 case Bytecodes::_goto: // fall through
2098 case Bytecodes::_goto_w: {
2099 int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest();
2101 // If this is a backwards branch in the bytecodes, add Safepoint
2102 maybe_add_safepoint(target_bci);
2104 // Update method data
2105 profile_taken_branch(target_bci);
2107 // Add loop predicate if it goes to a loop
2108 if (should_add_predicate(target_bci)){
2109 add_predicate();
2110 }
2111 // Merge the current control into the target basic block
2112 merge(target_bci);
2114 // See if we can get some profile data and hand it off to the next block
2115 Block *target_block = block()->successor_for_bci(target_bci);
2116 if (target_block->pred_count() != 1) break;
2117 ciMethodData* methodData = method()->method_data();
2118 if (!methodData->is_mature()) break;
2119 ciProfileData* data = methodData->bci_to_data(bci());
2120 assert( data->is_JumpData(), "" );
2121 int taken = ((ciJumpData*)data)->taken();
2122 taken = method()->scale_count(taken);
2123 target_block->set_count(taken);
2124 break;
2125 }
2127 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null;
2128 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
2129 handle_if_null:
2130 // If this is a backwards branch in the bytecodes, add Safepoint
2131 maybe_add_safepoint(iter().get_dest());
2132 a = null();
2133 b = pop();
2134 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
2135 do_ifnull(btest, c);
2136 break;
2138 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
2139 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
2140 handle_if_acmp:
2141 // If this is a backwards branch in the bytecodes, add Safepoint
2142 maybe_add_safepoint(iter().get_dest());
2143 a = pop();
2144 b = pop();
2145 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
2146 do_if(btest, c);
2147 break;
2149 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
2150 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
2151 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
2152 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
2153 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
2154 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
2155 handle_ifxx:
2156 // If this is a backwards branch in the bytecodes, add Safepoint
2157 maybe_add_safepoint(iter().get_dest());
2158 a = _gvn.intcon(0);
2159 b = pop();
2160 c = _gvn.transform( new (C, 3) CmpINode(b, a) );
2161 do_if(btest, c);
2162 break;
2164 case Bytecodes::_if_icmpeq: btest = BoolTest::eq; goto handle_if_icmp;
2165 case Bytecodes::_if_icmpne: btest = BoolTest::ne; goto handle_if_icmp;
2166 case Bytecodes::_if_icmplt: btest = BoolTest::lt; goto handle_if_icmp;
2167 case Bytecodes::_if_icmple: btest = BoolTest::le; goto handle_if_icmp;
2168 case Bytecodes::_if_icmpgt: btest = BoolTest::gt; goto handle_if_icmp;
2169 case Bytecodes::_if_icmpge: btest = BoolTest::ge; goto handle_if_icmp;
2170 handle_if_icmp:
2171 // If this is a backwards branch in the bytecodes, add Safepoint
2172 maybe_add_safepoint(iter().get_dest());
2173 a = pop();
2174 b = pop();
2175 c = _gvn.transform( new (C, 3) CmpINode( b, a ) );
2176 do_if(btest, c);
2177 break;
2179 case Bytecodes::_tableswitch:
2180 do_tableswitch();
2181 break;
2183 case Bytecodes::_lookupswitch:
2184 do_lookupswitch();
2185 break;
2187 case Bytecodes::_invokestatic:
2188 case Bytecodes::_invokedynamic:
2189 case Bytecodes::_invokespecial:
2190 case Bytecodes::_invokevirtual:
2191 case Bytecodes::_invokeinterface:
2192 do_call();
2193 break;
2194 case Bytecodes::_checkcast:
2195 do_checkcast();
2196 break;
2197 case Bytecodes::_instanceof:
2198 do_instanceof();
2199 break;
2200 case Bytecodes::_anewarray:
2201 do_anewarray();
2202 break;
2203 case Bytecodes::_newarray:
2204 do_newarray((BasicType)iter().get_index());
2205 break;
2206 case Bytecodes::_multianewarray:
2207 do_multianewarray();
2208 break;
2209 case Bytecodes::_new:
2210 do_new();
2211 break;
2213 case Bytecodes::_jsr:
2214 case Bytecodes::_jsr_w:
2215 do_jsr();
2216 break;
2218 case Bytecodes::_ret:
2219 do_ret();
2220 break;
2223 case Bytecodes::_monitorenter:
2224 do_monitor_enter();
2225 break;
2227 case Bytecodes::_monitorexit:
2228 do_monitor_exit();
2229 break;
2231 case Bytecodes::_breakpoint:
2232 // Breakpoint set concurrently to compile
2233 // %%% use an uncommon trap?
2234 C->record_failure("breakpoint in method");
2235 return;
2237 default:
2238 #ifndef PRODUCT
2239 map()->dump(99);
2240 #endif
2241 tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) );
2242 ShouldNotReachHere();
2243 }
2245 #ifndef PRODUCT
2246 IdealGraphPrinter *printer = IdealGraphPrinter::printer();
2247 if(printer) {
2248 char buffer[256];
2249 sprintf(buffer, "Bytecode %d: %s", bci(), Bytecodes::name(bc()));
2250 bool old = printer->traverse_outs();
2251 printer->set_traverse_outs(true);
2252 printer->print_method(C, buffer, 4);
2253 printer->set_traverse_outs(old);
2254 }
2255 #endif
2256 }