97 Semaphore* post,
98 G1FreeIdSet* set,
99 volatile size_t* total_allocations,
100 volatile bool* continue_running) :
101 JavaTestThread(post),
102 _set(set),
103 _total_allocations(total_allocations),
104 _continue_running(continue_running),
105 _allocations(0),
106 _thread_number(thread_number)
107 {}
108
109 virtual void main_run() {
110 while (Atomic::load_acquire(_continue_running)) {
111 uint id = _set->claim_par_id();
112 _set->release_par_id(id);
113 ++_allocations;
114 ThreadBlockInVM tbiv(this); // Safepoint check.
115 }
116 tty->print_cr("%u allocations: " SIZE_FORMAT, _thread_number, _allocations);
117 Atomic::add(_allocations, _total_allocations);
118 }
119 };
120
121 TEST_VM(G1FreeIdSetTest, stress) {
122 const uint start = 5;
123 const uint size = 3;
124 const uint nthreads = size + 1;
125 const uint milliseconds_to_run = 1000;
126
127 Semaphore post;
128 volatile size_t total_allocations = 0;
129 volatile bool continue_running = true;
130
131 G1FreeIdSet set(start, size);
132
133 TestG1FreeIdSetThread* threads[nthreads] = {};
134 for (uint i = 0; i < nthreads; ++i) {
135 threads[i] = new TestG1FreeIdSetThread(i,
136 &post,
137 &set,
|
97 Semaphore* post,
98 G1FreeIdSet* set,
99 volatile size_t* total_allocations,
100 volatile bool* continue_running) :
101 JavaTestThread(post),
102 _set(set),
103 _total_allocations(total_allocations),
104 _continue_running(continue_running),
105 _allocations(0),
106 _thread_number(thread_number)
107 {}
108
109 virtual void main_run() {
110 while (Atomic::load_acquire(_continue_running)) {
111 uint id = _set->claim_par_id();
112 _set->release_par_id(id);
113 ++_allocations;
114 ThreadBlockInVM tbiv(this); // Safepoint check.
115 }
116 tty->print_cr("%u allocations: " SIZE_FORMAT, _thread_number, _allocations);
117 Atomic::add(_total_allocations, _allocations);
118 }
119 };
120
121 TEST_VM(G1FreeIdSetTest, stress) {
122 const uint start = 5;
123 const uint size = 3;
124 const uint nthreads = size + 1;
125 const uint milliseconds_to_run = 1000;
126
127 Semaphore post;
128 volatile size_t total_allocations = 0;
129 volatile bool continue_running = true;
130
131 G1FreeIdSet set(start, size);
132
133 TestG1FreeIdSetThread* threads[nthreads] = {};
134 for (uint i = 0; i < nthreads; ++i) {
135 threads[i] = new TestG1FreeIdSetThread(i,
136 &post,
137 &set,
|