hotspot/src/share/vm/memory/cardTableModRefBS.hpp
changeset 1374 4c24294029a9
parent 360 21d113ecbf6a
child 1388 3677f5f3d66b
equal deleted inserted replaced
615:570062d730b2 1374:4c24294029a9
    52 
    52 
    53   enum CardValues {
    53   enum CardValues {
    54     clean_card                  = -1,
    54     clean_card                  = -1,
    55     dirty_card                  =  0,
    55     dirty_card                  =  0,
    56     precleaned_card             =  1,
    56     precleaned_card             =  1,
       
    57     claimed_card                =  3,
    57     last_card                   =  4,
    58     last_card                   =  4,
    58     CT_MR_BS_last_reserved      = 10
    59     CT_MR_BS_last_reserved      = 10
    59   };
    60   };
    60 
    61 
    61   // dirty and precleaned are equivalent wrt younger_refs_iter.
    62   // dirty and precleaned are equivalent wrt younger_refs_iter.
   146   // The card table byte one after the card marking array
   147   // The card table byte one after the card marking array
   147   // entry for argument address. Typically used for higher bounds
   148   // entry for argument address. Typically used for higher bounds
   148   // for loops iterating through the card table.
   149   // for loops iterating through the card table.
   149   jbyte* byte_after(const void* p) const {
   150   jbyte* byte_after(const void* p) const {
   150     return byte_for(p) + 1;
   151     return byte_for(p) + 1;
   151   }
       
   152 
       
   153   // Mapping from card marking array entry to address of first word
       
   154   HeapWord* addr_for(const jbyte* p) const {
       
   155     assert(p >= _byte_map && p < _byte_map + _byte_map_size,
       
   156            "out of bounds access to card marking array");
       
   157     size_t delta = pointer_delta(p, byte_map_base, sizeof(jbyte));
       
   158     HeapWord* result = (HeapWord*) (delta << card_shift);
       
   159     assert(_whole_heap.contains(result),
       
   160            "out of bounds accessor from card marking array");
       
   161     return result;
       
   162   }
   152   }
   163 
   153 
   164   // Iterate over the portion of the card-table which covers the given
   154   // Iterate over the portion of the card-table which covers the given
   165   // region mr in the given space and apply cl to any dirty sub-regions
   155   // region mr in the given space and apply cl to any dirty sub-regions
   166   // of mr. cl and dcto_cl must either be the same closure or cl must
   156   // of mr. cl and dcto_cl must either be the same closure or cl must
   261     card_shift                  = 9,
   251     card_shift                  = 9,
   262     card_size                   = 1 << card_shift,
   252     card_size                   = 1 << card_shift,
   263     card_size_in_words          = card_size / sizeof(HeapWord)
   253     card_size_in_words          = card_size / sizeof(HeapWord)
   264   };
   254   };
   265 
   255 
       
   256   static int clean_card_val()      { return clean_card; }
       
   257   static int dirty_card_val()      { return dirty_card; }
       
   258   static int claimed_card_val()    { return claimed_card; }
       
   259   static int precleaned_card_val() { return precleaned_card; }
       
   260 
   266   // For RTTI simulation.
   261   // For RTTI simulation.
   267   BarrierSet::Name kind() { return BarrierSet::CardTableModRef; }
       
   268   bool is_a(BarrierSet::Name bsn) {
   262   bool is_a(BarrierSet::Name bsn) {
   269     return bsn == BarrierSet::CardTableModRef || bsn == BarrierSet::ModRef;
   263     return bsn == BarrierSet::CardTableModRef || ModRefBarrierSet::is_a(bsn);
   270   }
   264   }
   271 
   265 
   272   CardTableModRefBS(MemRegion whole_heap, int max_covered_regions);
   266   CardTableModRefBS(MemRegion whole_heap, int max_covered_regions);
   273 
   267 
   274   // *** Barrier set functions.
   268   // *** Barrier set functions.
       
   269 
       
   270   bool has_write_ref_pre_barrier() { return false; }
   275 
   271 
   276   inline bool write_ref_needs_barrier(void* field, oop new_val) {
   272   inline bool write_ref_needs_barrier(void* field, oop new_val) {
   277     // Note that this assumes the perm gen is the highest generation
   273     // Note that this assumes the perm gen is the highest generation
   278     // in the address space
   274     // in the address space
   279     return new_val != NULL && !new_val->is_perm();
   275     return new_val != NULL && !new_val->is_perm();
   313     return is_card_aligned(addr);
   309     return is_card_aligned(addr);
   314   }
   310   }
   315 
   311 
   316   // *** Card-table-barrier-specific things.
   312   // *** Card-table-barrier-specific things.
   317 
   313 
       
   314   inline void inline_write_ref_field_pre(void* field, oop newVal) {}
       
   315 
   318   inline void inline_write_ref_field(void* field, oop newVal) {
   316   inline void inline_write_ref_field(void* field, oop newVal) {
   319     jbyte* byte = byte_for(field);
   317     jbyte* byte = byte_for(field);
   320     *byte = dirty_card;
   318     *byte = dirty_card;
       
   319   }
       
   320 
       
   321   // These are used by G1, when it uses the card table as a temporary data
       
   322   // structure for card claiming.
       
   323   bool is_card_dirty(size_t card_index) {
       
   324     return _byte_map[card_index] == dirty_card_val();
       
   325   }
       
   326 
       
   327   void mark_card_dirty(size_t card_index) {
       
   328     _byte_map[card_index] = dirty_card_val();
       
   329   }
       
   330 
       
   331   bool is_card_claimed(size_t card_index) {
       
   332     return _byte_map[card_index] == claimed_card_val();
       
   333   }
       
   334 
       
   335   bool claim_card(size_t card_index);
       
   336 
       
   337   bool is_card_clean(size_t card_index) {
       
   338     return _byte_map[card_index] == clean_card_val();
   321   }
   339   }
   322 
   340 
   323   // Card marking array base (adjusted for heap low boundary)
   341   // Card marking array base (adjusted for heap low boundary)
   324   // This would be the 0th element of _byte_map, if the heap started at 0x0.
   342   // This would be the 0th element of _byte_map, if the heap started at 0x0.
   325   // But since the heap starts at some higher address, this points to somewhere
   343   // But since the heap starts at some higher address, this points to somewhere
   342   PrecisionStyle precision() {
   360   PrecisionStyle precision() {
   343     return ObjHeadPreciseArray; // Only one supported for now.
   361     return ObjHeadPreciseArray; // Only one supported for now.
   344   }
   362   }
   345 
   363 
   346   // ModRefBS functions.
   364   // ModRefBS functions.
   347   void invalidate(MemRegion mr);
   365   virtual void invalidate(MemRegion mr, bool whole_heap = false);
   348   void clear(MemRegion mr);
   366   void clear(MemRegion mr);
       
   367   void dirty(MemRegion mr);
   349   void mod_oop_in_space_iterate(Space* sp, OopClosure* cl,
   368   void mod_oop_in_space_iterate(Space* sp, OopClosure* cl,
   350                                 bool clear = false,
   369                                 bool clear = false,
   351                                 bool before_save_marks = false);
   370                                 bool before_save_marks = false);
   352 
   371 
   353   // *** Card-table-RemSet-specific things.
   372   // *** Card-table-RemSet-specific things.
   373     non_clean_card_iterate_work(mr, cl, clear);
   392     non_clean_card_iterate_work(mr, cl, clear);
   374   }
   393   }
   375 
   394 
   376   static uintx ct_max_alignment_constraint();
   395   static uintx ct_max_alignment_constraint();
   377 
   396 
   378   // Apply closure cl to the dirty cards lying completely
   397   // Apply closure "cl" to the dirty cards containing some part of
   379   // within MemRegion mr, setting the cards to precleaned.
   398   // MemRegion "mr".
   380   void      dirty_card_iterate(MemRegion mr, MemRegionClosure* cl);
   399   void dirty_card_iterate(MemRegion mr, MemRegionClosure* cl);
   381 
   400 
   382   // Return the MemRegion corresponding to the first maximal run
   401   // Return the MemRegion corresponding to the first maximal run
   383   // of dirty cards lying completely within MemRegion mr, after
   402   // of dirty cards lying completely within MemRegion mr.
   384   // marking those cards precleaned.
   403   // If reset is "true", then sets those card table entries to the given
   385   MemRegion dirty_card_range_after_preclean(MemRegion mr);
   404   // value.
       
   405   MemRegion dirty_card_range_after_reset(MemRegion mr, bool reset,
       
   406                                          int reset_val);
   386 
   407 
   387   // Set all the dirty cards in the given region to precleaned state.
   408   // Set all the dirty cards in the given region to precleaned state.
   388   void preclean_dirty_cards(MemRegion mr);
   409   void preclean_dirty_cards(MemRegion mr);
       
   410 
       
   411   // Provide read-only access to the card table array.
       
   412   const jbyte* byte_for_const(const void* p) const {
       
   413     return byte_for(p);
       
   414   }
       
   415   const jbyte* byte_after_const(const void* p) const {
       
   416     return byte_after(p);
       
   417   }
       
   418 
       
   419   // Mapping from card marking array entry to address of first word
       
   420   HeapWord* addr_for(const jbyte* p) const {
       
   421     assert(p >= _byte_map && p < _byte_map + _byte_map_size,
       
   422            "out of bounds access to card marking array");
       
   423     size_t delta = pointer_delta(p, byte_map_base, sizeof(jbyte));
       
   424     HeapWord* result = (HeapWord*) (delta << card_shift);
       
   425     assert(_whole_heap.contains(result),
       
   426            "out of bounds accessor from card marking array");
       
   427     return result;
       
   428   }
   389 
   429 
   390   // Mapping from address to card marking array index.
   430   // Mapping from address to card marking array index.
   391   int index_for(void* p) {
   431   int index_for(void* p) {
   392     assert(_whole_heap.contains(p),
   432     assert(_whole_heap.contains(p),
   393            "out of bounds access to card marking array");
   433            "out of bounds access to card marking array");
   400   void verify_clean_region(MemRegion mr) PRODUCT_RETURN;
   440   void verify_clean_region(MemRegion mr) PRODUCT_RETURN;
   401 
   441 
   402   static size_t par_chunk_heapword_alignment() {
   442   static size_t par_chunk_heapword_alignment() {
   403     return CardsPerStrideChunk * card_size_in_words;
   443     return CardsPerStrideChunk * card_size_in_words;
   404   }
   444   }
       
   445 
   405 };
   446 };
   406 
   447 
   407 class CardTableRS;
   448 class CardTableRS;
   408 
   449 
   409 // A specialization for the CardTableRS gen rem set.
   450 // A specialization for the CardTableRS gen rem set.