Skip to content

Commit db67f23

Browse files
author
Datadog Syncup Service
committed
Merge branch 'upstream-master'
2 parents 958d1d2 + 61386c1 commit db67f23

File tree

75 files changed

+916
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+916
-475
lines changed

Diff for: src/hotspot/share/code/codeCache.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -1790,15 +1790,17 @@ void CodeCache::log_state(outputStream* st) {
17901790
#ifdef LINUX
17911791
void CodeCache::write_perf_map(const char* filename, outputStream* st) {
17921792
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1793-
1794-
// Perf expects to find the map file at /tmp/perf-<pid>.map
1795-
// if the file name is not specified.
1796-
char fname[32];
1793+
char fname[JVM_MAXPATHLEN];
17971794
if (filename == nullptr) {
1798-
jio_snprintf(fname, sizeof(fname), "/tmp/perf-%d.map", os::current_process_id());
1795+
// Invocation outside of jcmd requires pid substitution.
1796+
if (!Arguments::copy_expand_pid(DEFAULT_PERFMAP_FILENAME,
1797+
strlen(DEFAULT_PERFMAP_FILENAME),
1798+
fname, JVM_MAXPATHLEN)) {
1799+
st->print_cr("Warning: Not writing perf map as pid substitution failed.");
1800+
return;
1801+
}
17991802
filename = fname;
18001803
}
1801-
18021804
fileStream fs(filename, "w");
18031805
if (!fs.is_open()) {
18041806
st->print_cr("Warning: Failed to create %s for perf map", filename);

Diff for: src/hotspot/share/code/codeCache.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class ShenandoahParallelCodeHeapIterator;
8080
class NativePostCallNop;
8181
class DeoptimizationScope;
8282

83+
#ifdef LINUX
84+
#define DEFAULT_PERFMAP_FILENAME "/tmp/perf-%p.map"
85+
#endif
86+
8387
class CodeCache : AllStatic {
8488
friend class VMStructs;
8589
friend class JVMCIVMStructs;

Diff for: src/hotspot/share/compiler/compilationMemoryStatistic.cpp

+77-68
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,36 @@
5151
#include "utilities/quickSort.hpp"
5252
#include "utilities/resourceHash.hpp"
5353

54-
ArenaStatCounter::ArenaStatCounter() :
55-
_current(0), _start(0), _peak(0),
56-
_na(0), _ra(0),
57-
_limit(0), _hit_limit(false), _limit_in_process(false),
58-
_na_at_peak(0), _ra_at_peak(0), _live_nodes_at_peak(0)
59-
{}
60-
61-
size_t ArenaStatCounter::peak_since_start() const {
62-
return _peak > _start ? _peak - _start : 0;
54+
ArenaStatCounter::ArenaStatCounter() {
55+
reset();
56+
}
57+
58+
void ArenaStatCounter::reset() {
59+
_current = 0;
60+
_peak = 0;
61+
_current_by_tag.clear();
62+
_peak_by_tag.clear();
63+
_limit = 0;
64+
_hit_limit = false;
65+
_limit_in_process = false;
66+
_live_nodes_at_peak = 0;
67+
_active = false;
6368
}
6469

6570
void ArenaStatCounter::start(size_t limit) {
66-
_peak = _start = _current;
71+
reset();
72+
_active = true;
6773
_limit = limit;
68-
_hit_limit = false;
6974
}
7075

71-
void ArenaStatCounter::end(){
76+
void ArenaStatCounter::end() {
7277
_limit = 0;
7378
_hit_limit = false;
79+
_active = false;
7480
}
7581

7682
void ArenaStatCounter::update_c2_node_count() {
83+
assert(_active, "compilaton has not yet started");
7784
#ifdef COMPILER2
7885
CompilerThread* const th = Thread::current()->as_Compiler_thread();
7986
const CompileTask* const task = th->task();
@@ -90,43 +97,43 @@ void ArenaStatCounter::update_c2_node_count() {
9097

9198
// Account an arena allocation or de-allocation.
9299
bool ArenaStatCounter::account(ssize_t delta, int tag) {
100+
assert(_active, "compilaton has not yet started");
93101
bool rc = false;
94102
#ifdef ASSERT
95103
// Note: if this fires, we free more arena memory under the scope of the
96104
// CompilationMemoryHistoryMark than we allocate. This cannot be since we
97105
// assume arena allocations in CompilerThread to be stack bound and symmetric.
98106
assert(delta >= 0 || ((ssize_t)_current + delta) >= 0,
99-
"Negative overflow (d=%zd %zu %zu %zu)", delta, _current, _start, _peak);
107+
"Negative overflow (d=%zd %zu %zu)", delta, _current, _peak);
100108
#endif
101109
// Update totals
102110
_current += delta;
103-
// Update detail counter
104-
switch ((Arena::Tag)tag) {
105-
case Arena::Tag::tag_ra: _ra += delta; break;
106-
case Arena::Tag::tag_node: _na += delta; break;
107-
default: // ignore
108-
break;
109-
};
111+
_current_by_tag.add(tag, delta);
110112
// Did we reach a peak?
111113
if (_current > _peak) {
112114
_peak = _current;
113-
assert(delta > 0, "Sanity (%zu %zu %zu)", _current, _start, _peak);
114-
_na_at_peak = _na;
115-
_ra_at_peak = _ra;
115+
assert(delta > 0, "Sanity (%zu %zu)", _current, _peak);
116116
update_c2_node_count();
117+
_peak_by_tag = _current_by_tag;
117118
rc = true;
118119
// Did we hit the memory limit?
119-
if (!_hit_limit && _limit > 0 && peak_since_start() > _limit) {
120+
if (!_hit_limit && _limit > 0 && _peak > _limit) {
120121
_hit_limit = true;
121122
}
122123
}
123124
return rc;
124125
}
125126

126127
void ArenaStatCounter::print_on(outputStream* st) const {
127-
st->print("%zu [na %zu ra %zu]", peak_since_start(), _na_at_peak, _ra_at_peak);
128+
st->print("%zu [", _peak);
129+
for (int tag = 0; tag < _peak_by_tag.element_count(); tag++) {
130+
if (_peak_by_tag.counter(tag) > 0) {
131+
st->print("%s %zu ", _peak_by_tag.tag_name(tag), _peak_by_tag.counter(tag));
132+
}
133+
}
134+
st->print("]");
128135
#ifdef ASSERT
129-
st->print(" (%zu->%zu->%zu)", _start, _peak, _current);
136+
st->print(" (%zu->%zu)", _peak, _current);
130137
#endif
131138
}
132139

@@ -186,10 +193,8 @@ class MemStatEntry : public CHeapObj<mtInternal> {
186193

187194
// peak usage, bytes, over all arenas
188195
size_t _total;
189-
// usage in node arena when total peaked
190-
size_t _na_at_peak;
191-
// usage in resource area when total peaked
192-
size_t _ra_at_peak;
196+
// usage per arena tag when total peaked
197+
ArenaCountersByTag _peak_by_tag;
193198
// number of nodes (c2 only) when total peaked
194199
unsigned _live_nodes_at_peak;
195200
const char* _result;
@@ -199,8 +204,9 @@ class MemStatEntry : public CHeapObj<mtInternal> {
199204
MemStatEntry(FullMethodName method)
200205
: _method(method), _comptype(compiler_c1),
201206
_time(0), _num_recomp(0), _thread(nullptr), _limit(0),
202-
_total(0), _na_at_peak(0), _ra_at_peak(0), _live_nodes_at_peak(0),
207+
_total(0), _live_nodes_at_peak(0),
203208
_result(nullptr) {
209+
_peak_by_tag.clear();
204210
}
205211

206212
void set_comptype(CompilerType comptype) { _comptype = comptype; }
@@ -210,30 +216,42 @@ class MemStatEntry : public CHeapObj<mtInternal> {
210216
void inc_recompilation() { _num_recomp++; }
211217

212218
void set_total(size_t n) { _total = n; }
213-
void set_na_at_peak(size_t n) { _na_at_peak = n; }
214-
void set_ra_at_peak(size_t n) { _ra_at_peak = n; }
219+
void set_peak_by_tag(ArenaCountersByTag peak_by_tag) { _peak_by_tag = peak_by_tag; }
215220
void set_live_nodes_at_peak(unsigned n) { _live_nodes_at_peak = n; }
216221

217222
void set_result(const char* s) { _result = s; }
218223

219224
size_t total() const { return _total; }
220225

221226
static void print_legend(outputStream* st) {
227+
#define LEGEND_KEY_FMT "%11s"
222228
st->print_cr("Legend:");
223-
st->print_cr(" total : memory allocated via arenas while compiling");
224-
st->print_cr(" NA : ...how much in node arenas (if c2)");
225-
st->print_cr(" RA : ...how much in resource areas");
226-
st->print_cr(" result : Result: 'ok' finished successfully, 'oom' hit memory limit, 'err' compilation failed");
227-
st->print_cr(" #nodes : ...how many nodes (c2 only)");
228-
st->print_cr(" limit : memory limit, if set");
229-
st->print_cr(" time : time of last compilation (sec)");
230-
st->print_cr(" type : compiler type");
231-
st->print_cr(" #rc : how often recompiled");
232-
st->print_cr(" thread : compiler thread");
229+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "total", "memory allocated via arenas while compiling");
230+
for (int tag = 0; tag < Arena::tag_count(); tag++) {
231+
st->print_cr(" " LEGEND_KEY_FMT ": %s", Arena::tag_name[tag], Arena::tag_desc[tag]);
232+
}
233+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "result", "Result: 'ok' finished successfully, 'oom' hit memory limit, 'err' compilation failed");
234+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "#nodes", "...how many nodes (c2 only)");
235+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "limit", "memory limit, if set");
236+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "time", "time taken for last compilation (sec)");
237+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "type", "compiler type");
238+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "#rc", "how often recompiled");
239+
st->print_cr(" " LEGEND_KEY_FMT ": %s", "thread", "compiler thread");
240+
#undef LEGEND_KEY_FMT
233241
}
234242

235243
static void print_header(outputStream* st) {
236-
st->print_cr("total NA RA result #nodes limit time type #rc thread method");
244+
#define SIZE_FMT "%-10s"
245+
st->print(SIZE_FMT, "total");
246+
for (int tag = 0; tag < Arena::tag_count(); tag++) {
247+
st->print(SIZE_FMT, Arena::tag_name[tag]);
248+
}
249+
#define HDR_FMT1 "%-8s%-8s%-8s%-8s"
250+
#define HDR_FMT2 "%-6s%-4s%-19s%s"
251+
252+
st->print(HDR_FMT1, "result", "#nodes", "limit", "time");
253+
st->print(HDR_FMT2, "type", "#rc", "thread", "method");
254+
st->print_cr("");
237255
}
238256

239257
void print_on(outputStream* st, bool human_readable) const {
@@ -247,21 +265,14 @@ class MemStatEntry : public CHeapObj<mtInternal> {
247265
}
248266
col += 10; st->fill_to(col);
249267

250-
// NA
251-
if (human_readable) {
252-
st->print(PROPERFMT " ", PROPERFMTARGS(_na_at_peak));
253-
} else {
254-
st->print("%zu ", _na_at_peak);
255-
}
256-
col += 10; st->fill_to(col);
257-
258-
// RA
259-
if (human_readable) {
260-
st->print(PROPERFMT " ", PROPERFMTARGS(_ra_at_peak));
261-
} else {
262-
st->print("%zu ", _ra_at_peak);
268+
for (int tag = 0; tag < Arena::tag_count(); tag++) {
269+
if (human_readable) {
270+
st->print(PROPERFMT " ", PROPERFMTARGS(_peak_by_tag.counter(tag)));
271+
} else {
272+
st->print("%zu ", _peak_by_tag.counter(tag));
273+
}
274+
col += 10; st->fill_to(col);
263275
}
264-
col += 10; st->fill_to(col);
265276

266277
// result?
267278
st->print("%s ", _result ? _result : "");
@@ -296,7 +307,7 @@ class MemStatEntry : public CHeapObj<mtInternal> {
296307
col += 4; st->fill_to(col);
297308

298309
// Thread
299-
st->print(PTR_FORMAT " ", p2i(_thread));
310+
st->print(PTR_FORMAT " ", p2i(_thread));
300311

301312
// MethodName
302313
char buf[1024];
@@ -341,7 +352,7 @@ class MemStatTable :
341352
public:
342353

343354
void add(const FullMethodName& fmn, CompilerType comptype,
344-
size_t total, size_t na_at_peak, size_t ra_at_peak,
355+
size_t total, ArenaCountersByTag peak_by_tag,
345356
unsigned live_nodes_at_peak, size_t limit, const char* result) {
346357
assert_lock_strong(NMTCompilationCostHistory_lock);
347358
MemStatTableKey key(fmn, comptype);
@@ -360,8 +371,7 @@ class MemStatTable :
360371
e->set_comptype(comptype);
361372
e->inc_recompilation();
362373
e->set_total(total);
363-
e->set_na_at_peak(na_at_peak);
364-
e->set_ra_at_peak(ra_at_peak);
374+
e->set_peak_by_tag(peak_by_tag);
365375
e->set_live_nodes_at_peak(live_nodes_at_peak);
366376
e->set_limit(limit);
367377
e->set_result(result);
@@ -427,7 +437,7 @@ void CompilationMemoryStatistic::on_end_compilation() {
427437
const bool print = directive->should_print_memstat();
428438

429439
// Store memory used in task, for later processing by JFR
430-
task->set_arena_bytes(arena_stat->peak_since_start());
440+
task->set_arena_bytes(arena_stat->peak());
431441

432442
// Store result
433443
// For this to work, we must call on_end_compilation() at a point where
@@ -447,9 +457,8 @@ void CompilationMemoryStatistic::on_end_compilation() {
447457
assert(_the_table != nullptr, "not initialized");
448458

449459
_the_table->add(fmn, ct,
450-
arena_stat->peak_since_start(), // total
451-
arena_stat->na_at_peak(),
452-
arena_stat->ra_at_peak(),
460+
arena_stat->peak(), // total
461+
arena_stat->peak_by_tag(),
453462
arena_stat->live_nodes_at_peak(),
454463
arena_stat->limit(),
455464
result);
@@ -511,7 +520,7 @@ void CompilationMemoryStatistic::on_arena_change(ssize_t diff, const Arena* aren
511520

512521
bool hit_limit_before = arena_stat->hit_limit();
513522

514-
if (arena_stat->account(diff, (int)arena->get_tag())) { // new peak?
523+
if (arena_stat->is_active() && arena_stat->account(diff, (int)arena->get_tag())) { // new peak?
515524

516525
// Limit handling
517526
if (arena_stat->hit_limit()) {
@@ -545,7 +554,7 @@ void CompilationMemoryStatistic::on_arena_change(ssize_t diff, const Arena* aren
545554
}
546555
ss.print("Hit MemLimit %s(limit: %zu now: %zu)",
547556
(hit_limit_before ? "again " : ""),
548-
arena_stat->limit(), arena_stat->peak_since_start());
557+
arena_stat->limit(), arena_stat->peak());
549558
}
550559

551560
// log if needed

0 commit comments

Comments
 (0)