Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/hotspot/share/ci/ciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,6 @@ void ciEnv::register_method(ciMethod* target,
RTMState rtm_state) {
VM_ENTRY_MARK;
nmethod* nm = nullptr;
nmethod::ResultStatus result_status = nmethod::passed;
{
methodHandle method(THREAD, target->get_Method());

Expand Down Expand Up @@ -1125,14 +1124,12 @@ void ciEnv::register_method(ciMethod* target,
debug_info(), dependencies(), code_buffer,
frame_words, oop_map_set,
handler_table, inc_table,
compiler, CompLevel(task()->comp_level()),
result_status);
compiler, CompLevel(task()->comp_level()));

// Free codeBlobs
code_buffer->free_blob();

if (nm != nullptr) {
assert(result_status == nmethod::passed, "sanity");
nm->set_has_unsafe_access(has_unsafe_access);
nm->set_has_wide_vectors(has_wide_vectors);
nm->set_has_monitors(has_monitors);
Expand Down Expand Up @@ -1187,13 +1184,8 @@ void ciEnv::register_method(ciMethod* target,
nm->post_compiled_method(task());
task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
} else {
// The CodeCache is full or out of memeory.
if (result_status == nmethod::code_cache_full) {
record_failure("code cache is full");
} else {
assert(result_status == nmethod::out_of_memory, "sanity");
record_failure("out of memory to allocate immutable data");
}
// The CodeCache is full.
record_failure("code cache is full");
}

// safepoints are allowed again
Expand Down
71 changes: 42 additions & 29 deletions src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ struct java_nmethod_stats_struct {
if (metadata_size != 0) {
tty->print_cr(" metadata = %u (%f%%)", metadata_size, (metadata_size * 100.0f)/total_nm_size);
}
#if INCLUDE_JVMCI
if (jvmci_data_size != 0) {
tty->print_cr(" JVMCI data = %u (%f%%)", jvmci_data_size, (jvmci_data_size * 100.0f)/total_nm_size);
}
#endif
if (total_immut_size != 0) {
tty->print_cr(" immutable data = %u (%f%%)", total_immut_size, (total_immut_size * 100.0f)/total_size);
}
Expand All @@ -216,9 +221,6 @@ struct java_nmethod_stats_struct {
if (speculations_size != 0) {
tty->print_cr(" speculations = %u (%f%%)", speculations_size, (speculations_size * 100.0f)/total_immut_size);
}
if (jvmci_data_size != 0) {
tty->print_cr(" JVMCI data = %u (%f%%)", jvmci_data_size, (jvmci_data_size * 100.0f)/total_immut_size);
}
#endif
}
};
Expand Down Expand Up @@ -1131,8 +1133,7 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
CompLevel comp_level,
ResultStatus& result_status
CompLevel comp_level
#if INCLUDE_JVMCI
, char* speculations,
int speculations_len,
Expand All @@ -1144,10 +1145,12 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
code_buffer->finalize_oop_references(method);
// create nmethod
nmethod* nm = nullptr;
int nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));
#if INCLUDE_JVMCI
int jvmci_data_size = compiler->is_jvmci() ? jvmci_data->size() : 0;
if (compiler->is_jvmci()) {
nmethod_size += align_up(jvmci_data->size(), oopSize);
}
#endif
int nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod));

int immutable_data_size =
adjust_pcs_size(debug_info->pcs_size())
Expand All @@ -1156,7 +1159,6 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
+ align_up(nul_chk_table->size_in_bytes() , oopSize)
#if INCLUDE_JVMCI
+ align_up(speculations_len , oopSize)
+ align_up(jvmci_data_size , oopSize)
#endif
+ align_up(debug_info->data_size() , oopSize);

Expand All @@ -1165,8 +1167,8 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
if (immutable_data_size > 0) {
immutable_data = (address)os::malloc(immutable_data_size, mtCode);
if (immutable_data == nullptr) {
result_status = out_of_memory;
return nullptr; // OutOfMemory, bailout
vm_exit_out_of_memory(immutable_data_size, OOM_MALLOC_ERROR, "nmethod: no space for immutable data");
return nullptr;
}
}
{
Expand Down Expand Up @@ -1215,9 +1217,6 @@ nmethod* nmethod::new_nmethod(const methodHandle& method,
// Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
DEBUG_ONLY(nm->verify();)
nm->log_new_nmethod();
result_status = passed;
} else {
result_status = code_cache_full;
}
return nm;
}
Expand Down Expand Up @@ -1317,19 +1316,23 @@ nmethod::nmethod(
_unwind_handler_offset = 0;

CHECKED_CAST(_metadata_offset, uint16_t, (align_up(code_buffer->total_oop_size(), oopSize)));
DEBUG_ONLY( int data_end_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize); )
int data_end_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize);
#if INCLUDE_JVMCI
// jvmci_data_size is 0 in native wrapper but we need to set offset
// to correctly calculate metadata_end address
CHECKED_CAST(_jvmci_data_offset, uint16_t, data_end_offset);
#endif
assert((data_offset() + data_end_offset) <= nmethod_size, "wrong nmethod's size: %d < %d", nmethod_size, (data_offset() + data_end_offset));

