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