mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8233697: CHT: Iteration parallelization
Reviewed-by: tschatzl, rehn
This commit is contained in:
parent
7619602c36
commit
1a58cb1c02
4 changed files with 212 additions and 37 deletions
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/shared/workerThread.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/semaphore.hpp"
|
||||
|
@ -1145,3 +1146,79 @@ public:
|
|||
TEST_VM(ConcurrentHashTable, concurrent_mt_bulk_delete) {
|
||||
mt_test_doer<Driver_BD_Thread>();
|
||||
}
|
||||
|
||||
class CHTParallelScanTask: public WorkerTask {
|
||||
TestTable* _cht;
|
||||
TestTable::ScanTask* _scan_task;
|
||||
size_t *_total_scanned;
|
||||
|
||||
public:
|
||||
CHTParallelScanTask(TestTable* cht,
|
||||
TestTable::ScanTask* bc,
|
||||
size_t *total_scanned) :
|
||||
WorkerTask("CHT Parallel Scan"),
|
||||
_cht(cht),
|
||||
_scan_task(bc),
|
||||
_total_scanned(total_scanned)
|
||||
{ }
|
||||
|
||||
void work(uint worker_id) {
|
||||
ChtCountScan par_scan;
|
||||
_scan_task->do_safepoint_scan(par_scan);
|
||||
Atomic::add(_total_scanned, par_scan._count);
|
||||
}
|
||||
};
|
||||
|
||||
class CHTWorkers : AllStatic {
|
||||
static WorkerThreads* _workers;
|
||||
static WorkerThreads* workers() {
|
||||
if (_workers == nullptr) {
|
||||
_workers = new WorkerThreads("CHT Workers", MaxWorkers);
|
||||
_workers->initialize_workers();
|
||||
_workers->set_active_workers(MaxWorkers);
|
||||
}
|
||||
return _workers;
|
||||
}
|
||||
|
||||
public:
|
||||
static const uint MaxWorkers = 8;
|
||||
static void run_task(WorkerTask* task) {
|
||||
workers()->run_task(task);
|
||||
}
|
||||
};
|
||||
|
||||
WorkerThreads* CHTWorkers::_workers = nullptr;
|
||||
|
||||
class CHTParallelScan: public VM_GTestExecuteAtSafepoint {
|
||||
TestTable* _cht;
|
||||
uintptr_t _num_items;
|
||||
public:
|
||||
CHTParallelScan(TestTable* cht, uintptr_t num_items) :
|
||||
_cht(cht), _num_items(num_items)
|
||||
{}
|
||||
|
||||
void doit() {
|
||||
size_t total_scanned = 0;
|
||||
TestTable::ScanTask scan_task(_cht, 64);
|
||||
|
||||
CHTParallelScanTask task(_cht, &scan_task, &total_scanned);
|
||||
CHTWorkers::run_task(&task);
|
||||
|
||||
EXPECT_TRUE(total_scanned == (size_t)_num_items) << " Should scan all inserted items: " << total_scanned;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_VM(ConcurrentHashTable, concurrent_par_scan) {
|
||||
TestTable* cht = new TestTable(16, 16, 2);
|
||||
|
||||
uintptr_t num_items = 999999;
|
||||
for (uintptr_t v = 1; v <= num_items; v++ ) {
|
||||
TestLookup tl(v);
|
||||
EXPECT_TRUE(cht->insert(JavaThread::current(), tl, v)) << "Inserting an unique value should work.";
|
||||
}
|
||||
|
||||
// Run the test at a safepoint.
|
||||
CHTParallelScan op(cht, num_items);
|
||||
ThreadInVMfromNative invm(JavaThread::current());
|
||||
VMThread::execute(&op);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue