src/hotspot/share/opto/indexSet.cpp
changeset 59081 95a99e617f28
parent 53961 e5b461681b88
equal deleted inserted replaced
59075:355f4f42dda5 59081:95a99e617f28
   109 // corresponding to element.
   109 // corresponding to element.
   110 
   110 
   111 IndexSet::BitBlock *IndexSet::alloc_block_containing(uint element) {
   111 IndexSet::BitBlock *IndexSet::alloc_block_containing(uint element) {
   112   BitBlock *block = alloc_block();
   112   BitBlock *block = alloc_block();
   113   uint bi = get_block_index(element);
   113   uint bi = get_block_index(element);
       
   114   if (bi >= _current_block_limit) {
       
   115     _current_block_limit = bi + 1;
       
   116   }
   114   _blocks[bi] = block;
   117   _blocks[bi] = block;
   115   return block;
   118   return block;
   116 }
   119 }
   117 
   120 
   118 //---------------------------- IndexSet::free_block() -------------------------
   121 //---------------------------- IndexSet::free_block() -------------------------
   123   assert(i < _max_blocks, "block index too large");
   126   assert(i < _max_blocks, "block index too large");
   124   BitBlock *block = _blocks[i];
   127   BitBlock *block = _blocks[i];
   125   assert(block != &_empty_block, "cannot free the empty block");
   128   assert(block != &_empty_block, "cannot free the empty block");
   126   block->set_next((IndexSet::BitBlock*)Compile::current()->indexSet_free_block_list());
   129   block->set_next((IndexSet::BitBlock*)Compile::current()->indexSet_free_block_list());
   127   Compile::current()->set_indexSet_free_block_list(block);
   130   Compile::current()->set_indexSet_free_block_list(block);
   128   set_block(i,&_empty_block);
   131   set_block(i, &_empty_block);
   129 }
   132 }
   130 
   133 
   131 //------------------------------lrg_union--------------------------------------
   134 //------------------------------lrg_union--------------------------------------
   132 // Compute the union of all elements of one and two which interfere with
   135 // Compute the union of all elements of one and two which interfere with
   133 // the RegMask mask.  If the degree of the union becomes exceeds
   136 // the RegMask mask.  If the degree of the union becomes exceeds
   166   // Used to compute degree of register-only interferences.  Infinite-stack
   169   // Used to compute degree of register-only interferences.  Infinite-stack
   167   // neighbors do not alter colorability, as they can always color to some
   170   // neighbors do not alter colorability, as they can always color to some
   168   // other color.  (A variant of the Briggs assertion)
   171   // other color.  (A variant of the Briggs assertion)
   169   uint reg_degree = 0;
   172   uint reg_degree = 0;
   170 
   173 
   171   uint element;
   174   uint element = 0;
   172   // Load up the combined interference set with the neighbors of one
   175   // Load up the combined interference set with the neighbors of one
   173   IndexSetIterator elements(one);
   176   if (!one->is_empty()) {
   174   while ((element = elements.next()) != 0) {
   177     IndexSetIterator elements(one);
   175     LRG &lrg = ifg->lrgs(element);
   178     while ((element = elements.next()) != 0) {
   176     if (mask.overlap(lrg.mask())) {
   179       LRG &lrg = ifg->lrgs(element);
   177       insert(element);
   180       if (mask.overlap(lrg.mask())) {
   178       if( !lrg.mask().is_AllStack() ) {
   181         insert(element);
   179         reg_degree += lrg1.compute_degree(lrg);
   182         if (!lrg.mask().is_AllStack()) {
   180         if( reg_degree >= fail_degree ) return reg_degree;
   183           reg_degree += lrg1.compute_degree(lrg);
   181       } else {
   184           if (reg_degree >= fail_degree) return reg_degree;
   182         // !!!!! Danger!  No update to reg_degree despite having a neighbor.
       
   183         // A variant of the Briggs assertion.
       
   184         // Not needed if I simplify during coalesce, ala George/Appel.
       
   185         assert( lrg.lo_degree(), "" );
       
   186       }
       
   187     }
       
   188   }
       
   189   // Add neighbors of two as well
       
   190   IndexSetIterator elements2(two);
       
   191   while ((element = elements2.next()) != 0) {
       
   192     LRG &lrg = ifg->lrgs(element);
       
   193     if (mask.overlap(lrg.mask())) {
       
   194       if (insert(element)) {
       
   195         if( !lrg.mask().is_AllStack() ) {
       
   196           reg_degree += lrg2.compute_degree(lrg);
       
   197           if( reg_degree >= fail_degree ) return reg_degree;
       
   198         } else {
   185         } else {
   199           // !!!!! Danger!  No update to reg_degree despite having a neighbor.
   186           // !!!!! Danger!  No update to reg_degree despite having a neighbor.
   200           // A variant of the Briggs assertion.
   187           // A variant of the Briggs assertion.
   201           // Not needed if I simplify during coalesce, ala George/Appel.
   188           // Not needed if I simplify during coalesce, ala George/Appel.
   202           assert( lrg.lo_degree(), "" );
   189           assert(lrg.lo_degree(), "");
       
   190         }
       
   191       }
       
   192     }
       
   193   }
       
   194   // Add neighbors of two as well
       
   195 
       
   196   if (!two->is_empty()) {
       
   197     IndexSetIterator elements2(two);
       
   198     while ((element = elements2.next()) != 0) {
       
   199       LRG &lrg = ifg->lrgs(element);
       
   200       if (mask.overlap(lrg.mask())) {
       
   201         if (insert(element)) {
       
   202           if (!lrg.mask().is_AllStack()) {
       
   203             reg_degree += lrg2.compute_degree(lrg);
       
   204             if (reg_degree >= fail_degree) return reg_degree;
       
   205           } else {
       
   206             // !!!!! Danger!  No update to reg_degree despite having a neighbor.
       
   207             // A variant of the Briggs assertion.
       
   208             // Not needed if I simplify during coalesce, ala George/Appel.
       
   209             assert(lrg.lo_degree(), "");
       
   210           }
   203         }
   211         }
   204       }
   212       }
   205     }
   213     }
   206   }
   214   }
   207 
   215 
   217   set->check_watch("copied", _serial_number);
   225   set->check_watch("copied", _serial_number);
   218   check_watch("initialized by copy", set->_serial_number);
   226   check_watch("initialized by copy", set->_serial_number);
   219   _max_elements = set->_max_elements;
   227   _max_elements = set->_max_elements;
   220 #endif
   228 #endif
   221   _count = set->_count;
   229   _count = set->_count;
       
   230   _current_block_limit = set->_current_block_limit;
   222   _max_blocks = set->_max_blocks;
   231   _max_blocks = set->_max_blocks;
   223   if (_max_blocks <= preallocated_block_list_size) {
   232   if (_max_blocks <= preallocated_block_list_size) {
   224     _blocks = _preallocated_block_list;
   233     _blocks = _preallocated_block_list;
   225   } else {
   234   } else {
   226     _blocks =
   235     _blocks =
   246   _serial_number = _serial_count++;
   255   _serial_number = _serial_count++;
   247   check_watch("initialized", max_elements);
   256   check_watch("initialized", max_elements);
   248   _max_elements = max_elements;
   257   _max_elements = max_elements;
   249 #endif
   258 #endif
   250   _count = 0;
   259   _count = 0;
       
   260   _current_block_limit = 0;
   251   _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
   261   _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
   252 
   262 
   253   if (_max_blocks <= preallocated_block_list_size) {
   263   if (_max_blocks <= preallocated_block_list_size) {
   254     _blocks = _preallocated_block_list;
   264     _blocks = _preallocated_block_list;
   255   } else {
   265   } else {
   270   _serial_number = _serial_count++;
   280   _serial_number = _serial_count++;
   271   check_watch("initialized2", max_elements);
   281   check_watch("initialized2", max_elements);
   272   _max_elements = max_elements;
   282   _max_elements = max_elements;
   273 #endif // ASSERT
   283 #endif // ASSERT
   274   _count = 0;
   284   _count = 0;
       
   285   _current_block_limit = 0;
   275   _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
   286   _max_blocks = (max_elements + bits_per_block - 1) / bits_per_block;
   276 
   287 
   277   if (_max_blocks <= preallocated_block_list_size) {
   288   if (_max_blocks <= preallocated_block_list_size) {
   278     _blocks = _preallocated_block_list;
   289     _blocks = _preallocated_block_list;
   279   } else {
   290   } else {
   292   assert(_max_elements == set->_max_elements, "must have same universe size to swap");
   303   assert(_max_elements == set->_max_elements, "must have same universe size to swap");
   293   check_watch("swap", set->_serial_number);
   304   check_watch("swap", set->_serial_number);
   294   set->check_watch("swap", _serial_number);
   305   set->check_watch("swap", _serial_number);
   295 #endif
   306 #endif
   296 
   307 
   297   for (uint i = 0; i < _max_blocks; i++) {
   308   uint max = MAX2(_current_block_limit, set->_current_block_limit);
       
   309   for (uint i = 0; i < max; i++) {
   298     BitBlock *temp = _blocks[i];
   310     BitBlock *temp = _blocks[i];
   299     set_block(i, set->_blocks[i]);
   311     set_block(i, set->_blocks[i]);
   300     set->set_block(i, temp);
   312     set->set_block(i, temp);
   301   }
   313   }
   302   uint temp = _count;
   314   uint temp = _count;
   303   _count = set->_count;
   315   _count = set->_count;
   304   set->_count = temp;
   316   set->_count = temp;
       
   317 
       
   318   temp = _current_block_limit;
       
   319   _current_block_limit = set->_current_block_limit;
       
   320   set->_current_block_limit = temp;
       
   321 
   305 }
   322 }
   306 
   323 
   307 //---------------------------- IndexSet::dump() -----------------------------
   324 //---------------------------- IndexSet::dump() -----------------------------
   308 // Print this set.  Used for debugging.
   325 // Print this set.  Used for debugging.
   309 
   326 
   381 
   398 
   382 //---------------------------- IndexSetIterator() -----------------------------
   399 //---------------------------- IndexSetIterator() -----------------------------
   383 // Create an iterator for a set.  If empty blocks are detected when iterating
   400 // Create an iterator for a set.  If empty blocks are detected when iterating
   384 // over the set, these blocks are replaced.
   401 // over the set, these blocks are replaced.
   385 
   402 
   386 IndexSetIterator::IndexSetIterator(IndexSet *set) {
       
   387 #ifdef ASSERT
       
   388   if (CollectIndexSetStatistics) {
       
   389     set->tally_iteration_statistics();
       
   390   }
       
   391   set->check_watch("traversed", set->count());
       
   392 #endif
       
   393   if (set->is_empty()) {
       
   394     _current = 0;
       
   395     _next_word = IndexSet::words_per_block;
       
   396     _next_block = 1;
       
   397     _max_blocks = 1;
       
   398 
       
   399     // We don't need the following values when we iterate over an empty set.
       
   400     // The commented out code is left here to document that the omission
       
   401     // is intentional.
       
   402     //
       
   403     //_value = 0;
       
   404     //_words = NULL;
       
   405     //_blocks = NULL;
       
   406     //_set = NULL;
       
   407   } else {
       
   408     _current = 0;
       
   409     _value = 0;
       
   410     _next_block = 0;
       
   411     _next_word = IndexSet::words_per_block;
       
   412 
       
   413     _max_blocks = set->_max_blocks;
       
   414     _words = NULL;
       
   415     _blocks = set->_blocks;
       
   416     _set = set;
       
   417   }
       
   418 }
       
   419 
       
   420 //---------------------------- IndexSetIterator(const) -----------------------------
       
   421 // Iterate over a constant IndexSet.
       
   422 
       
   423 IndexSetIterator::IndexSetIterator(const IndexSet *set) {
       
   424 #ifdef ASSERT
       
   425   if (CollectIndexSetStatistics) {
       
   426     set->tally_iteration_statistics();
       
   427   }
       
   428   // We don't call check_watch from here to avoid bad recursion.
       
   429   //   set->check_watch("traversed const", set->count());
       
   430 #endif
       
   431   if (set->is_empty()) {
       
   432     _current = 0;
       
   433     _next_word = IndexSet::words_per_block;
       
   434     _next_block = 1;
       
   435     _max_blocks = 1;
       
   436 
       
   437     // We don't need the following values when we iterate over an empty set.
       
   438     // The commented out code is left here to document that the omission
       
   439     // is intentional.
       
   440     //
       
   441     //_value = 0;
       
   442     //_words = NULL;
       
   443     //_blocks = NULL;
       
   444     //_set = NULL;
       
   445   } else {
       
   446     _current = 0;
       
   447     _value = 0;
       
   448     _next_block = 0;
       
   449     _next_word = IndexSet::words_per_block;
       
   450 
       
   451     _max_blocks = set->_max_blocks;
       
   452     _words = NULL;
       
   453     _blocks = set->_blocks;
       
   454     _set = NULL;
       
   455   }
       
   456 }
       
   457 
       
   458 //---------------------------- List16Iterator::advance_and_next() -----------------------------
   403 //---------------------------- List16Iterator::advance_and_next() -----------------------------
   459 // Advance to the next non-empty word in the set being iterated over.  Return the next element
   404 // Advance to the next non-empty word in the set being iterated over.  Return the next element
   460 // if there is one.  If we are done, return 0.  This method is called from the next() method
   405 // if there is one.  If we are done, return 0.  This method is called from the next() method
   461 // when it gets done with a word.
   406 // when it gets done with a word.
   462 
   407 
   465   for (uint wi = _next_word; wi < (unsigned)IndexSet::words_per_block; wi++) {
   410   for (uint wi = _next_word; wi < (unsigned)IndexSet::words_per_block; wi++) {
   466     if (_words[wi] != 0) {
   411     if (_words[wi] != 0) {
   467       // Found a non-empty word.
   412       // Found a non-empty word.
   468       _value = ((_next_block - 1) * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
   413       _value = ((_next_block - 1) * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
   469       _current = _words[wi];
   414       _current = _words[wi];
   470 
   415       _next_word = wi + 1;
   471       _next_word = wi+1;
   416       return next_value();
   472 
       
   473       return next();
       
   474     }
   417     }
   475   }
   418   }
   476 
   419 
   477   // We ran out of words in the current block.  Advance to next non-empty block.
   420   // We ran out of words in the current block.  Advance to next non-empty block.
   478   for (uint bi = _next_block; bi < _max_blocks; bi++) {
   421   for (uint bi = _next_block; bi < _max_blocks; bi++) {
   486           _value = (bi * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
   429           _value = (bi * IndexSet::bits_per_block) + (wi * IndexSet::bits_per_word);
   487           _current = _words[wi];
   430           _current = _words[wi];
   488 
   431 
   489           _next_block = bi+1;
   432           _next_block = bi+1;
   490           _next_word = wi+1;
   433           _next_word = wi+1;
   491 
   434           return next_value();
   492           return next();
       
   493         }
   435         }
   494       }
   436       }
   495 
   437 
   496       // All of the words in the block were empty.  Replace
   438       // All of the words in the block were empty.  Replace
   497       // the block with the empty block.
   439       // the block with the empty block.
   499         _set->free_block(bi);
   441         _set->free_block(bi);
   500       }
   442       }
   501     }
   443     }
   502   }
   444   }
   503 
   445 
   504   // These assignments make redundant calls to next on a finished iterator
       
   505   // faster.  Probably not necessary.
       
   506   _next_block = _max_blocks;
       
   507   _next_word = IndexSet::words_per_block;
       
   508 
       
   509   // No more words.
   446   // No more words.
   510   return 0;
   447   return 0;
   511 }
   448 }