Skip to content

Commit

Permalink
undo c1 release buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
bulasevich committed Apr 25, 2024
1 parent b38c69a commit c51bf1c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
48 changes: 22 additions & 26 deletions src/hotspot/share/c1/c1_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,31 @@ Compiler::Compiler() : AbstractCompiler(compiler_c1) {
}

void Compiler::init_c1_runtime() {
if (Runtime1::blob_for((Runtime1::StubID)0) == nullptr) // check if Runtime1 is initialized
Runtime1::initialize(CompilerThread::current()->get_buffer_blob());
BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
Runtime1::initialize(buffer_blob);
FrameMap::initialize();
// initialize data structures
ValueType::initialize();
GraphBuilder::initialize();
// note: to use more than one instance of LinearScan at a time this function call has to
// be moved somewhere outside of this constructor:
Interval::initialize();
}


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

if (should_perform_init()) {
FrameMap::initialize();
// initialize data structures
ValueType::initialize();
GraphBuilder::initialize();
// note: to use more than one instance of LinearScan at a time this function call has to
// be moved somewhere outside of this constructor:
Interval::initialize();
set_state(initialized);
if (buffer_blob == nullptr) {
// When we come here we are in state 'initializing'; entire C1 compilation
// can be shut down.
set_state(failed);
} else {
init_c1_runtime();
set_state(initialized);
}
}
}

Expand All @@ -84,16 +95,9 @@ BufferBlob* Compiler::init_buffer_blob() {
CompilerThread::current()->set_buffer_blob(buffer_blob);
}

init_c1_runtime();
return buffer_blob;
}

void Compiler::release_buffer_blob() {
BufferBlob* buffer_blob = CompilerThread::current()->get_buffer_blob();
CompilerThread::current()->set_buffer_blob(nullptr);
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 @@ -245,13 +249,7 @@ 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();
if (buffer_blob == nullptr) { buffer_blob = init_buffer_blob(); }

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

assert(buffer_blob != nullptr, "Must exist");
// invoke compilation
{
// We are nested here because we need for the destructor
Expand All @@ -260,8 +258,6 @@ 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: 0 additions & 1 deletion src/hotspot/share/c1/c1_Compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Compiler: public AbstractCompiler {
private:
static void init_c1_runtime();
BufferBlob* init_buffer_blob();
void release_buffer_blob();

public:
// Creation
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void StubAssembler::set_num_rt_args(int args) {

// Implementation of Runtime1

CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids] = {nullptr};
CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids];
const char *Runtime1::_blob_names[] = {
RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME)
};
Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ void CodeCache::initialize_heaps() {

// Determine size of compiler buffers
size_t code_buffers_size = 0;
//##
#ifdef COMPILER1
// C1 temporary code buffers (see Compiler::init_buffer_blob())
const int c1_count = CompilationPolicy::c1_count();
code_buffers_size += c1_count * Compiler::code_buffer_size();
#endif
#ifdef COMPILER2
// C2 scratch buffers (see Compile::init_scratch_buffer_blob())
const int c2_count = CompilationPolicy::c2_count();
// Initial size of constant table (this may be increased if a compiled method needs more space)
code_buffers_size += c2_count * C2Compiler::initial_code_buffer_size();
#endif

// Increase default non_nmethod_size to account for compiler buffers
if (!non_nmethod_set) {
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,12 @@ 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 All @@ -1795,7 +1801,7 @@ void CompileBroker::free_buffer_blob_if_allocated(CompilerThread* thread) {
if (blob != nullptr) {
blob->purge(true /* free_code_cache_data */, true /* unregister_nmethod */);
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
if (!CodeCache::contains((void*)blob)) { free(blob); } else
if (!CodeCache::contains((void*)blob)) { std::free((char*)blob - 16); } else
CodeCache::free(blob);
}
}
Expand Down

0 comments on commit c51bf1c

Please sign in to comment.