src/share/vm/opto/live.cpp

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 1001
91263420e1c6
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

duke@435 1 /*
duke@435 2 * Copyright 1997-2005 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_live.cpp.incl"
duke@435 27
duke@435 28
duke@435 29
duke@435 30 //=============================================================================
duke@435 31 //------------------------------PhaseLive--------------------------------------
duke@435 32 // Compute live-in/live-out. We use a totally incremental algorithm. The LIVE
duke@435 33 // problem is monotonic. The steady-state solution looks like this: pull a
duke@435 34 // block from the worklist. It has a set of delta's - values which are newly
duke@435 35 // live-in from the block. Push these to the live-out sets of all predecessor
duke@435 36 // blocks. At each predecessor, the new live-out values are ANDed with what is
duke@435 37 // already live-out (extra stuff is added to the live-out sets). Then the
duke@435 38 // remaining new live-out values are ANDed with what is locally defined.
duke@435 39 // Leftover bits become the new live-in for the predecessor block, and the pred
duke@435 40 // block is put on the worklist.
duke@435 41 // The locally live-in stuff is computed once and added to predecessor
twisti@1040 42 // live-out sets. This separate compilation is done in the outer loop below.
duke@435 43 PhaseLive::PhaseLive( const PhaseCFG &cfg, LRG_List &names, Arena *arena ) : Phase(LIVE), _cfg(cfg), _names(names), _arena(arena), _live(0) {
duke@435 44 }
duke@435 45
duke@435 46 void PhaseLive::compute(uint maxlrg) {
duke@435 47 _maxlrg = maxlrg;
duke@435 48 _worklist = new (_arena) Block_List();
duke@435 49
duke@435 50 // Init the sparse live arrays. This data is live on exit from here!
duke@435 51 // The _live info is the live-out info.
duke@435 52 _live = (IndexSet*)_arena->Amalloc(sizeof(IndexSet)*_cfg._num_blocks);
duke@435 53 uint i;
duke@435 54 for( i=0; i<_cfg._num_blocks; i++ ) {
duke@435 55 _live[i].initialize(_maxlrg);
duke@435 56 }
duke@435 57
duke@435 58 // Init the sparse arrays for delta-sets.
duke@435 59 ResourceMark rm; // Nuke temp storage on exit
duke@435 60
duke@435 61 // Does the memory used by _defs and _deltas get reclaimed? Does it matter? TT
duke@435 62
duke@435 63 // Array of values defined locally in blocks
duke@435 64 _defs = NEW_RESOURCE_ARRAY(IndexSet,_cfg._num_blocks);
duke@435 65 for( i=0; i<_cfg._num_blocks; i++ ) {
duke@435 66 _defs[i].initialize(_maxlrg);
duke@435 67 }
duke@435 68
duke@435 69 // Array of delta-set pointers, indexed by block pre_order-1.
duke@435 70 _deltas = NEW_RESOURCE_ARRAY(IndexSet*,_cfg._num_blocks);
duke@435 71 memset( _deltas, 0, sizeof(IndexSet*)* _cfg._num_blocks);
duke@435 72
duke@435 73 _free_IndexSet = NULL;
duke@435 74
duke@435 75 // Blocks having done pass-1
duke@435 76 VectorSet first_pass(Thread::current()->resource_area());
duke@435 77
duke@435 78 // Outer loop: must compute local live-in sets and push into predecessors.
duke@435 79 uint iters = _cfg._num_blocks; // stat counters
duke@435 80 for( uint j=_cfg._num_blocks; j>0; j-- ) {
duke@435 81 Block *b = _cfg._blocks[j-1];
duke@435 82
duke@435 83 // Compute the local live-in set. Start with any new live-out bits.
duke@435 84 IndexSet *use = getset( b );
duke@435 85 IndexSet *def = &_defs[b->_pre_order-1];
duke@435 86 DEBUG_ONLY(IndexSet *def_outside = getfreeset();)
duke@435 87 uint i;
duke@435 88 for( i=b->_nodes.size(); i>1; i-- ) {
duke@435 89 Node *n = b->_nodes[i-1];
duke@435 90 if( n->is_Phi() ) break;
duke@435 91
duke@435 92 uint r = _names[n->_idx];
duke@435 93 assert(!def_outside->member(r), "Use of external LRG overlaps the same LRG defined in this block");
duke@435 94 def->insert( r );
duke@435 95 use->remove( r );
duke@435 96 uint cnt = n->req();
duke@435 97 for( uint k=1; k<cnt; k++ ) {
duke@435 98 Node *nk = n->in(k);
duke@435 99 uint nkidx = nk->_idx;
duke@435 100 if( _cfg._bbs[nkidx] != b ) {
duke@435 101 uint u = _names[nkidx];
duke@435 102 use->insert( u );
duke@435 103 DEBUG_ONLY(def_outside->insert( u );)
duke@435 104 }
duke@435 105 }
duke@435 106 }
duke@435 107 #ifdef ASSERT
duke@435 108 def_outside->set_next(_free_IndexSet);
duke@435 109 _free_IndexSet = def_outside; // Drop onto free list
duke@435 110 #endif
duke@435 111 // Remove anything defined by Phis and the block start instruction
duke@435 112 for( uint k=i; k>0; k-- ) {
duke@435 113 uint r = _names[b->_nodes[k-1]->_idx];
duke@435 114 def->insert( r );
duke@435 115 use->remove( r );
duke@435 116 }
duke@435 117
duke@435 118 // Push these live-in things to predecessors
duke@435 119 for( uint l=1; l<b->num_preds(); l++ ) {
duke@435 120 Block *p = _cfg._bbs[b->pred(l)->_idx];
duke@435 121 add_liveout( p, use, first_pass );
duke@435 122
duke@435 123 // PhiNode uses go in the live-out set of prior blocks.
duke@435 124 for( uint k=i; k>0; k-- )
duke@435 125 add_liveout( p, _names[b->_nodes[k-1]->in(l)->_idx], first_pass );
duke@435 126 }
duke@435 127 freeset( b );
duke@435 128 first_pass.set(b->_pre_order);
duke@435 129
duke@435 130 // Inner loop: blocks that picked up new live-out values to be propagated
duke@435 131 while( _worklist->size() ) {
duke@435 132 // !!!!!
duke@435 133 // #ifdef ASSERT
duke@435 134 iters++;
duke@435 135 // #endif
duke@435 136 Block *b = _worklist->pop();
duke@435 137 IndexSet *delta = getset(b);
duke@435 138 assert( delta->count(), "missing delta set" );
duke@435 139
duke@435 140 // Add new-live-in to predecessors live-out sets
duke@435 141 for( uint l=1; l<b->num_preds(); l++ )
duke@435 142 add_liveout( _cfg._bbs[b->pred(l)->_idx], delta, first_pass );
duke@435 143
duke@435 144 freeset(b);
duke@435 145 } // End of while-worklist-not-empty
duke@435 146
duke@435 147 } // End of for-all-blocks-outer-loop
duke@435 148
duke@435 149 // We explicitly clear all of the IndexSets which we are about to release.
duke@435 150 // This allows us to recycle their internal memory into IndexSet's free list.
duke@435 151
duke@435 152 for( i=0; i<_cfg._num_blocks; i++ ) {
duke@435 153 _defs[i].clear();
duke@435 154 if (_deltas[i]) {
duke@435 155 // Is this always true?
duke@435 156 _deltas[i]->clear();
duke@435 157 }
duke@435 158 }
duke@435 159 IndexSet *free = _free_IndexSet;
duke@435 160 while (free != NULL) {
duke@435 161 IndexSet *temp = free;
duke@435 162 free = free->next();
duke@435 163 temp->clear();
duke@435 164 }
duke@435 165
duke@435 166 }
duke@435 167
duke@435 168 //------------------------------stats------------------------------------------
duke@435 169 #ifndef PRODUCT
duke@435 170 void PhaseLive::stats(uint iters) const {
duke@435 171 }
duke@435 172 #endif
duke@435 173
duke@435 174 //------------------------------getset-----------------------------------------
duke@435 175 // Get an IndexSet for a block. Return existing one, if any. Make a new
duke@435 176 // empty one if a prior one does not exist.
duke@435 177 IndexSet *PhaseLive::getset( Block *p ) {
duke@435 178 IndexSet *delta = _deltas[p->_pre_order-1];
duke@435 179 if( !delta ) // Not on worklist?
duke@435 180 // Get a free set; flag as being on worklist
duke@435 181 delta = _deltas[p->_pre_order-1] = getfreeset();
duke@435 182 return delta; // Return set of new live-out items
duke@435 183 }
duke@435 184
duke@435 185 //------------------------------getfreeset-------------------------------------
duke@435 186 // Pull from free list, or allocate. Internal allocation on the returned set
duke@435 187 // is always from thread local storage.
duke@435 188 IndexSet *PhaseLive::getfreeset( ) {
duke@435 189 IndexSet *f = _free_IndexSet;
duke@435 190 if( !f ) {
duke@435 191 f = new IndexSet;
duke@435 192 // f->set_arena(Thread::current()->resource_area());
duke@435 193 f->initialize(_maxlrg, Thread::current()->resource_area());
duke@435 194 } else {
duke@435 195 // Pull from free list
duke@435 196 _free_IndexSet = f->next();
duke@435 197 //f->_cnt = 0; // Reset to empty
duke@435 198 // f->set_arena(Thread::current()->resource_area());
duke@435 199 f->initialize(_maxlrg, Thread::current()->resource_area());
duke@435 200 }
duke@435 201 return f;
duke@435 202 }
duke@435 203
duke@435 204 //------------------------------freeset----------------------------------------
duke@435 205 // Free an IndexSet from a block.
duke@435 206 void PhaseLive::freeset( const Block *p ) {
duke@435 207 IndexSet *f = _deltas[p->_pre_order-1];
duke@435 208 f->set_next(_free_IndexSet);
duke@435 209 _free_IndexSet = f; // Drop onto free list
duke@435 210 _deltas[p->_pre_order-1] = NULL;
duke@435 211 }
duke@435 212
duke@435 213 //------------------------------add_liveout------------------------------------
duke@435 214 // Add a live-out value to a given blocks live-out set. If it is new, then
duke@435 215 // also add it to the delta set and stick the block on the worklist.
duke@435 216 void PhaseLive::add_liveout( Block *p, uint r, VectorSet &first_pass ) {
duke@435 217 IndexSet *live = &_live[p->_pre_order-1];
duke@435 218 if( live->insert(r) ) { // If actually inserted...
duke@435 219 // We extended the live-out set. See if the value is generated locally.
duke@435 220 // If it is not, then we must extend the live-in set.
duke@435 221 if( !_defs[p->_pre_order-1].member( r ) ) {
duke@435 222 if( !_deltas[p->_pre_order-1] && // Not on worklist?
duke@435 223 first_pass.test(p->_pre_order) )
duke@435 224 _worklist->push(p); // Actually go on worklist if already 1st pass
duke@435 225 getset(p)->insert(r);
duke@435 226 }
duke@435 227 }
duke@435 228 }
duke@435 229
duke@435 230
duke@435 231 //------------------------------add_liveout------------------------------------
duke@435 232 // Add a vector of live-out values to a given blocks live-out set.
duke@435 233 void PhaseLive::add_liveout( Block *p, IndexSet *lo, VectorSet &first_pass ) {
duke@435 234 IndexSet *live = &_live[p->_pre_order-1];
duke@435 235 IndexSet *defs = &_defs[p->_pre_order-1];
duke@435 236 IndexSet *on_worklist = _deltas[p->_pre_order-1];
duke@435 237 IndexSet *delta = on_worklist ? on_worklist : getfreeset();
duke@435 238
duke@435 239 IndexSetIterator elements(lo);
duke@435 240 uint r;
duke@435 241 while ((r = elements.next()) != 0) {
duke@435 242 if( live->insert(r) && // If actually inserted...
duke@435 243 !defs->member( r ) ) // and not defined locally
duke@435 244 delta->insert(r); // Then add to live-in set
duke@435 245 }
duke@435 246
duke@435 247 if( delta->count() ) { // If actually added things
duke@435 248 _deltas[p->_pre_order-1] = delta; // Flag as on worklist now
duke@435 249 if( !on_worklist && // Not on worklist?
duke@435 250 first_pass.test(p->_pre_order) )
duke@435 251 _worklist->push(p); // Actually go on worklist if already 1st pass
duke@435 252 } else { // Nothing there; just free it
duke@435 253 delta->set_next(_free_IndexSet);
duke@435 254 _free_IndexSet = delta; // Drop onto free list
duke@435 255 }
duke@435 256 }
duke@435 257
duke@435 258 #ifndef PRODUCT
duke@435 259 //------------------------------dump-------------------------------------------
duke@435 260 // Dump the live-out set for a block
duke@435 261 void PhaseLive::dump( const Block *b ) const {
duke@435 262 tty->print("Block %d: ",b->_pre_order);
duke@435 263 tty->print("LiveOut: "); _live[b->_pre_order-1].dump();
duke@435 264 uint cnt = b->_nodes.size();
duke@435 265 for( uint i=0; i<cnt; i++ ) {
duke@435 266 tty->print("L%d/", _names[b->_nodes[i]->_idx] );
duke@435 267 b->_nodes[i]->dump();
duke@435 268 }
duke@435 269 tty->print("\n");
duke@435 270 }
duke@435 271
duke@435 272 //------------------------------verify_base_ptrs-------------------------------
duke@435 273 // Verify that base pointers and derived pointers are still sane.
duke@435 274 void PhaseChaitin::verify_base_ptrs( ResourceArea *a ) const {
kvn@985 275 #ifdef ASSERT
kvn@985 276 Unique_Node_List worklist(a);
duke@435 277 for( uint i = 0; i < _cfg._num_blocks; i++ ) {
duke@435 278 Block *b = _cfg._blocks[i];
duke@435 279 for( uint j = b->end_idx() + 1; j > 1; j-- ) {
duke@435 280 Node *n = b->_nodes[j-1];
duke@435 281 if( n->is_Phi() ) break;
duke@435 282 // Found a safepoint?
duke@435 283 if( n->is_MachSafePoint() ) {
duke@435 284 MachSafePointNode *sfpt = n->as_MachSafePoint();
duke@435 285 JVMState* jvms = sfpt->jvms();
duke@435 286 if (jvms != NULL) {
duke@435 287 // Now scan for a live derived pointer
duke@435 288 if (jvms->oopoff() < sfpt->req()) {
duke@435 289 // Check each derived/base pair
kvn@985 290 for (uint idx = jvms->oopoff(); idx < sfpt->req(); idx++) {
duke@435 291 Node *check = sfpt->in(idx);
kvn@985 292 bool is_derived = ((idx - jvms->oopoff()) & 1) == 0;
duke@435 293 // search upwards through spills and spill phis for AddP
kvn@985 294 worklist.clear();
kvn@985 295 worklist.push(check);
kvn@985 296 uint k = 0;
kvn@985 297 while( k < worklist.size() ) {
kvn@985 298 check = worklist.at(k);
kvn@985 299 assert(check,"Bad base or derived pointer");
kvn@985 300 // See PhaseChaitin::find_base_for_derived() for all cases.
kvn@985 301 int isc = check->is_Copy();
kvn@985 302 if( isc ) {
kvn@985 303 worklist.push(check->in(isc));
kvn@985 304 } else if( check->is_Phi() ) {
kvn@985 305 for (uint m = 1; m < check->req(); m++)
kvn@985 306 worklist.push(check->in(m));
kvn@985 307 } else if( check->is_Con() ) {
kvn@985 308 if (is_derived) {
kvn@985 309 // Derived is NULL+offset
kvn@985 310 assert(!is_derived || check->bottom_type()->is_ptr()->ptr() == TypePtr::Null,"Bad derived pointer");
kvn@985 311 } else {
kvn@985 312 assert(check->bottom_type()->is_ptr()->_offset == 0,"Bad base pointer");
kvn@985 313 // Base either ConP(NULL) or loadConP
kvn@985 314 if (check->is_Mach()) {
kvn@985 315 assert(check->as_Mach()->ideal_Opcode() == Op_ConP,"Bad base pointer");
kvn@985 316 } else {
kvn@985 317 assert(check->Opcode() == Op_ConP &&
kvn@985 318 check->bottom_type()->is_ptr()->ptr() == TypePtr::Null,"Bad base pointer");
kvn@985 319 }
kvn@985 320 }
kvn@985 321 } else if( check->bottom_type()->is_ptr()->_offset == 0 ) {
kvn@985 322 if(check->is_Proj() || check->is_Mach() &&
kvn@985 323 (check->as_Mach()->ideal_Opcode() == Op_CreateEx ||
kvn@985 324 check->as_Mach()->ideal_Opcode() == Op_ThreadLocal ||
kvn@985 325 check->as_Mach()->ideal_Opcode() == Op_CMoveP ||
kvn@985 326 check->as_Mach()->ideal_Opcode() == Op_CheckCastPP ||
kvn@985 327 #ifdef _LP64
kvn@985 328 UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_CastPP ||
kvn@985 329 UseCompressedOops && check->as_Mach()->ideal_Opcode() == Op_DecodeN ||
kvn@985 330 #endif
kvn@985 331 check->as_Mach()->ideal_Opcode() == Op_LoadP ||
kvn@1001 332 check->as_Mach()->ideal_Opcode() == Op_LoadKlass)) {
kvn@1001 333 // Valid nodes
kvn@1001 334 } else {
kvn@1001 335 check->dump();
kvn@985 336 assert(false,"Bad base or derived pointer");
kvn@1001 337 }
kvn@985 338 } else {
kvn@985 339 assert(is_derived,"Bad base pointer");
kvn@985 340 assert(check->is_Mach() && check->as_Mach()->ideal_Opcode() == Op_AddP,"Bad derived pointer");
kvn@985 341 }
kvn@985 342 k++;
kvn@985 343 assert(k < 100000,"Derived pointer checking in infinite loop");
duke@435 344 } // End while
duke@435 345 }
duke@435 346 } // End of check for derived pointers
duke@435 347 } // End of Kcheck for debug info
duke@435 348 } // End of if found a safepoint
duke@435 349 } // End of forall instructions in block
duke@435 350 } // End of forall blocks
kvn@985 351 #endif
duke@435 352 }
kvn@1001 353
kvn@1001 354 //------------------------------verify-------------------------------------
kvn@1001 355 // Verify that graphs and base pointers are still sane.
kvn@1001 356 void PhaseChaitin::verify( ResourceArea *a, bool verify_ifg ) const {
kvn@1001 357 #ifdef ASSERT
kvn@1001 358 if( VerifyOpto || VerifyRegisterAllocator ) {
kvn@1001 359 _cfg.verify();
kvn@1001 360 verify_base_ptrs(a);
kvn@1001 361 if(verify_ifg)
kvn@1001 362 _ifg->verify(this);
kvn@1001 363 }
duke@435 364 #endif
kvn@1001 365 }
kvn@1001 366
kvn@1001 367 #endif

mercurial