Skip to content

Commit

Permalink
release C1 scratch buffer after compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
bulasevich committed Apr 24, 2024
1 parent 2af0312 commit 13cfc1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
31 changes: 25 additions & 6 deletions src/hotspot/share/c1/c1_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ void Compiler::init_c1_runtime() {


void Compiler::initialize() {
// Buffer blob must be allocated per C1 compiler thread at startup
BufferBlob* buffer_blob = init_buffer_blob();

// MonitorLocker only_one(CompileThread_lock);
if (should_perform_init()) {
BufferBlob* buffer_blob = init_buffer_blob();
if (buffer_blob == nullptr) {
// When we come here we are in state 'initializing'; entire C1 compilation
// can be shut down.
Expand All @@ -74,6 +73,8 @@ void Compiler::initialize() {
init_c1_runtime();
set_state(initialized);
}
tty->print_cr("## Compiler::initialize -> c1_init");
release_buffer_blob();
}
}

Expand All @@ -82,8 +83,6 @@ uint Compiler::code_buffer_size() {
}

BufferBlob* Compiler::init_buffer_blob() {
// Allocate buffer blob once at startup since allocation for each
// compilation seems to be too expensive (at least on Intel win32).
assert (CompilerThread::current()->get_buffer_blob() == nullptr, "Should initialize only once");

// setup CodeBuffer. Preallocate a BufferBlob of size
Expand All @@ -96,6 +95,18 @@ BufferBlob* Compiler::init_buffer_blob() {
return buffer_blob;
}

void Compiler::release_buffer_blob() {
BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
if (buffer_blob != nullptr) {
CompilerThread::current()->set_buffer_blob(nullptr);
// Note.
// free_buffer_blob_if_allocated does the following. Why?
// blob->purge(true /* free_code_cache_data */, true /* unregister_nmethod */);
// MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
BufferBlob::free(buffer_blob);
}
}

bool Compiler::is_intrinsic_supported(const methodHandle& method) {
vmIntrinsics::ID id = method->intrinsic_id();
assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
Expand Down Expand Up @@ -247,7 +258,13 @@ bool Compiler::is_intrinsic_supported(vmIntrinsics::ID id) {

void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci, bool install_code, DirectiveSet* directive) {
BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
assert(buffer_blob != nullptr, "Must exist");
if (buffer_blob == nullptr) { buffer_blob = init_buffer_blob(); }

if (buffer_blob == nullptr) {
warning("no space to run C1 compiler");
return;
}

// invoke compilation
{
// We are nested here because we need for the destructor
Expand All @@ -256,6 +273,8 @@ void Compiler::compile_method(ciEnv* env, ciMethod* method, int entry_bci, bool
ResourceMark rm;
Compilation c(this, env, method, entry_bci, buffer_blob, install_code, directive);
}

release_buffer_blob();
}


Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/c1/c1_Compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Compiler: public AbstractCompiler {
private:
static void init_c1_runtime();
BufferBlob* init_buffer_blob();
void release_buffer_blob();

public:
// Creation
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,12 +1787,6 @@ bool CompileBroker::init_compiler_runtime() {
return false;
}

// C1 specific check
if (comp->is_c1() && (thread->get_buffer_blob() == nullptr)) {
warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
return false;
}

return true;
}

Expand Down

0 comments on commit 13cfc1a

Please sign in to comment.