2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2015-04-29 15:12:33 +03:00
|
|
|
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#ifndef SHARE_VM_GC_SHARED_WORKGROUP_HPP
|
|
|
|
#define SHARE_VM_GC_SHARED_WORKGROUP_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/taskqueue.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2011-03-17 10:32:46 -07:00
|
|
|
// Task class hierarchy:
|
|
|
|
// AbstractGangTask
|
|
|
|
// AbstractGangTaskWOopQueues
|
|
|
|
//
|
|
|
|
// Gang/Group class hierarchy:
|
|
|
|
// AbstractWorkGang
|
|
|
|
// WorkGang
|
|
|
|
// FlexibleWorkGang
|
|
|
|
// YieldingFlexibleWorkGang (defined in another file)
|
|
|
|
//
|
|
|
|
// Worker class hierarchy:
|
|
|
|
// GangWorker (subclass of WorkerThread)
|
|
|
|
// YieldingFlexibleGangWorker (defined in another file)
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Forward declarations of classes defined here
|
|
|
|
|
|
|
|
class WorkGang;
|
|
|
|
class GangWorker;
|
|
|
|
class YieldingFlexibleGangWorker;
|
|
|
|
class YieldingFlexibleGangTask;
|
|
|
|
class WorkData;
|
2010-09-20 14:38:38 -07:00
|
|
|
class AbstractWorkGang;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// An abstract task to be worked on by a gang.
|
|
|
|
// You subclass this to supply your own work() method
|
2009-02-10 18:39:09 +03:00
|
|
|
class AbstractGangTask VALUE_OBJ_CLASS_SPEC {
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
|
|
|
// The abstract work method.
|
|
|
|
// The argument tells you which member of the gang you are.
|
2011-12-14 13:34:57 -08:00
|
|
|
virtual void work(uint worker_id) = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
// This method configures the task for proper termination.
|
|
|
|
// Some tasks do not have any requirements on termination
|
|
|
|
// and may inherit this method that does nothing. Some
|
|
|
|
// tasks do some coordination on termination and override
|
|
|
|
// this method to implement that coordination.
|
2015-04-29 15:12:33 +03:00
|
|
|
virtual void set_for_termination(uint active_workers) {};
|
2010-09-20 14:38:38 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Debugging accessor for the name.
|
|
|
|
const char* name() const PRODUCT_RETURN_(return NULL;);
|
|
|
|
int counter() { return _counter; }
|
|
|
|
void set_counter(int value) { _counter = value; }
|
|
|
|
int *address_of_counter() { return &_counter; }
|
|
|
|
|
|
|
|
// RTTI
|
|
|
|
NOT_PRODUCT(virtual bool is_YieldingFlexibleGang_task() const {
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
|
|
|
|
private:
|
|
|
|
NOT_PRODUCT(const char* _name;)
|
|
|
|
// ??? Should a task have a priority associated with it?
|
|
|
|
// ??? Or can the run method adjust priority as needed?
|
|
|
|
int _counter;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Constructor and desctructor: only construct subclasses.
|
2011-08-09 10:16:01 -07:00
|
|
|
AbstractGangTask(const char* name)
|
|
|
|
{
|
2007-12-01 00:00:00 +00:00
|
|
|
NOT_PRODUCT(_name = name);
|
|
|
|
_counter = 0;
|
|
|
|
}
|
2012-12-17 15:25:26 +01:00
|
|
|
~AbstractGangTask() { }
|
2011-08-09 10:16:01 -07:00
|
|
|
|
|
|
|
public:
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
class AbstractGangTaskWOopQueues : public AbstractGangTask {
|
|
|
|
OopTaskQueueSet* _queues;
|
|
|
|
ParallelTaskTerminator _terminator;
|
|
|
|
public:
|
|
|
|
AbstractGangTaskWOopQueues(const char* name, OopTaskQueueSet* queues) :
|
|
|
|
AbstractGangTask(name), _queues(queues), _terminator(0, _queues) {}
|
|
|
|
ParallelTaskTerminator* terminator() { return &_terminator; }
|
2015-04-29 15:12:33 +03:00
|
|
|
virtual void set_for_termination(uint active_workers) {
|
2010-09-20 14:38:38 -07:00
|
|
|
terminator()->reset_for_reuse(active_workers);
|
|
|
|
}
|
|
|
|
OopTaskQueueSet* queues() { return _queues; }
|
|
|
|
};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2011-08-09 10:16:01 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Class AbstractWorkGang:
|
|
|
|
// An abstract class representing a gang of workers.
|
|
|
|
// You subclass this to supply an implementation of run_task().
|
2012-06-28 17:03:16 -04:00
|
|
|
class AbstractWorkGang: public CHeapObj<mtInternal> {
|
2007-12-01 00:00:00 +00:00
|
|
|
// Here's the public interface to this class.
|
|
|
|
public:
|
|
|
|
// Constructor and destructor.
|
2008-06-05 15:57:56 -07:00
|
|
|
AbstractWorkGang(const char* name, bool are_GC_task_threads,
|
|
|
|
bool are_ConcurrentGC_threads);
|
2007-12-01 00:00:00 +00:00
|
|
|
~AbstractWorkGang();
|
|
|
|
// Run a task, returns when the task is done (or terminated).
|
|
|
|
virtual void run_task(AbstractGangTask* task) = 0;
|
|
|
|
// Stop and terminate all workers.
|
|
|
|
virtual void stop();
|
2011-08-09 10:16:01 -07:00
|
|
|
// Return true if more workers should be applied to the task.
|
|
|
|
virtual bool needs_more_workers() const { return true; }
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
|
|
|
// Debugging.
|
|
|
|
const char* name() const;
|
|
|
|
protected:
|
|
|
|
// Initialize only instance data.
|
2008-06-05 15:57:56 -07:00
|
|
|
const bool _are_GC_task_threads;
|
|
|
|
const bool _are_ConcurrentGC_threads;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Printing support.
|
|
|
|
const char* _name;
|
|
|
|
// The monitor which protects these data,
|
|
|
|
// and notifies of changes in it.
|
|
|
|
Monitor* _monitor;
|
|
|
|
// The count of the number of workers in the gang.
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _total_workers;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Whether the workers should terminate.
|
|
|
|
bool _terminate;
|
|
|
|
// The array of worker threads for this gang.
|
|
|
|
// This is only needed for cleaning up.
|
|
|
|
GangWorker** _gang_workers;
|
|
|
|
// The task for this gang.
|
|
|
|
AbstractGangTask* _task;
|
|
|
|
// A sequence number for the current task.
|
|
|
|
int _sequence_number;
|
|
|
|
// The number of started workers.
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _started_workers;
|
2007-12-01 00:00:00 +00:00
|
|
|
// The number of finished workers.
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _finished_workers;
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
|
|
|
// Accessors for fields
|
|
|
|
Monitor* monitor() const {
|
|
|
|
return _monitor;
|
|
|
|
}
|
2011-12-14 13:34:57 -08:00
|
|
|
uint total_workers() const {
|
2007-12-01 00:00:00 +00:00
|
|
|
return _total_workers;
|
|
|
|
}
|
2011-12-14 13:34:57 -08:00
|
|
|
virtual uint active_workers() const {
|
2010-09-20 14:38:38 -07:00
|
|
|
return _total_workers;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
bool terminate() const {
|
|
|
|
return _terminate;
|
|
|
|
}
|
|
|
|
GangWorker** gang_workers() const {
|
|
|
|
return _gang_workers;
|
|
|
|
}
|
|
|
|
AbstractGangTask* task() const {
|
|
|
|
return _task;
|
|
|
|
}
|
|
|
|
int sequence_number() const {
|
|
|
|
return _sequence_number;
|
|
|
|
}
|
2011-12-14 13:34:57 -08:00
|
|
|
uint started_workers() const {
|
2007-12-01 00:00:00 +00:00
|
|
|
return _started_workers;
|
|
|
|
}
|
2011-12-14 13:34:57 -08:00
|
|
|
uint finished_workers() const {
|
2007-12-01 00:00:00 +00:00
|
|
|
return _finished_workers;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
bool are_GC_task_threads() const {
|
|
|
|
return _are_GC_task_threads;
|
|
|
|
}
|
|
|
|
bool are_ConcurrentGC_threads() const {
|
|
|
|
return _are_ConcurrentGC_threads;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
// Predicates.
|
|
|
|
bool is_idle() const {
|
|
|
|
return (task() == NULL);
|
|
|
|
}
|
|
|
|
// Return the Ith gang worker.
|
2011-12-14 13:34:57 -08:00
|
|
|
GangWorker* gang_worker(uint i) const;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
void threads_do(ThreadClosure* tc) const;
|
|
|
|
|
|
|
|
// Printing
|
|
|
|
void print_worker_threads_on(outputStream *st) const;
|
|
|
|
void print_worker_threads() const {
|
|
|
|
print_worker_threads_on(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class GangWorker;
|
|
|
|
friend class YieldingFlexibleGangWorker;
|
|
|
|
// Note activation and deactivation of workers.
|
|
|
|
// These methods should only be called with the mutex held.
|
|
|
|
void internal_worker_poll(WorkData* data) const;
|
|
|
|
void internal_note_start();
|
|
|
|
void internal_note_finish();
|
|
|
|
};
|
|
|
|
|
|
|
|
class WorkData: public StackObj {
|
|
|
|
// This would be a struct, but I want accessor methods.
|
|
|
|
private:
|
|
|
|
bool _terminate;
|
|
|
|
AbstractGangTask* _task;
|
|
|
|
int _sequence_number;
|
|
|
|
public:
|
|
|
|
// Constructor and destructor
|
|
|
|
WorkData() {
|
|
|
|
_terminate = false;
|
|
|
|
_task = NULL;
|
|
|
|
_sequence_number = 0;
|
|
|
|
}
|
|
|
|
~WorkData() {
|
|
|
|
}
|
|
|
|
// Accessors and modifiers
|
|
|
|
bool terminate() const { return _terminate; }
|
|
|
|
void set_terminate(bool value) { _terminate = value; }
|
|
|
|
AbstractGangTask* task() const { return _task; }
|
|
|
|
void set_task(AbstractGangTask* value) { _task = value; }
|
|
|
|
int sequence_number() const { return _sequence_number; }
|
|
|
|
void set_sequence_number(int value) { _sequence_number = value; }
|
|
|
|
|
|
|
|
YieldingFlexibleGangTask* yf_task() const {
|
|
|
|
return (YieldingFlexibleGangTask*)_task;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class WorkGang:
|
|
|
|
class WorkGang: public AbstractWorkGang {
|
|
|
|
public:
|
|
|
|
// Constructor
|
2011-12-14 13:34:57 -08:00
|
|
|
WorkGang(const char* name, uint workers,
|
2008-06-05 15:57:56 -07:00
|
|
|
bool are_GC_task_threads, bool are_ConcurrentGC_threads);
|
2007-12-01 00:00:00 +00:00
|
|
|
// Run a task, returns when the task is done (or terminated).
|
|
|
|
virtual void run_task(AbstractGangTask* task);
|
2010-09-20 14:38:38 -07:00
|
|
|
void run_task(AbstractGangTask* task, uint no_of_parallel_workers);
|
|
|
|
// Allocate a worker and return a pointer to it.
|
2011-12-14 13:34:57 -08:00
|
|
|
virtual GangWorker* allocate_worker(uint which);
|
2010-09-20 14:38:38 -07:00
|
|
|
// Initialize workers in the gang. Return true if initialization
|
|
|
|
// succeeded. The type of the worker can be overridden in a derived
|
|
|
|
// class with the appropriate implementation of allocate_worker().
|
|
|
|
bool initialize_workers();
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Class GangWorker:
|
|
|
|
// Several instances of this class run in parallel as workers for a gang.
|
|
|
|
class GangWorker: public WorkerThread {
|
|
|
|
public:
|
|
|
|
// Constructors and destructor.
|
|
|
|
GangWorker(AbstractWorkGang* gang, uint id);
|
|
|
|
|
|
|
|
// The only real method: run a task for the gang.
|
|
|
|
virtual void run();
|
|
|
|
// Predicate for Thread
|
|
|
|
virtual bool is_GC_task_thread() const;
|
2008-06-05 15:57:56 -07:00
|
|
|
virtual bool is_ConcurrentGC_thread() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Printing
|
|
|
|
void print_on(outputStream* st) const;
|
|
|
|
virtual void print() const { print_on(tty); }
|
|
|
|
protected:
|
|
|
|
AbstractWorkGang* _gang;
|
|
|
|
|
|
|
|
virtual void initialize();
|
|
|
|
virtual void loop();
|
|
|
|
|
|
|
|
public:
|
|
|
|
AbstractWorkGang* gang() const { return _gang; }
|
|
|
|
};
|
|
|
|
|
2011-08-09 10:16:01 -07:00
|
|
|
// Dynamic number of worker threads
|
|
|
|
//
|
|
|
|
// This type of work gang is used to run different numbers of
|
|
|
|
// worker threads at different times. The
|
|
|
|
// number of workers run for a task is "_active_workers"
|
|
|
|
// instead of "_total_workers" in a WorkGang. The method
|
|
|
|
// "needs_more_workers()" returns true until "_active_workers"
|
|
|
|
// have been started and returns false afterwards. The
|
|
|
|
// implementation of "needs_more_workers()" in WorkGang always
|
|
|
|
// returns true so that all workers are started. The method
|
|
|
|
// "loop()" in GangWorker was modified to ask "needs_more_workers()"
|
|
|
|
// in its loop to decide if it should start working on a task.
|
|
|
|
// A worker in "loop()" waits for notification on the WorkGang
|
|
|
|
// monitor and execution of each worker as it checks for work
|
|
|
|
// is serialized via the same monitor. The "needs_more_workers()"
|
|
|
|
// call is serialized and additionally the calculation for the
|
|
|
|
// "part" (effectively the worker id for executing the task) is
|
|
|
|
// serialized to give each worker a unique "part". Workers that
|
|
|
|
// are not needed for this tasks (i.e., "_active_workers" have
|
|
|
|
// been started before it, continue to wait for work.
|
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
class FlexibleWorkGang: public WorkGang {
|
2011-08-09 10:16:01 -07:00
|
|
|
// The currently active workers in this gang.
|
|
|
|
// This is a number that is dynamically adjusted
|
|
|
|
// and checked in the run_task() method at each invocation.
|
|
|
|
// As described above _active_workers determines the number
|
|
|
|
// of threads started on a task. It must also be used to
|
|
|
|
// determine completion.
|
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
protected:
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _active_workers;
|
2010-09-20 14:38:38 -07:00
|
|
|
public:
|
|
|
|
// Constructor and destructor.
|
2011-12-14 13:34:57 -08:00
|
|
|
FlexibleWorkGang(const char* name, uint workers,
|
2010-09-20 14:38:38 -07:00
|
|
|
bool are_GC_task_threads,
|
|
|
|
bool are_ConcurrentGC_threads) :
|
2011-08-09 10:16:01 -07:00
|
|
|
WorkGang(name, workers, are_GC_task_threads, are_ConcurrentGC_threads),
|
2015-05-21 14:10:15 +02:00
|
|
|
_active_workers(UseDynamicNumberOfGCThreads ? 1U : workers) {}
|
|
|
|
|
|
|
|
// Accessors for fields.
|
2011-12-14 13:34:57 -08:00
|
|
|
virtual uint active_workers() const { return _active_workers; }
|
|
|
|
void set_active_workers(uint v) {
|
2011-08-09 10:16:01 -07:00
|
|
|
assert(v <= _total_workers,
|
|
|
|
"Trying to set more workers active than there are");
|
|
|
|
_active_workers = MIN2(v, _total_workers);
|
|
|
|
assert(v != 0, "Trying to set active workers to 0");
|
2011-12-14 13:34:57 -08:00
|
|
|
_active_workers = MAX2(1U, _active_workers);
|
2011-08-09 10:16:01 -07:00
|
|
|
assert(UseDynamicNumberOfGCThreads || _active_workers == _total_workers,
|
|
|
|
"Unless dynamic should use total workers");
|
|
|
|
}
|
|
|
|
virtual void run_task(AbstractGangTask* task);
|
|
|
|
virtual bool needs_more_workers() const {
|
|
|
|
return _started_workers < _active_workers;
|
|
|
|
}
|
2010-09-20 14:38:38 -07:00
|
|
|
};
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// A class that acts as a synchronisation barrier. Workers enter
|
|
|
|
// the barrier and must wait until all other workers have entered
|
|
|
|
// before any of them may leave.
|
|
|
|
|
|
|
|
class WorkGangBarrierSync : public StackObj {
|
|
|
|
protected:
|
|
|
|
Monitor _monitor;
|
2014-05-14 13:32:44 +02:00
|
|
|
uint _n_workers;
|
|
|
|
uint _n_completed;
|
2008-06-05 15:57:56 -07:00
|
|
|
bool _should_reset;
|
2014-05-14 13:32:44 +02:00
|
|
|
bool _aborted;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
Monitor* monitor() { return &_monitor; }
|
2011-12-14 13:34:57 -08:00
|
|
|
uint n_workers() { return _n_workers; }
|
|
|
|
uint n_completed() { return _n_completed; }
|
2008-06-05 15:57:56 -07:00
|
|
|
bool should_reset() { return _should_reset; }
|
2014-05-14 13:32:44 +02:00
|
|
|
bool aborted() { return _aborted; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
void zero_completed() { _n_completed = 0; }
|
|
|
|
void inc_completed() { _n_completed++; }
|
2014-05-14 13:32:44 +02:00
|
|
|
void set_aborted() { _aborted = true; }
|
2008-06-05 15:57:56 -07:00
|
|
|
void set_should_reset(bool v) { _should_reset = v; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
WorkGangBarrierSync();
|
2011-12-14 13:34:57 -08:00
|
|
|
WorkGangBarrierSync(uint n_workers, const char* name);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the number of workers that will use the barrier.
|
|
|
|
// Must be called before any of the workers start running.
|
2011-12-14 13:34:57 -08:00
|
|
|
void set_n_workers(uint n_workers);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Enter the barrier. A worker that enters the barrier will
|
|
|
|
// not be allowed to leave until all other threads have
|
2014-05-14 13:32:44 +02:00
|
|
|
// also entered the barrier or the barrier is aborted.
|
|
|
|
// Returns false if the barrier was aborted.
|
|
|
|
bool enter();
|
|
|
|
|
|
|
|
// Aborts the barrier and wakes up any threads waiting for
|
|
|
|
// the barrier to complete. The barrier will remain in the
|
|
|
|
// aborted state until the next call to set_n_workers().
|
|
|
|
void abort();
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A class to manage claiming of subtasks within a group of tasks. The
|
|
|
|
// subtasks will be identified by integer indices, usually elements of an
|
|
|
|
// enumeration type.
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class SubTasksDone: public CHeapObj<mtInternal> {
|
2011-12-14 13:34:57 -08:00
|
|
|
uint* _tasks;
|
|
|
|
uint _n_tasks;
|
|
|
|
uint _threads_completed;
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef ASSERT
|
2011-12-14 13:34:57 -08:00
|
|
|
volatile uint _claimed;
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set all tasks to unclaimed.
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Initializes "this" to a state in which there are "n" tasks to be
|
|
|
|
// processed, none of the which are originally claimed. The number of
|
|
|
|
// threads doing the tasks is initialized 1.
|
2011-12-14 13:34:57 -08:00
|
|
|
SubTasksDone(uint n);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// True iff the object is in a valid state.
|
|
|
|
bool valid();
|
|
|
|
|
|
|
|
// Returns "false" if the task "t" is unclaimed, and ensures that task is
|
|
|
|
// claimed. The task "t" is required to be within the range of "this".
|
2011-12-14 13:34:57 -08:00
|
|
|
bool is_task_claimed(uint t);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// The calling thread asserts that it has attempted to claim all the
|
|
|
|
// tasks that it will try to claim. Every thread in the parallel task
|
|
|
|
// must execute this. (When the last thread does so, the task array is
|
|
|
|
// cleared.)
|
2015-05-21 09:23:46 +02:00
|
|
|
//
|
|
|
|
// n_threads - Number of threads executing the sub-tasks.
|
|
|
|
void all_tasks_completed(uint n_threads);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Destructor.
|
|
|
|
~SubTasksDone();
|
|
|
|
};
|
|
|
|
|
|
|
|
// As above, but for sequential tasks, i.e. instead of claiming
|
|
|
|
// sub-tasks from a set (possibly an enumeration), claim sub-tasks
|
|
|
|
// in sequential order. This is ideal for claiming dynamically
|
|
|
|
// partitioned tasks (like striding in the parallel remembered
|
|
|
|
// set scanning). Note that unlike the above class this is
|
|
|
|
// a stack object - is there any reason for it not to be?
|
|
|
|
|
|
|
|
class SequentialSubTasksDone : public StackObj {
|
|
|
|
protected:
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _n_tasks; // Total number of tasks available.
|
|
|
|
uint _n_claimed; // Number of tasks claimed.
|
2010-09-20 14:38:38 -07:00
|
|
|
// _n_threads is used to determine when a sub task is done.
|
|
|
|
// See comments on SubTasksDone::_n_threads
|
2011-12-14 13:34:57 -08:00
|
|
|
uint _n_threads; // Total number of parallel threads.
|
|
|
|
uint _n_completed; // Number of completed threads.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
public:
|
2010-09-20 14:38:38 -07:00
|
|
|
SequentialSubTasksDone() {
|
|
|
|
clear();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
~SequentialSubTasksDone() {}
|
|
|
|
|
|
|
|
// True iff the object is in a valid state.
|
|
|
|
bool valid();
|
|
|
|
|
|
|
|
// number of tasks
|
2011-12-14 13:34:57 -08:00
|
|
|
uint n_tasks() const { return _n_tasks; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-09-20 14:38:38 -07:00
|
|
|
// Get/set the number of parallel threads doing the tasks to t.
|
2007-12-01 00:00:00 +00:00
|
|
|
// Should be called before the task starts but it is safe
|
|
|
|
// to call this once a task is running provided that all
|
|
|
|
// threads agree on the number of threads.
|
2011-12-14 13:34:57 -08:00
|
|
|
uint n_threads() { return _n_threads; }
|
|
|
|
void set_n_threads(uint t) { _n_threads = t; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the number of tasks to be claimed to t. As above,
|
|
|
|
// should be called before the tasks start but it is safe
|
|
|
|
// to call this once a task is running provided all threads
|
|
|
|
// agree on the number of tasks.
|
2011-12-14 13:34:57 -08:00
|
|
|
void set_n_tasks(uint t) { _n_tasks = t; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Returns false if the next task in the sequence is unclaimed,
|
|
|
|
// and ensures that it is claimed. Will set t to be the index
|
|
|
|
// of the claimed task in the sequence. Will return true if
|
|
|
|
// the task cannot be claimed and there are none left to claim.
|
2011-12-14 13:34:57 -08:00
|
|
|
bool is_task_claimed(uint& t);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// The calling thread asserts that it has attempted to claim
|
|
|
|
// all the tasks it possibly can in the sequence. Every thread
|
|
|
|
// claiming tasks must promise call this. Returns true if this
|
|
|
|
// is the last thread to complete so that the thread can perform
|
|
|
|
// cleanup if necessary.
|
|
|
|
bool all_tasks_completed();
|
|
|
|
};
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Represents a set of free small integer ids.
|
2013-05-14 09:41:12 -07:00
|
|
|
class FreeIdSet : public CHeapObj<mtInternal> {
|
2008-06-05 15:57:56 -07:00
|
|
|
enum {
|
|
|
|
end_of_list = -1,
|
|
|
|
claimed = -2
|
|
|
|
};
|
|
|
|
|
|
|
|
int _sz;
|
|
|
|
Monitor* _mon;
|
|
|
|
|
|
|
|
int* _ids;
|
|
|
|
int _hd;
|
|
|
|
int _waiters;
|
|
|
|
int _claimed;
|
|
|
|
|
|
|
|
static bool _safepoint;
|
|
|
|
typedef FreeIdSet* FreeIdSetPtr;
|
|
|
|
static const int NSets = 10;
|
|
|
|
static FreeIdSetPtr _sets[NSets];
|
|
|
|
static bool _stat_init;
|
|
|
|
int _index;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FreeIdSet(int sz, Monitor* mon);
|
|
|
|
~FreeIdSet();
|
|
|
|
|
|
|
|
static void set_safepoint(bool b);
|
|
|
|
|
|
|
|
// Attempt to claim the given id permanently. Returns "true" iff
|
|
|
|
// successful.
|
|
|
|
bool claim_perm_id(int i);
|
|
|
|
|
|
|
|
// Returns an unclaimed parallel id (waiting for one to be released if
|
|
|
|
// necessary). Returns "-1" if a GC wakes up a wait for an id.
|
|
|
|
int claim_par_id();
|
|
|
|
|
|
|
|
void release_par_id(int id);
|
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#endif // SHARE_VM_GC_SHARED_WORKGROUP_HPP
|