1 /*
   2  * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates.
   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_SHENANDOAHHEAPREGION_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
  26 
  27 #include "gc/shared/space.hpp"
  28 #include "memory/universe.hpp"
  29 #include "utilities/sizes.hpp"
  30 
  31 class ShenandoahHeapRegion : public ContiguousSpace {
  32 private:
  33   static Monitor _mem_protect_lock;
  34 
  35 public:
  36   static size_t RegionSizeBytes;
  37   static size_t RegionSizeShift;
  38 
  39 private:
  40   size_t _region_number;
  41   volatile size_t liveData;
  42   MemRegion reserved;
  43   bool _is_in_collection_set;
  44 
  45   bool _humongous_start;
  46   bool _humongous_continuation;
  47 
  48   HeapWord* _top_at_mark_start;
  49   HeapWord* _top_at_prev_mark_start;
  50   HeapWord* _top_prev_mark_bitmap;
  51 
  52   HeapWord* _new_top;
  53 
  54 #ifdef ASSERT
  55   int _mem_protection_level;
  56 #endif
  57 
  58 public:
  59   static void setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size);
  60 
  61   jint initialize_heap_region(HeapWord* start, size_t regionSize, int index);
  62 
  63 
  64   size_t region_number() const;
  65 
  66   // Roll back the previous allocation of an object with specified size.
  67   // Returns TRUE when successful, FALSE if not successful or not supported.
  68   bool rollback_allocation(uint size);
  69 
  70   void clearLiveData();
  71   void setLiveData(size_t s);
  72   inline void increase_live_data(size_t s);
  73 
  74   size_t getLiveData() const;
  75 
  76   void print_on(outputStream* st) const;
  77 
  78   size_t garbage() const;
  79 
  80   void recycle();
  81   void reset();
  82 
  83   void oop_iterate_skip_unreachable(ExtendedOopClosure* cl, bool skip_unreachable_objects);
  84 
  85   void marked_object_iterate(ObjectClosure* blk);
  86 
  87   void object_iterate_interruptible(ObjectClosure* blk, bool allow_cancel);
  88 
  89   HeapWord* object_iterate_careful(ObjectClosureCareful* cl);
  90 
  91   HeapWord* block_start_const(const void* p) const;
  92 
  93   // Just before GC we need to fill the current region.
  94   void fill_region();
  95 
  96   bool is_in_collection_set() const;
  97 
  98   void set_is_in_collection_set(bool b);
  99 
 100   void set_humongous_start(bool start);
 101   void set_humongous_continuation(bool continuation);
 102 
 103   bool is_humongous() const;
 104   bool is_humongous_start() const;
 105   bool is_humongous_continuation() const;
 106 
 107 #ifdef ASSERT
 108   void memProtectionOn();
 109   void memProtectionOff();
 110 #endif
 111 
 112   static ByteSize is_in_collection_set_offset();
 113   // The following are for humongous regions.  We need to save the
 114   markOop saved_mark_word;
 115   void save_mark_word(oop obj) {saved_mark_word = obj->mark();}
 116   markOop mark_word() {return saved_mark_word;}
 117 
 118   virtual CompactibleSpace* next_compaction_space() const;
 119 
 120   // Override for scan_and_forward support.
 121   void prepare_for_compaction(CompactPoint* cp);
 122   void adjust_pointers();
 123   void compact();
 124 
 125   void init_top_at_mark_start();
 126   void set_top_at_mark_start(HeapWord* top);
 127   HeapWord* top_at_mark_start();
 128   void reset_top_at_prev_mark_start();
 129   HeapWord* top_at_prev_mark_start();
 130   HeapWord* top_prev_mark_bitmap();
 131 
 132   void set_top_prev_mark_bitmap(HeapWord* top);
 133   void swap_top_at_mark_start();
 134 
 135   inline bool allocated_after_mark_start(HeapWord* addr);
 136   bool allocated_after_prev_mark_start(HeapWord* addr) const;
 137 
 138   void set_new_top(HeapWord* new_top) { _new_top = new_top; }
 139   HeapWord* new_top() const { return _new_top; }
 140 
 141 private:
 142   void do_reset();
 143 
 144 };
 145 
 146 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP