// Test that a task that is added during runtime gets run.
TEST_VM(G1ServiceThread, test_add) { // Create thread and let it start.
G1ServiceThread* st = new G1ServiceThread();
os::naked_short_sleep(500);
// Give CheckTask time to run.
os::naked_short_sleep(500);
stop_service_thread(st);
ASSERT_GT(ct.execution_count(), 0);
}
// Test that a task that is added while the service thread is // waiting gets run in a timely manner.
TEST_VM(G1ServiceThread, test_add_while_waiting) { // Make sure default tasks use long intervals so that the service thread // is doing a long wait for the next execution.
AutoModifyRestore<uintx> f1(G1PeriodicGCInterval, 100000);
// Create thread and let it start.
G1ServiceThread* st = new G1ServiceThread();
os::naked_short_sleep(500);
// Register a new task that should run right away.
CheckTask ct("AddWhileWaiting");
st->register_task(&ct);
// Give CheckTask time to run.
os::naked_short_sleep(500);
stop_service_thread(st);
ASSERT_GT(ct.execution_count(), 0);
}
// Test that a task with negative timeout is not rescheduled.
TEST_VM(G1ServiceThread, test_add_run_once) { // Create thread and let it start.
G1ServiceThread* st = new G1ServiceThread();
os::naked_short_sleep(500);
// Set reschedule to false to only run once.
CheckTask ct("AddRunOnce");
ct.set_reschedule(false);
st->register_task(&ct);
// Give CheckTask time to run.
os::naked_short_sleep(500);
stop_service_thread(st);
// Should be exactly 1 since negative timeout should // prevent rescheduling.
ASSERT_EQ(ct.execution_count(), 1);
}
int num_test_tasks = 5; for (int i = 1; i <= num_test_tasks; i++) { // Create tasks with different timeout.
TestTask* task = new TestTask(100 * i);
queue.add_ordered(task);
}
// Now fake a run-loop, that reschedules the tasks using a // random multiplier. for (jlong now = 0; now < 1000000; now++) { // Random multiplier is at least 1 to ensure progress. int multiplier = 1 + os::random() % 10; while (queue.front()->time() < now) {
TestTask* task = (TestTask*) queue.front();
queue.remove_front(); // Update delay multiplier.
task->execute();
task->update_time(now, multiplier); // All additions will verify that the queue is sorted.
queue.add_ordered(task);
}
}
#ifdef ASSERT
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, remove_from_empty, ".*Should never try to verify empty queue") {
G1ServiceTaskQueue queue;
queue.remove_front();
}
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, get_from_empty, ".*Should never try to verify empty queue") {
G1ServiceTaskQueue queue;
queue.front();
}
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, set_time_in_queue, ".*Not allowed to update time while in queue") {
G1ServiceTaskQueue queue;
TestTask a(100);
queue.add_ordered(&a); // Not allowed to update time while in queue.
a.update_time(500, 1);
}
#endif
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.