Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8247319: Remove on-stack nmethod hotness counter sampling from safepo…
…ints

Reviewed-by: kvn, dholmes
  • Loading branch information
fisk committed Jun 23, 2020
1 parent a10a928 commit 2765410a2845e47b6595a5d441ffee1568218d6a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 47 deletions.
@@ -260,7 +260,7 @@ class nmethod : public CompiledMethod {
// The _hotness_counter indicates the hotness of a method. The higher
// the value the hotter the method. The hotness counter of a nmethod is
// set to [(ReservedCodeCacheSize / (1024 * 1024)) * 2] each time the method
// is active while stack scanning (mark_active_nmethods()). The hotness
// is active while stack scanning (do_stack_scanning()). The hotness
// counter is decreased (by 1) while sweeping.
int _hotness_counter;

@@ -502,12 +502,10 @@ bool SafepointSynchronize::is_cleanup_needed() {

class ParallelSPCleanupThreadClosure : public ThreadClosure {
private:
CodeBlobClosure* _nmethod_cl;
DeflateMonitorCounters* _counters;

public:
ParallelSPCleanupThreadClosure(DeflateMonitorCounters* counters) :
_nmethod_cl(UseCodeAging ? NMethodSweeper::prepare_reset_hotness_counters() : NULL),
_counters(counters) {}

void do_thread(Thread* thread) {
@@ -516,11 +514,6 @@ class ParallelSPCleanupThreadClosure : public ThreadClosure {
// there is a special cleanup request, deflation is handled now.
// Otherwise, async deflation is requested via a flag.
ObjectSynchronizer::deflate_thread_local_monitors(thread, _counters);
if (_nmethod_cl != NULL && thread->is_Java_thread() &&
! thread->is_Code_cache_sweeper_thread()) {
JavaThread* jt = (JavaThread*) thread;
jt->nmethods_do(_nmethod_cl);
}
}
};

@@ -141,17 +141,6 @@ class MarkActivationClosure: public CodeBlobClosure {
};
static MarkActivationClosure mark_activation_closure;

class SetHotnessClosure: public CodeBlobClosure {
public:
virtual void do_code_blob(CodeBlob* cb) {
assert(cb->is_nmethod(), "CodeBlob should be nmethod");
nmethod* nm = (nmethod*)cb;
nm->set_hotness_counter(NMethodSweeper::hotness_counter_reset_val());
}
};
static SetHotnessClosure set_hotness_closure;


int NMethodSweeper::hotness_counter_reset_val() {
if (_hotness_counter_reset_val == 0) {
_hotness_counter_reset_val = (ReservedCodeCacheSize < M) ? 1 : (ReservedCodeCacheSize / M) * 2;
@@ -204,29 +193,6 @@ CodeBlobClosure* NMethodSweeper::prepare_mark_active_nmethods() {
return &mark_activation_closure;
}

CodeBlobClosure* NMethodSweeper::prepare_reset_hotness_counters() {
assert(SafepointSynchronize::is_at_safepoint(), "must be executed at a safepoint");

// If we do not want to reclaim not-entrant or zombie methods there is no need
// to scan stacks
if (!MethodFlushing) {
return NULL;
}

// Check for restart
if (_current.method() != NULL) {
if (_current.method()->is_nmethod()) {
assert(CodeCache::find_blob_unsafe(_current.method()) == _current.method(), "Sweeper nmethod cached state invalid");
} else if (_current.method()->is_aot()) {
assert(CodeCache::find_blob_unsafe(_current.method()->code_begin()) == _current.method(), "Sweeper AOT method cached state invalid");
} else {
ShouldNotReachHere();
}
}

return &set_hotness_closure;
}

/**
* This function triggers a VM operation that does stack scanning of active
* methods. Stack scanning is mandatory for the sweeper to make progress.
@@ -37,8 +37,10 @@ class CodeBlobClosure;
// - reclamation of nmethods
// Removing nmethods from the code cache includes two operations
// 1) mark active nmethods
// Is done in 'mark_active_nmethods()'. This function is called at a
// safepoint and marks all nmethods that are active on a thread's stack.
// Is done in 'do_stack_scanning()'. This function invokes a thread-local handshake
// that marks all nmethods that are active on a thread's stack, and resets their
// hotness counters. This allows the sweeper to assume that a decayed hotness counter
// of an nmethod implies that it is seemingly not used actively.
// 2) sweep nmethods
// Is done in sweep_code_cache(). This function is the only place in the
// sweeper where memory is reclaimed. Note that sweep_code_cache() is not
@@ -110,8 +112,6 @@ class NMethodSweeper : public AllStatic {
#endif

static CodeBlobClosure* prepare_mark_active_nmethods();
static CodeBlobClosure* prepare_reset_hotness_counters();

static void sweeper_loop();
static bool should_start_aggressive_sweep(int code_blob_type);
static void force_sweep();
@@ -110,7 +110,6 @@
template(ClassLoaderHierarchyOperation) \
template(DumpHashtable) \
template(DumpTouchedMethods) \
template(MarkActiveNMethods) \
template(PrintCompileQueue) \
template(PrintClassHierarchy) \
template(ThreadSuspend) \

0 comments on commit 2765410

Please sign in to comment.