Skip to content

Commit 34a9e13

Browse files
committed
#923: cstack=vm support for JDK 23+
1 parent 0c4cd5c commit 34a9e13

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

src/profiler.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,11 +1124,8 @@ Error Profiler::start(Arguments& args, bool reset) {
11241124
return Error("DWARF unwinding is not supported on this platform");
11251125
} else if (_cstack == CSTACK_LBR && _engine != &perf_events) {
11261126
return Error("Branch stack is supported only with PMU events");
1127-
} else if (_cstack == CSTACK_VM) {
1128-
if (!VMStructs::hasStackStructs()) {
1129-
return Error("VMStructs stack walking is not supported on this JVM/platform");
1130-
}
1131-
Log::info("cstack=vm is an experimental option, use with care");
1127+
} else if (_cstack == CSTACK_VM && !VMStructs::hasStackStructs()) {
1128+
return Error("VMStructs stack walking is not supported on this JVM/platform");
11321129
}
11331130

11341131
// Kernel symbols are useful only for perf_events without --all-user

src/vmStructs.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,17 @@ void VMStructs::resolveOffsets() {
465465
_call_stub_return = *_call_stub_return_addr;
466466
}
467467

468+
// Since JDK 23, _metadata_offset is relative to _data_offset. See metadata()
469+
if (_nmethod_immutable_offset < 0) {
470+
_data_offset = 0;
471+
}
472+
468473
_has_stack_structs = _has_method_structs
469474
&& _interpreter_frame_bcp_offset != 0
470475
&& _code_offset != -1
476+
&& _data_offset >= 0
471477
&& _scopes_data_offset != -1
472478
&& _scopes_pcs_offset >= 0
473-
&& _nmethod_immutable_offset < 0 // TODO: not yet supported
474479
&& _nmethod_metadata_offset >= 0
475480
&& _thread_vframe_offset >= 0
476481
&& _thread_exception_offset >= 0
@@ -677,8 +682,8 @@ int NMethod::findScopeOffset(const void* pc) {
677682
}
678683

679684
const int* scopes_pcs = (const int*) at(_scopes_pcs_offset);
680-
PcDesc* pcd = (PcDesc*) at(scopes_pcs[0]);
681-
PcDesc* pcd_end = (PcDesc*) at(scopes_pcs[1]);
685+
PcDesc* pcd = (PcDesc*) immutableDataAt(scopes_pcs[0]);
686+
PcDesc* pcd_end = (PcDesc*) immutableDataAt(scopes_pcs[1]);
682687
int low = 0;
683688
int high = (pcd_end - pcd) - 1;
684689

src/vmStructs.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,20 @@ class NMethod : VMStructs {
396396
return *(short*) at(_frame_complete_offset);
397397
}
398398

399-
// TODO: offset is short on JDK 23+
400399
void setFrameCompleteOffset(int offset) {
401-
*(int*) at(_frame_complete_offset) = offset;
400+
if (_nmethod_immutable_offset > 0) {
401+
// _frame_complete_offset is short on JDK 23+
402+
*(short*) at(_frame_complete_offset) = offset;
403+
} else {
404+
*(int*) at(_frame_complete_offset) = offset;
405+
}
406+
}
407+
408+
const char* immutableDataAt(int offset) {
409+
if (_nmethod_immutable_offset > 0) {
410+
return *(const char**) at(_nmethod_immutable_offset) + offset;
411+
}
412+
return at(offset);
402413
}
403414

404415
const char* code() {
@@ -411,7 +422,7 @@ class NMethod : VMStructs {
411422

412423
const char* scopes() {
413424
if (_scopes_data_offset > 0) {
414-
return at(*(int*) at(_scopes_data_offset));
425+
return immutableDataAt(*(int*) at(_scopes_data_offset));
415426
} else {
416427
return *(const char**) at(-_scopes_data_offset);
417428
}
@@ -464,6 +475,9 @@ class NMethod : VMStructs {
464475
}
465476

466477
VMMethod** metadata() {
478+
if (_data_offset > 0) {
479+
return (VMMethod**) at(*(int*) at(_data_offset) + *(unsigned short*) at(_nmethod_metadata_offset));
480+
}
467481
return (VMMethod**) at(*(int*) at(_nmethod_metadata_offset));
468482
}
469483

@@ -556,27 +570,30 @@ class PcDesc {
556570

557571
class ScopeDesc : VMStructs {
558572
private:
559-
NMethod* _nm;
573+
const unsigned char* _scopes;
574+
VMMethod** _metadata;
560575
const unsigned char* _stream;
561576
int _method_offset;
562577
int _bci;
563578

564579
int readInt();
565580

566581
public:
567-
ScopeDesc(NMethod* nm) : _nm(nm) {
582+
ScopeDesc(NMethod* nm) {
583+
_scopes = (const unsigned char*)nm->scopes();
584+
_metadata = nm->metadata();
568585
}
569586

570587
int decode(int offset) {
571-
_stream = (const unsigned char*)_nm->scopes() + offset;
588+
_stream = _scopes + offset;
572589
int sender_offset = readInt();
573590
_method_offset = readInt();
574591
_bci = readInt() - 1;
575592
return sender_offset;
576593
}
577594

578595
VMMethod* method() {
579-
return _method_offset > 0 ? _nm->metadata()[_method_offset - 1] : NULL;
596+
return _method_offset > 0 ? _metadata[_method_offset - 1] : NULL;
580597
}
581598

582599
int bci() {

0 commit comments

Comments
 (0)