src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp

Wed, 03 Mar 2010 14:48:26 -0800

author
jcoomes
date
Wed, 03 Mar 2010 14:48:26 -0800
changeset 1746
2a1472c30599
parent 1383
89e0543e1737
child 1907
c18cbe5936b8
permissions
-rw-r--r--

4396719: Mark Sweep stack overflow on deeply nested Object arrays
Summary: Use an explicit stack for object arrays and process them in chunks.
Reviewed-by: iveresov, apetrusenko

duke@435 1 /*
xdono@1383 2 * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Move to some global location
duke@435 26 #define HAS_BEEN_MOVED 0x1501d01d
duke@435 27 // End move to some global location
duke@435 28
duke@435 29
duke@435 30 class MutableSpace;
duke@435 31 class PSOldGen;
duke@435 32 class ParCompactionManager;
duke@435 33 class ObjectStartArray;
duke@435 34 class ParallelCompactData;
duke@435 35 class ParMarkBitMap;
duke@435 36
duke@435 37 class ParCompactionManager : public CHeapObj {
duke@435 38 friend class ParallelTaskTerminator;
duke@435 39 friend class ParMarkBitMap;
duke@435 40 friend class PSParallelCompact;
jcoomes@810 41 friend class StealRegionCompactionTask;
duke@435 42 friend class UpdateAndFillClosure;
duke@435 43 friend class RefProcTaskExecutor;
duke@435 44
duke@435 45 public:
duke@435 46
duke@435 47 // ------------------------ Don't putback if not needed
duke@435 48 // Actions that the compaction manager should take.
duke@435 49 enum Action {
duke@435 50 Update,
duke@435 51 Copy,
duke@435 52 UpdateAndCopy,
duke@435 53 CopyAndUpdate,
duke@435 54 VerifyUpdate,
duke@435 55 ResetObjects,
duke@435 56 NotValid
duke@435 57 };
duke@435 58 // ------------------------ End don't putback if not needed
duke@435 59
duke@435 60 private:
jcoomes@1746 61 // 32-bit: 4K * 8 = 32KiB; 64-bit: 8K * 16 = 128KiB
jcoomes@1746 62 #define OBJARRAY_QUEUE_SIZE (1 << NOT_LP64(12) LP64_ONLY(13))
jcoomes@1746 63 typedef GenericTaskQueue<ObjArrayTask, OBJARRAY_QUEUE_SIZE> ObjArrayTaskQueue;
jcoomes@1746 64 typedef GenericTaskQueueSet<ObjArrayTaskQueue> ObjArrayTaskQueueSet;
jcoomes@1746 65 #undef OBJARRAY_QUEUE_SIZE
jcoomes@1746 66
jcoomes@810 67 static ParCompactionManager** _manager_array;
jcoomes@810 68 static OopTaskQueueSet* _stack_array;
jcoomes@1746 69 static ObjArrayTaskQueueSet* _objarray_queues;
jcoomes@810 70 static ObjectStartArray* _start_array;
jcoomes@810 71 static RegionTaskQueueSet* _region_array;
jcoomes@810 72 static PSOldGen* _old_gen;
duke@435 73
jcoomes@1746 74 private:
jcoomes@810 75 OopTaskQueue _marking_stack;
jcoomes@810 76 GrowableArray<oop>* _overflow_stack;
jcoomes@1746 77
jcoomes@1746 78 typedef GrowableArray<ObjArrayTask> ObjArrayOverflowStack;
jcoomes@1746 79 ObjArrayTaskQueue _objarray_queue;
jcoomes@1746 80 ObjArrayOverflowStack* _objarray_overflow_stack;
jcoomes@1746 81
duke@435 82 // Is there a way to reuse the _marking_stack for the
jcoomes@810 83 // saving empty regions? For now just create a different
duke@435 84 // type of TaskQueue.
duke@435 85
jcoomes@810 86 #ifdef USE_RegionTaskQueueWithOverflow
jcoomes@810 87 RegionTaskQueueWithOverflow _region_stack;
duke@435 88 #else
jcoomes@810 89 RegionTaskQueue _region_stack;
jcoomes@810 90 GrowableArray<size_t>* _region_overflow_stack;
duke@435 91 #endif
duke@435 92
duke@435 93 #if 1 // does this happen enough to need a per thread stack?
jcoomes@810 94 GrowableArray<Klass*>* _revisit_klass_stack;
ysr@1376 95 GrowableArray<DataLayout*>* _revisit_mdo_stack;
duke@435 96 #endif
duke@435 97 static ParMarkBitMap* _mark_bitmap;
duke@435 98
duke@435 99 Action _action;
duke@435 100
duke@435 101 static PSOldGen* old_gen() { return _old_gen; }
duke@435 102 static ObjectStartArray* start_array() { return _start_array; }
jcoomes@810 103 static OopTaskQueueSet* stack_array() { return _stack_array; }
duke@435 104
duke@435 105 static void initialize(ParMarkBitMap* mbm);
duke@435 106
duke@435 107 protected:
duke@435 108 // Array of tasks. Needed by the ParallelTaskTerminator.
jcoomes@810 109 static RegionTaskQueueSet* region_array() { return _region_array; }
jcoomes@810 110 OopTaskQueue* marking_stack() { return &_marking_stack; }
jcoomes@810 111 GrowableArray<oop>* overflow_stack() { return _overflow_stack; }
jcoomes@810 112 #ifdef USE_RegionTaskQueueWithOverflow
jcoomes@810 113 RegionTaskQueueWithOverflow* region_stack() { return &_region_stack; }
duke@435 114 #else
jcoomes@810 115 RegionTaskQueue* region_stack() { return &_region_stack; }
jcoomes@810 116 GrowableArray<size_t>* region_overflow_stack() {
jcoomes@810 117 return _region_overflow_stack;
jcoomes@810 118 }
duke@435 119 #endif
duke@435 120
duke@435 121 // Pushes onto the marking stack. If the marking stack is full,
duke@435 122 // pushes onto the overflow stack.
duke@435 123 void stack_push(oop obj);
duke@435 124 // Do not implement an equivalent stack_pop. Deal with the
duke@435 125 // marking stack and overflow stack directly.
duke@435 126
jcoomes@810 127 // Pushes onto the region stack. If the region stack is full,
jcoomes@810 128 // pushes onto the region overflow stack.
jcoomes@810 129 void region_stack_push(size_t region_index);
duke@435 130
jcoomes@1746 131 public:
duke@435 132 Action action() { return _action; }
duke@435 133 void set_action(Action v) { _action = v; }
duke@435 134
duke@435 135 inline static ParCompactionManager* manager_array(int index);
duke@435 136
duke@435 137 ParCompactionManager();
duke@435 138 ~ParCompactionManager();
duke@435 139
duke@435 140 void allocate_stacks();
duke@435 141 void deallocate_stacks();
duke@435 142 ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }
duke@435 143
duke@435 144 // Take actions in preparation for a compaction.
duke@435 145 static void reset();
duke@435 146
duke@435 147 // void drain_stacks();
duke@435 148
duke@435 149 bool should_update();
duke@435 150 bool should_copy();
duke@435 151 bool should_verify_only();
duke@435 152 bool should_reset_only();
duke@435 153
duke@435 154 #if 1
duke@435 155 // Probably stays as a growable array
duke@435 156 GrowableArray<Klass*>* revisit_klass_stack() { return _revisit_klass_stack; }
ysr@1376 157 GrowableArray<DataLayout*>* revisit_mdo_stack() { return _revisit_mdo_stack; }
duke@435 158 #endif
duke@435 159
duke@435 160 // Save oop for later processing. Must not fail.
duke@435 161 void save_for_scanning(oop m);
duke@435 162 // Get a oop for scanning. If returns null, no oop were found.
duke@435 163 oop retrieve_for_scanning();
duke@435 164
jcoomes@1746 165 inline void push_objarray(oop obj, size_t index);
jcoomes@1746 166
jcoomes@810 167 // Save region for later processing. Must not fail.
jcoomes@810 168 void save_for_processing(size_t region_index);
jcoomes@810 169 // Get a region for processing. If returns null, no region were found.
jcoomes@810 170 bool retrieve_for_processing(size_t& region_index);
duke@435 171
duke@435 172 // Access function for compaction managers
duke@435 173 static ParCompactionManager* gc_thread_compaction_manager(int index);
duke@435 174
duke@435 175 static bool steal(int queue_num, int* seed, Task& t) {
duke@435 176 return stack_array()->steal(queue_num, seed, t);
duke@435 177 }
duke@435 178
jcoomes@1746 179 static bool steal_objarray(int queue_num, int* seed, ObjArrayTask& t) {
jcoomes@1746 180 return _objarray_queues->steal(queue_num, seed, t);
jcoomes@1746 181 }
jcoomes@1746 182
jcoomes@810 183 static bool steal(int queue_num, int* seed, RegionTask& t) {
jcoomes@810 184 return region_array()->steal(queue_num, seed, t);
duke@435 185 }
duke@435 186
jcoomes@1746 187 // Process tasks remaining on any marking stack
jcoomes@1746 188 void follow_marking_stacks();
jcoomes@1746 189 inline bool marking_stacks_empty() const;
duke@435 190
duke@435 191 // Process tasks remaining on any stack
jcoomes@810 192 void drain_region_stacks();
duke@435 193
duke@435 194 // Process tasks remaining on any stack
jcoomes@810 195 void drain_region_overflow_stack();
duke@435 196
duke@435 197 // Debugging support
duke@435 198 #ifdef ASSERT
duke@435 199 bool stacks_have_been_allocated();
duke@435 200 #endif
duke@435 201 };
duke@435 202
duke@435 203 inline ParCompactionManager* ParCompactionManager::manager_array(int index) {
duke@435 204 assert(_manager_array != NULL, "access of NULL manager_array");
duke@435 205 assert(index >= 0 && index <= (int)ParallelGCThreads,
duke@435 206 "out of range manager_array access");
duke@435 207 return _manager_array[index];
duke@435 208 }
jcoomes@1746 209
jcoomes@1746 210 bool ParCompactionManager::marking_stacks_empty() const {
jcoomes@1746 211 return _marking_stack.size() == 0 && _overflow_stack->is_empty() &&
jcoomes@1746 212 _objarray_queue.size() == 0 && _objarray_overflow_stack->is_empty();
jcoomes@1746 213 }

mercurial