Skip to content

Commit e683001

Browse files
jbachorikapangin
andauthored
cstack=vm support for JDK 23+ (#157)
Co-authored-by: Andrei Pangin <noreply@pangin.pro>
1 parent d756726 commit e683001

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
fi
4444
fi
4545
check-formatting:
46-
runs-on: ubuntu-latest
46+
runs-on: ubuntu-22.04
4747
needs: check-for-pr
4848
if: needs.check-for-pr.outputs.skip != 'true'
4949
steps:

ddprof-lib/src/main/cpp/vmStructs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,15 @@ void VMStructs::resolveOffsets() {
411411
_call_stub_return = *_call_stub_return_addr;
412412
}
413413

414+
// Since JDK 23, _metadata_offset is relative to _data_offset. See metadata()
415+
if (_nmethod_immutable_offset < 0) {
416+
_data_offset = 0;
417+
}
418+
414419
_has_stack_structs =
415420
_has_method_structs && _interpreter_frame_bcp_offset != 0 &&
416421
_code_offset != -1 && _scopes_data_offset != -1 &&
422+
_data_offset >= 0 &&
417423
_scopes_pcs_offset >= 0 &&
418424
_nmethod_immutable_offset < 0 // TODO: not yet supported
419425
&& _nmethod_metadata_offset >= 0 && _thread_vframe_offset >= 0 &&
@@ -854,8 +860,8 @@ int NMethod::findScopeOffset(const void *pc) {
854860
}
855861

856862
const int *scopes_pcs = (const int *)at(_scopes_pcs_offset);
857-
PcDesc *pcd = (PcDesc *)at(scopes_pcs[0]);
858-
PcDesc *pcd_end = (PcDesc *)at(scopes_pcs[1]);
863+
PcDesc* pcd = (PcDesc*) immutableDataAt(scopes_pcs[0]);
864+
PcDesc* pcd_end = (PcDesc*) immutableDataAt(scopes_pcs[1]);
859865
int low = 0;
860866
int high = (pcd_end - pcd) - 1;
861867

ddprof-lib/src/main/cpp/vmStructs.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,20 @@ class NMethod : VMStructs {
329329

330330
short frameCompleteOffset() { return *(short *)at(_frame_complete_offset); }
331331

332-
// TODO: offset is short on JDK 23+
333332
void setFrameCompleteOffset(int offset) {
334-
*(int *)at(_frame_complete_offset) = offset;
333+
if (_nmethod_immutable_offset > 0) {
334+
// _frame_complete_offset is short on JDK 23+
335+
*(short*) at(_frame_complete_offset) = offset;
336+
} else {
337+
*(int*) at(_frame_complete_offset) = offset;
338+
}
339+
}
340+
341+
const char* immutableDataAt(int offset) {
342+
if (_nmethod_immutable_offset > 0) {
343+
return *(const char**) at(_nmethod_immutable_offset) + offset;
344+
}
345+
return at(offset);
335346
}
336347

337348
const char *code() {
@@ -344,7 +355,7 @@ class NMethod : VMStructs {
344355

345356
const char *scopes() {
346357
if (_scopes_data_offset > 0) {
347-
return at(*(int *)at(_scopes_data_offset));
358+
return immutableDataAt(*(int*) at(_scopes_data_offset));
348359
} else {
349360
return *(const char **)at(-_scopes_data_offset);
350361
}
@@ -391,6 +402,9 @@ class NMethod : VMStructs {
391402
}
392403

393404
VMMethod **metadata() {
405+
if (_data_offset > 0) {
406+
return (VMMethod**) at(*(int*) at(_data_offset) + *(unsigned short*) at(_nmethod_metadata_offset));
407+
}
394408
return (VMMethod **)at(*(int *)at(_nmethod_metadata_offset));
395409
}
396410

@@ -663,26 +677,30 @@ class PcDesc {
663677

664678
class ScopeDesc : VMStructs {
665679
private:
666-
NMethod *_nm;
680+
const unsigned char* _scopes;
681+
VMMethod** _metadata;
667682
const unsigned char *_stream;
668683
int _method_offset;
669684
int _bci;
670685

671686
int readInt();
672687

673688
public:
674-
ScopeDesc(NMethod *nm) : _nm(nm) {}
689+
ScopeDesc(NMethod *nm) {
690+
_scopes = (const unsigned char*)nm->scopes();
691+
_metadata = nm->metadata();
692+
}
675693

676694
int decode(int offset) {
677-
_stream = (const unsigned char *)_nm->scopes() + offset;
695+
_stream = _scopes + offset;
678696
int sender_offset = readInt();
679697
_method_offset = readInt();
680698
_bci = readInt() - 1;
681699
return sender_offset;
682700
}
683701

684702
VMMethod *method() {
685-
return _method_offset > 0 ? _nm->metadata()[_method_offset - 1] : NULL;
703+
return _method_offset > 0 ? _metadata[_method_offset - 1] : NULL;
686704
}
687705

688706
int bci() { return _bci; }

0 commit comments

Comments
 (0)