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