hotspot/src/share/vm/gc/cms/yieldingWorkgroup.hpp
author brutisso
Fri, 11 Mar 2016 11:34:22 +0100
changeset 37073 c39d0903390b
parent 32360 86790204fc23
permissions -rw-r--r--
8151605: Change warning() to log_warning(gc) in the GC code Reviewed-by: jwilhelm, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 19974
diff changeset
     2
 * Copyright (c) 2005, 2015, 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: 1374
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1374
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: 1374
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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 19974
diff changeset
    25
#ifndef SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 19974
diff changeset
    26
#define SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6763
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 19974
diff changeset
    28
#include "gc/shared/workgroup.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14841
diff changeset
    29
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Forward declarations
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    32
class YieldingFlexibleGangTask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class YieldingFlexibleWorkGang;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Status of tasks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
enum Status {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    INACTIVE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    ACTIVE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    YIELDING,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    YIELDED,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    ABORTING,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    ABORTED,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    COMPLETING,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    COMPLETED
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    47
class YieldingWorkData: public StackObj {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    48
  // This would be a struct, but I want accessor methods.
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    49
private:
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    50
  AbstractGangTask* _task;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    51
  int               _sequence_number;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    52
public:
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    53
  // Constructor and destructor
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    54
  YieldingWorkData() : _task(NULL), _sequence_number(0) {}
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    55
  ~YieldingWorkData() {}
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    56
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    57
  // Accessors and modifiers
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    58
  AbstractGangTask* task()               const { return _task; }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    59
  void set_task(AbstractGangTask* value)       { _task = value; }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    60
  int sequence_number()                  const { return _sequence_number; }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    61
  void set_sequence_number(int value)          { _sequence_number = value; }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    62
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    63
  YieldingFlexibleGangTask* yf_task()    const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    64
    return (YieldingFlexibleGangTask*)_task;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    65
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    66
};
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    67
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// Class YieldingFlexibleGangWorker:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//   Several instances of this class run in parallel as workers for a gang.
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    70
class YieldingFlexibleGangWorker: public AbstractGangWorker {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
public:
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
    72
  YieldingFlexibleGangWorker(YieldingFlexibleWorkGang* gang, int id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  YieldingFlexibleWorkGang* yf_gang() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    { return (YieldingFlexibleWorkGang*)gang(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
protected: // Override from parent class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  virtual void loop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    82
class FlexibleGangTask: public AbstractGangTask {
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    83
  int _actual_size;                      // size of gang obtained
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    84
protected:
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    85
  int _requested_size;                   // size of gang requested
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    86
public:
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    87
 FlexibleGangTask(const char* name): AbstractGangTask(name),
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    88
    _requested_size(0) {}
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    89
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    90
  // The abstract work method.
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    91
  // The argument tells you which member of the gang you are.
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
    92
  virtual void work(uint worker_id) = 0;
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    93
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    94
  int requested_size() const { return _requested_size; }
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    95
  int actual_size()    const { return _actual_size; }
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    96
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    97
  void set_requested_size(int sz) { _requested_size = sz; }
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    98
  void set_actual_size(int sz)    { _actual_size    = sz; }
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
    99
};
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   100
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// An abstract task to be worked on by a flexible work gang,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
// and where the workers will periodically yield, usually
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// in response to some condition that is signalled by means
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
// that are specific to the task at hand.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// You subclass this to supply your own work() method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
// A second feature of this kind of work gang is that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// it allows for the signalling of certain exceptional
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
// conditions that may be encountered during the performance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// of the task and that may require the task at hand to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
// `aborted' forthwith. Finally, these gangs are `flexible'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// in that they can operate at partial capacity with some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// gang workers waiting on the bench; in other words, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// size of the active worker pool can flex (up to an apriori
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// maximum) in response to task requests at certain points.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// The last part (the flexible part) has not yet been fully
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// fleshed out and is a work in progress.
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   117
class YieldingFlexibleGangTask: public FlexibleGangTask {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  Status _status;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  YieldingFlexibleWorkGang* _gang;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Constructor and desctructor: only construct subclasses.
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   123
  YieldingFlexibleGangTask(const char* name): FlexibleGangTask(name),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    _status(INACTIVE),
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   125
    _gang(NULL) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
14841
d069f5506f71 8004845: Catch incorrect usage of new and delete during compile time for value objects and stack objects
brutisso
parents: 11396
diff changeset
   127
  ~YieldingFlexibleGangTask() { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  friend class YieldingFlexibleWorkGang;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  friend class YieldingFlexibleGangWorker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void set_status(Status s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _status = s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  YieldingFlexibleWorkGang* gang() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return _gang;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  void set_gang(YieldingFlexibleWorkGang* gang) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    assert(_gang == NULL || gang == NULL, "Clobber without intermediate reset?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    _gang = gang;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // The abstract work method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // The argument tells you which member of the gang you are.
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
   146
  virtual void work(uint worker_id) = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Subclasses should call the parent's yield() method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // after having done any work specific to the subclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  virtual void yield();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // An abstract method supplied by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // a concrete sub-class which is used by the coordinator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // to do any "central yielding" work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  virtual void coordinator_yield() = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // Subclasses should call the parent's abort() method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // after having done any work specific to the sunbclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  virtual void abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  Status status()  const { return _status; }
6763
711b8a44c4dd 6692906: CMS: parallel concurrent marking may be prone to hanging or stalling mutators for periods of time
ysr
parents: 6759
diff changeset
   162
  bool yielding()  const { return _status == YIELDING; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  bool yielded()   const { return _status == YIELDED; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  bool completed() const { return _status == COMPLETED; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  bool aborted()   const { return _status == ABORTED; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  bool active()    const { return _status == ACTIVE; }
30881
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   167
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   168
  // This method configures the task for proper termination.
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   169
  // Some tasks do not have any requirements on termination
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   170
  // and may inherit this method that does nothing.  Some
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   171
  // tasks do some coordination on termination and override
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   172
  // this method to implement that coordination.
7a3899d7cea0 8080879: Remove FlexibleWorkGang::set_for_termination
stefank
parents: 30764
diff changeset
   173
  virtual void set_for_termination(uint active_workers) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// Class YieldingWorkGang: A subclass of WorkGang.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// In particular, a YieldingWorkGang is made up of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// YieldingGangWorkers, and provides infrastructure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// supporting yielding to the "GangOverseer",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// being the thread that orchestrates the WorkGang via run_task().
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   180
class YieldingFlexibleWorkGang: public AbstractWorkGang {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // Here's the public interface to this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Constructor and destructor.
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
   184
  YieldingFlexibleWorkGang(const char* name, uint workers,
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   185
                           bool are_GC_task_threads);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  YieldingFlexibleGangTask* yielding_task() const {
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   188
    return task();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   190
  // Allocate a worker and return a pointer to it.
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   191
  AbstractGangWorker* allocate_worker(uint which);
6759
67b1a69ef5aa 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 5547
diff changeset
   192
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // Run a task; returns when the task is done, or the workers yield,
31030
811c2501a5a6 8081682: AbstractWorkGang::_terminate is never used
stefank
parents: 30881
diff changeset
   194
  // or the task is aborted.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // A task that has been yielded can be continued via this same interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // by using the same task repeatedly as the argument to the call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // It is expected that the YieldingFlexibleGangTask carries the appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // continuation information used by workers to continue the task
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // from its last yield point. Thus, a completed task will return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // immediately with no actual work having been done by the workers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void run_task(AbstractGangTask* task) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    guarantee(false, "Use start_task instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  void start_task(YieldingFlexibleGangTask* new_task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  void continue_task(YieldingFlexibleGangTask* gang_task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // Abort a currently running task, if any; returns when all the workers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // have stopped working on the current task and have returned to their
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // waiting stations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  void abort_task();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Yield: workers wait at their current working stations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // until signalled to proceed by the overseer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  void yield();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Abort: workers are expected to return to their waiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // stations, whence they are ready for the next task dispatched
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // by the overseer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  void abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
private:
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
   222
  uint _yielded_workers;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  void wait_for_gang();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // Accessors for fields
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
   227
  uint yielded_workers() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    return _yielded_workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  friend class YieldingFlexibleGangWorker;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  void reset(); // NYI
32360
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   234
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   235
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   236
  // The monitor which protects these data,
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   237
  // and notifies of changes in it.
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   238
  Monitor*   _monitor;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   239
  // Accessors for fields
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   240
  Monitor* monitor() const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   241
    return _monitor;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   242
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   243
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   244
  // The number of started workers.
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   245
  uint _started_workers;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   246
  // The number of finished workers.
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   247
  uint _finished_workers;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   248
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   249
  uint started_workers() const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   250
    return _started_workers;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   251
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   252
  uint finished_workers() const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   253
    return _finished_workers;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   254
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   255
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   256
  // A sequence number for the current task.
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   257
  int _sequence_number;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   258
  int sequence_number() const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   259
    return _sequence_number;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   260
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   261
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   262
  YieldingFlexibleGangTask* _task;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   263
  YieldingFlexibleGangTask* task() const {
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   264
    return _task;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   265
  }
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   266
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   267
  void internal_worker_poll(YieldingWorkData* data) const;
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   268
  void internal_note_start();
86790204fc23 8087323: Unify and split the work gang classes
stefank
parents: 31030
diff changeset
   269
  void internal_note_finish();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6763
diff changeset
   271
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 19974
diff changeset
   272
#endif // SHARE_VM_GC_CMS_YIELDINGWORKGROUP_HPP