Wed, 24 Sep 2008 15:34:06 -0400
Merge
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 explicit_null_checks_inserted++;
930 // Generate real control flow
931 Node *tst = _gvn.transform( new (C, 2) BoolNode( c, btest ) );
933 // Sanity check the probability value
934 assert(prob > 0.0f,"Bad probability in Parser");
935 // Need xform to put node in hash table
936 IfNode *iff = create_and_xform_if( control(), tst, prob, cnt );
937 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
938 // True branch
939 { PreserveJVMState pjvms(this);
940 Node* iftrue = _gvn.transform( new (C, 1) IfTrueNode (iff) );
941 set_control(iftrue);
943 if (stopped()) { // Path is dead?
944 explicit_null_checks_elided++;
945 if (EliminateAutoBox) {
946 // Mark the successor block as parsed
947 branch_block->next_path_num();
948 }
949 } else { // Path is live.
950 // Update method data
951 profile_taken_branch(target_bci);
952 adjust_map_after_if(btest, c, prob, branch_block, next_block);
953 if (!stopped())
954 merge(target_bci);
955 }
956 }
958 // False branch
959 Node* iffalse = _gvn.transform( new (C, 1) IfFalseNode(iff) );
960 set_control(iffalse);
962 if (stopped()) { // Path is dead?
963 explicit_null_checks_elided++;
964 if (EliminateAutoBox) {
965 // Mark the successor block as parsed
966 next_block->next_path_num();
967 }
968 } else { // Path is live.
969 // Update method data
970 profile_not_taken_branch();
971 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
972 next_block, branch_block);
973 }
974 }
976 //------------------------------------do_if------------------------------------
977 void Parse::do_if(BoolTest::mask btest, Node* c) {
978 int target_bci = iter().get_dest();
980 Block* branch_block = successor_for_bci(target_bci);
981 Block* next_block = successor_for_bci(iter().next_bci());
983 float cnt;
984 float prob = branch_prediction(cnt, btest, target_bci);
985 float untaken_prob = 1.0 - prob;
987 if (prob == PROB_UNKNOWN) {
988 #ifndef PRODUCT
989 if (PrintOpto && Verbose)
990 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
991 #endif
992 repush_if_args(); // to gather stats on loop
993 // We need to mark this branch as taken so that if we recompile we will
994 // see that it is possible. In the tiered system the interpreter doesn't
995 // do profiling and by the time we get to the lower tier from the interpreter
996 // the path may be cold again. Make sure it doesn't look untaken
997 profile_taken_branch(target_bci, !ProfileInterpreter);
998 uncommon_trap(Deoptimization::Reason_unreached,
999 Deoptimization::Action_reinterpret,
1000 NULL, "cold");
1001 if (EliminateAutoBox) {
1002 // Mark the successor blocks as parsed
1003 branch_block->next_path_num();
1004 next_block->next_path_num();
1005 }
1006 return;
1007 }
1009 // Sanity check the probability value
1010 assert(0.0f < prob && prob < 1.0f,"Bad probability in Parser");
1012 bool taken_if_true = true;
1013 // Convert BoolTest to canonical form:
1014 if (!BoolTest(btest).is_canonical()) {
1015 btest = BoolTest(btest).negate();
1016 taken_if_true = false;
1017 // prob is NOT updated here; it remains the probability of the taken
1018 // path (as opposed to the prob of the path guarded by an 'IfTrueNode').
1019 }
1020 assert(btest != BoolTest::eq, "!= is the only canonical exact test");
1022 Node* tst0 = new (C, 2) BoolNode(c, btest);
1023 Node* tst = _gvn.transform(tst0);
1024 BoolTest::mask taken_btest = BoolTest::illegal;
1025 BoolTest::mask untaken_btest = BoolTest::illegal;
1027 if (tst->is_Bool()) {
1028 // Refresh c from the transformed bool node, since it may be
1029 // simpler than the original c. Also re-canonicalize btest.
1030 // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)).
1031 // That can arise from statements like: if (x instanceof C) ...
1032 if (tst != tst0) {
1033 // Canonicalize one more time since transform can change it.
1034 btest = tst->as_Bool()->_test._test;
1035 if (!BoolTest(btest).is_canonical()) {
1036 // Reverse edges one more time...
1037 tst = _gvn.transform( tst->as_Bool()->negate(&_gvn) );
1038 btest = tst->as_Bool()->_test._test;
1039 assert(BoolTest(btest).is_canonical(), "sanity");
1040 taken_if_true = !taken_if_true;
1041 }
1042 c = tst->in(1);
1043 }
1044 BoolTest::mask neg_btest = BoolTest(btest).negate();
1045 taken_btest = taken_if_true ? btest : neg_btest;
1046 untaken_btest = taken_if_true ? neg_btest : btest;
1047 }
1049 // Generate real control flow
1050 float true_prob = (taken_if_true ? prob : untaken_prob);
1051 IfNode* iff = create_and_map_if(control(), tst, true_prob, cnt);
1052 assert(iff->_prob > 0.0f,"Optimizer made bad probability in parser");
1053 Node* taken_branch = new (C, 1) IfTrueNode(iff);
1054 Node* untaken_branch = new (C, 1) IfFalseNode(iff);
1055 if (!taken_if_true) { // Finish conversion to canonical form
1056 Node* tmp = taken_branch;
1057 taken_branch = untaken_branch;
1058 untaken_branch = tmp;
1059 }
1061 // Branch is taken:
1062 { PreserveJVMState pjvms(this);
1063 taken_branch = _gvn.transform(taken_branch);
1064 set_control(taken_branch);
1066 if (stopped()) {
1067 if (EliminateAutoBox) {
1068 // Mark the successor block as parsed
1069 branch_block->next_path_num();
1070 }
1071 } else {
1072 // Update method data
1073 profile_taken_branch(target_bci);
1074 adjust_map_after_if(taken_btest, c, prob, branch_block, next_block);
1075 if (!stopped())
1076 merge(target_bci);
1077 }
1078 }
1080 untaken_branch = _gvn.transform(untaken_branch);
1081 set_control(untaken_branch);
1083 // Branch not taken.
1084 if (stopped()) {
1085 if (EliminateAutoBox) {
1086 // Mark the successor block as parsed
1087 next_block->next_path_num();
1088 }
1089 } else {
1090 // Update method data
1091 profile_not_taken_branch();
1092 adjust_map_after_if(untaken_btest, c, untaken_prob,
1093 next_block, branch_block);
1094 }
1095 }
1097 //----------------------------adjust_map_after_if------------------------------
1098 // Adjust the JVM state to reflect the result of taking this path.
1099 // Basically, it means inspecting the CmpNode controlling this
1100 // branch, seeing how it constrains a tested value, and then
1101 // deciding if it's worth our while to encode this constraint
1102 // as graph nodes in the current abstract interpretation map.
1103 void Parse::adjust_map_after_if(BoolTest::mask btest, Node* c, float prob,
1104 Block* path, Block* other_path) {
1105 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal)
1106 return; // nothing to do
1108 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
1110 int cop = c->Opcode();
1111 if (seems_never_taken(prob) && cop == Op_CmpP && btest == BoolTest::eq) {
1112 // (An earlier version of do_if omitted '&& btest == BoolTest::eq'.)
1113 //
1114 // If this might possibly turn into an implicit null check,
1115 // and the null has never yet been seen, we need to generate
1116 // an uncommon trap, so as to recompile instead of suffering
1117 // with very slow branches. (We'll get the slow branches if
1118 // the program ever changes phase and starts seeing nulls here.)
1119 //
1120 // The tests we worry about are of the form (p == null).
1121 // We do not simply inspect for a null constant, since a node may
1122 // optimize to 'null' later on.
1123 repush_if_args();
1124 // We need to mark this branch as taken so that if we recompile we will
1125 // see that it is possible. In the tiered system the interpreter doesn't
1126 // do profiling and by the time we get to the lower tier from the interpreter
1127 // the path may be cold again. Make sure it doesn't look untaken
1128 if (is_fallthrough) {
1129 profile_not_taken_branch(!ProfileInterpreter);
1130 } else {
1131 profile_taken_branch(iter().get_dest(), !ProfileInterpreter);
1132 }
1133 uncommon_trap(Deoptimization::Reason_unreached,
1134 Deoptimization::Action_reinterpret,
1135 NULL,
1136 (is_fallthrough ? "taken always" : "taken never"));
1137 return;
1138 }
1140 Node* val = c->in(1);
1141 Node* con = c->in(2);
1142 const Type* tcon = _gvn.type(con);
1143 const Type* tval = _gvn.type(val);
1144 bool have_con = tcon->singleton();
1145 if (tval->singleton()) {
1146 if (!have_con) {
1147 // Swap, so constant is in con.
1148 con = val;
1149 tcon = tval;
1150 val = c->in(2);
1151 tval = _gvn.type(val);
1152 btest = BoolTest(btest).commute();
1153 have_con = true;
1154 } else {
1155 // Do we have two constants? Then leave well enough alone.
1156 have_con = false;
1157 }
1158 }
1159 if (!have_con) // remaining adjustments need a con
1160 return;
1163 int val_in_map = map()->find_edge(val);
1164 if (val_in_map < 0) return; // replace_in_map would be useless
1165 {
1166 JVMState* jvms = this->jvms();
1167 if (!(jvms->is_loc(val_in_map) ||
1168 jvms->is_stk(val_in_map)))
1169 return; // again, it would be useless
1170 }
1172 // Check for a comparison to a constant, and "know" that the compared
1173 // value is constrained on this path.
1174 assert(tcon->singleton(), "");
1175 ConstraintCastNode* ccast = NULL;
1176 Node* cast = NULL;
1178 switch (btest) {
1179 case BoolTest::eq: // Constant test?
1180 {
1181 const Type* tboth = tcon->join(tval);
1182 if (tboth == tval) break; // Nothing to gain.
1183 if (tcon->isa_int()) {
1184 ccast = new (C, 2) CastIINode(val, tboth);
1185 } else if (tcon == TypePtr::NULL_PTR) {
1186 // Cast to null, but keep the pointer identity temporarily live.
1187 ccast = new (C, 2) CastPPNode(val, tboth);
1188 } else {
1189 const TypeF* tf = tcon->isa_float_constant();
1190 const TypeD* td = tcon->isa_double_constant();
1191 // Exclude tests vs float/double 0 as these could be
1192 // either +0 or -0. Just because you are equal to +0
1193 // doesn't mean you ARE +0!
1194 if ((!tf || tf->_f != 0.0) &&
1195 (!td || td->_d != 0.0))
1196 cast = con; // Replace non-constant val by con.
1197 }
1198 }
1199 break;
1201 case BoolTest::ne:
1202 if (tcon == TypePtr::NULL_PTR) {
1203 cast = cast_not_null(val, false);
1204 }
1205 break;
1207 default:
1208 // (At this point we could record int range types with CastII.)
1209 break;
1210 }
1212 if (ccast != NULL) {
1213 const Type* tcc = ccast->as_Type()->type();
1214 assert(tcc != tval && tcc->higher_equal(tval), "must improve");
1215 // Delay transform() call to allow recovery of pre-cast value
1216 // at the control merge.
1217 ccast->set_req(0, control());
1218 _gvn.set_type_bottom(ccast);
1219 record_for_igvn(ccast);
1220 cast = ccast;
1221 }
1223 if (cast != NULL) { // Here's the payoff.
1224 replace_in_map(val, cast);
1225 }
1226 }
1229 //------------------------------do_one_bytecode--------------------------------
1230 // Parse this bytecode, and alter the Parsers JVM->Node mapping
1231 void Parse::do_one_bytecode() {
1232 Node *a, *b, *c, *d; // Handy temps
1233 BoolTest::mask btest;
1234 int i;
1236 assert(!has_exceptions(), "bytecode entry state must be clear of throws");
1238 if (C->check_node_count(NodeLimitFudgeFactor * 5,
1239 "out of nodes parsing method")) {
1240 return;
1241 }
1243 #ifdef ASSERT
1244 // for setting breakpoints
1245 if (TraceOptoParse) {
1246 tty->print(" @");
1247 dump_bci(bci());
1248 }
1249 #endif
1251 switch (bc()) {
1252 case Bytecodes::_nop:
1253 // do nothing
1254 break;
1255 case Bytecodes::_lconst_0:
1256 push_pair(longcon(0));
1257 break;
1259 case Bytecodes::_lconst_1:
1260 push_pair(longcon(1));
1261 break;
1263 case Bytecodes::_fconst_0:
1264 push(zerocon(T_FLOAT));
1265 break;
1267 case Bytecodes::_fconst_1:
1268 push(makecon(TypeF::ONE));
1269 break;
1271 case Bytecodes::_fconst_2:
1272 push(makecon(TypeF::make(2.0f)));
1273 break;
1275 case Bytecodes::_dconst_0:
1276 push_pair(zerocon(T_DOUBLE));
1277 break;
1279 case Bytecodes::_dconst_1:
1280 push_pair(makecon(TypeD::ONE));
1281 break;
1283 case Bytecodes::_iconst_m1:push(intcon(-1)); break;
1284 case Bytecodes::_iconst_0: push(intcon( 0)); break;
1285 case Bytecodes::_iconst_1: push(intcon( 1)); break;
1286 case Bytecodes::_iconst_2: push(intcon( 2)); break;
1287 case Bytecodes::_iconst_3: push(intcon( 3)); break;
1288 case Bytecodes::_iconst_4: push(intcon( 4)); break;
1289 case Bytecodes::_iconst_5: push(intcon( 5)); break;
1290 case Bytecodes::_bipush: push(intcon( iter().get_byte())); break;
1291 case Bytecodes::_sipush: push(intcon( iter().get_short())); break;
1292 case Bytecodes::_aconst_null: push(null()); break;
1293 case Bytecodes::_ldc:
1294 case Bytecodes::_ldc_w:
1295 case Bytecodes::_ldc2_w:
1296 // If the constant is unresolved, run this BC once in the interpreter.
1297 if (iter().is_unresolved_string()) {
1298 uncommon_trap(Deoptimization::make_trap_request
1299 (Deoptimization::Reason_unloaded,
1300 Deoptimization::Action_reinterpret,
1301 iter().get_constant_index()),
1302 NULL, "unresolved_string");
1303 break;
1304 } else {
1305 ciConstant constant = iter().get_constant();
1306 if (constant.basic_type() == T_OBJECT) {
1307 ciObject* c = constant.as_object();
1308 if (c->is_klass()) {
1309 // The constant returned for a klass is the ciKlass for the
1310 // entry. We want the java_mirror so get it.
1311 ciKlass* klass = c->as_klass();
1312 if (klass->is_loaded()) {
1313 constant = ciConstant(T_OBJECT, klass->java_mirror());
1314 } else {
1315 uncommon_trap(Deoptimization::make_trap_request
1316 (Deoptimization::Reason_unloaded,
1317 Deoptimization::Action_reinterpret,
1318 iter().get_constant_index()),
1319 NULL, "unresolved_klass");
1320 break;
1321 }
1322 }
1323 }
1324 push_constant(constant);
1325 }
1327 break;
1329 case Bytecodes::_aload_0:
1330 push( local(0) );
1331 break;
1332 case Bytecodes::_aload_1:
1333 push( local(1) );
1334 break;
1335 case Bytecodes::_aload_2:
1336 push( local(2) );
1337 break;
1338 case Bytecodes::_aload_3:
1339 push( local(3) );
1340 break;
1341 case Bytecodes::_aload:
1342 push( local(iter().get_index()) );
1343 break;
1345 case Bytecodes::_fload_0:
1346 case Bytecodes::_iload_0:
1347 push( local(0) );
1348 break;
1349 case Bytecodes::_fload_1:
1350 case Bytecodes::_iload_1:
1351 push( local(1) );
1352 break;
1353 case Bytecodes::_fload_2:
1354 case Bytecodes::_iload_2:
1355 push( local(2) );
1356 break;
1357 case Bytecodes::_fload_3:
1358 case Bytecodes::_iload_3:
1359 push( local(3) );
1360 break;
1361 case Bytecodes::_fload:
1362 case Bytecodes::_iload:
1363 push( local(iter().get_index()) );
1364 break;
1365 case Bytecodes::_lload_0:
1366 push_pair_local( 0 );
1367 break;
1368 case Bytecodes::_lload_1:
1369 push_pair_local( 1 );
1370 break;
1371 case Bytecodes::_lload_2:
1372 push_pair_local( 2 );
1373 break;
1374 case Bytecodes::_lload_3:
1375 push_pair_local( 3 );
1376 break;
1377 case Bytecodes::_lload:
1378 push_pair_local( iter().get_index() );
1379 break;
1381 case Bytecodes::_dload_0:
1382 push_pair_local(0);
1383 break;
1384 case Bytecodes::_dload_1:
1385 push_pair_local(1);
1386 break;
1387 case Bytecodes::_dload_2:
1388 push_pair_local(2);
1389 break;
1390 case Bytecodes::_dload_3:
1391 push_pair_local(3);
1392 break;
1393 case Bytecodes::_dload:
1394 push_pair_local(iter().get_index());
1395 break;
1396 case Bytecodes::_fstore_0:
1397 case Bytecodes::_istore_0:
1398 case Bytecodes::_astore_0:
1399 set_local( 0, pop() );
1400 break;
1401 case Bytecodes::_fstore_1:
1402 case Bytecodes::_istore_1:
1403 case Bytecodes::_astore_1:
1404 set_local( 1, pop() );
1405 break;
1406 case Bytecodes::_fstore_2:
1407 case Bytecodes::_istore_2:
1408 case Bytecodes::_astore_2:
1409 set_local( 2, pop() );
1410 break;
1411 case Bytecodes::_fstore_3:
1412 case Bytecodes::_istore_3:
1413 case Bytecodes::_astore_3:
1414 set_local( 3, pop() );
1415 break;
1416 case Bytecodes::_fstore:
1417 case Bytecodes::_istore:
1418 case Bytecodes::_astore:
1419 set_local( iter().get_index(), pop() );
1420 break;
1421 // long stores
1422 case Bytecodes::_lstore_0:
1423 set_pair_local( 0, pop_pair() );
1424 break;
1425 case Bytecodes::_lstore_1:
1426 set_pair_local( 1, pop_pair() );
1427 break;
1428 case Bytecodes::_lstore_2:
1429 set_pair_local( 2, pop_pair() );
1430 break;
1431 case Bytecodes::_lstore_3:
1432 set_pair_local( 3, pop_pair() );
1433 break;
1434 case Bytecodes::_lstore:
1435 set_pair_local( iter().get_index(), pop_pair() );
1436 break;
1438 // double stores
1439 case Bytecodes::_dstore_0:
1440 set_pair_local( 0, dstore_rounding(pop_pair()) );
1441 break;
1442 case Bytecodes::_dstore_1:
1443 set_pair_local( 1, dstore_rounding(pop_pair()) );
1444 break;
1445 case Bytecodes::_dstore_2:
1446 set_pair_local( 2, dstore_rounding(pop_pair()) );
1447 break;
1448 case Bytecodes::_dstore_3:
1449 set_pair_local( 3, dstore_rounding(pop_pair()) );
1450 break;
1451 case Bytecodes::_dstore:
1452 set_pair_local( iter().get_index(), dstore_rounding(pop_pair()) );
1453 break;
1455 case Bytecodes::_pop: _sp -= 1; break;
1456 case Bytecodes::_pop2: _sp -= 2; break;
1457 case Bytecodes::_swap:
1458 a = pop();
1459 b = pop();
1460 push(a);
1461 push(b);
1462 break;
1463 case Bytecodes::_dup:
1464 a = pop();
1465 push(a);
1466 push(a);
1467 break;
1468 case Bytecodes::_dup_x1:
1469 a = pop();
1470 b = pop();
1471 push( a );
1472 push( b );
1473 push( a );
1474 break;
1475 case Bytecodes::_dup_x2:
1476 a = pop();
1477 b = pop();
1478 c = pop();
1479 push( a );
1480 push( c );
1481 push( b );
1482 push( a );
1483 break;
1484 case Bytecodes::_dup2:
1485 a = pop();
1486 b = pop();
1487 push( b );
1488 push( a );
1489 push( b );
1490 push( a );
1491 break;
1493 case Bytecodes::_dup2_x1:
1494 // before: .. c, b, a
1495 // after: .. b, a, c, b, a
1496 // not tested
1497 a = pop();
1498 b = pop();
1499 c = pop();
1500 push( b );
1501 push( a );
1502 push( c );
1503 push( b );
1504 push( a );
1505 break;
1506 case Bytecodes::_dup2_x2:
1507 // before: .. d, c, b, a
1508 // after: .. b, a, d, c, b, a
1509 // not tested
1510 a = pop();
1511 b = pop();
1512 c = pop();
1513 d = pop();
1514 push( b );
1515 push( a );
1516 push( d );
1517 push( c );
1518 push( b );
1519 push( a );
1520 break;
1522 case Bytecodes::_arraylength: {
1523 // Must do null-check with value on expression stack
1524 Node *ary = do_null_check(peek(), T_ARRAY);
1525 // Compile-time detect of null-exception?
1526 if (stopped()) return;
1527 a = pop();
1528 push(load_array_length(a));
1529 break;
1530 }
1532 case Bytecodes::_baload: array_load(T_BYTE); break;
1533 case Bytecodes::_caload: array_load(T_CHAR); break;
1534 case Bytecodes::_iaload: array_load(T_INT); break;
1535 case Bytecodes::_saload: array_load(T_SHORT); break;
1536 case Bytecodes::_faload: array_load(T_FLOAT); break;
1537 case Bytecodes::_aaload: array_load(T_OBJECT); break;
1538 case Bytecodes::_laload: {
1539 a = array_addressing(T_LONG, 0);
1540 if (stopped()) return; // guarenteed null or range check
1541 _sp -= 2; // Pop array and index
1542 push_pair( make_load(control(), a, TypeLong::LONG, T_LONG, TypeAryPtr::LONGS));
1543 break;
1544 }
1545 case Bytecodes::_daload: {
1546 a = array_addressing(T_DOUBLE, 0);
1547 if (stopped()) return; // guarenteed null or range check
1548 _sp -= 2; // Pop array and index
1549 push_pair( make_load(control(), a, Type::DOUBLE, T_DOUBLE, TypeAryPtr::DOUBLES));
1550 break;
1551 }
1552 case Bytecodes::_bastore: array_store(T_BYTE); break;
1553 case Bytecodes::_castore: array_store(T_CHAR); break;
1554 case Bytecodes::_iastore: array_store(T_INT); break;
1555 case Bytecodes::_sastore: array_store(T_SHORT); break;
1556 case Bytecodes::_fastore: array_store(T_FLOAT); break;
1557 case Bytecodes::_aastore: {
1558 d = array_addressing(T_OBJECT, 1);
1559 if (stopped()) return; // guarenteed null or range check
1560 array_store_check();
1561 c = pop(); // Oop to store
1562 b = pop(); // index (already used)
1563 a = pop(); // the array itself
1564 const Type* elemtype = _gvn.type(a)->is_aryptr()->elem();
1565 const TypeAryPtr* adr_type = TypeAryPtr::OOPS;
1566 Node* store = store_oop_to_array(control(), a, d, adr_type, c, elemtype, T_OBJECT);
1567 break;
1568 }
1569 case Bytecodes::_lastore: {
1570 a = array_addressing(T_LONG, 2);
1571 if (stopped()) return; // guarenteed null or range check
1572 c = pop_pair();
1573 _sp -= 2; // Pop array and index
1574 store_to_memory(control(), a, c, T_LONG, TypeAryPtr::LONGS);
1575 break;
1576 }
1577 case Bytecodes::_dastore: {
1578 a = array_addressing(T_DOUBLE, 2);
1579 if (stopped()) return; // guarenteed null or range check
1580 c = pop_pair();
1581 _sp -= 2; // Pop array and index
1582 c = dstore_rounding(c);
1583 store_to_memory(control(), a, c, T_DOUBLE, TypeAryPtr::DOUBLES);
1584 break;
1585 }
1586 case Bytecodes::_getfield:
1587 do_getfield();
1588 break;
1590 case Bytecodes::_getstatic:
1591 do_getstatic();
1592 break;
1594 case Bytecodes::_putfield:
1595 do_putfield();
1596 break;
1598 case Bytecodes::_putstatic:
1599 do_putstatic();
1600 break;
1602 case Bytecodes::_irem:
1603 do_irem();
1604 break;
1605 case Bytecodes::_idiv:
1606 // Must keep both values on the expression-stack during null-check
1607 do_null_check(peek(), T_INT);
1608 // Compile-time detect of null-exception?
1609 if (stopped()) return;
1610 b = pop();
1611 a = pop();
1612 push( _gvn.transform( new (C, 3) DivINode(control(),a,b) ) );
1613 break;
1614 case Bytecodes::_imul:
1615 b = pop(); a = pop();
1616 push( _gvn.transform( new (C, 3) MulINode(a,b) ) );
1617 break;
1618 case Bytecodes::_iadd:
1619 b = pop(); a = pop();
1620 push( _gvn.transform( new (C, 3) AddINode(a,b) ) );
1621 break;
1622 case Bytecodes::_ineg:
1623 a = pop();
1624 push( _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),a)) );
1625 break;
1626 case Bytecodes::_isub:
1627 b = pop(); a = pop();
1628 push( _gvn.transform( new (C, 3) SubINode(a,b) ) );
1629 break;
1630 case Bytecodes::_iand:
1631 b = pop(); a = pop();
1632 push( _gvn.transform( new (C, 3) AndINode(a,b) ) );
1633 break;
1634 case Bytecodes::_ior:
1635 b = pop(); a = pop();
1636 push( _gvn.transform( new (C, 3) OrINode(a,b) ) );
1637 break;
1638 case Bytecodes::_ixor:
1639 b = pop(); a = pop();
1640 push( _gvn.transform( new (C, 3) XorINode(a,b) ) );
1641 break;
1642 case Bytecodes::_ishl:
1643 b = pop(); a = pop();
1644 push( _gvn.transform( new (C, 3) LShiftINode(a,b) ) );
1645 break;
1646 case Bytecodes::_ishr:
1647 b = pop(); a = pop();
1648 push( _gvn.transform( new (C, 3) RShiftINode(a,b) ) );
1649 break;
1650 case Bytecodes::_iushr:
1651 b = pop(); a = pop();
1652 push( _gvn.transform( new (C, 3) URShiftINode(a,b) ) );
1653 break;
1655 case Bytecodes::_fneg:
1656 a = pop();
1657 b = _gvn.transform(new (C, 2) NegFNode (a));
1658 push(b);
1659 break;
1661 case Bytecodes::_fsub:
1662 b = pop();
1663 a = pop();
1664 c = _gvn.transform( new (C, 3) SubFNode(a,b) );
1665 d = precision_rounding(c);
1666 push( d );
1667 break;
1669 case Bytecodes::_fadd:
1670 b = pop();
1671 a = pop();
1672 c = _gvn.transform( new (C, 3) AddFNode(a,b) );
1673 d = precision_rounding(c);
1674 push( d );
1675 break;
1677 case Bytecodes::_fmul:
1678 b = pop();
1679 a = pop();
1680 c = _gvn.transform( new (C, 3) MulFNode(a,b) );
1681 d = precision_rounding(c);
1682 push( d );
1683 break;
1685 case Bytecodes::_fdiv:
1686 b = pop();
1687 a = pop();
1688 c = _gvn.transform( new (C, 3) DivFNode(0,a,b) );
1689 d = precision_rounding(c);
1690 push( d );
1691 break;
1693 case Bytecodes::_frem:
1694 if (Matcher::has_match_rule(Op_ModF)) {
1695 // Generate a ModF node.
1696 b = pop();
1697 a = pop();
1698 c = _gvn.transform( new (C, 3) ModFNode(0,a,b) );
1699 d = precision_rounding(c);
1700 push( d );
1701 }
1702 else {
1703 // Generate a call.
1704 modf();
1705 }
1706 break;
1708 case Bytecodes::_fcmpl:
1709 b = pop();
1710 a = pop();
1711 c = _gvn.transform( new (C, 3) CmpF3Node( a, b));
1712 push(c);
1713 break;
1714 case Bytecodes::_fcmpg:
1715 b = pop();
1716 a = pop();
1718 // Same as fcmpl but need to flip the unordered case. Swap the inputs,
1719 // which negates the result sign except for unordered. Flip the unordered
1720 // as well by using CmpF3 which implements unordered-lesser instead of
1721 // unordered-greater semantics. Finally, commute the result bits. Result
1722 // is same as using a CmpF3Greater except we did it with CmpF3 alone.
1723 c = _gvn.transform( new (C, 3) CmpF3Node( b, a));
1724 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
1725 push(c);
1726 break;
1728 case Bytecodes::_f2i:
1729 a = pop();
1730 push(_gvn.transform(new (C, 2) ConvF2INode(a)));
1731 break;
1733 case Bytecodes::_d2i:
1734 a = pop_pair();
1735 b = _gvn.transform(new (C, 2) ConvD2INode(a));
1736 push( b );
1737 break;
1739 case Bytecodes::_f2d:
1740 a = pop();
1741 b = _gvn.transform( new (C, 2) ConvF2DNode(a));
1742 push_pair( b );
1743 break;
1745 case Bytecodes::_d2f:
1746 a = pop_pair();
1747 b = _gvn.transform( new (C, 2) ConvD2FNode(a));
1748 // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed)
1749 //b = _gvn.transform(new (C, 2) RoundFloatNode(0, b) );
1750 push( b );
1751 break;
1753 case Bytecodes::_l2f:
1754 if (Matcher::convL2FSupported()) {
1755 a = pop_pair();
1756 b = _gvn.transform( new (C, 2) ConvL2FNode(a));
1757 // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits.
1758 // Rather than storing the result into an FP register then pushing
1759 // out to memory to round, the machine instruction that implements
1760 // ConvL2D is responsible for rounding.
1761 // c = precision_rounding(b);
1762 c = _gvn.transform(b);
1763 push(c);
1764 } else {
1765 l2f();
1766 }
1767 break;
1769 case Bytecodes::_l2d:
1770 a = pop_pair();
1771 b = _gvn.transform( new (C, 2) ConvL2DNode(a));
1772 // For i486.ad, rounding is always necessary (see _l2f above).
1773 // c = dprecision_rounding(b);
1774 c = _gvn.transform(b);
1775 push_pair(c);
1776 break;
1778 case Bytecodes::_f2l:
1779 a = pop();
1780 b = _gvn.transform( new (C, 2) ConvF2LNode(a));
1781 push_pair(b);
1782 break;
1784 case Bytecodes::_d2l:
1785 a = pop_pair();
1786 b = _gvn.transform( new (C, 2) ConvD2LNode(a));
1787 push_pair(b);
1788 break;
1790 case Bytecodes::_dsub:
1791 b = pop_pair();
1792 a = pop_pair();
1793 c = _gvn.transform( new (C, 3) SubDNode(a,b) );
1794 d = dprecision_rounding(c);
1795 push_pair( d );
1796 break;
1798 case Bytecodes::_dadd:
1799 b = pop_pair();
1800 a = pop_pair();
1801 c = _gvn.transform( new (C, 3) AddDNode(a,b) );
1802 d = dprecision_rounding(c);
1803 push_pair( d );
1804 break;
1806 case Bytecodes::_dmul:
1807 b = pop_pair();
1808 a = pop_pair();
1809 c = _gvn.transform( new (C, 3) MulDNode(a,b) );
1810 d = dprecision_rounding(c);
1811 push_pair( d );
1812 break;
1814 case Bytecodes::_ddiv:
1815 b = pop_pair();
1816 a = pop_pair();
1817 c = _gvn.transform( new (C, 3) DivDNode(0,a,b) );
1818 d = dprecision_rounding(c);
1819 push_pair( d );
1820 break;
1822 case Bytecodes::_dneg:
1823 a = pop_pair();
1824 b = _gvn.transform(new (C, 2) NegDNode (a));
1825 push_pair(b);
1826 break;
1828 case Bytecodes::_drem:
1829 if (Matcher::has_match_rule(Op_ModD)) {
1830 // Generate a ModD node.
1831 b = pop_pair();
1832 a = pop_pair();
1833 // a % b
1835 c = _gvn.transform( new (C, 3) ModDNode(0,a,b) );
1836 d = dprecision_rounding(c);
1837 push_pair( d );
1838 }
1839 else {
1840 // Generate a call.
1841 modd();
1842 }
1843 break;
1845 case Bytecodes::_dcmpl:
1846 b = pop_pair();
1847 a = pop_pair();
1848 c = _gvn.transform( new (C, 3) CmpD3Node( a, b));
1849 push(c);
1850 break;
1852 case Bytecodes::_dcmpg:
1853 b = pop_pair();
1854 a = pop_pair();
1855 // Same as dcmpl but need to flip the unordered case.
1856 // Commute the inputs, which negates the result sign except for unordered.
1857 // Flip the unordered as well by using CmpD3 which implements
1858 // unordered-lesser instead of unordered-greater semantics.
1859 // Finally, negate the result bits. Result is same as using a
1860 // CmpD3Greater except we did it with CmpD3 alone.
1861 c = _gvn.transform( new (C, 3) CmpD3Node( b, a));
1862 c = _gvn.transform( new (C, 3) SubINode(_gvn.intcon(0),c) );
1863 push(c);
1864 break;
1867 // Note for longs -> lo word is on TOS, hi word is on TOS - 1
1868 case Bytecodes::_land:
1869 b = pop_pair();
1870 a = pop_pair();
1871 c = _gvn.transform( new (C, 3) AndLNode(a,b) );
1872 push_pair(c);
1873 break;
1874 case Bytecodes::_lor:
1875 b = pop_pair();
1876 a = pop_pair();
1877 c = _gvn.transform( new (C, 3) OrLNode(a,b) );
1878 push_pair(c);
1879 break;
1880 case Bytecodes::_lxor:
1881 b = pop_pair();
1882 a = pop_pair();
1883 c = _gvn.transform( new (C, 3) XorLNode(a,b) );
1884 push_pair(c);
1885 break;
1887 case Bytecodes::_lshl:
1888 b = pop(); // the shift count
1889 a = pop_pair(); // value to be shifted
1890 c = _gvn.transform( new (C, 3) LShiftLNode(a,b) );
1891 push_pair(c);
1892 break;
1893 case Bytecodes::_lshr:
1894 b = pop(); // the shift count
1895 a = pop_pair(); // value to be shifted
1896 c = _gvn.transform( new (C, 3) RShiftLNode(a,b) );
1897 push_pair(c);
1898 break;
1899 case Bytecodes::_lushr:
1900 b = pop(); // the shift count
1901 a = pop_pair(); // value to be shifted
1902 c = _gvn.transform( new (C, 3) URShiftLNode(a,b) );
1903 push_pair(c);
1904 break;
1905 case Bytecodes::_lmul:
1906 b = pop_pair();
1907 a = pop_pair();
1908 c = _gvn.transform( new (C, 3) MulLNode(a,b) );
1909 push_pair(c);
1910 break;
1912 case Bytecodes::_lrem:
1913 // Must keep both values on the expression-stack during null-check
1914 assert(peek(0) == top(), "long word order");
1915 do_null_check(peek(1), T_LONG);
1916 // Compile-time detect of null-exception?
1917 if (stopped()) return;
1918 b = pop_pair();
1919 a = pop_pair();
1920 c = _gvn.transform( new (C, 3) ModLNode(control(),a,b) );
1921 push_pair(c);
1922 break;
1924 case Bytecodes::_ldiv:
1925 // Must keep both values on the expression-stack during null-check
1926 assert(peek(0) == top(), "long word order");
1927 do_null_check(peek(1), T_LONG);
1928 // Compile-time detect of null-exception?
1929 if (stopped()) return;
1930 b = pop_pair();
1931 a = pop_pair();
1932 c = _gvn.transform( new (C, 3) DivLNode(control(),a,b) );
1933 push_pair(c);
1934 break;
1936 case Bytecodes::_ladd:
1937 b = pop_pair();
1938 a = pop_pair();
1939 c = _gvn.transform( new (C, 3) AddLNode(a,b) );
1940 push_pair(c);
1941 break;
1942 case Bytecodes::_lsub:
1943 b = pop_pair();
1944 a = pop_pair();
1945 c = _gvn.transform( new (C, 3) SubLNode(a,b) );
1946 push_pair(c);
1947 break;
1948 case Bytecodes::_lcmp:
1949 // Safepoints are now inserted _before_ branches. The long-compare
1950 // bytecode painfully produces a 3-way value (-1,0,+1) which requires a
1951 // slew of control flow. These are usually followed by a CmpI vs zero and
1952 // a branch; this pattern then optimizes to the obvious long-compare and
1953 // branch. However, if the branch is backwards there's a Safepoint
1954 // inserted. The inserted Safepoint captures the JVM state at the
1955 // pre-branch point, i.e. it captures the 3-way value. Thus if a
1956 // long-compare is used to control a loop the debug info will force
1957 // computation of the 3-way value, even though the generated code uses a
1958 // long-compare and branch. We try to rectify the situation by inserting
1959 // a SafePoint here and have it dominate and kill the safepoint added at a
1960 // following backwards branch. At this point the JVM state merely holds 2
1961 // longs but not the 3-way value.
1962 if( UseLoopSafepoints ) {
1963 switch( iter().next_bc() ) {
1964 case Bytecodes::_ifgt:
1965 case Bytecodes::_iflt:
1966 case Bytecodes::_ifge:
1967 case Bytecodes::_ifle:
1968 case Bytecodes::_ifne:
1969 case Bytecodes::_ifeq:
1970 // If this is a backwards branch in the bytecodes, add Safepoint
1971 maybe_add_safepoint(iter().next_get_dest());
1972 }
1973 }
1974 b = pop_pair();
1975 a = pop_pair();
1976 c = _gvn.transform( new (C, 3) CmpL3Node( a, b ));
1977 push(c);
1978 break;
1980 case Bytecodes::_lneg:
1981 a = pop_pair();
1982 b = _gvn.transform( new (C, 3) SubLNode(longcon(0),a));
1983 push_pair(b);
1984 break;
1985 case Bytecodes::_l2i:
1986 a = pop_pair();
1987 push( _gvn.transform( new (C, 2) ConvL2INode(a)));
1988 break;
1989 case Bytecodes::_i2l:
1990 a = pop();
1991 b = _gvn.transform( new (C, 2) ConvI2LNode(a));
1992 push_pair(b);
1993 break;
1994 case Bytecodes::_i2b:
1995 // Sign extend
1996 a = pop();
1997 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(24)) );
1998 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(24)) );
1999 push( a );
2000 break;
2001 case Bytecodes::_i2s:
2002 a = pop();
2003 a = _gvn.transform( new (C, 3) LShiftINode(a,_gvn.intcon(16)) );
2004 a = _gvn.transform( new (C, 3) RShiftINode(a,_gvn.intcon(16)) );
2005 push( a );
2006 break;
2007 case Bytecodes::_i2c:
2008 a = pop();
2009 push( _gvn.transform( new (C, 3) AndINode(a,_gvn.intcon(0xFFFF)) ) );
2010 break;
2012 case Bytecodes::_i2f:
2013 a = pop();
2014 b = _gvn.transform( new (C, 2) ConvI2FNode(a) ) ;
2015 c = precision_rounding(b);
2016 push (b);
2017 break;
2019 case Bytecodes::_i2d:
2020 a = pop();
2021 b = _gvn.transform( new (C, 2) ConvI2DNode(a));
2022 push_pair(b);
2023 break;
2025 case Bytecodes::_iinc: // Increment local
2026 i = iter().get_index(); // Get local index
2027 set_local( i, _gvn.transform( new (C, 3) AddINode( _gvn.intcon(iter().get_iinc_con()), local(i) ) ) );
2028 break;
2030 // Exit points of synchronized methods must have an unlock node
2031 case Bytecodes::_return:
2032 return_current(NULL);
2033 break;
2035 case Bytecodes::_ireturn:
2036 case Bytecodes::_areturn:
2037 case Bytecodes::_freturn:
2038 return_current(pop());
2039 break;
2040 case Bytecodes::_lreturn:
2041 return_current(pop_pair());
2042 break;
2043 case Bytecodes::_dreturn:
2044 return_current(pop_pair());
2045 break;
2047 case Bytecodes::_athrow:
2048 // null exception oop throws NULL pointer exception
2049 do_null_check(peek(), T_OBJECT);
2050 if (stopped()) return;
2051 if (JvmtiExport::can_post_exceptions()) {
2052 // "Full-speed throwing" is not necessary here,
2053 // since we're notifying the VM on every throw.
2054 uncommon_trap(Deoptimization::Reason_unhandled,
2055 Deoptimization::Action_none);
2056 return;
2057 }
2058 // Hook the thrown exception directly to subsequent handlers.
2059 if (BailoutToInterpreterForThrows) {
2060 // Keep method interpreted from now on.
2061 uncommon_trap(Deoptimization::Reason_unhandled,
2062 Deoptimization::Action_make_not_compilable);
2063 return;
2064 }
2065 add_exception_state(make_exception_state(peek()));
2066 break;
2068 case Bytecodes::_goto: // fall through
2069 case Bytecodes::_goto_w: {
2070 int target_bci = (bc() == Bytecodes::_goto) ? iter().get_dest() : iter().get_far_dest();
2072 // If this is a backwards branch in the bytecodes, add Safepoint
2073 maybe_add_safepoint(target_bci);
2075 // Update method data
2076 profile_taken_branch(target_bci);
2078 // Merge the current control into the target basic block
2079 merge(target_bci);
2081 // See if we can get some profile data and hand it off to the next block
2082 Block *target_block = block()->successor_for_bci(target_bci);
2083 if (target_block->pred_count() != 1) break;
2084 ciMethodData* methodData = method()->method_data();
2085 if (!methodData->is_mature()) break;
2086 ciProfileData* data = methodData->bci_to_data(bci());
2087 assert( data->is_JumpData(), "" );
2088 int taken = ((ciJumpData*)data)->taken();
2089 taken = method()->scale_count(taken);
2090 target_block->set_count(taken);
2091 break;
2092 }
2094 case Bytecodes::_ifnull: btest = BoolTest::eq; goto handle_if_null;
2095 case Bytecodes::_ifnonnull: btest = BoolTest::ne; goto handle_if_null;
2096 handle_if_null:
2097 // If this is a backwards branch in the bytecodes, add Safepoint
2098 maybe_add_safepoint(iter().get_dest());
2099 a = null();
2100 b = pop();
2101 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
2102 do_ifnull(btest, c);
2103 break;
2105 case Bytecodes::_if_acmpeq: btest = BoolTest::eq; goto handle_if_acmp;
2106 case Bytecodes::_if_acmpne: btest = BoolTest::ne; goto handle_if_acmp;
2107 handle_if_acmp:
2108 // If this is a backwards branch in the bytecodes, add Safepoint
2109 maybe_add_safepoint(iter().get_dest());
2110 a = pop();
2111 b = pop();
2112 c = _gvn.transform( new (C, 3) CmpPNode(b, a) );
2113 do_if(btest, c);
2114 break;
2116 case Bytecodes::_ifeq: btest = BoolTest::eq; goto handle_ifxx;
2117 case Bytecodes::_ifne: btest = BoolTest::ne; goto handle_ifxx;
2118 case Bytecodes::_iflt: btest = BoolTest::lt; goto handle_ifxx;
2119 case Bytecodes::_ifle: btest = BoolTest::le; goto handle_ifxx;
2120 case Bytecodes::_ifgt: btest = BoolTest::gt; goto handle_ifxx;
2121 case Bytecodes::_ifge: btest = BoolTest::ge; goto handle_ifxx;
2122 handle_ifxx:
2123 // If this is a backwards branch in the bytecodes, add Safepoint
2124 maybe_add_safepoint(iter().get_dest());
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 // If this is a backwards branch in the bytecodes, add Safepoint
2139 maybe_add_safepoint(iter().get_dest());
2140 a = pop();
2141 b = pop();
2142 c = _gvn.transform( new (C, 3) CmpINode( b, a ) );
2143 do_if(btest, c);
2144 break;
2146 case Bytecodes::_tableswitch:
2147 do_tableswitch();
2148 break;
2150 case Bytecodes::_lookupswitch:
2151 do_lookupswitch();
2152 break;
2154 case Bytecodes::_invokestatic:
2155 case Bytecodes::_invokespecial:
2156 case Bytecodes::_invokevirtual:
2157 case Bytecodes::_invokeinterface:
2158 do_call();
2159 break;
2160 case Bytecodes::_checkcast:
2161 do_checkcast();
2162 break;
2163 case Bytecodes::_instanceof:
2164 do_instanceof();
2165 break;
2166 case Bytecodes::_anewarray:
2167 do_anewarray();
2168 break;
2169 case Bytecodes::_newarray:
2170 do_newarray((BasicType)iter().get_index());
2171 break;
2172 case Bytecodes::_multianewarray:
2173 do_multianewarray();
2174 break;
2175 case Bytecodes::_new:
2176 do_new();
2177 break;
2179 case Bytecodes::_jsr:
2180 case Bytecodes::_jsr_w:
2181 do_jsr();
2182 break;
2184 case Bytecodes::_ret:
2185 do_ret();
2186 break;
2189 case Bytecodes::_monitorenter:
2190 do_monitor_enter();
2191 break;
2193 case Bytecodes::_monitorexit:
2194 do_monitor_exit();
2195 break;
2197 case Bytecodes::_breakpoint:
2198 // Breakpoint set concurrently to compile
2199 // %%% use an uncommon trap?
2200 C->record_failure("breakpoint in method");
2201 return;
2203 default:
2204 #ifndef PRODUCT
2205 map()->dump(99);
2206 #endif
2207 tty->print("\nUnhandled bytecode %s\n", Bytecodes::name(bc()) );
2208 ShouldNotReachHere();
2209 }
2211 #ifndef PRODUCT
2212 IdealGraphPrinter *printer = IdealGraphPrinter::printer();
2213 if(printer) {
2214 char buffer[256];
2215 sprintf(buffer, "Bytecode %d: %s", bci(), Bytecodes::name(bc()));
2216 bool old = printer->traverse_outs();
2217 printer->set_traverse_outs(true);
2218 printer->print_method(C, buffer, 4);
2219 printer->set_traverse_outs(old);
2220 }
2221 #endif
2222 }