Skip to content

Commit 2cac855

Browse files
author
Thomas Schatzl
committed
additional tracing code
1 parent cc98cce commit 2cac855

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/hotspot/share/code/compiledMethod.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "runtime/mutexLocker.hpp"
4949
#include "runtime/sharedRuntime.hpp"
5050

51+
#include "gc/shared/classUnloadingContext.hpp"
52+
5153
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout,
5254
int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps,
5355
bool caller_must_gc_arguments, bool compiled)
@@ -407,15 +409,25 @@ void CompiledMethod::clear_inline_caches() {
407409
}
408410
}
409411

412+
static void record(jlong& start, uint id) {
413+
ClassUnloadingContext* ctx = ClassUnloadingContext::context();
414+
415+
jlong end = os::elapsed_counter();
416+
ctx->_times[id] += end - start;
417+
start = end;
418+
}
419+
410420
// Clear IC callsites
411421
// as well as any associated CompiledICHolders.
412422
void CompiledMethod::purge_ic_callsites() {
413423
ResourceMark rm;
414424
RelocIterator iter(this);
415425
while(iter.next()) {
416426
if (iter.type() == relocInfo::virtual_call_type) {
427+
jlong start = os::elapsed_counter();
417428
CompiledIC* ic = CompiledIC_at(&iter);
418429
delete ic->data();
430+
record(start, 7);
419431
}
420432
}
421433
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,17 +1444,28 @@ void nmethod::unlink() {
14441444
ClassUnloadingContext::context()->register_unlinked_nmethod(this);
14451445
}
14461446

1447+
static void record(jlong& start, uint id) {
1448+
ClassUnloadingContext* ctx = ClassUnloadingContext::context();
1449+
1450+
jlong end = os::elapsed_counter();
1451+
ctx->_times[id] += end - start;
1452+
start = end;
1453+
}
1454+
14471455
void nmethod::purge(bool free_code_cache_data, bool unregister_nmethod) {
14481456
assert(!free_code_cache_data, "must only call not freeing code cache data");
14491457

1458+
jlong start = os::elapsed_counter();
14501459
MutexLocker ml(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1460+
record(start, 0);
14511461

14521462
// completely deallocate this method
14531463
Events::log(Thread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this));
14541464
log_debug(codecache)("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT
14551465
"/Free CodeCache:" SIZE_FORMAT "Kb",
14561466
is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(),
14571467
CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024);
1468+
record(start, 1);
14581469

14591470
// We need to deallocate any ExceptionCache data.
14601471
// Note that we do not need to grab the nmethod lock for this, it
@@ -1465,15 +1476,22 @@ void nmethod::purge(bool free_code_cache_data, bool unregister_nmethod) {
14651476
delete ec;
14661477
ec = next;
14671478
}
1479+
record(start, 2);
14681480

14691481
purge_ic_callsites();
1482+
record(start, 3);
14701483

14711484
if (unregister_nmethod) {
14721485
Universe::heap()->unregister_nmethod(this);
14731486
}
1487+
record(start, 4);
1488+
14741489
CodeCache::unregister_old_nmethod(this);
1490+
record(start, 5);
1491+
14751492

14761493
CodeBlob::purge(free_code_cache_data, unregister_nmethod);
1494+
record(start, 6);
14771495
}
14781496

14791497
oop nmethod::oop_at(int index) const {

src/hotspot/share/gc/shared/classUnloadingContext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "runtime/mutexLocker.hpp"
3131
#include "utilities/growableArray.hpp"
3232

33+
#include "logging/logStream.hpp"
34+
3335
ClassUnloadingContext* ClassUnloadingContext::_context = nullptr;
3436

3537
ClassUnloadingContext::ClassUnloadingContext(uint num_workers,
@@ -50,6 +52,10 @@ ClassUnloadingContext::ClassUnloadingContext(uint num_workers,
5052
for (uint i = 0; i < num_workers; ++i) {
5153
_unlinked_nmethods[i] = new NMethodSet();
5254
}
55+
56+
for (uint i = 0; i < NUM_COUNTERS; i++) {
57+
_times[i] = 0;
58+
}
5359
}
5460

5561
ClassUnloadingContext::~ClassUnloadingContext() {
@@ -120,6 +126,15 @@ void ClassUnloadingContext::purge_nmethods() {
120126
}
121127
}
122128

129+
LogTarget(Trace, gc, sweep) lt;
130+
if (lt.is_enabled()) {
131+
LogStream ls(lt);
132+
ls.print("Purge_nmethods: ");
133+
for (uint i = 0; i < NUM_COUNTERS; i++) {
134+
ls.print("%.2f ", TimeHelper::counter_to_millis(_times[i]));
135+
}
136+
ls.cr();
137+
}
123138
CodeCache::maybe_restart_compiler(freed_memory);
124139
}
125140

src/hotspot/share/gc/shared/classUnloadingContext.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ClassUnloadingContext : public CHeapObj<mtGC> {
4646
bool _lock_codeblob_free_separately;
4747

4848
public:
49+
static const uint NUM_COUNTERS = 8;
50+
jlong _times[NUM_COUNTERS];
4951
static ClassUnloadingContext* context() { assert(_context != nullptr, "context not set"); return _context; }
5052

5153
// Num_nmethod_unlink_workers configures the maximum numbers of threads unlinking

0 commit comments

Comments
 (0)