Wed, 13 Apr 2011 14:33:03 -0700
6988308: assert((cnt > 0.0f) && (prob > 0.0f)) failed: Bad frequency assignment in if
Summary: Make sure cnt doesn't become negative and integer overflow doesn't happen.
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
trims@2708 | 2 | * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "compiler/oopMap.hpp" |
stefank@2314 | 27 | #include "opto/addnode.hpp" |
stefank@2314 | 28 | #include "opto/callnode.hpp" |
stefank@2314 | 29 | #include "opto/compile.hpp" |
stefank@2314 | 30 | #include "opto/machnode.hpp" |
stefank@2314 | 31 | #include "opto/matcher.hpp" |
stefank@2314 | 32 | #include "opto/phase.hpp" |
stefank@2314 | 33 | #include "opto/regalloc.hpp" |
stefank@2314 | 34 | #include "opto/rootnode.hpp" |
stefank@2314 | 35 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 36 | # include "vmreg_x86.inline.hpp" |
stefank@2314 | 37 | #endif |
stefank@2314 | 38 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 39 | # include "vmreg_sparc.inline.hpp" |
stefank@2314 | 40 | #endif |
stefank@2314 | 41 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 42 | # include "vmreg_zero.inline.hpp" |
stefank@2314 | 43 | #endif |
bobv@2508 | 44 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 45 | # include "vmreg_arm.inline.hpp" |
bobv@2508 | 46 | #endif |
bobv@2508 | 47 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 48 | # include "vmreg_ppc.inline.hpp" |
bobv@2508 | 49 | #endif |
duke@435 | 50 | |
duke@435 | 51 | // The functions in this file builds OopMaps after all scheduling is done. |
duke@435 | 52 | // |
duke@435 | 53 | // OopMaps contain a list of all registers and stack-slots containing oops (so |
duke@435 | 54 | // they can be updated by GC). OopMaps also contain a list of derived-pointer |
duke@435 | 55 | // base-pointer pairs. When the base is moved, the derived pointer moves to |
duke@435 | 56 | // follow it. Finally, any registers holding callee-save values are also |
duke@435 | 57 | // recorded. These might contain oops, but only the caller knows. |
duke@435 | 58 | // |
duke@435 | 59 | // BuildOopMaps implements a simple forward reaching-defs solution. At each |
duke@435 | 60 | // GC point we'll have the reaching-def Nodes. If the reaching Nodes are |
duke@435 | 61 | // typed as pointers (no offset), then they are oops. Pointers+offsets are |
duke@435 | 62 | // derived pointers, and bases can be found from them. Finally, we'll also |
duke@435 | 63 | // track reaching callee-save values. Note that a copy of a callee-save value |
duke@435 | 64 | // "kills" it's source, so that only 1 copy of a callee-save value is alive at |
duke@435 | 65 | // a time. |
duke@435 | 66 | // |
duke@435 | 67 | // We run a simple bitvector liveness pass to help trim out dead oops. Due to |
duke@435 | 68 | // irreducible loops, we can have a reaching def of an oop that only reaches |
duke@435 | 69 | // along one path and no way to know if it's valid or not on the other path. |
duke@435 | 70 | // The bitvectors are quite dense and the liveness pass is fast. |
duke@435 | 71 | // |
duke@435 | 72 | // At GC points, we consult this information to build OopMaps. All reaching |
duke@435 | 73 | // defs typed as oops are added to the OopMap. Only 1 instance of a |
duke@435 | 74 | // callee-save register can be recorded. For derived pointers, we'll have to |
duke@435 | 75 | // find and record the register holding the base. |
duke@435 | 76 | // |
duke@435 | 77 | // The reaching def's is a simple 1-pass worklist approach. I tried a clever |
duke@435 | 78 | // breadth-first approach but it was worse (showed O(n^2) in the |
duke@435 | 79 | // pick-next-block code). |
duke@435 | 80 | // |
twisti@1040 | 81 | // The relevant data is kept in a struct of arrays (it could just as well be |
duke@435 | 82 | // an array of structs, but the struct-of-arrays is generally a little more |
duke@435 | 83 | // efficient). The arrays are indexed by register number (including |
duke@435 | 84 | // stack-slots as registers) and so is bounded by 200 to 300 elements in |
duke@435 | 85 | // practice. One array will map to a reaching def Node (or NULL for |
duke@435 | 86 | // conflict/dead). The other array will map to a callee-saved register or |
duke@435 | 87 | // OptoReg::Bad for not-callee-saved. |
duke@435 | 88 | |
duke@435 | 89 | |
duke@435 | 90 | //------------------------------OopFlow---------------------------------------- |
duke@435 | 91 | // Structure to pass around |
duke@435 | 92 | struct OopFlow : public ResourceObj { |
duke@435 | 93 | short *_callees; // Array mapping register to callee-saved |
duke@435 | 94 | Node **_defs; // array mapping register to reaching def |
duke@435 | 95 | // or NULL if dead/conflict |
duke@435 | 96 | // OopFlow structs, when not being actively modified, describe the _end_ of |
duke@435 | 97 | // this block. |
duke@435 | 98 | Block *_b; // Block for this struct |
duke@435 | 99 | OopFlow *_next; // Next free OopFlow |
kvn@1268 | 100 | // or NULL if dead/conflict |
kvn@1268 | 101 | Compile* C; |
duke@435 | 102 | |
kvn@1268 | 103 | OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs), |
kvn@1268 | 104 | _b(NULL), _next(NULL), C(c) { } |
duke@435 | 105 | |
duke@435 | 106 | // Given reaching-defs for this block start, compute it for this block end |
duke@435 | 107 | void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ); |
duke@435 | 108 | |
duke@435 | 109 | // Merge these two OopFlows into the 'this' pointer. |
duke@435 | 110 | void merge( OopFlow *flow, int max_reg ); |
duke@435 | 111 | |
duke@435 | 112 | // Copy a 'flow' over an existing flow |
duke@435 | 113 | void clone( OopFlow *flow, int max_size); |
duke@435 | 114 | |
duke@435 | 115 | // Make a new OopFlow from scratch |
kvn@1268 | 116 | static OopFlow *make( Arena *A, int max_size, Compile* C ); |
duke@435 | 117 | |
duke@435 | 118 | // Build an oopmap from the current flow info |
duke@435 | 119 | OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ); |
duke@435 | 120 | }; |
duke@435 | 121 | |
duke@435 | 122 | //------------------------------compute_reach---------------------------------- |
duke@435 | 123 | // Given reaching-defs for this block start, compute it for this block end |
duke@435 | 124 | void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) { |
duke@435 | 125 | |
duke@435 | 126 | for( uint i=0; i<_b->_nodes.size(); i++ ) { |
duke@435 | 127 | Node *n = _b->_nodes[i]; |
duke@435 | 128 | |
duke@435 | 129 | if( n->jvms() ) { // Build an OopMap here? |
duke@435 | 130 | JVMState *jvms = n->jvms(); |
duke@435 | 131 | // no map needed for leaf calls |
duke@435 | 132 | if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) { |
duke@435 | 133 | int *live = (int*) (*safehash)[n]; |
duke@435 | 134 | assert( live, "must find live" ); |
duke@435 | 135 | n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) ); |
duke@435 | 136 | } |
duke@435 | 137 | } |
duke@435 | 138 | |
duke@435 | 139 | // Assign new reaching def's. |
duke@435 | 140 | // Note that I padded the _defs and _callees arrays so it's legal |
duke@435 | 141 | // to index at _defs[OptoReg::Bad]. |
duke@435 | 142 | OptoReg::Name first = regalloc->get_reg_first(n); |
duke@435 | 143 | OptoReg::Name second = regalloc->get_reg_second(n); |
duke@435 | 144 | _defs[first] = n; |
duke@435 | 145 | _defs[second] = n; |
duke@435 | 146 | |
duke@435 | 147 | // Pass callee-save info around copies |
duke@435 | 148 | int idx = n->is_Copy(); |
duke@435 | 149 | if( idx ) { // Copies move callee-save info |
duke@435 | 150 | OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx)); |
duke@435 | 151 | OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx)); |
duke@435 | 152 | int tmp_first = _callees[old_first]; |
duke@435 | 153 | int tmp_second = _callees[old_second]; |
duke@435 | 154 | _callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location |
duke@435 | 155 | _callees[old_second] = OptoReg::Bad; |
duke@435 | 156 | _callees[first] = tmp_first; |
duke@435 | 157 | _callees[second] = tmp_second; |
duke@435 | 158 | } else if( n->is_Phi() ) { // Phis do not mod callee-saves |
duke@435 | 159 | assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" ); |
duke@435 | 160 | assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" ); |
duke@435 | 161 | assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" ); |
duke@435 | 162 | assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" ); |
duke@435 | 163 | } else { |
duke@435 | 164 | _callees[first] = OptoReg::Bad; // No longer holding a callee-save value |
duke@435 | 165 | _callees[second] = OptoReg::Bad; |
duke@435 | 166 | |
duke@435 | 167 | // Find base case for callee saves |
duke@435 | 168 | if( n->is_Proj() && n->in(0)->is_Start() ) { |
duke@435 | 169 | if( OptoReg::is_reg(first) && |
duke@435 | 170 | regalloc->_matcher.is_save_on_entry(first) ) |
duke@435 | 171 | _callees[first] = first; |
duke@435 | 172 | if( OptoReg::is_reg(second) && |
duke@435 | 173 | regalloc->_matcher.is_save_on_entry(second) ) |
duke@435 | 174 | _callees[second] = second; |
duke@435 | 175 | } |
duke@435 | 176 | } |
duke@435 | 177 | } |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | //------------------------------merge------------------------------------------ |
duke@435 | 181 | // Merge the given flow into the 'this' flow |
duke@435 | 182 | void OopFlow::merge( OopFlow *flow, int max_reg ) { |
duke@435 | 183 | assert( _b == NULL, "merging into a happy flow" ); |
duke@435 | 184 | assert( flow->_b, "this flow is still alive" ); |
duke@435 | 185 | assert( flow != this, "no self flow" ); |
duke@435 | 186 | |
duke@435 | 187 | // Do the merge. If there are any differences, drop to 'bottom' which |
duke@435 | 188 | // is OptoReg::Bad or NULL depending. |
duke@435 | 189 | for( int i=0; i<max_reg; i++ ) { |
duke@435 | 190 | // Merge the callee-save's |
duke@435 | 191 | if( _callees[i] != flow->_callees[i] ) |
duke@435 | 192 | _callees[i] = OptoReg::Bad; |
duke@435 | 193 | // Merge the reaching defs |
duke@435 | 194 | if( _defs[i] != flow->_defs[i] ) |
duke@435 | 195 | _defs[i] = NULL; |
duke@435 | 196 | } |
duke@435 | 197 | |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | //------------------------------clone------------------------------------------ |
duke@435 | 201 | void OopFlow::clone( OopFlow *flow, int max_size ) { |
duke@435 | 202 | _b = flow->_b; |
duke@435 | 203 | memcpy( _callees, flow->_callees, sizeof(short)*max_size); |
duke@435 | 204 | memcpy( _defs , flow->_defs , sizeof(Node*)*max_size); |
duke@435 | 205 | } |
duke@435 | 206 | |
duke@435 | 207 | //------------------------------make------------------------------------------- |
kvn@1268 | 208 | OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) { |
duke@435 | 209 | short *callees = NEW_ARENA_ARRAY(A,short,max_size+1); |
duke@435 | 210 | Node **defs = NEW_ARENA_ARRAY(A,Node*,max_size+1); |
duke@435 | 211 | debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) ); |
kvn@1268 | 212 | OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C); |
duke@435 | 213 | assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" ); |
duke@435 | 214 | assert( &flow->_defs [OptoReg::Bad] == defs , "Ok to index at OptoReg::Bad" ); |
duke@435 | 215 | return flow; |
duke@435 | 216 | } |
duke@435 | 217 | |
duke@435 | 218 | //------------------------------bit twiddlers---------------------------------- |
duke@435 | 219 | static int get_live_bit( int *live, int reg ) { |
duke@435 | 220 | return live[reg>>LogBitsPerInt] & (1<<(reg&(BitsPerInt-1))); } |
duke@435 | 221 | static void set_live_bit( int *live, int reg ) { |
duke@435 | 222 | live[reg>>LogBitsPerInt] |= (1<<(reg&(BitsPerInt-1))); } |
duke@435 | 223 | static void clr_live_bit( int *live, int reg ) { |
duke@435 | 224 | live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); } |
duke@435 | 225 | |
duke@435 | 226 | //------------------------------build_oop_map---------------------------------- |
duke@435 | 227 | // Build an oopmap from the current flow info |
duke@435 | 228 | OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) { |
duke@435 | 229 | int framesize = regalloc->_framesize; |
duke@435 | 230 | int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP); |
duke@435 | 231 | debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0()); |
duke@435 | 232 | memset(dup_check,0,OptoReg::stack0()) ); |
duke@435 | 233 | |
duke@435 | 234 | OopMap *omap = new OopMap( framesize, max_inarg_slot ); |
duke@435 | 235 | MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL; |
duke@435 | 236 | JVMState* jvms = n->jvms(); |
duke@435 | 237 | |
duke@435 | 238 | // For all registers do... |
duke@435 | 239 | for( int reg=0; reg<max_reg; reg++ ) { |
duke@435 | 240 | if( get_live_bit(live,reg) == 0 ) |
duke@435 | 241 | continue; // Ignore if not live |
duke@435 | 242 | |
duke@435 | 243 | // %%% C2 can use 2 OptoRegs when the physical register is only one 64bit |
duke@435 | 244 | // register in that case we'll get an non-concrete register for the second |
duke@435 | 245 | // half. We only need to tell the map the register once! |
duke@435 | 246 | // |
duke@435 | 247 | // However for the moment we disable this change and leave things as they |
duke@435 | 248 | // were. |
duke@435 | 249 | |
duke@435 | 250 | VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot); |
duke@435 | 251 | |
duke@435 | 252 | if (false && r->is_reg() && !r->is_concrete()) { |
duke@435 | 253 | continue; |
duke@435 | 254 | } |
duke@435 | 255 | |
duke@435 | 256 | // See if dead (no reaching def). |
duke@435 | 257 | Node *def = _defs[reg]; // Get reaching def |
duke@435 | 258 | assert( def, "since live better have reaching def" ); |
duke@435 | 259 | |
duke@435 | 260 | // Classify the reaching def as oop, derived, callee-save, dead, or other |
duke@435 | 261 | const Type *t = def->bottom_type(); |
duke@435 | 262 | if( t->isa_oop_ptr() ) { // Oop or derived? |
duke@435 | 263 | assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" ); |
duke@435 | 264 | #ifdef _LP64 |
duke@435 | 265 | // 64-bit pointers record oop-ishness on 2 aligned adjacent registers. |
duke@435 | 266 | // Make sure both are record from the same reaching def, but do not |
duke@435 | 267 | // put both into the oopmap. |
duke@435 | 268 | if( (reg&1) == 1 ) { // High half of oop-pair? |
duke@435 | 269 | assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" ); |
duke@435 | 270 | continue; // Do not record high parts in oopmap |
duke@435 | 271 | } |
duke@435 | 272 | #endif |
duke@435 | 273 | |
duke@435 | 274 | // Check for a legal reg name in the oopMap and bailout if it is not. |
duke@435 | 275 | if (!omap->legal_vm_reg_name(r)) { |
duke@435 | 276 | regalloc->C->record_method_not_compilable("illegal oopMap register name"); |
duke@435 | 277 | continue; |
duke@435 | 278 | } |
duke@435 | 279 | if( t->is_ptr()->_offset == 0 ) { // Not derived? |
duke@435 | 280 | if( mcall ) { |
duke@435 | 281 | // Outgoing argument GC mask responsibility belongs to the callee, |
duke@435 | 282 | // not the caller. Inspect the inputs to the call, to see if |
duke@435 | 283 | // this live-range is one of them. |
duke@435 | 284 | uint cnt = mcall->tf()->domain()->cnt(); |
duke@435 | 285 | uint j; |
duke@435 | 286 | for( j = TypeFunc::Parms; j < cnt; j++) |
duke@435 | 287 | if( mcall->in(j) == def ) |
duke@435 | 288 | break; // reaching def is an argument oop |
duke@435 | 289 | if( j < cnt ) // arg oops dont go in GC map |
duke@435 | 290 | continue; // Continue on to the next register |
duke@435 | 291 | } |
duke@435 | 292 | omap->set_oop(r); |
duke@435 | 293 | } else { // Else it's derived. |
duke@435 | 294 | // Find the base of the derived value. |
duke@435 | 295 | uint i; |
duke@435 | 296 | // Fast, common case, scan |
duke@435 | 297 | for( i = jvms->oopoff(); i < n->req(); i+=2 ) |
duke@435 | 298 | if( n->in(i) == def ) break; // Common case |
duke@435 | 299 | if( i == n->req() ) { // Missed, try a more generous scan |
duke@435 | 300 | // Scan again, but this time peek through copies |
duke@435 | 301 | for( i = jvms->oopoff(); i < n->req(); i+=2 ) { |
duke@435 | 302 | Node *m = n->in(i); // Get initial derived value |
duke@435 | 303 | while( 1 ) { |
duke@435 | 304 | Node *d = def; // Get initial reaching def |
duke@435 | 305 | while( 1 ) { // Follow copies of reaching def to end |
duke@435 | 306 | if( m == d ) goto found; // breaks 3 loops |
duke@435 | 307 | int idx = d->is_Copy(); |
duke@435 | 308 | if( !idx ) break; |
duke@435 | 309 | d = d->in(idx); // Link through copy |
duke@435 | 310 | } |
duke@435 | 311 | int idx = m->is_Copy(); |
duke@435 | 312 | if( !idx ) break; |
duke@435 | 313 | m = m->in(idx); |
duke@435 | 314 | } |
duke@435 | 315 | } |
kvn@1268 | 316 | guarantee( 0, "must find derived/base pair" ); |
duke@435 | 317 | } |
duke@435 | 318 | found: ; |
duke@435 | 319 | Node *base = n->in(i+1); // Base is other half of pair |
duke@435 | 320 | int breg = regalloc->get_reg_first(base); |
duke@435 | 321 | VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot); |
duke@435 | 322 | |
duke@435 | 323 | // I record liveness at safepoints BEFORE I make the inputs |
duke@435 | 324 | // live. This is because argument oops are NOT live at a |
duke@435 | 325 | // safepoint (or at least they cannot appear in the oopmap). |
duke@435 | 326 | // Thus bases of base/derived pairs might not be in the |
duke@435 | 327 | // liveness data but they need to appear in the oopmap. |
duke@435 | 328 | if( get_live_bit(live,breg) == 0 ) {// Not live? |
duke@435 | 329 | // Flag it, so next derived pointer won't re-insert into oopmap |
duke@435 | 330 | set_live_bit(live,breg); |
duke@435 | 331 | // Already missed our turn? |
duke@435 | 332 | if( breg < reg ) { |
duke@435 | 333 | if (b->is_stack() || b->is_concrete() || true ) { |
duke@435 | 334 | omap->set_oop( b); |
duke@435 | 335 | } |
duke@435 | 336 | } |
duke@435 | 337 | } |
duke@435 | 338 | if (b->is_stack() || b->is_concrete() || true ) { |
duke@435 | 339 | omap->set_derived_oop( r, b); |
duke@435 | 340 | } |
duke@435 | 341 | } |
duke@435 | 342 | |
coleenp@548 | 343 | } else if( t->isa_narrowoop() ) { |
coleenp@548 | 344 | assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" ); |
coleenp@548 | 345 | // Check for a legal reg name in the oopMap and bailout if it is not. |
coleenp@548 | 346 | if (!omap->legal_vm_reg_name(r)) { |
coleenp@548 | 347 | regalloc->C->record_method_not_compilable("illegal oopMap register name"); |
coleenp@548 | 348 | continue; |
coleenp@548 | 349 | } |
coleenp@548 | 350 | if( mcall ) { |
coleenp@548 | 351 | // Outgoing argument GC mask responsibility belongs to the callee, |
coleenp@548 | 352 | // not the caller. Inspect the inputs to the call, to see if |
coleenp@548 | 353 | // this live-range is one of them. |
coleenp@548 | 354 | uint cnt = mcall->tf()->domain()->cnt(); |
coleenp@548 | 355 | uint j; |
coleenp@548 | 356 | for( j = TypeFunc::Parms; j < cnt; j++) |
coleenp@548 | 357 | if( mcall->in(j) == def ) |
coleenp@548 | 358 | break; // reaching def is an argument oop |
coleenp@548 | 359 | if( j < cnt ) // arg oops dont go in GC map |
coleenp@548 | 360 | continue; // Continue on to the next register |
coleenp@548 | 361 | } |
coleenp@548 | 362 | omap->set_narrowoop(r); |
duke@435 | 363 | } else if( OptoReg::is_valid(_callees[reg])) { // callee-save? |
duke@435 | 364 | // It's a callee-save value |
duke@435 | 365 | assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" ); |
duke@435 | 366 | debug_only( dup_check[_callees[reg]]=1; ) |
duke@435 | 367 | VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg])); |
duke@435 | 368 | if ( callee->is_concrete() || true ) { |
duke@435 | 369 | omap->set_callee_saved( r, callee); |
duke@435 | 370 | } |
duke@435 | 371 | |
duke@435 | 372 | } else { |
duke@435 | 373 | // Other - some reaching non-oop value |
duke@435 | 374 | omap->set_value( r); |
kvn@1268 | 375 | #ifdef ASSERT |
kvn@1268 | 376 | if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) { |
kvn@1268 | 377 | def->dump(); |
kvn@1268 | 378 | n->dump(); |
kvn@1268 | 379 | assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint"); |
kvn@1268 | 380 | } |
kvn@1268 | 381 | #endif |
duke@435 | 382 | } |
duke@435 | 383 | |
duke@435 | 384 | } |
duke@435 | 385 | |
duke@435 | 386 | #ifdef ASSERT |
duke@435 | 387 | /* Nice, Intel-only assert |
duke@435 | 388 | int cnt_callee_saves=0; |
duke@435 | 389 | int reg2 = 0; |
duke@435 | 390 | while (OptoReg::is_reg(reg2)) { |
duke@435 | 391 | if( dup_check[reg2] != 0) cnt_callee_saves++; |
duke@435 | 392 | assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" ); |
duke@435 | 393 | reg2++; |
duke@435 | 394 | } |
duke@435 | 395 | */ |
duke@435 | 396 | #endif |
duke@435 | 397 | |
kvn@1164 | 398 | #ifdef ASSERT |
kvn@1164 | 399 | for( OopMapStream oms1(omap, OopMapValue::derived_oop_value); !oms1.is_done(); oms1.next()) { |
kvn@1164 | 400 | OopMapValue omv1 = oms1.current(); |
kvn@1164 | 401 | bool found = false; |
kvn@1164 | 402 | for( OopMapStream oms2(omap,OopMapValue::oop_value); !oms2.is_done(); oms2.next()) { |
kvn@1164 | 403 | if( omv1.content_reg() == oms2.current().reg() ) { |
kvn@1164 | 404 | found = true; |
kvn@1164 | 405 | break; |
kvn@1164 | 406 | } |
kvn@1164 | 407 | } |
kvn@1164 | 408 | assert( found, "derived with no base in oopmap" ); |
kvn@1164 | 409 | } |
kvn@1164 | 410 | #endif |
kvn@1164 | 411 | |
duke@435 | 412 | return omap; |
duke@435 | 413 | } |
duke@435 | 414 | |
duke@435 | 415 | //------------------------------do_liveness------------------------------------ |
duke@435 | 416 | // Compute backwards liveness on registers |
duke@435 | 417 | static void do_liveness( PhaseRegAlloc *regalloc, PhaseCFG *cfg, Block_List *worklist, int max_reg_ints, Arena *A, Dict *safehash ) { |
duke@435 | 418 | int *live = NEW_ARENA_ARRAY(A, int, (cfg->_num_blocks+1) * max_reg_ints); |
duke@435 | 419 | int *tmp_live = &live[cfg->_num_blocks * max_reg_ints]; |
duke@435 | 420 | Node *root = cfg->C->root(); |
duke@435 | 421 | // On CISC platforms, get the node representing the stack pointer that regalloc |
duke@435 | 422 | // used for spills |
duke@435 | 423 | Node *fp = NodeSentinel; |
duke@435 | 424 | if (UseCISCSpill && root->req() > 1) { |
duke@435 | 425 | fp = root->in(1)->in(TypeFunc::FramePtr); |
duke@435 | 426 | } |
duke@435 | 427 | memset( live, 0, cfg->_num_blocks * (max_reg_ints<<LogBytesPerInt) ); |
duke@435 | 428 | // Push preds onto worklist |
duke@435 | 429 | for( uint i=1; i<root->req(); i++ ) |
duke@435 | 430 | worklist->push(cfg->_bbs[root->in(i)->_idx]); |
duke@435 | 431 | |
duke@435 | 432 | // ZKM.jar includes tiny infinite loops which are unreached from below. |
duke@435 | 433 | // If we missed any blocks, we'll retry here after pushing all missed |
duke@435 | 434 | // blocks on the worklist. Normally this outer loop never trips more |
duke@435 | 435 | // than once. |
duke@435 | 436 | while( 1 ) { |
duke@435 | 437 | |
duke@435 | 438 | while( worklist->size() ) { // Standard worklist algorithm |
duke@435 | 439 | Block *b = worklist->rpop(); |
duke@435 | 440 | |
duke@435 | 441 | // Copy first successor into my tmp_live space |
duke@435 | 442 | int s0num = b->_succs[0]->_pre_order; |
duke@435 | 443 | int *t = &live[s0num*max_reg_ints]; |
duke@435 | 444 | for( int i=0; i<max_reg_ints; i++ ) |
duke@435 | 445 | tmp_live[i] = t[i]; |
duke@435 | 446 | |
duke@435 | 447 | // OR in the remaining live registers |
duke@435 | 448 | for( uint j=1; j<b->_num_succs; j++ ) { |
duke@435 | 449 | uint sjnum = b->_succs[j]->_pre_order; |
duke@435 | 450 | int *t = &live[sjnum*max_reg_ints]; |
duke@435 | 451 | for( int i=0; i<max_reg_ints; i++ ) |
duke@435 | 452 | tmp_live[i] |= t[i]; |
duke@435 | 453 | } |
duke@435 | 454 | |
duke@435 | 455 | // Now walk tmp_live up the block backwards, computing live |
duke@435 | 456 | for( int k=b->_nodes.size()-1; k>=0; k-- ) { |
duke@435 | 457 | Node *n = b->_nodes[k]; |
duke@435 | 458 | // KILL def'd bits |
duke@435 | 459 | int first = regalloc->get_reg_first(n); |
duke@435 | 460 | int second = regalloc->get_reg_second(n); |
duke@435 | 461 | if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first); |
duke@435 | 462 | if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second); |
duke@435 | 463 | |
duke@435 | 464 | MachNode *m = n->is_Mach() ? n->as_Mach() : NULL; |
duke@435 | 465 | |
duke@435 | 466 | // Check if m is potentially a CISC alternate instruction (i.e, possibly |
duke@435 | 467 | // synthesized by RegAlloc from a conventional instruction and a |
duke@435 | 468 | // spilled input) |
duke@435 | 469 | bool is_cisc_alternate = false; |
duke@435 | 470 | if (UseCISCSpill && m) { |
duke@435 | 471 | is_cisc_alternate = m->is_cisc_alternate(); |
duke@435 | 472 | } |
duke@435 | 473 | |
duke@435 | 474 | // GEN use'd bits |
duke@435 | 475 | for( uint l=1; l<n->req(); l++ ) { |
duke@435 | 476 | Node *def = n->in(l); |
duke@435 | 477 | assert(def != 0, "input edge required"); |
duke@435 | 478 | int first = regalloc->get_reg_first(def); |
duke@435 | 479 | int second = regalloc->get_reg_second(def); |
duke@435 | 480 | if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first); |
duke@435 | 481 | if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second); |
duke@435 | 482 | // If we use the stack pointer in a cisc-alternative instruction, |
duke@435 | 483 | // check for use as a memory operand. Then reconstruct the RegName |
duke@435 | 484 | // for this stack location, and set the appropriate bit in the |
duke@435 | 485 | // live vector 4987749. |
duke@435 | 486 | if (is_cisc_alternate && def == fp) { |
duke@435 | 487 | const TypePtr *adr_type = NULL; |
duke@435 | 488 | intptr_t offset; |
duke@435 | 489 | const Node* base = m->get_base_and_disp(offset, adr_type); |
duke@435 | 490 | if (base == NodeSentinel) { |
duke@435 | 491 | // Machnode has multiple memory inputs. We are unable to reason |
duke@435 | 492 | // with these, but are presuming (with trepidation) that not any of |
duke@435 | 493 | // them are oops. This can be fixed by making get_base_and_disp() |
duke@435 | 494 | // look at a specific input instead of all inputs. |
duke@435 | 495 | assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input"); |
duke@435 | 496 | } else if (base != fp || offset == Type::OffsetBot) { |
duke@435 | 497 | // Do nothing: the fp operand is either not from a memory use |
duke@435 | 498 | // (base == NULL) OR the fp is used in a non-memory context |
duke@435 | 499 | // (base is some other register) OR the offset is not constant, |
duke@435 | 500 | // so it is not a stack slot. |
duke@435 | 501 | } else { |
duke@435 | 502 | assert(offset >= 0, "unexpected negative offset"); |
duke@435 | 503 | offset -= (offset % jintSize); // count the whole word |
duke@435 | 504 | int stack_reg = regalloc->offset2reg(offset); |
duke@435 | 505 | if (OptoReg::is_stack(stack_reg)) { |
duke@435 | 506 | set_live_bit(tmp_live, stack_reg); |
duke@435 | 507 | } else { |
duke@435 | 508 | assert(false, "stack_reg not on stack?"); |
duke@435 | 509 | } |
duke@435 | 510 | } |
duke@435 | 511 | } |
duke@435 | 512 | } |
duke@435 | 513 | |
duke@435 | 514 | if( n->jvms() ) { // Record liveness at safepoint |
duke@435 | 515 | |
duke@435 | 516 | // This placement of this stanza means inputs to calls are |
duke@435 | 517 | // considered live at the callsite's OopMap. Argument oops are |
duke@435 | 518 | // hence live, but NOT included in the oopmap. See cutout in |
duke@435 | 519 | // build_oop_map. Debug oops are live (and in OopMap). |
duke@435 | 520 | int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints); |
duke@435 | 521 | for( int l=0; l<max_reg_ints; l++ ) |
duke@435 | 522 | n_live[l] = tmp_live[l]; |
duke@435 | 523 | safehash->Insert(n,n_live); |
duke@435 | 524 | } |
duke@435 | 525 | |
duke@435 | 526 | } |
duke@435 | 527 | |
duke@435 | 528 | // Now at block top, see if we have any changes. If so, propagate |
duke@435 | 529 | // to prior blocks. |
duke@435 | 530 | int *old_live = &live[b->_pre_order*max_reg_ints]; |
duke@435 | 531 | int l; |
duke@435 | 532 | for( l=0; l<max_reg_ints; l++ ) |
duke@435 | 533 | if( tmp_live[l] != old_live[l] ) |
duke@435 | 534 | break; |
duke@435 | 535 | if( l<max_reg_ints ) { // Change! |
duke@435 | 536 | // Copy in new value |
duke@435 | 537 | for( l=0; l<max_reg_ints; l++ ) |
duke@435 | 538 | old_live[l] = tmp_live[l]; |
duke@435 | 539 | // Push preds onto worklist |
duke@435 | 540 | for( l=1; l<(int)b->num_preds(); l++ ) |
duke@435 | 541 | worklist->push(cfg->_bbs[b->pred(l)->_idx]); |
duke@435 | 542 | } |
duke@435 | 543 | } |
duke@435 | 544 | |
duke@435 | 545 | // Scan for any missing safepoints. Happens to infinite loops |
duke@435 | 546 | // ala ZKM.jar |
duke@435 | 547 | uint i; |
duke@435 | 548 | for( i=1; i<cfg->_num_blocks; i++ ) { |
duke@435 | 549 | Block *b = cfg->_blocks[i]; |
duke@435 | 550 | uint j; |
duke@435 | 551 | for( j=1; j<b->_nodes.size(); j++ ) |
duke@435 | 552 | if( b->_nodes[j]->jvms() && |
duke@435 | 553 | (*safehash)[b->_nodes[j]] == NULL ) |
duke@435 | 554 | break; |
duke@435 | 555 | if( j<b->_nodes.size() ) break; |
duke@435 | 556 | } |
duke@435 | 557 | if( i == cfg->_num_blocks ) |
duke@435 | 558 | break; // Got 'em all |
duke@435 | 559 | #ifndef PRODUCT |
duke@435 | 560 | if( PrintOpto && Verbose ) |
duke@435 | 561 | tty->print_cr("retripping live calc"); |
duke@435 | 562 | #endif |
duke@435 | 563 | // Force the issue (expensively): recheck everybody |
duke@435 | 564 | for( i=1; i<cfg->_num_blocks; i++ ) |
duke@435 | 565 | worklist->push(cfg->_blocks[i]); |
duke@435 | 566 | } |
duke@435 | 567 | |
duke@435 | 568 | } |
duke@435 | 569 | |
duke@435 | 570 | //------------------------------BuildOopMaps----------------------------------- |
duke@435 | 571 | // Collect GC mask info - where are all the OOPs? |
duke@435 | 572 | void Compile::BuildOopMaps() { |
duke@435 | 573 | NOT_PRODUCT( TracePhase t3("bldOopMaps", &_t_buildOopMaps, TimeCompiler); ) |
duke@435 | 574 | // Can't resource-mark because I need to leave all those OopMaps around, |
duke@435 | 575 | // or else I need to resource-mark some arena other than the default. |
duke@435 | 576 | // ResourceMark rm; // Reclaim all OopFlows when done |
duke@435 | 577 | int max_reg = _regalloc->_max_reg; // Current array extent |
duke@435 | 578 | |
duke@435 | 579 | Arena *A = Thread::current()->resource_area(); |
duke@435 | 580 | Block_List worklist; // Worklist of pending blocks |
duke@435 | 581 | |
duke@435 | 582 | int max_reg_ints = round_to(max_reg, BitsPerInt)>>LogBitsPerInt; |
duke@435 | 583 | Dict *safehash = NULL; // Used for assert only |
duke@435 | 584 | // Compute a backwards liveness per register. Needs a bitarray of |
duke@435 | 585 | // #blocks x (#registers, rounded up to ints) |
duke@435 | 586 | safehash = new Dict(cmpkey,hashkey,A); |
duke@435 | 587 | do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash ); |
duke@435 | 588 | OopFlow *free_list = NULL; // Free, unused |
duke@435 | 589 | |
duke@435 | 590 | // Array mapping blocks to completed oopflows |
duke@435 | 591 | OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->_num_blocks); |
duke@435 | 592 | memset( flows, 0, _cfg->_num_blocks*sizeof(OopFlow*) ); |
duke@435 | 593 | |
duke@435 | 594 | |
duke@435 | 595 | // Do the first block 'by hand' to prime the worklist |
duke@435 | 596 | Block *entry = _cfg->_blocks[1]; |
kvn@1268 | 597 | OopFlow *rootflow = OopFlow::make(A,max_reg,this); |
duke@435 | 598 | // Initialize to 'bottom' (not 'top') |
duke@435 | 599 | memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) ); |
duke@435 | 600 | memset( rootflow->_defs , 0, max_reg*sizeof(Node*) ); |
duke@435 | 601 | flows[entry->_pre_order] = rootflow; |
duke@435 | 602 | |
duke@435 | 603 | // Do the first block 'by hand' to prime the worklist |
duke@435 | 604 | rootflow->_b = entry; |
duke@435 | 605 | rootflow->compute_reach( _regalloc, max_reg, safehash ); |
duke@435 | 606 | for( uint i=0; i<entry->_num_succs; i++ ) |
duke@435 | 607 | worklist.push(entry->_succs[i]); |
duke@435 | 608 | |
duke@435 | 609 | // Now worklist contains blocks which have some, but perhaps not all, |
duke@435 | 610 | // predecessors visited. |
duke@435 | 611 | while( worklist.size() ) { |
duke@435 | 612 | // Scan for a block with all predecessors visited, or any randoms slob |
duke@435 | 613 | // otherwise. All-preds-visited order allows me to recycle OopFlow |
duke@435 | 614 | // structures rapidly and cut down on the memory footprint. |
duke@435 | 615 | // Note: not all predecessors might be visited yet (must happen for |
duke@435 | 616 | // irreducible loops). This is OK, since every live value must have the |
duke@435 | 617 | // SAME reaching def for the block, so any reaching def is OK. |
duke@435 | 618 | uint i; |
duke@435 | 619 | |
duke@435 | 620 | Block *b = worklist.pop(); |
duke@435 | 621 | // Ignore root block |
duke@435 | 622 | if( b == _cfg->_broot ) continue; |
duke@435 | 623 | // Block is already done? Happens if block has several predecessors, |
duke@435 | 624 | // he can get on the worklist more than once. |
duke@435 | 625 | if( flows[b->_pre_order] ) continue; |
duke@435 | 626 | |
duke@435 | 627 | // If this block has a visited predecessor AND that predecessor has this |
duke@435 | 628 | // last block as his only undone child, we can move the OopFlow from the |
duke@435 | 629 | // pred to this block. Otherwise we have to grab a new OopFlow. |
duke@435 | 630 | OopFlow *flow = NULL; // Flag for finding optimized flow |
duke@435 | 631 | Block *pred = (Block*)0xdeadbeef; |
duke@435 | 632 | uint j; |
duke@435 | 633 | // Scan this block's preds to find a done predecessor |
duke@435 | 634 | for( j=1; j<b->num_preds(); j++ ) { |
duke@435 | 635 | Block *p = _cfg->_bbs[b->pred(j)->_idx]; |
duke@435 | 636 | OopFlow *p_flow = flows[p->_pre_order]; |
duke@435 | 637 | if( p_flow ) { // Predecessor is done |
duke@435 | 638 | assert( p_flow->_b == p, "cross check" ); |
duke@435 | 639 | pred = p; // Record some predecessor |
duke@435 | 640 | // If all successors of p are done except for 'b', then we can carry |
duke@435 | 641 | // p_flow forward to 'b' without copying, otherwise we have to draw |
duke@435 | 642 | // from the free_list and clone data. |
duke@435 | 643 | uint k; |
duke@435 | 644 | for( k=0; k<p->_num_succs; k++ ) |
duke@435 | 645 | if( !flows[p->_succs[k]->_pre_order] && |
duke@435 | 646 | p->_succs[k] != b ) |
duke@435 | 647 | break; |
duke@435 | 648 | |
duke@435 | 649 | // Either carry-forward the now-unused OopFlow for b's use |
duke@435 | 650 | // or draw a new one from the free list |
duke@435 | 651 | if( k==p->_num_succs ) { |
duke@435 | 652 | flow = p_flow; |
duke@435 | 653 | break; // Found an ideal pred, use him |
duke@435 | 654 | } |
duke@435 | 655 | } |
duke@435 | 656 | } |
duke@435 | 657 | |
duke@435 | 658 | if( flow ) { |
duke@435 | 659 | // We have an OopFlow that's the last-use of a predecessor. |
duke@435 | 660 | // Carry it forward. |
duke@435 | 661 | } else { // Draw a new OopFlow from the freelist |
duke@435 | 662 | if( !free_list ) |
kvn@1268 | 663 | free_list = OopFlow::make(A,max_reg,C); |
duke@435 | 664 | flow = free_list; |
duke@435 | 665 | assert( flow->_b == NULL, "oopFlow is not free" ); |
duke@435 | 666 | free_list = flow->_next; |
duke@435 | 667 | flow->_next = NULL; |
duke@435 | 668 | |
duke@435 | 669 | // Copy/clone over the data |
duke@435 | 670 | flow->clone(flows[pred->_pre_order], max_reg); |
duke@435 | 671 | } |
duke@435 | 672 | |
duke@435 | 673 | // Mark flow for block. Blocks can only be flowed over once, |
duke@435 | 674 | // because after the first time they are guarded from entering |
duke@435 | 675 | // this code again. |
duke@435 | 676 | assert( flow->_b == pred, "have some prior flow" ); |
duke@435 | 677 | flow->_b = NULL; |
duke@435 | 678 | |
duke@435 | 679 | // Now push flow forward |
duke@435 | 680 | flows[b->_pre_order] = flow;// Mark flow for this block |
duke@435 | 681 | flow->_b = b; |
duke@435 | 682 | flow->compute_reach( _regalloc, max_reg, safehash ); |
duke@435 | 683 | |
duke@435 | 684 | // Now push children onto worklist |
duke@435 | 685 | for( i=0; i<b->_num_succs; i++ ) |
duke@435 | 686 | worklist.push(b->_succs[i]); |
duke@435 | 687 | |
duke@435 | 688 | } |
duke@435 | 689 | } |