Skip to content

Commit

Permalink
additional tracing code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schatzl committed Jan 25, 2024
1 parent cc98cce commit 2cac855
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/hotspot/share/code/compiledMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "runtime/mutexLocker.hpp"
#include "runtime/sharedRuntime.hpp"

#include "gc/shared/classUnloadingContext.hpp"

CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout,
int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps,
bool caller_must_gc_arguments, bool compiled)
Expand Down Expand Up @@ -407,15 +409,25 @@ void CompiledMethod::clear_inline_caches() {
}
}

static void record(jlong& start, uint id) {
ClassUnloadingContext* ctx = ClassUnloadingContext::context();

jlong end = os::elapsed_counter();
ctx->_times[id] += end - start;
start = end;
}

// Clear IC callsites
// as well as any associated CompiledICHolders.
void CompiledMethod::purge_ic_callsites() {
ResourceMark rm;
RelocIterator iter(this);
while(iter.next()) {
if (iter.type() == relocInfo::virtual_call_type) {
jlong start = os::elapsed_counter();
CompiledIC* ic = CompiledIC_at(&iter);
delete ic->data();
record(start, 7);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,17 +1444,28 @@ void nmethod::unlink() {
ClassUnloadingContext::context()->register_unlinked_nmethod(this);
}

static void record(jlong& start, uint id) {
ClassUnloadingContext* ctx = ClassUnloadingContext::context();

jlong end = os::elapsed_counter();
ctx->_times[id] += end - start;
start = end;
}

void nmethod::purge(bool free_code_cache_data, bool unregister_nmethod) {
assert(!free_code_cache_data, "must only call not freeing code cache data");

jlong start = os::elapsed_counter();
MutexLocker ml(CodeCache_lock, Mutex::_no_safepoint_check_flag);
record(start, 0);

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

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

purge_ic_callsites();
record(start, 3);

if (unregister_nmethod) {
Universe::heap()->unregister_nmethod(this);
}
record(start, 4);

CodeCache::unregister_old_nmethod(this);
record(start, 5);


CodeBlob::purge(free_code_cache_data, unregister_nmethod);
record(start, 6);
}

oop nmethod::oop_at(int index) const {
Expand Down
15 changes: 15 additions & 0 deletions src/hotspot/share/gc/shared/classUnloadingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "runtime/mutexLocker.hpp"
#include "utilities/growableArray.hpp"

#include "logging/logStream.hpp"

ClassUnloadingContext* ClassUnloadingContext::_context = nullptr;

ClassUnloadingContext::ClassUnloadingContext(uint num_workers,
Expand All @@ -50,6 +52,10 @@ ClassUnloadingContext::ClassUnloadingContext(uint num_workers,
for (uint i = 0; i < num_workers; ++i) {
_unlinked_nmethods[i] = new NMethodSet();
}

for (uint i = 0; i < NUM_COUNTERS; i++) {
_times[i] = 0;
}
}

ClassUnloadingContext::~ClassUnloadingContext() {
Expand Down Expand Up @@ -120,6 +126,15 @@ void ClassUnloadingContext::purge_nmethods() {
}
}

LogTarget(Trace, gc, sweep) lt;
if (lt.is_enabled()) {
LogStream ls(lt);
ls.print("Purge_nmethods: ");
for (uint i = 0; i < NUM_COUNTERS; i++) {
ls.print("%.2f ", TimeHelper::counter_to_millis(_times[i]));
}
ls.cr();
}
CodeCache::maybe_restart_compiler(freed_memory);
}

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shared/classUnloadingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ClassUnloadingContext : public CHeapObj<mtGC> {
bool _lock_codeblob_free_separately;

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

// Num_nmethod_unlink_workers configures the maximum numbers of threads unlinking
Expand Down

0 comments on commit 2cac855

Please sign in to comment.