Skip to content

Commit a29612e

Browse files
committed
8255661: TestHeapDumpOnOutOfMemoryError fails with EOFException
Reviewed-by: rrich, cjplummer
1 parent a555fd8 commit a29612e

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

src/hotspot/share/services/heapDumper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class DumpWriter : public StackObj {
444444
void finish_dump_segment();
445445

446446
// Called by threads used for parallel writing.
447-
void writer_loop() { _backend.thread_loop(false); }
447+
void writer_loop() { _backend.thread_loop(); }
448448
// Called when finished to release the threads.
449449
void deactivate() { flush(); _backend.deactivate(); }
450450
};

src/hotspot/share/services/heapDumperCompression.cpp

+23-33
Original file line numberDiff line numberDiff line change
@@ -250,48 +250,30 @@ void CompressionBackend::deactivate() {
250250
ml.notify_all();
251251
}
252252

253-
// Wait for the threads to drain the compression work list.
253+
// Wait for the threads to drain the compression work list and do some work yourself.
254254
while (!_to_compress.is_empty()) {
255-
// If we have no threads, compress the current one itself.
256-
if (_nr_of_threads == 0) {
257-
MutexUnlocker mu(_lock, Mutex::_no_safepoint_check_flag);
258-
thread_loop(true);
259-
} else {
260-
ml.wait();
261-
}
255+
do_foreground_work();
262256
}
263257

264258
_active = false;
265259
ml.notify_all();
266260
}
267261

268-
void CompressionBackend::thread_loop(bool single_run) {
269-
// Register if this is a worker thread.
270-
if (!single_run) {
262+
void CompressionBackend::thread_loop() {
263+
{
271264
MonitorLocker ml(_lock, Mutex::_no_safepoint_check_flag);
272265
_nr_of_threads++;
273266
}
274267

275-
while (true) {
276-
WriteWork* work = get_work();
277-
278-
if (work == NULL) {
279-
assert(!single_run, "Should never happen for single thread");
280-
MonitorLocker ml(_lock, Mutex::_no_safepoint_check_flag);
281-
_nr_of_threads--;
282-
assert(_nr_of_threads >= 0, "Too many threads finished");
283-
ml.notify_all();
284-
285-
return;
286-
} else {
287-
do_compress(work);
288-
finish_work(work);
289-
}
290-
291-
if (single_run) {
292-
return;
293-
}
268+
WriteWork* work;
269+
while ((work = get_work()) != NULL) {
270+
do_compress(work);
271+
finish_work(work);
294272
}
273+
274+
MonitorLocker ml(_lock, Mutex::_no_safepoint_check_flag);
275+
_nr_of_threads--;
276+
assert(_nr_of_threads >= 0, "Too many threads finished");
295277
}
296278

297279
void CompressionBackend::set_error(char const* new_error) {
@@ -363,6 +345,16 @@ void CompressionBackend::free_work_list(WorkList* list) {
363345
}
364346
}
365347

348+
void CompressionBackend::do_foreground_work() {
349+
assert(!_to_compress.is_empty(), "Must have work to do");
350+
assert(_lock->owned_by_self(), "Must have the lock");
351+
352+
WriteWork* work = _to_compress.remove_first();
353+
MutexUnlocker mu(_lock, Mutex::_no_safepoint_check_flag);
354+
do_compress(work);
355+
finish_work(work);
356+
}
357+
366358
WriteWork* CompressionBackend::get_work() {
367359
MonitorLocker ml(_lock, Mutex::_no_safepoint_check_flag);
368360

@@ -405,9 +397,7 @@ void CompressionBackend::get_new_buffer(char** buffer, size_t* used, size_t* max
405397
_unused.add_first(work);
406398
}
407399
} else if (!_to_compress.is_empty() && (_nr_of_threads == 0)) {
408-
// If we have no threads, compress the current one itself.
409-
MutexUnlocker mu(_lock, Mutex::_no_safepoint_check_flag);
410-
thread_loop(true);
400+
do_foreground_work();
411401
} else {
412402
ml.wait();
413403
}

src/hotspot/share/services/heapDumperCompression.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class CompressionBackend : StackObj {
199199
void free_work(WriteWork* work);
200200
void free_work_list(WorkList* list);
201201

202+
void do_foreground_work();
202203
WriteWork* get_work();
203204
void do_compress(WriteWork* work);
204205
void finish_work(WriteWork* work);
@@ -221,8 +222,8 @@ class CompressionBackend : StackObj {
221222
// Commits the old buffer (using the value in *used) and sets up a new one.
222223
void get_new_buffer(char** buffer, size_t* used, size_t* max);
223224

224-
// The entry point for a worker thread. If single_run is true, we only handle one entry.
225-
void thread_loop(bool single_run);
225+
// The entry point for a worker thread.
226+
void thread_loop();
226227

227228
// Shuts down the backend, releasing all threads.
228229
void deactivate();

0 commit comments

Comments
 (0)