Skip to content

Commit

Permalink
Fixing TestFindInstMemRecursion test fail with XX:+StressReflectiveCo…
Browse files Browse the repository at this point in the history
…de option:

_relocation_size can exceed 64Kb, in this case _metadata_offset do not fit into int16.
Fix: use _oops_size int16 field to calculate metadata offset
  • Loading branch information
bulasevich committed Jan 15, 2025
1 parent 6b97993 commit 40fa960
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
32 changes: 11 additions & 21 deletions src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,17 +1327,12 @@ nmethod::nmethod(
_deopt_mh_handler_offset = 0;
_unwind_handler_offset = 0;

int reloc_size = align_up(code_buffer->total_relocation_size(), oopSize);
int oop_size = align_up(code_buffer->total_oop_size(), oopSize);
CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
int metadata_size = align_up(code_buffer->total_metadata_size(), wordSize);
CHECKED_CAST(_metadata_offset, uint16_t, reloc_size + oop_size);
int data_end_offset = _metadata_offset + metadata_size;
#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_end_offset <= mutable_data_size, "wrong nmutable_data_size: %d < %d", data_end_offset, mutable_data_size);
JVMCI_ONLY( _jvmci_data_size = 0; )
assert(_mutable_data_size == _relocation_size + _oops_size + metadata_size,
"wrong mutable data size: %d != %d + %d + %d",
_mutable_data_size, _relocation_size, _oops_size, metadata_size);

// native wrapper does not have read-only data but we need unique not null address
_immutable_data = blob_end();
Expand Down Expand Up @@ -1506,18 +1501,13 @@ nmethod::nmethod(
_unwind_handler_offset = -1;
}

int reloc_size = align_up(code_buffer->total_relocation_size(), oopSize);
int oop_size = align_up(code_buffer->total_oop_size(), oopSize);
int metadata_size = align_up(code_buffer->total_metadata_size(), wordSize);
CHECKED_CAST(_metadata_offset, uint16_t, reloc_size + oop_size);
int jvmci_data_size = 0;
#if INCLUDE_JVMCI
CHECKED_CAST(_jvmci_data_offset, uint16_t, _metadata_offset + metadata_size);
jvmci_data_size = align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize);
#endif
assert(_mutable_data_size == reloc_size + oop_size + metadata_size + jvmci_data_size,
CHECKED_CAST(_oops_size, uint16_t, align_up(code_buffer->total_oop_size(), oopSize));
uint16_t metadata_size = (uint16_t)align_up(code_buffer->total_metadata_size(), wordSize);
JVMCI_ONLY(CHECKED_CAST(_jvmci_data_size, uint16_t, align_up(compiler->is_jvmci() ? jvmci_data->size() : 0, oopSize)));
int jvmci_data_size = 0 JVMCI_ONLY(+ _jvmci_data_size);
assert(_mutable_data_size == _relocation_size + _oops_size + metadata_size + jvmci_data_size,
"wrong mutable data size: %d != %d + %d + %d + %d",
_mutable_data_size, reloc_size, oop_size, metadata_size, jvmci_data_size);
_mutable_data_size, _relocation_size, _oops_size, metadata_size, jvmci_data_size);
assert(nmethod_size == code_end() - header_begin(), "wrong nmethod size: %d != %d",
nmethod_size, (int)(code_end() - header_begin()));

