hotspot/src/share/vm/gc_implementation/parallelScavenge/psCompactionManager.hpp
author jcoomes
Tue, 30 Sep 2008 11:49:31 -0700
changeset 1406 e5e2b519fc11
parent 1 489c9b5090e2
child 1407 9006b01ba3fd
permissions -rw-r--r--
6716466: par compact - remove VerifyParallelOldWithMarkSweep code Reviewed-by: jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// psPromotionManager is used by a single thread to manage object survival
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// during a scavenge. The promotion manager contains thread local data only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// NOTE! Be carefull when allocating the stacks on cheap. If you are going
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// to use a promotion manager in more than one thread, the stacks MUST be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// on cheap. This can lead to memory leaks, though, as they are not auto
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// deallocated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// FIX ME FIX ME Add a destructor, and don't rely on the user to drain/flush/deallocate!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Move to some global location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#define HAS_BEEN_MOVED 0x1501d01d
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// End move to some global location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class MutableSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class PSOldGen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class ParCompactionManager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class ObjectStartArray;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class ParallelCompactData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class ParMarkBitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// Move to it's own file if this works out.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
class ParCompactionManager : public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  friend class ParallelTaskTerminator;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  friend class ParMarkBitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  friend class PSParallelCompact;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  friend class StealChunkCompactionTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  friend class UpdateAndFillClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  friend class RefProcTaskExecutor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// ------------------------  Don't putback if not needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Actions that the compaction manager should take.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  enum Action {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    Update,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    Copy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    UpdateAndCopy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    CopyAndUpdate,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    VerifyUpdate,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    ResetObjects,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    NotValid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// ------------------------  End don't putback if not needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static ParCompactionManager**  _manager_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  static OopTaskQueueSet*      _stack_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static ObjectStartArray*     _start_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static ChunkTaskQueueSet*    _chunk_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static PSOldGen*             _old_gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  OopTaskQueue                 _marking_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  GrowableArray<oop>*          _overflow_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Is there a way to reuse the _marking_stack for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // saving empty chunks?  For now just create a different
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // type of TaskQueue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#ifdef USE_ChunkTaskQueueWithOverflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  ChunkTaskQueueWithOverflow   _chunk_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  ChunkTaskQueue               _chunk_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  GrowableArray<size_t>*       _chunk_overflow_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#if 1  // does this happen enough to need a per thread stack?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  GrowableArray<Klass*>*       _revisit_klass_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static ParMarkBitMap* _mark_bitmap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  Action _action;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  static PSOldGen* old_gen()             { return _old_gen; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  static ObjectStartArray* start_array() { return _start_array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static OopTaskQueueSet* stack_array()   { return _stack_array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  static void initialize(ParMarkBitMap* mbm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Array of tasks.  Needed by the ParallelTaskTerminator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static ChunkTaskQueueSet* chunk_array()   { return _chunk_array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  OopTaskQueue*  marking_stack()          { return &_marking_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  GrowableArray<oop>* overflow_stack()    { return _overflow_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
#ifdef USE_ChunkTaskQueueWithOverflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  ChunkTaskQueueWithOverflow* chunk_stack() { return &_chunk_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  ChunkTaskQueue*  chunk_stack()          { return &_chunk_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  GrowableArray<size_t>* chunk_overflow_stack() { return _chunk_overflow_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // Pushes onto the marking stack.  If the marking stack is full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // pushes onto the overflow stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void stack_push(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // Do not implement an equivalent stack_pop.  Deal with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // marking stack and overflow stack directly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Pushes onto the chunk stack.  If the chunk stack is full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // pushes onto the chunk overflow stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void chunk_stack_push(size_t chunk_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  Action action() { return _action; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void set_action(Action v) { _action = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  inline static ParCompactionManager* manager_array(int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  ~ParCompactionManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  void allocate_stacks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void deallocate_stacks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  ParMarkBitMap* mark_bitmap() { return _mark_bitmap; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // Take actions in preparation for a compaction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static void reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // void drain_stacks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  bool should_update();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  bool should_copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  bool should_verify_only();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  bool should_reset_only();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
#if 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Probably stays as a growable array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  GrowableArray<Klass*>* revisit_klass_stack() { return _revisit_klass_stack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Save oop for later processing.  Must not fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  void save_for_scanning(oop m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Get a oop for scanning.  If returns null, no oop were found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  oop retrieve_for_scanning();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Save chunk for later processing.  Must not fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  void save_for_processing(size_t chunk_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // Get a chunk for processing.  If returns null, no chunk were found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  bool retrieve_for_processing(size_t& chunk_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Access function for compaction managers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  static ParCompactionManager* gc_thread_compaction_manager(int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  static bool steal(int queue_num, int* seed, Task& t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return stack_array()->steal(queue_num, seed, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  static bool steal(int queue_num, int* seed, ChunkTask& t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    return chunk_array()->steal(queue_num, seed, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Process tasks remaining on any stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void drain_marking_stacks(OopClosure *blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Process tasks remaining on any stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  void drain_chunk_stacks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Process tasks remaining on any stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  void drain_chunk_overflow_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  bool stacks_have_been_allocated();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
inline ParCompactionManager* ParCompactionManager::manager_array(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  assert(_manager_array != NULL, "access of NULL manager_array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert(index >= 0 && index <= (int)ParallelGCThreads,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    "out of range manager_array access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  return _manager_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}