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