hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.hpp
author tonyp
Thu, 22 Jul 2010 10:27:41 -0400
changeset 6248 2e661807cef0
parent 5547 f4b087cbb361
child 7397 5b173b4ca846
permissions -rw-r--r--
6962589: remove breadth first scanning code from parallel gc Summary: Remove the breadth-first copying order from ParallelScavenge and use depth-first by default. Reviewed-by: jcoomes, ysr, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
     2
 * Copyright (c) 2001, 2009, Oracle and/or its affiliates. All rights reserved.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     4
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     8
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    13
 * accompanied this code).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    14
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    22
 *
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    23
 */
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    24
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    25
class VoidClosure;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    26
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    27
// A SuspendibleThreadSet is (obviously) a set of threads that can be
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    28
// suspended.  A thread can join and later leave the set, and periodically
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    29
// yield.  If some thread (not in the set) requests, via suspend_all, that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    30
// the threads be suspended, then the requesting thread is blocked until
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    31
// all the threads in the set have yielded or left the set.  (Threads may
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    32
// not enter the set when an attempted suspension is in progress.)  The
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    33
// suspending thread later calls resume_all, allowing the suspended threads
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    34
// to continue.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    35
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    36
class SuspendibleThreadSet {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    37
  Monitor* _m;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    38
  int      _async;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    39
  bool     _async_stop;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    40
  int      _async_stopped;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    41
  bool     _initialized;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    42
  double   _suspend_all_start;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    43
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    44
  void initialize_work();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    45
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    46
 public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    47
  SuspendibleThreadSet() : _initialized(false) {}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    48
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    49
  // Add the current thread to the set.  May block if a suspension
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    50
  // is in progress.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    51
  void join();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    52
  // Removes the current thread from the set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    53
  void leave();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    54
  // Returns "true" iff an suspension is in progress.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    55
  bool should_yield() { return _async_stop; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    56
  // Suspends the current thread if a suspension is in progress (for
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    57
  // the duration of the suspension.)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    58
  void yield(const char* id);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    59
  // Return when all threads in the set are suspended.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    60
  void suspend_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    61
  // Allow suspended threads to resume.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    62
  void resume_all();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    63
  // Redundant initializations okay.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    64
  void initialize() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    65
    // Double-check dirty read idiom.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    66
    if (!_initialized) initialize_work();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    67
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    68
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    69
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    70
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    71
class ConcurrentGCThread: public NamedThread {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    72
  friend class VMStructs;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    73
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    74
protected:
2881
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 1374
diff changeset
    75
  bool _should_terminate;
74a1337e4acc 6484957: G1: parallel concurrent refinement
iveresov
parents: 1374
diff changeset
    76
  bool _has_terminated;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    77
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    78
  enum CGC_flag_type {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    79
    CGC_nil           = 0x0,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    80
    CGC_dont_suspend  = 0x1,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    81
    CGC_CGC_safepoint = 0x2,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    82
    CGC_VM_safepoint  = 0x4
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    83
  };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    84
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    85
  static int _CGC_flag;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    86
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    87
  static bool CGC_flag_is_set(int b)       { return (_CGC_flag & b) != 0; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    88
  static int set_CGC_flag(int b)           { return _CGC_flag |= b; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    89
  static int reset_CGC_flag(int b)         { return _CGC_flag &= ~b; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    90
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    91
  void stopWorldAndDo(VoidClosure* op);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    92
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    93
  // All instances share this one set.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    94
  static SuspendibleThreadSet _sts;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    95
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    96
  // Create and start the thread (setting it's priority high.)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    97
  void create_and_start();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    98
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
    99
  // Do initialization steps in the thread: record stack base and size,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   100
  // init thread local storage, set JNI handle block.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   101
  void initialize_in_thread();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   102
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   103
  // Wait until Universe::is_fully_initialized();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   104
  void wait_for_universe_init();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   105
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   106
  // Record that the current thread is terminating, and will do more
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   107
  // concurrent work.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   108
  void terminate();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   109
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   110
public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   111
  // Constructor
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   112
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   113
  ConcurrentGCThread();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   114
  ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   115
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   116
  // Tester
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   117
  bool is_ConcurrentGC_thread() const          { return true;       }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   118
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   119
  static void safepoint_synchronize();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   120
  static void safepoint_desynchronize();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   121
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   122
  // All overridings should probably do _sts::yield, but we allow
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   123
  // overriding for distinguished debugging messages.  Default is to do
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   124
  // nothing.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   125
  virtual void yield() {}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   126
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   127
  bool should_yield() { return _sts.should_yield(); }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   128
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   129
  // they are prefixed by sts since there are already yield() and
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   130
  // should_yield() (non-static) methods in this class and it was an
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   131
  // easy way to differentiate them.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   132
  static void stsYield(const char* id);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   133
  static bool stsShouldYield();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   134
  static void stsJoin();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   135
  static void stsLeave();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   136
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   137
};
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   138
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   139
// The SurrogateLockerThread is used by concurrent GC threads for
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   140
// manipulating Java monitors, in particular, currently for
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   141
// manipulating the pending_list_lock. XXX
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   142
class SurrogateLockerThread: public JavaThread {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   143
  friend class VMStructs;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   144
 public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   145
  enum SLT_msg_type {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   146
    empty = 0,           // no message
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   147
    acquirePLL,          // acquire pending list lock
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   148
    releaseAndNotifyPLL  // notify and release pending list lock
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   149
  };
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   150
 private:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   151
  // the following are shared with the CMSThread
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   152
  SLT_msg_type  _buffer;  // communication buffer
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   153
  Monitor       _monitor; // monitor controlling buffer
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   154
  BasicLock     _basicLock; // used for PLL locking
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   155
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   156
 public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   157
  static SurrogateLockerThread* make(TRAPS);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   158
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   159
  SurrogateLockerThread();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   160
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   161
  bool is_hidden_from_external_view() const     { return true; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   162
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   163
  void loop(); // main method
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   164
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   165
  void manipulatePLL(SLT_msg_type msg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   166
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
   167
};