psCompactionManager.hpp 5.8 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 *
 */

// Move to some global location
#define HAS_BEEN_MOVED 0x1501d01d
// End move to some global location


class MutableSpace;
class PSOldGen;
class ParCompactionManager;
class ObjectStartArray;
class ParallelCompactData;
class ParMarkBitMap;

class ParCompactionManager : public CHeapObj {
  friend class ParallelTaskTerminator;
  friend class ParMarkBitMap;
  friend class PSParallelCompact;
41
  friend class StealRegionCompactionTask;
D
duke 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
  friend class UpdateAndFillClosure;
  friend class RefProcTaskExecutor;

 public:

// ------------------------  Don't putback if not needed
  // Actions that the compaction manager should take.
  enum Action {
    Update,
    Copy,
    UpdateAndCopy,
    CopyAndUpdate,
    VerifyUpdate,
    ResetObjects,
    NotValid
  };
// ------------------------  End don't putback if not needed

 private:
61
  // 32-bit:  4K * 8 = 32KiB; 64-bit:  8K * 16 = 128KiB
62 63 64 65
  #define QUEUE_SIZE (1 << NOT_LP64(12) LP64_ONLY(13))
  typedef OverflowTaskQueue<ObjArrayTask, QUEUE_SIZE> ObjArrayTaskQueue;
  typedef GenericTaskQueueSet<ObjArrayTaskQueue>      ObjArrayTaskQueueSet;
  #undef QUEUE_SIZE
66

67 68
  static ParCompactionManager** _manager_array;
  static OopTaskQueueSet*       _stack_array;
69
  static ObjArrayTaskQueueSet*  _objarray_queues;
70 71 72 73
  static ObjectStartArray*      _start_array;
  static RegionTaskQueueSet*    _region_array;
  static PSOldGen*              _old_gen;

74
private:
75 76
  OverflowTaskQueue<oop>        _marking_stack;
  ObjArrayTaskQueue             _objarray_stack;
77

D
duke 已提交
78
  // Is there a way to reuse the _marking_stack for the
79
  // saving empty regions?  For now just create a different
D
duke 已提交
80
  // type of TaskQueue.
81
  RegionTaskQueue               _region_stack;
D
duke 已提交
82 83

#if 1  // does this happen enough to need a per thread stack?
84
  GrowableArray<Klass*>*        _revisit_klass_stack;
Y
ysr 已提交
85
  GrowableArray<DataLayout*>*   _revisit_mdo_stack;
D
duke 已提交
86 87 88 89 90 91 92
#endif
  static ParMarkBitMap* _mark_bitmap;

  Action _action;

  static PSOldGen* old_gen()             { return _old_gen; }
  static ObjectStartArray* start_array() { return _start_array; }
93
  static OopTaskQueueSet* stack_array()  { return _stack_array; }
D
duke 已提交
94 95 96 97 98

  static void initialize(ParMarkBitMap* mbm);

 protected:
  // Array of tasks.  Needed by the ParallelTaskTerminator.
99
  static RegionTaskQueueSet* region_array()      { return _region_array; }
100 101
  OverflowTaskQueue<oop>*  marking_stack()       { return &_marking_stack; }
  RegionTaskQueue* region_stack()                { return &_region_stack; }
D
duke 已提交
102 103 104 105 106 107 108

  // Pushes onto the marking stack.  If the marking stack is full,
  // pushes onto the overflow stack.
  void stack_push(oop obj);
  // Do not implement an equivalent stack_pop.  Deal with the
  // marking stack and overflow stack directly.

109
 public:
D
duke 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  Action action() { return _action; }
  void set_action(Action v) { _action = v; }

  inline static ParCompactionManager* manager_array(int index);

  ParCompactionManager();
  ~ParCompactionManager();

  void allocate_stacks();
  void deallocate_stacks();
  ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }

  // Take actions in preparation for a compaction.
  static void reset();

  // void drain_stacks();

  bool should_update();
  bool should_copy();
  bool should_verify_only();
  bool should_reset_only();

#if 1
  // Probably stays as a growable array
  GrowableArray<Klass*>* revisit_klass_stack() { return _revisit_klass_stack; }
Y
ysr 已提交
135
  GrowableArray<DataLayout*>* revisit_mdo_stack() { return _revisit_mdo_stack; }
D
duke 已提交
136 137
#endif

138 139 140 141
  // Save for later processing.  Must not fail.
  inline void push(oop obj) { _marking_stack.push(obj); }
  inline void push_objarray(oop objarray, size_t index);
  inline void push_region(size_t index);
D
duke 已提交
142 143 144 145

  // Access function for compaction managers
  static ParCompactionManager* gc_thread_compaction_manager(int index);

146
  static bool steal(int queue_num, int* seed, oop& t) {
D
duke 已提交
147 148 149
    return stack_array()->steal(queue_num, seed, t);
  }

150 151 152 153
  static bool steal_objarray(int queue_num, int* seed, ObjArrayTask& t) {
    return _objarray_queues->steal(queue_num, seed, t);
  }

154 155
  static bool steal(int queue_num, int* seed, size_t& region) {
    return region_array()->steal(queue_num, seed, region);
D
duke 已提交
156 157
  }

158 159 160
  // Process tasks remaining on any marking stack
  void follow_marking_stacks();
  inline bool marking_stacks_empty() const;
D
duke 已提交
161 162

  // Process tasks remaining on any stack
163
  void drain_region_stacks();
D
duke 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176

  // Debugging support
#ifdef ASSERT
  bool stacks_have_been_allocated();
#endif
};

inline ParCompactionManager* ParCompactionManager::manager_array(int index) {
  assert(_manager_array != NULL, "access of NULL manager_array");
  assert(index >= 0 && index <= (int)ParallelGCThreads,
    "out of range manager_array access");
  return _manager_array[index];
}
177 178

bool ParCompactionManager::marking_stacks_empty() const {
179
  return _marking_stack.is_empty() && _objarray_stack.is_empty();
180
}