< prev index next >

src/share/vm/gc/cms/parCardTableModRefBS.cpp

Print this page
rev 12906 : [mq]: gc_interface


  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/cardTableModRefBS.hpp"
  27 #include "gc/shared/cardTableRS.hpp"
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/genCollectedHeap.hpp"
  30 #include "gc/shared/space.inline.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/virtualspace.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/java.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/orderAccess.inline.hpp"
  37 #include "runtime/vmThread.hpp"
  38 
  39 void CardTableModRefBSForCTRS::


  40 non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
  41                                      OopsInGenClosure* cl,
  42                                      CardTableRS* ct,
  43                                      uint n_threads) {
  44   assert(n_threads > 0, "expected n_threads > 0");
  45   assert(n_threads <= ParallelGCThreads,
  46          "n_threads: %u > ParallelGCThreads: %u", n_threads, ParallelGCThreads);
  47 
  48   // Make sure the LNC array is valid for the space.
  49   jbyte**   lowest_non_clean;
  50   uintptr_t lowest_non_clean_base_chunk_index;
  51   size_t    lowest_non_clean_chunk_size;
  52   get_LNC_array_for_space(sp, lowest_non_clean,
  53                           lowest_non_clean_base_chunk_index,
  54                           lowest_non_clean_chunk_size);
  55 
  56   uint n_strides = n_threads * ParGCStridesPerThread;
  57   SequentialSubTasksDone* pst = sp->par_seq_tasks();
  58   // Sets the condition for completion of the subtask (how many threads
  59   // need to finish in order to be done).


  65     process_stride(sp, mr, stride, n_strides,
  66                    cl, ct,
  67                    lowest_non_clean,
  68                    lowest_non_clean_base_chunk_index,
  69                    lowest_non_clean_chunk_size);
  70   }
  71   if (pst->all_tasks_completed()) {
  72     // Clear lowest_non_clean array for next time.
  73     intptr_t first_chunk_index = addr_to_chunk_index(mr.start());
  74     uintptr_t last_chunk_index  = addr_to_chunk_index(mr.last());
  75     for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) {
  76       intptr_t ind = ch - lowest_non_clean_base_chunk_index;
  77       assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size,
  78              "Bounds error");
  79       lowest_non_clean[ind] = NULL;
  80     }
  81   }
  82 }
  83 
  84 void
  85 CardTableModRefBSForCTRS::
  86 process_stride(Space* sp,
  87                MemRegion used,
  88                jint stride, int n_strides,
  89                OopsInGenClosure* cl,
  90                CardTableRS* ct,
  91                jbyte** lowest_non_clean,
  92                uintptr_t lowest_non_clean_base_chunk_index,
  93                size_t    lowest_non_clean_chunk_size) {
  94   // We go from higher to lower addresses here; it wouldn't help that much
  95   // because of the strided parallelism pattern used here.
  96 
  97   // Find the first card address of the first chunk in the stride that is
  98   // at least "bottom" of the used region.
  99   jbyte*    start_card  = byte_for(used.start());
 100   jbyte*    end_card    = byte_after(used.last());
 101   uintptr_t start_chunk = addr_to_chunk_index(used.start());
 102   uintptr_t start_chunk_stride_num = start_chunk % n_strides;
 103   jbyte* chunk_card_start;
 104 
 105   if ((uintptr_t)stride >= start_chunk_stride_num) {


 145                              used,
 146                              lowest_non_clean,
 147                              lowest_non_clean_base_chunk_index,
 148                              lowest_non_clean_chunk_size);
 149 
 150     // We want the LNC array updates above in process_chunk_boundaries
 151     // to be visible before any of the card table value changes as a
 152     // result of the dirty card iteration below.
 153     OrderAccess::storestore();
 154 
 155     // We want to clear the cards: clear_cl here does the work of finding
 156     // contiguous dirty ranges of cards to process and clear.
 157     clear_cl.do_MemRegion(chunk_mr);
 158 
 159     // Find the next chunk of the stride.
 160     chunk_card_start += ParGCCardsPerStrideChunk * n_strides;
 161   }
 162 }
 163 
 164 void
 165 CardTableModRefBSForCTRS::
 166 process_chunk_boundaries(Space* sp,
 167                          DirtyCardToOopClosure* dcto_cl,
 168                          MemRegion chunk_mr,
 169                          MemRegion used,
 170                          jbyte** lowest_non_clean,
 171                          uintptr_t lowest_non_clean_base_chunk_index,
 172                          size_t    lowest_non_clean_chunk_size)
 173 {
 174   // We must worry about non-array objects that cross chunk boundaries,
 175   // because such objects are both precisely and imprecisely marked:
 176   // .. if the head of such an object is dirty, the entire object
 177   //    needs to be scanned, under the interpretation that this
 178   //    was an imprecise mark
 179   // .. if the head of such an object is not dirty, we can assume
 180   //    precise marking and it's efficient to scan just the dirty
 181   //    cards.
 182   // In either case, each scanned reference must be scanned precisely
 183   // once so as to avoid cloning of a young referent. For efficiency,
 184   // our closures depend on this property and do not protect against
 185   // double scans.


 354           }  // else continue to look for a non-NULL entry if any
 355         }
 356         assert(limit_card != NULL && max_to_do != NULL, "Error");
 357       }
 358       assert(max_to_do != NULL, "OOPS 1 !");
 359     }
 360     assert(max_to_do != NULL, "OOPS 2!");
 361   } else {
 362     max_to_do = used.end();
 363   }
 364   assert(max_to_do != NULL, "OOPS 3!");
 365   // Now we can set the closure we're using so it doesn't to beyond
 366   // max_to_do.
 367   dcto_cl->set_min_done(max_to_do);
 368 #ifndef PRODUCT
 369   dcto_cl->set_last_bottom(max_to_do);
 370 #endif
 371 }
 372 
 373 void
 374 CardTableModRefBSForCTRS::
 375 get_LNC_array_for_space(Space* sp,
 376                         jbyte**& lowest_non_clean,
 377                         uintptr_t& lowest_non_clean_base_chunk_index,
 378                         size_t& lowest_non_clean_chunk_size) {
 379 
 380   int       i        = find_covering_region_containing(sp->bottom());
 381   MemRegion covered  = _covered[i];
 382   size_t    n_chunks = chunks_to_cover(covered);
 383 
 384   // Only the first thread to obtain the lock will resize the
 385   // LNC array for the covered region.  Any later expansion can't affect
 386   // the used_at_save_marks region.
 387   // (I observed a bug in which the first thread to execute this would
 388   // resize, and then it would cause "expand_and_allocate" that would
 389   // increase the number of chunks in the covered region.  Then a second
 390   // thread would come and execute this, see that the size didn't match,
 391   // and free and allocate again.  So the first thread would be using a
 392   // freed "_lowest_non_clean" array.)
 393 
 394   // Do a dirty read here. If we pass the conditional then take the rare




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/cardTableModRefBS.hpp"
  27 #include "gc/shared/cardTableRS.hpp"
  28 #include "gc/shared/collectedHeap.hpp"
  29 #include "gc/shared/genCollectedHeap.hpp"
  30 #include "gc/shared/space.inline.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/virtualspace.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "runtime/java.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/orderAccess.inline.hpp"
  37 #include "runtime/vmThread.hpp"
  38 
  39 // TODO: Split out CMS parts of CardTableRS to a CMS-owned card table class
  40 
  41 void CardTableRS::
  42 non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
  43                                      OopsInGenClosure* cl,
  44                                      CardTableRS* ct,
  45                                      uint n_threads) {
  46   assert(n_threads > 0, "expected n_threads > 0");
  47   assert(n_threads <= ParallelGCThreads,
  48          "n_threads: %u > ParallelGCThreads: %u", n_threads, ParallelGCThreads);
  49 
  50   // Make sure the LNC array is valid for the space.
  51   jbyte**   lowest_non_clean;
  52   uintptr_t lowest_non_clean_base_chunk_index;
  53   size_t    lowest_non_clean_chunk_size;
  54   get_LNC_array_for_space(sp, lowest_non_clean,
  55                           lowest_non_clean_base_chunk_index,
  56                           lowest_non_clean_chunk_size);
  57 
  58   uint n_strides = n_threads * ParGCStridesPerThread;
  59   SequentialSubTasksDone* pst = sp->par_seq_tasks();
  60   // Sets the condition for completion of the subtask (how many threads
  61   // need to finish in order to be done).


  67     process_stride(sp, mr, stride, n_strides,
  68                    cl, ct,
  69                    lowest_non_clean,
  70                    lowest_non_clean_base_chunk_index,
  71                    lowest_non_clean_chunk_size);
  72   }
  73   if (pst->all_tasks_completed()) {
  74     // Clear lowest_non_clean array for next time.
  75     intptr_t first_chunk_index = addr_to_chunk_index(mr.start());
  76     uintptr_t last_chunk_index  = addr_to_chunk_index(mr.last());
  77     for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) {
  78       intptr_t ind = ch - lowest_non_clean_base_chunk_index;
  79       assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size,
  80              "Bounds error");
  81       lowest_non_clean[ind] = NULL;
  82     }
  83   }
  84 }
  85 
  86 void
  87 CardTableRS::
  88 process_stride(Space* sp,
  89                MemRegion used,
  90                jint stride, int n_strides,
  91                OopsInGenClosure* cl,
  92                CardTableRS* ct,
  93                jbyte** lowest_non_clean,
  94                uintptr_t lowest_non_clean_base_chunk_index,
  95                size_t    lowest_non_clean_chunk_size) {
  96   // We go from higher to lower addresses here; it wouldn't help that much
  97   // because of the strided parallelism pattern used here.
  98 
  99   // Find the first card address of the first chunk in the stride that is
 100   // at least "bottom" of the used region.
 101   jbyte*    start_card  = byte_for(used.start());
 102   jbyte*    end_card    = byte_after(used.last());
 103   uintptr_t start_chunk = addr_to_chunk_index(used.start());
 104   uintptr_t start_chunk_stride_num = start_chunk % n_strides;
 105   jbyte* chunk_card_start;
 106 
 107   if ((uintptr_t)stride >= start_chunk_stride_num) {


 147                              used,
 148                              lowest_non_clean,
 149                              lowest_non_clean_base_chunk_index,
 150                              lowest_non_clean_chunk_size);
 151 
 152     // We want the LNC array updates above in process_chunk_boundaries
 153     // to be visible before any of the card table value changes as a
 154     // result of the dirty card iteration below.
 155     OrderAccess::storestore();
 156 
 157     // We want to clear the cards: clear_cl here does the work of finding
 158     // contiguous dirty ranges of cards to process and clear.
 159     clear_cl.do_MemRegion(chunk_mr);
 160 
 161     // Find the next chunk of the stride.
 162     chunk_card_start += ParGCCardsPerStrideChunk * n_strides;
 163   }
 164 }
 165 
 166 void
 167 CardTableRS::
 168 process_chunk_boundaries(Space* sp,
 169                          DirtyCardToOopClosure* dcto_cl,
 170                          MemRegion chunk_mr,
 171                          MemRegion used,
 172                          jbyte** lowest_non_clean,
 173                          uintptr_t lowest_non_clean_base_chunk_index,
 174                          size_t    lowest_non_clean_chunk_size)
 175 {
 176   // We must worry about non-array objects that cross chunk boundaries,
 177   // because such objects are both precisely and imprecisely marked:
 178   // .. if the head of such an object is dirty, the entire object
 179   //    needs to be scanned, under the interpretation that this
 180   //    was an imprecise mark
 181   // .. if the head of such an object is not dirty, we can assume
 182   //    precise marking and it's efficient to scan just the dirty
 183   //    cards.
 184   // In either case, each scanned reference must be scanned precisely
 185   // once so as to avoid cloning of a young referent. For efficiency,
 186   // our closures depend on this property and do not protect against
 187   // double scans.


 356           }  // else continue to look for a non-NULL entry if any
 357         }
 358         assert(limit_card != NULL && max_to_do != NULL, "Error");
 359       }
 360       assert(max_to_do != NULL, "OOPS 1 !");
 361     }
 362     assert(max_to_do != NULL, "OOPS 2!");
 363   } else {
 364     max_to_do = used.end();
 365   }
 366   assert(max_to_do != NULL, "OOPS 3!");
 367   // Now we can set the closure we're using so it doesn't to beyond
 368   // max_to_do.
 369   dcto_cl->set_min_done(max_to_do);
 370 #ifndef PRODUCT
 371   dcto_cl->set_last_bottom(max_to_do);
 372 #endif
 373 }
 374 
 375 void
 376 CardTableRS::
 377 get_LNC_array_for_space(Space* sp,
 378                         jbyte**& lowest_non_clean,
 379                         uintptr_t& lowest_non_clean_base_chunk_index,
 380                         size_t& lowest_non_clean_chunk_size) {
 381 
 382   int       i        = find_covering_region_containing(sp->bottom());
 383   MemRegion covered  = _covered[i];
 384   size_t    n_chunks = chunks_to_cover(covered);
 385 
 386   // Only the first thread to obtain the lock will resize the
 387   // LNC array for the covered region.  Any later expansion can't affect
 388   // the used_at_save_marks region.
 389   // (I observed a bug in which the first thread to execute this would
 390   // resize, and then it would cause "expand_and_allocate" that would
 391   // increase the number of chunks in the covered region.  Then a second
 392   // thread would come and execute this, see that the size didn't match,
 393   // and free and allocate again.  So the first thread would be using a
 394   // freed "_lowest_non_clean" array.)
 395 
 396   // Do a dirty read here. If we pass the conditional then take the rare


< prev index next >