1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/buildOopMap.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,689 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "compiler/oopMap.hpp" 1.30 +#include "opto/addnode.hpp" 1.31 +#include "opto/callnode.hpp" 1.32 +#include "opto/compile.hpp" 1.33 +#include "opto/machnode.hpp" 1.34 +#include "opto/matcher.hpp" 1.35 +#include "opto/phase.hpp" 1.36 +#include "opto/regalloc.hpp" 1.37 +#include "opto/rootnode.hpp" 1.38 +#ifdef TARGET_ARCH_x86 1.39 +# include "vmreg_x86.inline.hpp" 1.40 +#endif 1.41 +#ifdef TARGET_ARCH_sparc 1.42 +# include "vmreg_sparc.inline.hpp" 1.43 +#endif 1.44 +#ifdef TARGET_ARCH_zero 1.45 +# include "vmreg_zero.inline.hpp" 1.46 +#endif 1.47 +#ifdef TARGET_ARCH_arm 1.48 +# include "vmreg_arm.inline.hpp" 1.49 +#endif 1.50 +#ifdef TARGET_ARCH_ppc 1.51 +# include "vmreg_ppc.inline.hpp" 1.52 +#endif 1.53 + 1.54 +// The functions in this file builds OopMaps after all scheduling is done. 1.55 +// 1.56 +// OopMaps contain a list of all registers and stack-slots containing oops (so 1.57 +// they can be updated by GC). OopMaps also contain a list of derived-pointer 1.58 +// base-pointer pairs. When the base is moved, the derived pointer moves to 1.59 +// follow it. Finally, any registers holding callee-save values are also 1.60 +// recorded. These might contain oops, but only the caller knows. 1.61 +// 1.62 +// BuildOopMaps implements a simple forward reaching-defs solution. At each 1.63 +// GC point we'll have the reaching-def Nodes. If the reaching Nodes are 1.64 +// typed as pointers (no offset), then they are oops. Pointers+offsets are 1.65 +// derived pointers, and bases can be found from them. Finally, we'll also 1.66 +// track reaching callee-save values. Note that a copy of a callee-save value 1.67 +// "kills" it's source, so that only 1 copy of a callee-save value is alive at 1.68 +// a time. 1.69 +// 1.70 +// We run a simple bitvector liveness pass to help trim out dead oops. Due to 1.71 +// irreducible loops, we can have a reaching def of an oop that only reaches 1.72 +// along one path and no way to know if it's valid or not on the other path. 1.73 +// The bitvectors are quite dense and the liveness pass is fast. 1.74 +// 1.75 +// At GC points, we consult this information to build OopMaps. All reaching 1.76 +// defs typed as oops are added to the OopMap. Only 1 instance of a 1.77 +// callee-save register can be recorded. For derived pointers, we'll have to 1.78 +// find and record the register holding the base. 1.79 +// 1.80 +// The reaching def's is a simple 1-pass worklist approach. I tried a clever 1.81 +// breadth-first approach but it was worse (showed O(n^2) in the 1.82 +// pick-next-block code). 1.83 +// 1.84 +// The relevant data is kept in a struct of arrays (it could just as well be 1.85 +// an array of structs, but the struct-of-arrays is generally a little more 1.86 +// efficient). The arrays are indexed by register number (including 1.87 +// stack-slots as registers) and so is bounded by 200 to 300 elements in 1.88 +// practice. One array will map to a reaching def Node (or NULL for 1.89 +// conflict/dead). The other array will map to a callee-saved register or 1.90 +// OptoReg::Bad for not-callee-saved. 1.91 + 1.92 + 1.93 +// Structure to pass around 1.94 +struct OopFlow : public ResourceObj { 1.95 + short *_callees; // Array mapping register to callee-saved 1.96 + Node **_defs; // array mapping register to reaching def 1.97 + // or NULL if dead/conflict 1.98 + // OopFlow structs, when not being actively modified, describe the _end_ of 1.99 + // this block. 1.100 + Block *_b; // Block for this struct 1.101 + OopFlow *_next; // Next free OopFlow 1.102 + // or NULL if dead/conflict 1.103 + Compile* C; 1.104 + 1.105 + OopFlow( short *callees, Node **defs, Compile* c ) : _callees(callees), _defs(defs), 1.106 + _b(NULL), _next(NULL), C(c) { } 1.107 + 1.108 + // Given reaching-defs for this block start, compute it for this block end 1.109 + void compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ); 1.110 + 1.111 + // Merge these two OopFlows into the 'this' pointer. 1.112 + void merge( OopFlow *flow, int max_reg ); 1.113 + 1.114 + // Copy a 'flow' over an existing flow 1.115 + void clone( OopFlow *flow, int max_size); 1.116 + 1.117 + // Make a new OopFlow from scratch 1.118 + static OopFlow *make( Arena *A, int max_size, Compile* C ); 1.119 + 1.120 + // Build an oopmap from the current flow info 1.121 + OopMap *build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ); 1.122 +}; 1.123 + 1.124 +// Given reaching-defs for this block start, compute it for this block end 1.125 +void OopFlow::compute_reach( PhaseRegAlloc *regalloc, int max_reg, Dict *safehash ) { 1.126 + 1.127 + for( uint i=0; i<_b->number_of_nodes(); i++ ) { 1.128 + Node *n = _b->get_node(i); 1.129 + 1.130 + if( n->jvms() ) { // Build an OopMap here? 1.131 + JVMState *jvms = n->jvms(); 1.132 + // no map needed for leaf calls 1.133 + if( n->is_MachSafePoint() && !n->is_MachCallLeaf() ) { 1.134 + int *live = (int*) (*safehash)[n]; 1.135 + assert( live, "must find live" ); 1.136 + n->as_MachSafePoint()->set_oop_map( build_oop_map(n,max_reg,regalloc, live) ); 1.137 + } 1.138 + } 1.139 + 1.140 + // Assign new reaching def's. 1.141 + // Note that I padded the _defs and _callees arrays so it's legal 1.142 + // to index at _defs[OptoReg::Bad]. 1.143 + OptoReg::Name first = regalloc->get_reg_first(n); 1.144 + OptoReg::Name second = regalloc->get_reg_second(n); 1.145 + _defs[first] = n; 1.146 + _defs[second] = n; 1.147 + 1.148 + // Pass callee-save info around copies 1.149 + int idx = n->is_Copy(); 1.150 + if( idx ) { // Copies move callee-save info 1.151 + OptoReg::Name old_first = regalloc->get_reg_first(n->in(idx)); 1.152 + OptoReg::Name old_second = regalloc->get_reg_second(n->in(idx)); 1.153 + int tmp_first = _callees[old_first]; 1.154 + int tmp_second = _callees[old_second]; 1.155 + _callees[old_first] = OptoReg::Bad; // callee-save is moved, dead in old location 1.156 + _callees[old_second] = OptoReg::Bad; 1.157 + _callees[first] = tmp_first; 1.158 + _callees[second] = tmp_second; 1.159 + } else if( n->is_Phi() ) { // Phis do not mod callee-saves 1.160 + assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(1))], "" ); 1.161 + assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(1))], "" ); 1.162 + assert( _callees[first] == _callees[regalloc->get_reg_first(n->in(n->req()-1))], "" ); 1.163 + assert( _callees[second] == _callees[regalloc->get_reg_second(n->in(n->req()-1))], "" ); 1.164 + } else { 1.165 + _callees[first] = OptoReg::Bad; // No longer holding a callee-save value 1.166 + _callees[second] = OptoReg::Bad; 1.167 + 1.168 + // Find base case for callee saves 1.169 + if( n->is_Proj() && n->in(0)->is_Start() ) { 1.170 + if( OptoReg::is_reg(first) && 1.171 + regalloc->_matcher.is_save_on_entry(first) ) 1.172 + _callees[first] = first; 1.173 + if( OptoReg::is_reg(second) && 1.174 + regalloc->_matcher.is_save_on_entry(second) ) 1.175 + _callees[second] = second; 1.176 + } 1.177 + } 1.178 + } 1.179 +} 1.180 + 1.181 +// Merge the given flow into the 'this' flow 1.182 +void OopFlow::merge( OopFlow *flow, int max_reg ) { 1.183 + assert( _b == NULL, "merging into a happy flow" ); 1.184 + assert( flow->_b, "this flow is still alive" ); 1.185 + assert( flow != this, "no self flow" ); 1.186 + 1.187 + // Do the merge. If there are any differences, drop to 'bottom' which 1.188 + // is OptoReg::Bad or NULL depending. 1.189 + for( int i=0; i<max_reg; i++ ) { 1.190 + // Merge the callee-save's 1.191 + if( _callees[i] != flow->_callees[i] ) 1.192 + _callees[i] = OptoReg::Bad; 1.193 + // Merge the reaching defs 1.194 + if( _defs[i] != flow->_defs[i] ) 1.195 + _defs[i] = NULL; 1.196 + } 1.197 + 1.198 +} 1.199 + 1.200 +void OopFlow::clone( OopFlow *flow, int max_size ) { 1.201 + _b = flow->_b; 1.202 + memcpy( _callees, flow->_callees, sizeof(short)*max_size); 1.203 + memcpy( _defs , flow->_defs , sizeof(Node*)*max_size); 1.204 +} 1.205 + 1.206 +OopFlow *OopFlow::make( Arena *A, int max_size, Compile* C ) { 1.207 + short *callees = NEW_ARENA_ARRAY(A,short,max_size+1); 1.208 + Node **defs = NEW_ARENA_ARRAY(A,Node*,max_size+1); 1.209 + debug_only( memset(defs,0,(max_size+1)*sizeof(Node*)) ); 1.210 + OopFlow *flow = new (A) OopFlow(callees+1, defs+1, C); 1.211 + assert( &flow->_callees[OptoReg::Bad] == callees, "Ok to index at OptoReg::Bad" ); 1.212 + assert( &flow->_defs [OptoReg::Bad] == defs , "Ok to index at OptoReg::Bad" ); 1.213 + return flow; 1.214 +} 1.215 + 1.216 +static int get_live_bit( int *live, int reg ) { 1.217 + return live[reg>>LogBitsPerInt] & (1<<(reg&(BitsPerInt-1))); } 1.218 +static void set_live_bit( int *live, int reg ) { 1.219 + live[reg>>LogBitsPerInt] |= (1<<(reg&(BitsPerInt-1))); } 1.220 +static void clr_live_bit( int *live, int reg ) { 1.221 + live[reg>>LogBitsPerInt] &= ~(1<<(reg&(BitsPerInt-1))); } 1.222 + 1.223 +// Build an oopmap from the current flow info 1.224 +OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, int* live ) { 1.225 + int framesize = regalloc->_framesize; 1.226 + int max_inarg_slot = OptoReg::reg2stack(regalloc->_matcher._new_SP); 1.227 + debug_only( char *dup_check = NEW_RESOURCE_ARRAY(char,OptoReg::stack0()); 1.228 + memset(dup_check,0,OptoReg::stack0()) ); 1.229 + 1.230 + OopMap *omap = new OopMap( framesize, max_inarg_slot ); 1.231 + MachCallNode *mcall = n->is_MachCall() ? n->as_MachCall() : NULL; 1.232 + JVMState* jvms = n->jvms(); 1.233 + 1.234 + // For all registers do... 1.235 + for( int reg=0; reg<max_reg; reg++ ) { 1.236 + if( get_live_bit(live,reg) == 0 ) 1.237 + continue; // Ignore if not live 1.238 + 1.239 + // %%% C2 can use 2 OptoRegs when the physical register is only one 64bit 1.240 + // register in that case we'll get an non-concrete register for the second 1.241 + // half. We only need to tell the map the register once! 1.242 + // 1.243 + // However for the moment we disable this change and leave things as they 1.244 + // were. 1.245 + 1.246 + VMReg r = OptoReg::as_VMReg(OptoReg::Name(reg), framesize, max_inarg_slot); 1.247 + 1.248 + if (false && r->is_reg() && !r->is_concrete()) { 1.249 + continue; 1.250 + } 1.251 + 1.252 + // See if dead (no reaching def). 1.253 + Node *def = _defs[reg]; // Get reaching def 1.254 + assert( def, "since live better have reaching def" ); 1.255 + 1.256 + // Classify the reaching def as oop, derived, callee-save, dead, or other 1.257 + const Type *t = def->bottom_type(); 1.258 + if( t->isa_oop_ptr() ) { // Oop or derived? 1.259 + assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" ); 1.260 +#ifdef _LP64 1.261 + // 64-bit pointers record oop-ishness on 2 aligned adjacent registers. 1.262 + // Make sure both are record from the same reaching def, but do not 1.263 + // put both into the oopmap. 1.264 + if( (reg&1) == 1 ) { // High half of oop-pair? 1.265 + assert( _defs[reg-1] == _defs[reg], "both halves from same reaching def" ); 1.266 + continue; // Do not record high parts in oopmap 1.267 + } 1.268 +#endif 1.269 + 1.270 + // Check for a legal reg name in the oopMap and bailout if it is not. 1.271 + if (!omap->legal_vm_reg_name(r)) { 1.272 + regalloc->C->record_method_not_compilable("illegal oopMap register name"); 1.273 + continue; 1.274 + } 1.275 + if( t->is_ptr()->_offset == 0 ) { // Not derived? 1.276 + if( mcall ) { 1.277 + // Outgoing argument GC mask responsibility belongs to the callee, 1.278 + // not the caller. Inspect the inputs to the call, to see if 1.279 + // this live-range is one of them. 1.280 + uint cnt = mcall->tf()->domain()->cnt(); 1.281 + uint j; 1.282 + for( j = TypeFunc::Parms; j < cnt; j++) 1.283 + if( mcall->in(j) == def ) 1.284 + break; // reaching def is an argument oop 1.285 + if( j < cnt ) // arg oops dont go in GC map 1.286 + continue; // Continue on to the next register 1.287 + } 1.288 + omap->set_oop(r); 1.289 + } else { // Else it's derived. 1.290 + // Find the base of the derived value. 1.291 + uint i; 1.292 + // Fast, common case, scan 1.293 + for( i = jvms->oopoff(); i < n->req(); i+=2 ) 1.294 + if( n->in(i) == def ) break; // Common case 1.295 + if( i == n->req() ) { // Missed, try a more generous scan 1.296 + // Scan again, but this time peek through copies 1.297 + for( i = jvms->oopoff(); i < n->req(); i+=2 ) { 1.298 + Node *m = n->in(i); // Get initial derived value 1.299 + while( 1 ) { 1.300 + Node *d = def; // Get initial reaching def 1.301 + while( 1 ) { // Follow copies of reaching def to end 1.302 + if( m == d ) goto found; // breaks 3 loops 1.303 + int idx = d->is_Copy(); 1.304 + if( !idx ) break; 1.305 + d = d->in(idx); // Link through copy 1.306 + } 1.307 + int idx = m->is_Copy(); 1.308 + if( !idx ) break; 1.309 + m = m->in(idx); 1.310 + } 1.311 + } 1.312 + guarantee( 0, "must find derived/base pair" ); 1.313 + } 1.314 + found: ; 1.315 + Node *base = n->in(i+1); // Base is other half of pair 1.316 + int breg = regalloc->get_reg_first(base); 1.317 + VMReg b = OptoReg::as_VMReg(OptoReg::Name(breg), framesize, max_inarg_slot); 1.318 + 1.319 + // I record liveness at safepoints BEFORE I make the inputs 1.320 + // live. This is because argument oops are NOT live at a 1.321 + // safepoint (or at least they cannot appear in the oopmap). 1.322 + // Thus bases of base/derived pairs might not be in the 1.323 + // liveness data but they need to appear in the oopmap. 1.324 + if( get_live_bit(live,breg) == 0 ) {// Not live? 1.325 + // Flag it, so next derived pointer won't re-insert into oopmap 1.326 + set_live_bit(live,breg); 1.327 + // Already missed our turn? 1.328 + if( breg < reg ) { 1.329 + if (b->is_stack() || b->is_concrete() || true ) { 1.330 + omap->set_oop( b); 1.331 + } 1.332 + } 1.333 + } 1.334 + if (b->is_stack() || b->is_concrete() || true ) { 1.335 + omap->set_derived_oop( r, b); 1.336 + } 1.337 + } 1.338 + 1.339 + } else if( t->isa_narrowoop() ) { 1.340 + assert( !OptoReg::is_valid(_callees[reg]), "oop can't be callee save" ); 1.341 + // Check for a legal reg name in the oopMap and bailout if it is not. 1.342 + if (!omap->legal_vm_reg_name(r)) { 1.343 + regalloc->C->record_method_not_compilable("illegal oopMap register name"); 1.344 + continue; 1.345 + } 1.346 + if( mcall ) { 1.347 + // Outgoing argument GC mask responsibility belongs to the callee, 1.348 + // not the caller. Inspect the inputs to the call, to see if 1.349 + // this live-range is one of them. 1.350 + uint cnt = mcall->tf()->domain()->cnt(); 1.351 + uint j; 1.352 + for( j = TypeFunc::Parms; j < cnt; j++) 1.353 + if( mcall->in(j) == def ) 1.354 + break; // reaching def is an argument oop 1.355 + if( j < cnt ) // arg oops dont go in GC map 1.356 + continue; // Continue on to the next register 1.357 + } 1.358 + omap->set_narrowoop(r); 1.359 + } else if( OptoReg::is_valid(_callees[reg])) { // callee-save? 1.360 + // It's a callee-save value 1.361 + assert( dup_check[_callees[reg]]==0, "trying to callee save same reg twice" ); 1.362 + debug_only( dup_check[_callees[reg]]=1; ) 1.363 + VMReg callee = OptoReg::as_VMReg(OptoReg::Name(_callees[reg])); 1.364 + if ( callee->is_concrete() || true ) { 1.365 + omap->set_callee_saved( r, callee); 1.366 + } 1.367 + 1.368 + } else { 1.369 + // Other - some reaching non-oop value 1.370 + omap->set_value( r); 1.371 +#ifdef ASSERT 1.372 + if( t->isa_rawptr() && C->cfg()->_raw_oops.member(def) ) { 1.373 + def->dump(); 1.374 + n->dump(); 1.375 + assert(false, "there should be a oop in OopMap instead of a live raw oop at safepoint"); 1.376 + } 1.377 +#endif 1.378 + } 1.379 + 1.380 + } 1.381 + 1.382 +#ifdef ASSERT 1.383 + /* Nice, Intel-only assert 1.384 + int cnt_callee_saves=0; 1.385 + int reg2 = 0; 1.386 + while (OptoReg::is_reg(reg2)) { 1.387 + if( dup_check[reg2] != 0) cnt_callee_saves++; 1.388 + assert( cnt_callee_saves==3 || cnt_callee_saves==5, "missed some callee-save" ); 1.389 + reg2++; 1.390 + } 1.391 + */ 1.392 +#endif 1.393 + 1.394 +#ifdef ASSERT 1.395 + for( OopMapStream oms1(omap, OopMapValue::derived_oop_value); !oms1.is_done(); oms1.next()) { 1.396 + OopMapValue omv1 = oms1.current(); 1.397 + bool found = false; 1.398 + for( OopMapStream oms2(omap,OopMapValue::oop_value); !oms2.is_done(); oms2.next()) { 1.399 + if( omv1.content_reg() == oms2.current().reg() ) { 1.400 + found = true; 1.401 + break; 1.402 + } 1.403 + } 1.404 + assert( found, "derived with no base in oopmap" ); 1.405 + } 1.406 +#endif 1.407 + 1.408 + return omap; 1.409 +} 1.410 + 1.411 +// Compute backwards liveness on registers 1.412 +static void do_liveness(PhaseRegAlloc* regalloc, PhaseCFG* cfg, Block_List* worklist, int max_reg_ints, Arena* A, Dict* safehash) { 1.413 + int* live = NEW_ARENA_ARRAY(A, int, (cfg->number_of_blocks() + 1) * max_reg_ints); 1.414 + int* tmp_live = &live[cfg->number_of_blocks() * max_reg_ints]; 1.415 + Node* root = cfg->get_root_node(); 1.416 + // On CISC platforms, get the node representing the stack pointer that regalloc 1.417 + // used for spills 1.418 + Node *fp = NodeSentinel; 1.419 + if (UseCISCSpill && root->req() > 1) { 1.420 + fp = root->in(1)->in(TypeFunc::FramePtr); 1.421 + } 1.422 + memset(live, 0, cfg->number_of_blocks() * (max_reg_ints << LogBytesPerInt)); 1.423 + // Push preds onto worklist 1.424 + for (uint i = 1; i < root->req(); i++) { 1.425 + Block* block = cfg->get_block_for_node(root->in(i)); 1.426 + worklist->push(block); 1.427 + } 1.428 + 1.429 + // ZKM.jar includes tiny infinite loops which are unreached from below. 1.430 + // If we missed any blocks, we'll retry here after pushing all missed 1.431 + // blocks on the worklist. Normally this outer loop never trips more 1.432 + // than once. 1.433 + while (1) { 1.434 + 1.435 + while( worklist->size() ) { // Standard worklist algorithm 1.436 + Block *b = worklist->rpop(); 1.437 + 1.438 + // Copy first successor into my tmp_live space 1.439 + int s0num = b->_succs[0]->_pre_order; 1.440 + int *t = &live[s0num*max_reg_ints]; 1.441 + for( int i=0; i<max_reg_ints; i++ ) 1.442 + tmp_live[i] = t[i]; 1.443 + 1.444 + // OR in the remaining live registers 1.445 + for( uint j=1; j<b->_num_succs; j++ ) { 1.446 + uint sjnum = b->_succs[j]->_pre_order; 1.447 + int *t = &live[sjnum*max_reg_ints]; 1.448 + for( int i=0; i<max_reg_ints; i++ ) 1.449 + tmp_live[i] |= t[i]; 1.450 + } 1.451 + 1.452 + // Now walk tmp_live up the block backwards, computing live 1.453 + for( int k=b->number_of_nodes()-1; k>=0; k-- ) { 1.454 + Node *n = b->get_node(k); 1.455 + // KILL def'd bits 1.456 + int first = regalloc->get_reg_first(n); 1.457 + int second = regalloc->get_reg_second(n); 1.458 + if( OptoReg::is_valid(first) ) clr_live_bit(tmp_live,first); 1.459 + if( OptoReg::is_valid(second) ) clr_live_bit(tmp_live,second); 1.460 + 1.461 + MachNode *m = n->is_Mach() ? n->as_Mach() : NULL; 1.462 + 1.463 + // Check if m is potentially a CISC alternate instruction (i.e, possibly 1.464 + // synthesized by RegAlloc from a conventional instruction and a 1.465 + // spilled input) 1.466 + bool is_cisc_alternate = false; 1.467 + if (UseCISCSpill && m) { 1.468 + is_cisc_alternate = m->is_cisc_alternate(); 1.469 + } 1.470 + 1.471 + // GEN use'd bits 1.472 + for( uint l=1; l<n->req(); l++ ) { 1.473 + Node *def = n->in(l); 1.474 + assert(def != 0, "input edge required"); 1.475 + int first = regalloc->get_reg_first(def); 1.476 + int second = regalloc->get_reg_second(def); 1.477 + if( OptoReg::is_valid(first) ) set_live_bit(tmp_live,first); 1.478 + if( OptoReg::is_valid(second) ) set_live_bit(tmp_live,second); 1.479 + // If we use the stack pointer in a cisc-alternative instruction, 1.480 + // check for use as a memory operand. Then reconstruct the RegName 1.481 + // for this stack location, and set the appropriate bit in the 1.482 + // live vector 4987749. 1.483 + if (is_cisc_alternate && def == fp) { 1.484 + const TypePtr *adr_type = NULL; 1.485 + intptr_t offset; 1.486 + const Node* base = m->get_base_and_disp(offset, adr_type); 1.487 + if (base == NodeSentinel) { 1.488 + // Machnode has multiple memory inputs. We are unable to reason 1.489 + // with these, but are presuming (with trepidation) that not any of 1.490 + // them are oops. This can be fixed by making get_base_and_disp() 1.491 + // look at a specific input instead of all inputs. 1.492 + assert(!def->bottom_type()->isa_oop_ptr(), "expecting non-oop mem input"); 1.493 + } else if (base != fp || offset == Type::OffsetBot) { 1.494 + // Do nothing: the fp operand is either not from a memory use 1.495 + // (base == NULL) OR the fp is used in a non-memory context 1.496 + // (base is some other register) OR the offset is not constant, 1.497 + // so it is not a stack slot. 1.498 + } else { 1.499 + assert(offset >= 0, "unexpected negative offset"); 1.500 + offset -= (offset % jintSize); // count the whole word 1.501 + int stack_reg = regalloc->offset2reg(offset); 1.502 + if (OptoReg::is_stack(stack_reg)) { 1.503 + set_live_bit(tmp_live, stack_reg); 1.504 + } else { 1.505 + assert(false, "stack_reg not on stack?"); 1.506 + } 1.507 + } 1.508 + } 1.509 + } 1.510 + 1.511 + if( n->jvms() ) { // Record liveness at safepoint 1.512 + 1.513 + // This placement of this stanza means inputs to calls are 1.514 + // considered live at the callsite's OopMap. Argument oops are 1.515 + // hence live, but NOT included in the oopmap. See cutout in 1.516 + // build_oop_map. Debug oops are live (and in OopMap). 1.517 + int *n_live = NEW_ARENA_ARRAY(A, int, max_reg_ints); 1.518 + for( int l=0; l<max_reg_ints; l++ ) 1.519 + n_live[l] = tmp_live[l]; 1.520 + safehash->Insert(n,n_live); 1.521 + } 1.522 + 1.523 + } 1.524 + 1.525 + // Now at block top, see if we have any changes. If so, propagate 1.526 + // to prior blocks. 1.527 + int *old_live = &live[b->_pre_order*max_reg_ints]; 1.528 + int l; 1.529 + for( l=0; l<max_reg_ints; l++ ) 1.530 + if( tmp_live[l] != old_live[l] ) 1.531 + break; 1.532 + if( l<max_reg_ints ) { // Change! 1.533 + // Copy in new value 1.534 + for( l=0; l<max_reg_ints; l++ ) 1.535 + old_live[l] = tmp_live[l]; 1.536 + // Push preds onto worklist 1.537 + for (l = 1; l < (int)b->num_preds(); l++) { 1.538 + Block* block = cfg->get_block_for_node(b->pred(l)); 1.539 + worklist->push(block); 1.540 + } 1.541 + } 1.542 + } 1.543 + 1.544 + // Scan for any missing safepoints. Happens to infinite loops 1.545 + // ala ZKM.jar 1.546 + uint i; 1.547 + for (i = 1; i < cfg->number_of_blocks(); i++) { 1.548 + Block* block = cfg->get_block(i); 1.549 + uint j; 1.550 + for (j = 1; j < block->number_of_nodes(); j++) { 1.551 + if (block->get_node(j)->jvms() && (*safehash)[block->get_node(j)] == NULL) { 1.552 + break; 1.553 + } 1.554 + } 1.555 + if (j < block->number_of_nodes()) { 1.556 + break; 1.557 + } 1.558 + } 1.559 + if (i == cfg->number_of_blocks()) { 1.560 + break; // Got 'em all 1.561 + } 1.562 +#ifndef PRODUCT 1.563 + if( PrintOpto && Verbose ) 1.564 + tty->print_cr("retripping live calc"); 1.565 +#endif 1.566 + // Force the issue (expensively): recheck everybody 1.567 + for (i = 1; i < cfg->number_of_blocks(); i++) { 1.568 + worklist->push(cfg->get_block(i)); 1.569 + } 1.570 + } 1.571 +} 1.572 + 1.573 +// Collect GC mask info - where are all the OOPs? 1.574 +void Compile::BuildOopMaps() { 1.575 + NOT_PRODUCT( TracePhase t3("bldOopMaps", &_t_buildOopMaps, TimeCompiler); ) 1.576 + // Can't resource-mark because I need to leave all those OopMaps around, 1.577 + // or else I need to resource-mark some arena other than the default. 1.578 + // ResourceMark rm; // Reclaim all OopFlows when done 1.579 + int max_reg = _regalloc->_max_reg; // Current array extent 1.580 + 1.581 + Arena *A = Thread::current()->resource_area(); 1.582 + Block_List worklist; // Worklist of pending blocks 1.583 + 1.584 + int max_reg_ints = round_to(max_reg, BitsPerInt)>>LogBitsPerInt; 1.585 + Dict *safehash = NULL; // Used for assert only 1.586 + // Compute a backwards liveness per register. Needs a bitarray of 1.587 + // #blocks x (#registers, rounded up to ints) 1.588 + safehash = new Dict(cmpkey,hashkey,A); 1.589 + do_liveness( _regalloc, _cfg, &worklist, max_reg_ints, A, safehash ); 1.590 + OopFlow *free_list = NULL; // Free, unused 1.591 + 1.592 + // Array mapping blocks to completed oopflows 1.593 + OopFlow **flows = NEW_ARENA_ARRAY(A, OopFlow*, _cfg->number_of_blocks()); 1.594 + memset( flows, 0, _cfg->number_of_blocks() * sizeof(OopFlow*) ); 1.595 + 1.596 + 1.597 + // Do the first block 'by hand' to prime the worklist 1.598 + Block *entry = _cfg->get_block(1); 1.599 + OopFlow *rootflow = OopFlow::make(A,max_reg,this); 1.600 + // Initialize to 'bottom' (not 'top') 1.601 + memset( rootflow->_callees, OptoReg::Bad, max_reg*sizeof(short) ); 1.602 + memset( rootflow->_defs , 0, max_reg*sizeof(Node*) ); 1.603 + flows[entry->_pre_order] = rootflow; 1.604 + 1.605 + // Do the first block 'by hand' to prime the worklist 1.606 + rootflow->_b = entry; 1.607 + rootflow->compute_reach( _regalloc, max_reg, safehash ); 1.608 + for( uint i=0; i<entry->_num_succs; i++ ) 1.609 + worklist.push(entry->_succs[i]); 1.610 + 1.611 + // Now worklist contains blocks which have some, but perhaps not all, 1.612 + // predecessors visited. 1.613 + while( worklist.size() ) { 1.614 + // Scan for a block with all predecessors visited, or any randoms slob 1.615 + // otherwise. All-preds-visited order allows me to recycle OopFlow 1.616 + // structures rapidly and cut down on the memory footprint. 1.617 + // Note: not all predecessors might be visited yet (must happen for 1.618 + // irreducible loops). This is OK, since every live value must have the 1.619 + // SAME reaching def for the block, so any reaching def is OK. 1.620 + uint i; 1.621 + 1.622 + Block *b = worklist.pop(); 1.623 + // Ignore root block 1.624 + if (b == _cfg->get_root_block()) { 1.625 + continue; 1.626 + } 1.627 + // Block is already done? Happens if block has several predecessors, 1.628 + // he can get on the worklist more than once. 1.629 + if( flows[b->_pre_order] ) continue; 1.630 + 1.631 + // If this block has a visited predecessor AND that predecessor has this 1.632 + // last block as his only undone child, we can move the OopFlow from the 1.633 + // pred to this block. Otherwise we have to grab a new OopFlow. 1.634 + OopFlow *flow = NULL; // Flag for finding optimized flow 1.635 + Block *pred = (Block*)0xdeadbeef; 1.636 + // Scan this block's preds to find a done predecessor 1.637 + for (uint j = 1; j < b->num_preds(); j++) { 1.638 + Block* p = _cfg->get_block_for_node(b->pred(j)); 1.639 + OopFlow *p_flow = flows[p->_pre_order]; 1.640 + if( p_flow ) { // Predecessor is done 1.641 + assert( p_flow->_b == p, "cross check" ); 1.642 + pred = p; // Record some predecessor 1.643 + // If all successors of p are done except for 'b', then we can carry 1.644 + // p_flow forward to 'b' without copying, otherwise we have to draw 1.645 + // from the free_list and clone data. 1.646 + uint k; 1.647 + for( k=0; k<p->_num_succs; k++ ) 1.648 + if( !flows[p->_succs[k]->_pre_order] && 1.649 + p->_succs[k] != b ) 1.650 + break; 1.651 + 1.652 + // Either carry-forward the now-unused OopFlow for b's use 1.653 + // or draw a new one from the free list 1.654 + if( k==p->_num_succs ) { 1.655 + flow = p_flow; 1.656 + break; // Found an ideal pred, use him 1.657 + } 1.658 + } 1.659 + } 1.660 + 1.661 + if( flow ) { 1.662 + // We have an OopFlow that's the last-use of a predecessor. 1.663 + // Carry it forward. 1.664 + } else { // Draw a new OopFlow from the freelist 1.665 + if( !free_list ) 1.666 + free_list = OopFlow::make(A,max_reg,C); 1.667 + flow = free_list; 1.668 + assert( flow->_b == NULL, "oopFlow is not free" ); 1.669 + free_list = flow->_next; 1.670 + flow->_next = NULL; 1.671 + 1.672 + // Copy/clone over the data 1.673 + flow->clone(flows[pred->_pre_order], max_reg); 1.674 + } 1.675 + 1.676 + // Mark flow for block. Blocks can only be flowed over once, 1.677 + // because after the first time they are guarded from entering 1.678 + // this code again. 1.679 + assert( flow->_b == pred, "have some prior flow" ); 1.680 + flow->_b = NULL; 1.681 + 1.682 + // Now push flow forward 1.683 + flows[b->_pre_order] = flow;// Mark flow for this block 1.684 + flow->_b = b; 1.685 + flow->compute_reach( _regalloc, max_reg, safehash ); 1.686 + 1.687 + // Now push children onto worklist 1.688 + for( i=0; i<b->_num_succs; i++ ) 1.689 + worklist.push(b->_succs[i]); 1.690 + 1.691 + } 1.692 +}