// native wrapper does not have read-only data but we need unique not null address
_immutable_data = data_end();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use nullptr because VM expects not null address when it checks, for example, dependencies_begin() even so sizes are 0.
I used data_end() instead of nullptr in other places too.

_immutable_data_size = 0;
_nul_chk_table_offset = 0;
_handler_table_offset = _nul_chk_table_offset;
_scopes_pcs_offset = _handler_table_offset;
_scopes_data_offset = _scopes_pcs_offset;
_handler_table_offset = 0;
_scopes_pcs_offset = 0;
_scopes_data_offset = 0;
#if INCLUDE_JVMCI
_speculations_offset = _scopes_data_offset;
_jvmci_data_offset = _speculations_offset;
_speculations_offset = 0;
#endif

code_buffer->copy_code_and_locs_to(this);
Expand Down Expand Up @@ -1481,13 +1484,23 @@ nmethod::nmethod(
// C1 generates UnwindHandler at the end of instructions section.
// Calculate positive offset as distance between the start of stubs section
// (which is also the end of instructions section) and the start of the handler.
CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - code_offset() - offsets->value(CodeOffsets::UnwindHandler)));
int unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
CHECKED_CAST(_unwind_handler_offset, int16_t, (_stub_offset - unwind_handler_offset));
} else {
_unwind_handler_offset = -1;
}
CHECKED_CAST(_metadata_offset, uint16_t, (align_up(code_buffer->total_oop_size(), oopSize)));
DEBUG_ONLY( int data_end_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize); )
assert((data_offset() + data_end_offset) <= nmethod_size, "wrong nmethod's size: %d < %d", nmethod_size, (data_offset() + data_end_offset));
int metadata_end_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize);

#if INCLUDE_JVMCI
CHECKED_CAST(_jvmci_data_offset, uint16_t, metadata_end_offset);
int jvmci_data_size = compiler->is_jvmci() ? jvmci_data->size() : 0;
DEBUG_ONLY( int data_end_offset = _jvmci_data_offset + align_up(jvmci_data_size, oopSize); )
#else
DEBUG_ONLY( int data_end_offset = metadata_end_offset; )
#endif
assert((data_offset() + data_end_offset) <= nmethod_size, "wrong nmethod's size: %d > %d",
(data_offset() + data_end_offset), nmethod_size);