Expand Down
14 changes: 7 additions & 7 deletions src/hotspot/share/code/nmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class nmethod : public CodeBlob {
// Number of arguments passed on the stack
uint16_t _num_stack_arg_slots;

// Offsets in mutable data section
uint16_t _metadata_offset; // embedded meta data table
// mutable data section
uint16_t _oops_size;
#if INCLUDE_JVMCI
uint16_t _jvmci_data_offset;
uint16_t _jvmci_data_size;
#endif

// Offset in immutable data section
Expand Down Expand Up @@ -533,11 +533,11 @@ class nmethod : public CodeBlob {

// mutable data
oop* oops_begin () const { return (oop*) (mutable_data_begin() + _relocation_size); }
oop* oops_end () const { return (oop*) (mutable_data_begin() + _metadata_offset); }
Metadata** metadata_begin () const { return (Metadata**) (mutable_data_begin() + _metadata_offset); }
oop* oops_end () const { return (oop*) (mutable_data_begin() + _relocation_size + _oops_size); }
Metadata** metadata_begin () const { return (Metadata**) (mutable_data_begin() + _relocation_size + _oops_size); }
#if INCLUDE_JVMCI
Metadata** metadata_end () const { return (Metadata**) (mutable_data_begin() + _jvmci_data_offset); }
address jvmci_data_begin () const { return mutable_data_begin() + _jvmci_data_offset; }
Metadata** metadata_end () const { return (Metadata**) (mutable_data_end() - _jvmci_data_size); }
address jvmci_data_begin () const { return mutable_data_end() - _jvmci_data_size; }
address jvmci_data_end () const { return mutable_data_end(); }
#else
Metadata** metadata_end () const { return (Metadata**) mutable_data_end(); }
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@
nonstatic_field(nmethod, _deopt_mh_handler_offset, int) \
nonstatic_field(nmethod, _orig_pc_offset, int) \
nonstatic_field(nmethod, _stub_offset, int) \
nonstatic_field(nmethod, _metadata_offset, u2) \
nonstatic_field(nmethod, _scopes_pcs_offset, int) \
nonstatic_field(nmethod, _oops_size, u2) \
nonstatic_field(nmethod, _scopes_pcs_offset, int) \
nonstatic_field(nmethod, _scopes_data_offset, int) \
nonstatic_field(nmethod, _handler_table_offset, u2) \
nonstatic_field(nmethod, _nul_chk_table_offset, u2) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class NMethod extends CodeBlob {
private static CIntegerField deoptMhHandlerOffsetField;
private static CIntegerField origPCOffsetField;
private static CIntegerField stubOffsetField;
private static CIntField metadataOffsetField;
private static CIntField oopsSizeField;
private static CIntField handlerTableOffsetField;
private static CIntField nulChkTableOffsetField;
private static CIntegerField scopesPCsOffsetField;
Expand Down Expand Up @@ -97,7 +97,7 @@ private static void initialize(TypeDataBase db) {
deoptMhHandlerOffsetField = type.getCIntegerField("_deopt_mh_handler_offset");
origPCOffsetField = type.getCIntegerField("_orig_pc_offset");
stubOffsetField = type.getCIntegerField("_stub_offset");
metadataOffsetField = new CIntField(type.getCIntegerField("_metadata_offset"), 0);
oopsSizeField = new CIntField(type.getCIntegerField("_oops_size"), 0);
scopesPCsOffsetField = type.getCIntegerField("_scopes_pcs_offset");
scopesDataOffsetField = type.getCIntegerField("_scopes_data_offset");
handlerTableOffsetField = new CIntField(type.getCIntegerField("_handler_table_offset"), 0);
Expand Down Expand Up @@ -156,8 +156,8 @@ public Method getMethod() {
public Address mutableDataEnd() { return mutableDataBegin().addOffsetTo(getMutableDataSize()); }

public Address oopsBegin() { return mutableDataBegin().addOffsetTo(getRelocationSize()); }
public Address oopsEnd() { return mutableDataBegin().addOffsetTo(getMetadataOffset()); }
public Address metadataBegin() { return mutableDataBegin().addOffsetTo(getMetadataOffset()); }
public Address oopsEnd() { return mutableDataBegin().addOffsetTo(getRelocationSize() + getOopsSize()); }
public Address metadataBegin() { return mutableDataBegin().addOffsetTo(getRelocationSize() + getOopsSize()); }
public Address metadataEnd() { return mutableDataEnd(); }

public int getImmutableDataSize() { return (int) immutableDataSizeField.getValue(addr); }
Expand Down Expand Up @@ -547,7 +547,7 @@ public void dumpReplayData(PrintStream out) {
private int getDeoptHandlerOffset() { return (int) deoptHandlerOffsetField .getValue(addr); }
private int getDeoptMhHandlerOffset() { return (int) deoptMhHandlerOffsetField.getValue(addr); }
private int getStubOffset() { return (int) stubOffsetField .getValue(addr); }
private int getMetadataOffset() { return (int) metadataOffsetField .getValue(addr); }
private int getOopsSize() { return (int) oopsSizeField .getValue(addr); }
private int getScopesDataOffset() { return (int) scopesDataOffsetField .getValue(addr); }
private int getScopesPCsOffset() { return (int) scopesPCsOffsetField .getValue(addr); }
private int getHandlerTableOffset() { return (int) handlerTableOffsetField.getValue(addr); }
Expand Down

0 comments on commit 40fa960

Please sign in to comment.