13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 #ifndef SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP 26 #define SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP 27 28 #include "memory/allocation.hpp" 29 #include "memory/padded.hpp" 30 #include "oops/oop.hpp" 31 #include "utilities/stack.hpp" 32 33 class GCTaskManager; 34 class WorkGang; 35 36 class PreservedMarks VALUE_OBJ_CLASS_SPEC { 37 private: 38 class OopAndMarkOop { 39 private: 40 oop _o; 41 markOop _m; 42 43 public: 44 OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { } 45 46 void set_mark() const { 47 _o->set_mark(_m); 48 } 49 }; 50 typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack; 51 52 OopAndMarkOopStack _stack; 53 54 inline bool should_preserve_mark(oop obj, markOop m) const; 55 inline void push(oop obj, markOop m); 56 57 public: 58 size_t size() const { return _stack.size(); } 59 inline void push_if_necessary(oop obj, markOop m); 60 // Iterate over the stack, restore all preserved marks, and 61 // reclaim the memory taken up by the stack segments. 62 void restore(); 63 64 inline static void init_forwarded_mark(oop obj); 65 66 // Assert the stack is empty and has no cached segments. 67 void assert_empty() PRODUCT_RETURN; 68 69 inline PreservedMarks(); 70 ~PreservedMarks() { assert_empty(); } 71 }; 72 73 class RemoveForwardedPointerClosure: public ObjectClosure { 74 public: 75 virtual void do_object(oop obj); 76 }; 77 78 class PreservedMarksSet : public CHeapObj<mtGC> { 79 private: 80 // true -> _stacks will be allocated in the C heap 81 // false -> _stacks will be allocated in the resource arena 82 const bool _in_c_heap; 83 84 // Number of stacks we have allocated (typically, one stack per GC worker). 85 // This should be >= 1 if the stacks have been initialized, 86 // or == 0 if they have not. 87 uint _num; 88 89 // Stack array (typically, one stack per GC worker) of length _num. 90 // This should be != NULL if the stacks have been initialized, 91 // or == NULL if they have not. 92 Padded<PreservedMarks>* _stacks; 93 94 // Internal version of restore() that uses a WorkGang for parallelism. 95 void restore_internal(WorkGang* workers, volatile size_t* total_size_addr); 96 97 // Internal version of restore() that uses a GCTaskManager for parallelism. 98 void restore_internal(GCTaskManager* gc_task_manager, 99 volatile size_t* total_size_addr); 100 101 public: 102 uint num() const { return _num; } 103 104 // Return the i'th stack. 105 PreservedMarks* get(uint i = 0) const { 106 assert(_num > 0 && _stacks != NULL, "stacks should have been initialized"); 107 assert(i < _num, "pre-condition"); 108 return (_stacks + i); 109 } 110 111 // Allocate stack array. 112 void init(uint num); 113 114 // Itrerate over all stacks, restore all presered marks, and reclaim 115 // the memory taken up by the stack segments. If the executor is 116 // NULL, restoration will be done serially. If the executor is not 117 // NULL, restoration could be done in parallel (when it makes 118 // sense). Supported executors: WorkGang (Serial, CMS, G1), 119 // GCTaskManager (PS). 120 template <class E> 121 inline void restore(E* executor); 122 123 // Reclaim stack array. 124 void reclaim(); 125 126 // Assert all the stacks are empty and have no cached segments. 127 void assert_empty() PRODUCT_RETURN; 128 129 PreservedMarksSet(bool in_c_heap) 130 : _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { } 131 132 ~PreservedMarksSet() { 133 assert(_stacks == NULL && _num == 0, "stacks should have been reclaimed"); 134 } 135 }; 136 137 #endif // SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP | 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 #ifndef SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP 26 #define SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP 27 28 #include "memory/allocation.hpp" 29 #include "memory/padded.hpp" 30 #include "oops/oop.hpp" 31 #include "utilities/stack.hpp" 32 33 class PreservedMarksSet; 34 class WorkGang; 35 36 class PreservedMarks VALUE_OBJ_CLASS_SPEC { 37 private: 38 class OopAndMarkOop { 39 private: 40 oop _o; 41 markOop _m; 42 43 public: 44 OopAndMarkOop(oop obj, markOop m) : _o(obj), _m(m) { } 45 46 void set_mark() const { 47 _o->set_mark(_m); 48 } 49 }; 50 typedef Stack<OopAndMarkOop, mtGC> OopAndMarkOopStack; 51 52 OopAndMarkOopStack _stack; 53 54 inline bool should_preserve_mark(oop obj, markOop m) const; 55 inline void push(oop obj, markOop m); 56 57 public: 58 size_t size() const { return _stack.size(); } 59 inline void push_if_necessary(oop obj, markOop m); 60 // Iterate over the stack, restore all preserved marks, and 61 // reclaim the memory taken up by the stack segments. 62 void restore(); 63 64 void restore_and_increment(volatile size_t* const _total_size_addr); 65 inline static void init_forwarded_mark(oop obj); 66 67 // Assert the stack is empty and has no cached segments. 68 void assert_empty() PRODUCT_RETURN; 69 70 inline PreservedMarks(); 71 ~PreservedMarks() { assert_empty(); } 72 }; 73 74 class RemoveForwardedPointerClosure: public ObjectClosure { 75 public: 76 virtual void do_object(oop obj); 77 }; 78 79 class RestorePreservedMarksTaskExecutor { 80 public: 81 void virtual restore(PreservedMarksSet* preserved_marks_set, 82 volatile size_t* total_size_addr) = 0; 83 }; 84 85 class SharedRestorePreservedMarksTaskExecutor : public RestorePreservedMarksTaskExecutor { 86 private: 87 WorkGang* _workers; 88 89 public: 90 SharedRestorePreservedMarksTaskExecutor(WorkGang* workers) : _workers(workers) { } 91 92 void restore(PreservedMarksSet* preserved_marks_set, 93 volatile size_t* total_size_addr); 94 95 }; 96 97 class PreservedMarksSet : public CHeapObj<mtGC> { 98 private: 99 // true -> _stacks will be allocated in the C heap 100 // false -> _stacks will be allocated in the resource arena 101 const bool _in_c_heap; 102 103 // Number of stacks we have allocated (typically, one stack per GC worker). 104 // This should be >= 1 if the stacks have been initialized, 105 // or == 0 if they have not. 106 uint _num; 107 108 // Stack array (typically, one stack per GC worker) of length _num. 109 // This should be != NULL if the stacks have been initialized, 110 // or == NULL if they have not. 111 Padded<PreservedMarks>* _stacks; 112 113 public: 114 uint num() const { return _num; } 115 116 // Return the i'th stack. 117 PreservedMarks* get(uint i = 0) const { 118 assert(_num > 0 && _stacks != NULL, "stacks should have been initialized"); 119 assert(i < _num, "pre-condition"); 120 return (_stacks + i); 121 } 122 123 // Allocate stack array. 124 void init(uint num); 125 126 // Iterate over all stacks, restore all preserved marks, and reclaim 127 // the memory taken up by the stack segments. 128 // Supported executors: SharedRestorePreservedMarksTaskExecutor (Serial, CMS, G1), 129 // PSRestorePreservedMarksTaskExecutor (PS). 130 inline void restore(RestorePreservedMarksTaskExecutor* executor); 131 132 // Reclaim stack array. 133 void reclaim(); 134 135 // Assert all the stacks are empty and have no cached segments. 136 void assert_empty() PRODUCT_RETURN; 137 138 PreservedMarksSet(bool in_c_heap) 139 : _in_c_heap(in_c_heap), _num(0), _stacks(NULL) { } 140 141 ~PreservedMarksSet() { 142 assert(_stacks == NULL && _num == 0, "stacks should have been reclaimed"); 143 } 144 }; 145 146 #endif // SHARE_VM_GC_SHARED_PRESERVEDMARKS_HPP |