1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_HPP
  26 
  27 #include "gc/shared/markBitMap.hpp"
  28 #include "memory/allocation.hpp"
  29 #include "memory/memRegion.hpp"
  30 #include "oops/oopsHierarchy.hpp"
  31 
  32 class HeapWord;
  33 
  34 /**
  35  * Encapsulate a marking bitmap with the top-at-mark-start and top-bitmaps array.
  36  */
  37 class ShenandoahMarkingContext : public CHeapObj<mtGC> {
  38 private:
  39   MarkBitMap _mark_bit_map;
  40 
  41   HeapWord** const _top_bitmaps;
  42   HeapWord** const _top_at_mark_starts_base;
  43   HeapWord** const _top_at_mark_starts;
  44 
  45   ShenandoahSharedFlag _is_complete;
  46 
  47 public:
  48   ShenandoahMarkingContext(MemRegion heap_region, MemRegion bitmap_region, size_t num_regions);
  49 
  50   /*
  51    * Marks the object. Returns true if the object has not been marked before and has
  52    * been marked by this thread. Returns false if the object has already been marked,
  53    * or if a competing thread succeeded in marking this object.
  54    */
  55   inline bool mark(oop obj);
  56 
  57   inline bool is_marked(oop obj) const;
  58 
  59   inline bool allocated_after_mark_start(HeapWord* addr) const;
  60 
  61   inline MarkBitMap* mark_bit_map();
  62 
  63   HeapWord* top_at_mark_start(ShenandoahHeapRegion* r) const;
  64   void capture_top_at_mark_start(ShenandoahHeapRegion* r);
  65   void reset_top_at_mark_start(ShenandoahHeapRegion* r);
  66   void initialize_top_at_mark_start(ShenandoahHeapRegion* r);
  67 
  68   void reset_top_bitmap(ShenandoahHeapRegion *r);
  69   void clear_bitmap(ShenandoahHeapRegion *r);
  70 
  71   bool is_bitmap_clear() const;
  72   bool is_bitmap_clear_range(HeapWord* start, HeapWord* end) const;
  73 
  74   bool is_complete();
  75   void mark_complete();
  76   void mark_incomplete();
  77 
  78 };
  79 
  80 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHMARKINGCONTEXT_HPP