src/hotspot/share/gc/parallel/gcTaskManager.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 49392 2956d0ece7a9
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
     2
 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
    25
#ifndef SHARE_GC_PARALLEL_GCTASKMANAGER_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
    26
#define SHARE_GC_PARALLEL_GCTASKMANAGER_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// The GCTaskManager is a queue of GCTasks, and accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// to allow the queue to be accessed from many threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Forward declarations of types defined in this file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class GCTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class GCTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class SynchronizedGCTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class GCTaskManager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Some useful subclasses of GCTask.  You can also make up your own.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class NoopGCTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class WaitForBarrierGCTask;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    44
class IdleGCTask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// A free list of Monitor*'s.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class MonitorSupply;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Forward declarations of classes referenced in this file via pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class GCTaskThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
class Mutex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
class Monitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
class ThreadClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// The abstract base GCTask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
class GCTask : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Known kinds of GCTasks, for predicates.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  class Kind : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    enum kind {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      unknown_task,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      ordinary_task,
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
    63
      wait_for_barrier_task,
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    64
      noop_task,
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
    65
      idle_task
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    static const char* to_string(kind value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Instance state.
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    71
  Kind::kind       _kind;               // For runtime type checking.
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    72
  uint             _affinity;           // Which worker should run task.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  GCTask*          _newer;              // Tasks are on doubly-linked ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  GCTask*          _older;              // ... lists.
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    75
  uint             _gc_id;              // GC Id to use for the thread that executes this task
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  virtual char* name() { return (char *)"task"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    79
  uint gc_id() { return _gc_id; }
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
    80
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Abstract do_it method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  virtual void do_it(GCTaskManager* manager, uint which) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  Kind::kind kind() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return _kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  uint affinity() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return _affinity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  GCTask* newer() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return _newer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void set_newer(GCTask* n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    _newer = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  GCTask* older() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return _older;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void set_older(GCTask* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    _older = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Predicates.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  bool is_ordinary_task() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    return kind()==Kind::ordinary_task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  bool is_barrier_task() const {
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   107
    return kind()==Kind::wait_for_barrier_task;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  bool is_noop_task() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return kind()==Kind::noop_task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   112
  bool is_idle_task() const {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   113
    return kind()==Kind::idle_task;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   114
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void print(const char* message) const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Constructors: Only create subclasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  //     An ordinary GCTask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  GCTask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  //     A GCTask of a particular kind, usually barrier or noop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  GCTask(Kind::kind kind);
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   122
  GCTask(Kind::kind kind, uint gc_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // We want a virtual destructor because virtual methods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // but since ResourceObj's don't have their destructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // called, we don't have one at all.  Instead we have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // this method, which gets called by subclasses to clean up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  virtual void destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Methods.
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   129
  void initialize(Kind::kind kind, uint gc_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// A doubly-linked list of GCTasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// The list is not synchronized, because sometimes we want to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// build up a list and then make it available to other threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// See also: SynchronizedGCTaskQueue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
class GCTaskQueue : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // Instance state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  GCTask*    _insert_end;               // Tasks are enqueued at this end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  GCTask*    _remove_end;               // Tasks are dequeued from this end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  uint       _length;                   // The current length of the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  const bool _is_c_heap_obj;            // Is this a CHeapObj?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Factory create and destroy methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  //     Create as ResourceObj.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static GCTaskQueue* create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  //     Create as CHeapObj.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static GCTaskQueue* create_on_c_heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  //     Destroyer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  static void destroy(GCTaskQueue* that);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  //     These just examine the state of the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  bool is_empty() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    assert(((insert_end() == NULL && remove_end() == NULL) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
            (insert_end() != NULL && remove_end() != NULL)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
           "insert_end and remove_end don't match");
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   157
    assert((insert_end() != NULL) || (_length == 0), "Not empty");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    return insert_end() == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  uint length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    return _length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  //     Enqueue one task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  void enqueue(GCTask* task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  //     Enqueue a list of tasks.  Empties the argument list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  void enqueue(GCTaskQueue* list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  //     Dequeue one task.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  GCTask* dequeue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  //     Dequeue one task, preferring one with affinity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  GCTask* dequeue(uint affinity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Constructor. Clients use factory, but there might be subclasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  GCTaskQueue(bool on_c_heap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Destructor-like method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // Because ResourceMark doesn't call destructors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // This method cleans up like one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  virtual void destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  GCTask* insert_end() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return _insert_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  void set_insert_end(GCTask* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _insert_end = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  GCTask* remove_end() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    return _remove_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  void set_remove_end(GCTask* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    _remove_end = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  void increment_length() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    _length += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  void decrement_length() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    _length -= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  void set_length(uint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    _length = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  bool is_c_heap_obj() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    return _is_c_heap_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  GCTask* remove();                     // Remove from remove end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  GCTask* remove(GCTask* task);         // Remove from the middle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  void print(const char* message) const PRODUCT_RETURN;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   209
  // Debug support
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   210
  void verify_length() const PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// A GCTaskQueue that can be synchronized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// This "has-a" GCTaskQueue and a mutex to do the exclusion.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11174
diff changeset
   215
class SynchronizedGCTaskQueue : public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Instance state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  GCTaskQueue* _unsynchronized_queue;   // Has-a unsynchronized queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  Monitor *    _lock;                   // Lock to control access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // Factory create and destroy methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  static SynchronizedGCTaskQueue* create(GCTaskQueue* queue, Monitor * lock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return new SynchronizedGCTaskQueue(queue, lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  static void destroy(SynchronizedGCTaskQueue* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    if (that != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      delete that;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  GCTaskQueue* unsynchronized_queue() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return _unsynchronized_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  Monitor * lock() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return _lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // GCTaskQueue wrapper methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // These check that you hold the lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // and then call the method on the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  bool is_empty() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    return unsynchronized_queue()->is_empty();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  void enqueue(GCTask* task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    unsynchronized_queue()->enqueue(task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  void enqueue(GCTaskQueue* list) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    unsynchronized_queue()->enqueue(list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  GCTask* dequeue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    return unsynchronized_queue()->dequeue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  GCTask* dequeue(uint affinity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    return unsynchronized_queue()->dequeue(affinity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  uint length() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    guarantee(own_lock(), "don't own the lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    return unsynchronized_queue()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // For guarantees.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  bool own_lock() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return lock()->owned_by_self();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // Constructor.  Clients use factory, but there might be subclasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  SynchronizedGCTaskQueue(GCTaskQueue* queue, Monitor * lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // Destructor.  Not virtual because no virtuals.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  ~SynchronizedGCTaskQueue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
   275
class WaitHelper {
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   276
 private:
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   277
  Monitor*      _monitor;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   278
  volatile bool _should_wait;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   279
 public:
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   280
  WaitHelper();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   281
  ~WaitHelper();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   282
  void wait_for(bool reset);
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   283
  void notify();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   284
  void set_should_wait(bool value) {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   285
    _should_wait = value;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   286
  }
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   287
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   288
  Monitor* monitor() const {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   289
    return _monitor;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   290
  }
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   291
  bool should_wait() const {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   292
    return _should_wait;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   293
  }
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   294
  void release_monitor();
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   295
};
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   296
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   297
// Dynamic number of GC threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   298
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   299
//  GC threads wait in get_task() for work (i.e., a task) to perform.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   300
// When the number of GC threads was static, the number of tasks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   301
// created to do a job was equal to or greater than the maximum
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   302
// number of GC threads (ParallelGCThreads).  The job might be divided
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   303
// into a number of tasks greater than the number of GC threads for
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   304
// load balancing (i.e., over partitioning).  The last task to be
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   305
// executed by a GC thread in a job is a work stealing task.  A
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   306
// GC  thread that gets a work stealing task continues to execute
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13963
diff changeset
   307
// that task until the job is done.  In the static number of GC threads
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   308
// case, tasks are added to a queue (FIFO).  The work stealing tasks are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   309
// the last to be added.  Once the tasks are added, the GC threads grab
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   310
// a task and go.  A single thread can do all the non-work stealing tasks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   311
// and then execute a work stealing and wait for all the other GC threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   312
// to execute their work stealing task.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   313
//  In the dynamic number of GC threads implementation, idle-tasks are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   314
// created to occupy the non-participating or "inactive" threads.  An
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   315
// idle-task makes the GC thread wait on a barrier that is part of the
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   316
// GCTaskManager.  The GC threads that have been "idled" in a IdleGCTask
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   317
// are released once all the active GC threads have finished their work
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   318
// stealing tasks.  The GCTaskManager does not wait for all the "idled"
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   319
// GC threads to resume execution. When those GC threads do resume
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   320
// execution in the course of the thread scheduling, they call get_tasks()
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   321
// as all the other GC threads do.  Because all the "idled" threads are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   322
// not required to execute in order to finish a job, it is possible for
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   323
// a GC thread to still be "idled" when the next job is started.  Such
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   324
// a thread stays "idled" for the next job.  This can result in a new
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   325
// job not having all the expected active workers.  For example if on
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   326
// job requests 4 active workers out of a total of 10 workers so the
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   327
// remaining 6 are "idled", if the next job requests 6 active workers
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   328
// but all 6 of the "idled" workers are still idle, then the next job
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   329
// will only get 4 active workers.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   330
//  The implementation for the parallel old compaction phase has an
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   331
// added complication.  In the static case parold partitions the chunks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   332
// ready to be filled into stacks, one for each GC thread.  A GC thread
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   333
// executing a draining task (drains the stack of ready chunks)
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   334
// claims a stack according to it's id (the unique ordinal value assigned
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   335
// to each GC thread).  In the dynamic case not all GC threads will
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   336
// actively participate so stacks with ready to fill chunks can only be
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   337
// given to the active threads.  An initial implementation chose stacks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   338
// number 1-n to get the ready chunks and required that GC threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   339
// 1-n be the active workers.  This was undesirable because it required
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   340
// certain threads to participate.  In the final implementation a
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   341
// list of stacks equal in number to the active workers are filled
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   342
// with ready chunks.  GC threads that participate get a stack from
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   343
// the task (DrainStacksCompactionTask), empty the stack, and then add it to a
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   344
// recycling list at the end of the task.  If the same GC thread gets
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   345
// a second task, it gets a second stack to drain and returns it.  The
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   346
// stacks are added to a recycling list so that later stealing tasks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   347
// for this tasks can get a stack from the recycling list.  Stealing tasks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   348
// use the stacks in its work in a way similar to the draining tasks.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   349
// A thread is not guaranteed to get anything but a stealing task and
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   350
// a thread that only gets a stealing task has to get a stack. A failed
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   351
// implementation tried to have the GC threads keep the stack they used
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   352
// during a draining task for later use in the stealing task but that didn't
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   353
// work because as noted a thread is not guaranteed to get a draining task.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   354
//
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   355
// For PSScavenge and ParCompactionManager the GC threads are
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   356
// held in the GCTaskThread** _thread array in GCTaskManager.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   357
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   358
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11174
diff changeset
   359
class GCTaskManager : public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
 friend class ParCompactionManager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
 friend class PSParallelCompact;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
 friend class PSScavenge;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
 friend class PSRefProcTaskExecutor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
 friend class RefProcTaskExecutor;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   365
 friend class GCTaskThread;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   366
 friend class IdleGCTask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  // Instance state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  const uint                _workers;           // Number of workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  Monitor*                  _monitor;           // Notification of changes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  SynchronizedGCTaskQueue*  _queue;             // Queue of tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  GCTaskThread**            _thread;            // Array of worker threads.
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   373
  uint                      _created_workers;   // Number of workers created.
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   374
  uint                      _active_workers;    // Number of active workers.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  uint                      _busy_workers;      // Number of busy workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  uint                      _blocking_worker;   // The worker that's blocking.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  bool*                     _resource_flag;     // Array of flag per threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  uint                      _delivered_tasks;   // Count of delivered tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  uint                      _completed_tasks;   // Count of completed tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  uint                      _barriers;          // Count of barrier tasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  uint                      _emptied_queue;     // Times we emptied the queue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  NoopGCTask*               _noop_task;         // The NoopGCTask instance.
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   383
  WaitHelper                _wait_helper;       // Used by inactive worker
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   384
  volatile uint             _idle_workers;      // Number of idled workers
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   385
  uint*                     _processor_assignment; // Worker to cpu mappings. May
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   386
                                                   // be used lazily
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  // Factory create and destroy methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  static GCTaskManager* create(uint workers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    return new GCTaskManager(workers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  static void destroy(GCTaskManager* that) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    if (that != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
      delete that;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  uint busy_workers() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    return _busy_workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   401
  volatile uint idle_workers() const {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   402
    return _idle_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   403
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  //     Pun between Monitor* and Mutex*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  Monitor* monitor() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    return _monitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  Monitor * lock() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    return _monitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  }
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   411
  WaitHelper* wait_helper() {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   412
    return &_wait_helper;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   413
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  // Methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  //     Add the argument task to be run.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  void add_task(GCTask* task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  //     Add a list of tasks.  Removes task from the argument list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  void add_list(GCTaskQueue* list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  //     Claim a task for argument worker.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  GCTask* get_task(uint which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  //     Note the completion of a task by the argument worker.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  void note_completion(uint which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  //     Is the queue blocked from handing out new tasks?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  bool is_blocked() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    return (blocking_worker() != sentinel_worker());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  //     Request that all workers release their resources.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  void release_all_resources();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  //     Ask if a particular worker should release its resources.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  bool should_release_resources(uint which); // Predicate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  //     Note the release of resources by the argument worker.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  void note_release(uint which);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   433
  //     Create IdleGCTasks for inactive workers and start workers
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   434
  void task_idle_workers();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   435
  //     Release the workers in IdleGCTasks
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   436
  void release_idle_workers();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  // Constants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  //     A sentinel worker identifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  static uint sentinel_worker() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    return (uint) -1;                   // Why isn't there a max_uint?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  //     Execute the task queue and wait for the completion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  void execute_and_wait(GCTaskQueue* list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  void print_task_time_stamps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  void print_threads_on(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  void threads_do(ThreadClosure* tc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // Constructors.  Clients use factory, but there might be subclasses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  //     Create a GCTaskManager with the appropriate number of workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  GCTaskManager(uint workers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  //     Make virtual if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  ~GCTaskManager();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  uint workers() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    return _workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
40096
246c62cd9180 8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents: 39704
diff changeset
   460
  uint update_active_workers(uint v) {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   461
    assert(v <= _workers, "Trying to set more workers active than there are");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   462
    _active_workers = MIN2(v, _workers);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   463
    assert(v != 0, "Trying to set active workers to 0");
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   464
    _active_workers = MAX2(1U, _active_workers);
40096
246c62cd9180 8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents: 39704
diff changeset
   465
    return _active_workers;
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   466
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   467
  // Sets the number of threads that will be used in a collection
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   468
  void set_active_gang();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   469
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  SynchronizedGCTaskQueue* queue() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    return _queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  NoopGCTask* noop_task() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    return _noop_task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  //     Bounds-checking per-thread data accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  GCTaskThread* thread(uint which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  void set_thread(uint which, GCTaskThread* value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  bool resource_flag(uint which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  void set_resource_flag(uint which, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  // Modifier methods with some semantics.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  //     Is any worker blocking handing out new tasks?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  uint blocking_worker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    return _blocking_worker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  void set_blocking_worker(uint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    _blocking_worker = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  void set_unblocked() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    set_blocking_worker(sentinel_worker());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  //     Count of busy workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  void reset_busy_workers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    _busy_workers = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  uint increment_busy_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  uint decrement_busy_workers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  //     Count of tasks delivered to workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  uint delivered_tasks() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    return _delivered_tasks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  void increment_delivered_tasks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    _delivered_tasks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  void reset_delivered_tasks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    _delivered_tasks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  //     Count of tasks completed by workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  uint completed_tasks() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    return _completed_tasks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  void increment_completed_tasks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    _completed_tasks += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  void reset_completed_tasks() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    _completed_tasks = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  //     Count of barrier tasks completed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  uint barriers() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    return _barriers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  void increment_barriers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    _barriers += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  void reset_barriers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    _barriers = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  //     Count of how many times the queue has emptied.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  uint emptied_queue() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    return _emptied_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  void increment_emptied_queue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    _emptied_queue += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  void reset_emptied_queue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    _emptied_queue = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   538
  void increment_idle_workers() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   539
    _idle_workers++;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   540
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   541
  void decrement_idle_workers() {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   542
    _idle_workers--;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   543
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // Other methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  void initialize();
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   546
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   547
 public:
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   548
  // Return true if all workers are currently active.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   549
  bool all_workers_active() { return workers() == active_workers(); }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   550
  uint active_workers() const {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   551
    return _active_workers;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   552
  }
38216
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   553
  uint created_workers() const {
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   554
    return _created_workers;
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   555
  }
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   556
  // Create a GC worker and install into GCTaskManager
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   557
  GCTaskThread* install_worker(uint worker_id);
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   558
  // Add GC workers as needed.
250794c6f95f 6858051: Create GC worker threads dynamically
jmasa
parents: 33126
diff changeset
   559
  void add_workers(bool initializing);
39704
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
   560
  // Base name (without worker id #) of threads.
157f39705057 8157240: GC task trace logging is incomprehensible
jmasa
parents: 38216
diff changeset
   561
  const char* group_name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
// Some exemplary GCTasks.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
// A noop task that does nothing,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
// except take us around the GCTaskThread loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
class NoopGCTask : public GCTask {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  // Factory create and destroy methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  static NoopGCTask* create_on_c_heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  static void destroy(NoopGCTask* that);
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   575
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   576
  virtual char* name() { return (char *)"noop task"; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // Methods from GCTask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  void do_it(GCTaskManager* manager, uint which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    // Nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // Constructor.
33126
260ff671354b 8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents: 33125
diff changeset
   583
  NoopGCTask();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // Destructor-like method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  void destruct();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   588
// A WaitForBarrierGCTask is a GCTask
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
// with a method you can call to wait until
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
// the BarrierGCTask is done.
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   591
class WaitForBarrierGCTask : public GCTask {
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   592
  friend class GCTaskManager;
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   593
  friend class IdleGCTask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  // Instance state.
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   596
  WaitHelper    _wait_helper;
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   597
  WaitForBarrierGCTask();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  virtual char* name() { return (char *) "waitfor-barrier-task"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  // Factory create and destroy methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  static WaitForBarrierGCTask* create();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  static void destroy(WaitForBarrierGCTask* that);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  // Methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  void     do_it(GCTaskManager* manager, uint which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  // Destructor-like method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  void destruct();
33124
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   609
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   610
  // Methods.
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   611
  //     Wait for this to be the only task running.
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   612
  void do_it_internal(GCTaskManager* manager, uint which);
e256f7a94c38 8138862: Remove some unused code and subclasses in gcTaskManager.hpp/cpp
brutisso
parents: 30764
diff changeset
   613
33125
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   614
  void wait_for(bool reset) {
bc61fce9bac3 8138863: Refactor WaitForBarrierGCTask
brutisso
parents: 33124
diff changeset
   615
    _wait_helper.wait_for(reset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   617
};
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   618
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   619
// Task that is used to idle a GC task when fewer than
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   620
// the maximum workers are wanted.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   621
class IdleGCTask : public GCTask {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   622
  const bool    _is_c_heap_obj;            // Was allocated on the heap.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   623
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  bool is_c_heap_obj() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    return _is_c_heap_obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  }
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   627
  // Factory create and destroy methods.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   628
  static IdleGCTask* create();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   629
  static IdleGCTask* create_on_c_heap();
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   630
  static void destroy(IdleGCTask* that);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   631
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   632
  virtual char* name() { return (char *)"idle task"; }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   633
  // Methods from GCTask.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   634
  virtual void do_it(GCTaskManager* manager, uint which);
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   635
protected:
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   636
  // Constructor.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   637
  IdleGCTask(bool on_c_heap) :
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   638
    GCTask(GCTask::Kind::idle_task),
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   639
    _is_c_heap_obj(on_c_heap) {
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   640
    // Nothing to do.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   641
  }
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   642
  // Destructor-like method.
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 7397
diff changeset
   643
  void destruct();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
class MonitorSupply : public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  // State.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  //     Control multi-threaded access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  static Mutex*                   _lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  //     The list of available Monitor*'s.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  static GrowableArray<Monitor*>* _freelist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  // Reserve a Monitor*.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  static Monitor* reserve();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // Release a Monitor*.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  static void release(Monitor* instance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  static Mutex* lock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    return _lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  static GrowableArray<Monitor*>* freelist() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    return _freelist;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   667
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49392
diff changeset
   668
#endif // SHARE_GC_PARALLEL_GCTASKMANAGER_HPP