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 "memory/space.hpp"
  28 
  29 class ShenandoahHeapRegion : public ContiguousSpace {
  30 private:
  31   static Monitor _mem_protect_lock;
  32 
  33 private:
  34   static size_t RegionSizeBytes;
  35   static size_t RegionSizeShift;
  36 
  37 private:
  38   ShenandoahHeap* _heap;
  39   size_t _region_number;
  40   volatile jint _live_data;
  41   MemRegion reserved;
  42 
  43   bool _humongous_start;
  44   bool _humongous_continuation;
  45 
  46   bool _recycled;
  47 
  48   HeapWord* _new_top;
  49 
  50   volatile jint _critical_pins;
  51 
  52 #ifdef ASSERT
  53   int _mem_protection_level;
  54 #endif
  55 
  56 public:
  57   ShenandoahHeapRegion(ShenandoahHeap* heap, HeapWord* start, size_t regionSize, size_t index);
  58 
  59   static void setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size);
  60 
  61   inline static size_t region_size_bytes() {
  62     return ShenandoahHeapRegion::RegionSizeBytes;
  63   }
  64 
  65   inline static size_t region_size_shift() {
  66     return ShenandoahHeapRegion::RegionSizeShift;
  67   }
  68 
  69   // Convert to jint with sanity checking
  70   inline static jint region_size_bytes_jint() {
  71     assert (ShenandoahHeapRegion::RegionSizeBytes <= (size_t)max_jint, "sanity");
  72     return (jint)ShenandoahHeapRegion::RegionSizeBytes;
  73   }
  74 
  75   // Convert to jint with sanity checking
  76   inline static jint region_size_shift_jint() {
  77     assert (ShenandoahHeapRegion::RegionSizeShift <= (size_t)max_jint, "sanity");
  78     return (jint)ShenandoahHeapRegion::RegionSizeShift;
  79   }
  80 
  81   size_t region_number() const;
  82 
  83   // Roll back the previous allocation of an object with specified size.
  84   // Returns TRUE when successful, FALSE if not successful or not supported.
  85   bool rollback_allocation(uint size);
  86 
  87   void clear_live_data();
  88   void set_live_data(size_t s);
  89   inline void increase_live_data_words(size_t s);
  90   inline void increase_live_data_words(jint s);
  91 
  92   void set_recently_allocated(bool value);
  93   bool is_recently_allocated() const;
  94 
  95   bool has_live() const;
  96   size_t get_live_data_bytes() const;
  97   size_t get_live_data_words() const;
  98 
  99   void print_on(outputStream* st) const;
 100 
 101   size_t garbage() const;
 102 
 103   void recycle();
 104 
 105   void oop_iterate_skip_unreachable(ExtendedOopClosure* cl, bool skip_unreachable_objects);
 106 
 107   void object_iterate_interruptible(ObjectClosure* blk, bool allow_cancel);
 108 
 109   HeapWord* object_iterate_careful(ObjectClosureCareful* cl);
 110 
 111   HeapWord* block_start_const(const void* p) const;
 112 
 113   // Just before GC we need to fill the current region.
 114   void fill_region();
 115 
 116   bool in_collection_set() const;
 117 
 118   void set_in_collection_set(bool b);
 119 
 120   void set_humongous_start(bool start);
 121   void set_humongous_continuation(bool continuation);
 122 
 123   bool is_humongous() const;
 124   bool is_humongous_start() const;
 125   bool is_humongous_continuation() const;
 126 
 127 #ifdef ASSERT
 128   void memProtectionOn();
 129   void memProtectionOff();
 130 #endif
 131 
 132   // The following are for humongous regions.  We need to save the
 133   markOop saved_mark_word;
 134   void save_mark_word(oop obj) {saved_mark_word = obj->mark();}
 135   markOop mark_word() {return saved_mark_word;}
 136 
 137   void set_new_top(HeapWord* new_top) { _new_top = new_top; }
 138   HeapWord* new_top() const { return _new_top; }
 139 
 140   void pin();
 141   void unpin();
 142 
 143   bool is_pinned();
 144 
 145 };
 146 
 147 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP