parse2.cpp revision 726
1472N/A * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1472N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A#
include "incls/_precompiled.incl" 0N/A//---------------------------------array_load---------------------------------- 0N/A if (
stopped())
return;
// guaranteed null or range check 0N/A _sp -=
2;
// Pop array and index 0N/A//--------------------------------array_store---------------------------------- 0N/A if (
stopped())
return;
// guaranteed null or range check 0N/A _sp -=
2;
// Pop array and index 0N/A//------------------------------array_addressing------------------------------- 0N/A// Pull array and index from the stack. Compute pointer-to-element. 0N/A // Null check the array base, with correct stack contents 0N/A // Compile-time detect of null-exception? 0N/A // If we load from "AbstractClass[]" we must see "ConcreteSubClass". 0N/A // Check for big class initializers with all constant offsets 0N/A // feeding into a known-size array. 0N/A // See if the highest idx value is less than the lowest array bound, 0N/A // and if the idx value cannot be negative: 0N/A // Only fails for some -Xcomp runs 0N/A // The class is unloaded. We have to run this bytecode in the interpreter. 0N/A // Do the range check 0N/A // The greatest array bound is negative, so we can conclude that we're 0N/A // compiling unreachable code, but the unsigned compare trick used below 0N/A // only works with non-negative lengths. Instead, hack "tst" to be zero so 0N/A // the uncommon_trap path will always be taken. 0N/A // Range is constant in array-oop, so we can use the original state of mem 0N/A // Test length vs index (standard trick using unsigned compare) 0N/A // Branch to failure if out of bounds 0N/A // Do not use builtin_throw, since range checks are sometimes 0N/A // made more stringent by an optimistic transformation. 0N/A // This creates "tentative" range checks at this point, 0N/A // which are not guaranteed to throw exceptions. 0N/A // See IfNode::Ideal, is_range_check, adjust_check. 0N/A // If we have already recompiled with the range-check-widening 0N/A // heroic optimization turned off, then we must really be throwing 0N/A // range check exceptions. // Check for always knowing you are throwing a range-check exception assert(
ptr !=
top(),
"top should go hand-in-hand with stopped");
//------------------------------helper for tableswitch------------------------- // True branch, use existing map info // True branch, use existing map info // False branch, use existing map and control() static int jint_cmp(
const void *i,
const void *j) {
return a > b ?
1 : a < b ? -
1 : 0;
// Default value for methodData switch indexing. Must be a negative value to avoid // conflict with any legal switch index. // a range of integers coupled with a bci destination //-------------------------------do_tableswitch-------------------------------- // Get information about tableswitch // If this is a backward branch, add safepoint // generate decision tree, using trichotomy when possible for (
int j = 0; j <
len; j++) {
// Safepoint in case if backward branch observed //------------------------------do_lookupswitch-------------------------------- // Get information about lookupswitch if (
len <
1) {
// If this is a backward branch, add safepoint // generate decision tree, using trichotomy when possible for(
int j = 0; j <
len; j++ ) {
for(
int j = 0; j <
len; j++ ) {
// Safepoint in case backward branch observed //----------------------------create_jump_tables------------------------------- // Are jumptables enabled // Are jumptables supported // Don't make jump table if profiling // Decide if a guard is needed to lop off big ranges at either (or // both) end(s) of the input set. We'll call this the default target // even though we can't be sure that it is the true "default". // If a guard test will eliminate very sparse end ranges, then // it is worth the cost of an extra jump. // Find the total number of cases and ranges // Don't create table if: too large, too small, or too sparse. // Normalize table lookups to zero // Generate a guard to protect against input keyvals that aren't // Create an ideal node JumpTable that has projections // of all possible ranges for a switch statement // The key_val input must be converted to a pointer offset and scaled. // Compare Parse::array_addressing above. // Clean the 32-bit int into a real 64-bit offset. // Otherwise, the jint value 0 might turn into an offset of 0x0800000000. // Shift the value by wordsize so we have an index into the table, rather // These are the switch destinations hanging off the jumpnode for (
int j = r->
lo(); j <= r->
hi(); j++, i++) {
//----------------------------jump_switch_ranges------------------------------- // Do special processing for the top-level call. // Decrement pred-numbers for the unique set of nodes. // Ensure that the block's successors are a (duplicate-free) set. // Check that the set of successors is the same in both places. // Maybe prune the inputs, based on the type of key_val. assert(
lo <=
hi,
"must be a non-empty set of ranges");
// if there is an easy choice, pivot at a singleton: // Special Case: If there are exactly three ranges, and the high // and low range each go to the same place, omit the "gt" test, // since it will not discriminate anything. // if there is a higher range, test for it and process it: // two comparisons of same values--should enable 1 test for 2 branches // Use BoolTest::le instead of BoolTest::gt // mid is a range, not a singleton, so treat mid..hi as a unit // if there is a higher range, test for it and process it: // in any case, process the lower range // Decrease pred_count for each successor after all is done. // Throw away the pre-allocated path for each unique successor. for( r =
lo; r <=
hi; r++ ) {
tty->
print_cr(
" %d ranges (%d singletons), max_depth=%d, est_depth=%d",
for( r =
lo; r <=
hi; r++ ) {
"frem",
NULL,
//no memory effects "drem",
NULL,
//no memory effects "l2f",
NULL,
//no memory effects // Must keep both values on the expression-stack during null-check // Compile-time detect of null-exception? // check for positive power of 2 // Sigh, must handle negative dividends // Handle jsr and jsr_w bytecode // Store information about current state, tagged with new _jsr_bci // The way we do things now, there is only one successor block // for the jsr, because the target code is cloned by ciTypeFlow. // Effect on jsr on stack // Find to whom we return. #
if 0
// %%%% MAKE THIS WORK//--------------------------dynamic_branch_prediction-------------------------- // Try to gather dynamic branch prediction behavior. Return a probability // of the branch being taken and set the "cnt" field. Returns a -1.0 // if we need to use static prediction for some reason. // Use MethodData information if it is available // FIXME: free the ProfileData structure // get taken and not taken values // scale the counts to be commensurate with invocation counts: // Give up if too few counts to be meaningful // Compute frequency that we arrive here // Adjust, if this block is a cloned private block but the // Jump counts are shared. Taken the private counts for // just this path instead of the shared counts. // Pin probability to sane limits else {
// Compute probability of true path "Bad frequency assignment in if");
C->
log()->
elem(
"branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
//-----------------------------branch_prediction------------------------------- // If prob is unknown, switch to static prediction // If this is a conditional test guarding a backwards branch, // assume its a loop-back edge. Make it a likely taken branch. if (
is_osr_parse()) {
// Could be a hot OSR'd loop; force deopt // Since it's an OSR, we probably have profile data, but since // branch_prediction returned PROB_UNKNOWN, the counts are too small. // Let's make a special check here for completely zero counts. // Only stop for truly zero counts, which mean an unknown part // of the OSR-ed method, and we want to deopt to gather more stats. // If you have ANY counts, then this loop is simply 'cold' relative // This is the only way to return PROB_UNKNOWN: // The magic constants are chosen so as to match the output of // branch_prediction() when the profile reports a zero taken count. // It is important to distinguish zero counts unambiguously, because // some branches (e.g., _213_javac.Assembler.eliminate) validly produce // very small but nonzero probabilities, which if confused with zero // counts would keep the program recompiling indefinitely. //-------------------------------repush_if_args-------------------------------- // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. tty->
print(
"defending against excessive implicit null exceptions on %s @%d in ",
//----------------------------------do_ifnull---------------------------------- // (An earlier version of do_ifnull omitted this trap for OSR methods.) // We need to mark this branch as taken so that if we recompile we will // see that it is possible. In the tiered system the interpreter doesn't // do profiling and by the time we get to the lower tier from the interpreter // the path may be cold again. Make sure it doesn't look untaken // Mark the successor blocks as parsed // Generate real control flow // Sanity check the probability value // Need xform to put node in hash table // Mark the successor block as parsed }
else {
// Path is live. // Mark the successor block as parsed }
else {
// Path is live.//------------------------------------do_if------------------------------------ // We need to mark this branch as taken so that if we recompile we will // see that it is possible. In the tiered system the interpreter doesn't // do profiling and by the time we get to the lower tier from the interpreter // the path may be cold again. Make sure it doesn't look untaken // Mark the successor blocks as parsed // Sanity check the probability value // Convert BoolTest to canonical form: // prob is NOT updated here; it remains the probability of the taken // path (as opposed to the prob of the path guarded by an 'IfTrueNode'). // Refresh c from the transformed bool node, since it may be // simpler than the original c. Also re-canonicalize btest. // This wins when (Bool ne (Conv2B p) 0) => (Bool ne (CmpP p NULL)). // That can arise from statements like: if (x instanceof C) ... // Canonicalize one more time since transform can change it. // Reverse edges one more time... // Generate real control flow // Mark the successor block as parsed // Mark the successor block as parsed //----------------------------adjust_map_after_if------------------------------ // Adjust the JVM state to reflect the result of taking this path. // Basically, it means inspecting the CmpNode controlling this // branch, seeing how it constrains a tested value, and then // deciding if it's worth our while to encode this constraint // as graph nodes in the current abstract interpretation map. // (An earlier version of do_if omitted '&& btest == BoolTest::eq'.) // If this might possibly turn into an implicit null check, // and the null has never yet been seen, we need to generate // an uncommon trap, so as to recompile instead of suffering // with very slow branches. (We'll get the slow branches if // the program ever changes phase and starts seeing nulls here.) // The tests we worry about are of the form (p == null). // We do not simply inspect for a null constant, since a node may // optimize to 'null' later on. // We need to mark this branch as taken so that if we recompile we will // see that it is possible. In the tiered system the interpreter doesn't // do profiling and by the time we get to the lower tier from the interpreter // the path may be cold again. Make sure it doesn't look untaken // Swap, so constant is in con. // Do we have two constants? Then leave well enough alone. if (!
have_con)
// remaining adjustments need a con if (
val_in_map < 0)
return;
// replace_in_map would be useless return;
// again, it would be useless // Check for a comparison to a constant, and "know" that the compared // value is constrained on this path. if (
tboth ==
tval)
break;
// Nothing to gain. // Cast to null, but keep the pointer identity temporarily live. // either +0 or -0. Just because you are equal to +0 // doesn't mean you ARE +0! cast =
con;
// Replace non-constant val by con. // (At this point we could record int range types with CastII.) // Delay transform() call to allow recovery of pre-cast value if (
cast !=
NULL) {
// Here's the payoff. //------------------------------do_one_bytecode-------------------------------- // Parse this bytecode, and alter the Parsers JVM->Node mapping Node *a, *b, *c, *d;
// Handy temps "out of nodes parsing method")) {
// for setting breakpoints // If the constant is unresolved, run this BC once in the interpreter. NULL,
"unresolved_string");
// The constant returned for a klass is the ciKlass for the // entry. We want the java_mirror so get it. NULL,
"unresolved_klass");
// after: .. b, a, c, b, a // after: .. b, a, d, c, b, a // Must do null-check with value on expression stack // Compile-time detect of null-exception? if (
stopped())
return;
// guaranteed null or range check _sp -=
2;
// Pop array and index if (
stopped())
return;
// guaranteed null or range check _sp -=
2;
// Pop array and index if (
stopped())
return;
// guaranteed null or range check c =
pop();
// Oop to store b =
pop();
// index (already used) a =
pop();
// the array itself if (
stopped())
return;
// guaranteed null or range check _sp -=
2;
// Pop array and index if (
stopped())
return;
// guaranteed null or range check _sp -=
2;
// Pop array and index // Must keep both values on the expression-stack during null-check // Compile-time detect of null-exception? // Same as fcmpl but need to flip the unordered case. Swap the inputs, // which negates the result sign except for unordered. Flip the unordered // as well by using CmpF3 which implements unordered-lesser instead of // unordered-greater semantics. Finally, commute the result bits. Result // is same as using a CmpF3Greater except we did it with CmpF3 alone. // This breaks _227_mtrt (speed & correctness) and _222_mpegaudio (speed) //b = _gvn.transform(new (C, 2) RoundFloatNode(0, b) ); // For i486.ad, FILD doesn't restrict precision to 24 or 53 bits. // Rather than storing the result into an FP register then pushing // out to memory to round, the machine instruction that implements // ConvL2D is responsible for rounding. // c = precision_rounding(b); // For i486.ad, rounding is always necessary (see _l2f above). // c = dprecision_rounding(b); // Same as dcmpl but need to flip the unordered case. // Commute the inputs, which negates the result sign except for unordered. // Flip the unordered as well by using CmpD3 which implements // unordered-lesser instead of unordered-greater semantics. // Finally, negate the result bits. Result is same as using a // CmpD3Greater except we did it with CmpD3 alone. // Note for longs -> lo word is on TOS, hi word is on TOS - 1 b =
pop();
// the shift count b =
pop();
// the shift count b =
pop();
// the shift count // Must keep both values on the expression-stack during null-check // Compile-time detect of null-exception? // Must keep both values on the expression-stack during null-check // Compile-time detect of null-exception? // Safepoints are now inserted _before_ branches. The long-compare // bytecode painfully produces a 3-way value (-1,0,+1) which requires a // slew of control flow. These are usually followed by a CmpI vs zero and // a branch; this pattern then optimizes to the obvious long-compare and // branch. However, if the branch is backwards there's a Safepoint // inserted. The inserted Safepoint captures the JVM state at the // pre-branch point, i.e. it captures the 3-way value. Thus if a // long-compare is used to control a loop the debug info will force // computation of the 3-way value, even though the generated code uses a // long-compare and branch. We try to rectify the situation by inserting // a SafePoint here and have it dominate and kill the safepoint added at a // following backwards branch. At this point the JVM state merely holds 2 // longs but not the 3-way value. // If this is a backwards branch in the bytecodes, add Safepoint // Exit points of synchronized methods must have an unlock node // null exception oop throws NULL pointer exception // "Full-speed throwing" is not necessary here, // since we're notifying the VM on every throw. // Hook the thrown exception directly to subsequent handlers. // Keep method interpreted from now on. // If this is a backwards branch in the bytecodes, add Safepoint // Merge the current control into the target basic block // See if we can get some profile data and hand it off to the next block // If this is a backwards branch in the bytecodes, add Safepoint // If this is a backwards branch in the bytecodes, add Safepoint // If this is a backwards branch in the bytecodes, add Safepoint // If this is a backwards branch in the bytecodes, add Safepoint // Breakpoint set concurrently to compile // %%% use an uncommon trap?