Skip to content

Commit

Permalink
Use the stream directly when printing the report.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelter-sap committed Jul 17, 2023
1 parent 568cd0c commit ea7b0d6
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions src/hotspot/share/vitals/vitals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,26 +781,6 @@ class SampleTables: public CHeapObj<mtInternal> {

int _count;

// A pre-allocated buffer for printing reports. We preallocate this since
// when we want to print the report we may be in no condition to allocate memory.
char _temp_buffer[196 * K];

static void dump_stream(bool no_alloc, stringStream* in, outputStream* out) {
if (no_alloc) {
g_vitals_lock.unlock();
out->print_raw(in->base());

if (in->size() >= (size_t)(sizeof(_temp_buffer) - 1)) {
out->cr();
out->print_cr("-- Buffer overflow, truncated (total: " SIZE_FORMAT ").", (size_t)in->count());
out->cr();
}

g_vitals_lock.lock();
in->reset();
}
}

static void print_table(const SampleTable* table, outputStream* st,
const ColumnWidths* widths, const print_info_t* pi) {
if (table->is_empty()) {
Expand Down Expand Up @@ -900,19 +880,11 @@ class SampleTables: public CHeapObj<mtInternal> {
}
}

void print_all(outputStream* external_stream, const print_info_t* pi, const Sample* sample_now) {

// We are paranoid about blocking inside a lock. So we print to a preallocated buffer under
// lock protection, and copy ot the outside stream when out of the lock.
stringStream no_alloc_stream(_temp_buffer, sizeof(_temp_buffer));
outputStream* st = pi->no_alloc ? &no_alloc_stream : external_stream;
void print_all(outputStream* st, const print_info_t* pi, const Sample* sample_now) {

{ // lock start
AutoLock autolock(&g_vitals_lock);

// We dump each table seperately to save memory in our preallocated buffer. Since we have
// to give up the lock for a short time, we don't get a consistent snapshot, but it should
// not be a big deal.
if (sample_now != NULL) {
ColumnWidths widths;
MeasureColumnWidthsClosure mcwclos(pi, &widths);
Expand All @@ -921,7 +893,6 @@ class SampleTables: public CHeapObj<mtInternal> {
print_headers(st, &widths, pi);
print_one_sample(st, sample_now, NULL, &widths, pi);
st->cr();
dump_stream(pi->no_alloc , &no_alloc_stream, external_stream);
}

if (!_short_term_table.is_empty()) {
Expand All @@ -935,7 +906,6 @@ class SampleTables: public CHeapObj<mtInternal> {
print_headers(st, &widths, pi);
print_table(&_short_term_table, st, &widths, pi);
st->cr();
dump_stream(pi->no_alloc, &no_alloc_stream, external_stream);
}

if (!_long_term_table.is_empty()) {
Expand All @@ -946,7 +916,6 @@ class SampleTables: public CHeapObj<mtInternal> {
print_headers(st, &widths, pi);
print_table(&_long_term_table, st, &widths, pi);
st->cr();
dump_stream(pi->no_alloc, &no_alloc_stream, external_stream);
}

if (StoreVitalsExtremas && !_extremum_samples.is_empty() && !_last_extremum_samples.is_empty()) {
Expand All @@ -973,8 +942,6 @@ class SampleTables: public CHeapObj<mtInternal> {
column->extremum() == MIN ? "-" : "+");
}
}

dump_stream(pi->no_alloc, &no_alloc_stream, external_stream);
}

st->cr();
Expand Down

0 comments on commit ea7b0d6

Please sign in to comment.