_immutable_data_size = immutable_data_size;
if (immutable_data_size > 0) {
Expand All @@ -1504,9 +1517,7 @@ nmethod::nmethod(

#if INCLUDE_JVMCI
_speculations_offset = _scopes_data_offset + align_up(debug_info->data_size(), oopSize);
_jvmci_data_offset = _speculations_offset + align_up(speculations_len, oopSize);
int jvmci_data_size = compiler->is_jvmci() ? jvmci_data->size() : 0;
DEBUG_ONLY( int immutable_data_end_offset = _jvmci_data_offset + align_up(jvmci_data_size, oopSize); )
DEBUG_ONLY( int immutable_data_end_offset = _speculations_offset + align_up(speculations_len, oopSize); )
#else
DEBUG_ONLY( int immutable_data_end_offset = _scopes_data_offset + align_up(debug_info->data_size(), oopSize); )
#endif
Expand Down Expand Up @@ -3078,6 +3089,12 @@ void nmethod::print(outputStream* st) const {
p2i(metadata_begin()),
p2i(metadata_end()),
metadata_size());
#if INCLUDE_JVMCI
if (jvmci_data_size () > 0) st->print_cr(" JVMCI data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
p2i(jvmci_data_begin()),
p2i(jvmci_data_end()),
jvmci_data_size());
#endif
if (immutable_data_size() > 0) st->print_cr(" immutable data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
p2i(immutable_data_begin()),
p2i(immutable_data_end()),
Expand Down Expand Up @@ -3107,10 +3124,6 @@ void nmethod::print(outputStream* st) const {
p2i(speculations_begin()),
p2i(speculations_end()),
speculations_size());
if (jvmci_data_size () > 0) st->print_cr(" JVMCI data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d",
p2i(jvmci_data_begin()),
p2i(jvmci_data_end()),
jvmci_data_size());
#endif
}

Expand Down
32 changes: 16 additions & 16 deletions src/hotspot/share/code/nmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,12 @@ class nmethod : public CodeBlob {
uint16_t _num_stack_arg_slots;
uint16_t _skipped_instructions_size;

// Offsets in mutable data section
// _oops_offset == _data_offset, offset where embedded oop table begins (inside data)
uint16_t _metadata_offset; // embedded meta data table
#if INCLUDE_JVMCI
uint16_t _jvmci_data_offset;
#endif

// Offset in immutable data section
// _dependencies_offset == 0
Expand All @@ -245,7 +249,6 @@ class nmethod : public CodeBlob {
int _scopes_data_offset;
#if INCLUDE_JVMCI
int _speculations_offset;
int _jvmci_data_offset;
#endif

// location in frame (offset for sp) that deopt can store the original
Expand Down Expand Up @@ -470,12 +473,6 @@ class nmethod : public CodeBlob {
void oops_do_set_strong_done(nmethod* old_head);

public:
enum ResultStatus {
passed,
code_cache_full,
out_of_memory
};

// create nmethod with entry_bci
static nmethod* new_nmethod(const methodHandle& method,
int compile_id,
Expand All @@ -490,8 +487,7 @@ class nmethod : public CodeBlob {
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* nul_chk_table,
AbstractCompiler* compiler,
CompLevel comp_level,
ResultStatus& result_status
CompLevel comp_level
#if INCLUDE_JVMCI
, char* speculations = nullptr,
int speculations_len = 0,
Expand Down Expand Up @@ -540,13 +536,19 @@ class nmethod : public CodeBlob {
address deopt_mh_handler_begin() const { return header_begin() + _deopt_mh_handler_offset ; }
address unwind_handler_begin () const { return _unwind_handler_offset != -1 ? (insts_end() - _unwind_handler_offset) : nullptr; }

oop* oops_begin () const { return (oop*) data_begin(); }
oop* oops_end () const { return (oop*) (data_begin() + _metadata_offset) ; }

// mutable data
oop* oops_begin () const { return (oop*) data_begin(); }
oop* oops_end () const { return (oop*) (data_begin() + _metadata_offset) ; }
Metadata** metadata_begin () const { return (Metadata**) (data_begin() + _metadata_offset) ; }
#if INCLUDE_JVMCI
Metadata** metadata_end () const { return (Metadata**) (data_begin() + _jvmci_data_offset) ; }
address jvmci_data_begin () const { return data_begin() + _jvmci_data_offset ; }
address jvmci_data_end () const { return data_end(); }
#else
Metadata** metadata_end () const { return (Metadata**) data_end(); }
#endif

// read-only data
// immutable data
address immutable_data_begin () const { return _immutable_data; }
address immutable_data_end () const { return _immutable_data + _immutable_data_size ; }
address dependencies_begin () const { return _immutable_data; }
Expand All @@ -562,9 +564,7 @@ class nmethod : public CodeBlob {
#if INCLUDE_JVMCI
address scopes_data_end () const { return _immutable_data + _speculations_offset ; }
address speculations_begin () const { return _immutable_data + _speculations_offset ; }
address speculations_end () const { return _immutable_data + _jvmci_data_offset ; }
address jvmci_data_begin () const { return _immutable_data + _jvmci_data_offset ; }
address jvmci_data_end () const { return immutable_data_end(); }
address speculations_end () const { return immutable_data_end(); }
#else
address scopes_data_end () const { return immutable_data_end(); }
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,6 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
nmethod_entry_patch_offset,
nmethod_mirror_name,
failed_speculations);
nmethod::ResultStatus result_status;
nm = nmethod::new_nmethod(method,
compile_id,
entry_bci,
Expand All @@ -2184,7 +2183,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
debug_info, dependencies, code_buffer,
frame_words, oop_map_set,
handler_table, implicit_exception_table,
compiler, comp_level, result_status,
compiler, comp_level,
speculations, speculations_len, data);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ public void dumpReplayData(PrintStream out) {
private int getMetadataOffset() { return (int) metadataOffsetField .getValue(addr); }
private int getScopesDataOffset() { return (int) scopesDataOffsetField .getValue(addr); }
private int getScopesPCsOffset() { return (int) scopesPCsOffsetField .getValue(addr); }
private int getDependenciesOffset() { return (int) 0; }
private int getHandlerTableOffset() { return (int) handlerTableOffsetField.getValue(addr); }
private int getNulChkTableOffset() { return (int) nulChkTableOffsetField .getValue(addr); }
private int getCompLevel() { return (int) compLevelField .getValue(addr); }
Expand Down