KEMBAR78
Allow VMX to work on native applications by Baraa-Hasheesh · Pull Request #1354 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

@Baraa-Hasheesh
Copy link
Contributor

Description

Allow VMX stack walking to work on applications without checking if JVM is present or not.

Previously any continuous profiling agent on a native application would have to use other stack walking modes.
Those stack walking modes once a JVM is detected will start to use AsyncGetCallTrace method which is error prone.

The VMX makes sense for such native applications (applications that start a JVM instance) as they need both native stack & java stack unwinding

Related issues

N/A

Motivation and context

Allow continuous profiling on native application using VMX

How has this been tested?

test/test/nonjava/NonjavaTests.java was changed to use VMX
make test


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

src/profiler.cpp Outdated
} else if (_cstack == CSTACK_LBR && _engine != &perf_events) {
return Error("Branch stack is supported only with PMU events");
} else if (_cstack >= CSTACK_VM && !VMStructs::hasStackStructs()) {
} else if (_cstack == CSTACK_VM && !VMStructs::hasStackStructs()) {
Copy link
Member

Choose a reason for hiding this comment

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

This check should not be simply disabled. We should not let users select vmx mode if the target JVM does not really support it (e.g. Zing, OpenJ9), or if it is new version of HotSpot where some VM structures have been changed. Otherwise this may lead to JVM crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated check here 89f10a4

The check specifically check that libjvm is loaded & attached to the profiler now

Copy link
Member

Choose a reason for hiding this comment

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

VM::loaded() is the canonical way to check JVM presence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems I forgot about that function, thanks for the catch

updated here d1a07f8

src/profiler.cpp Outdated
} else if (args._cstack == CSTACK_LBR && _engine != &perf_events) {
return Error("Branch stack is supported only with PMU events");
} else if (args._cstack >= CSTACK_VM && !VMStructs::hasStackStructs()) {
} else if (_cstack >= CSTACK_VM && VM::loaded() && !VMStructs::hasStackStructs()) {
Copy link
Member

Choose a reason for hiding this comment

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

args._cstack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry my bad in copy & paste,

handled here 4de1eb4


// jvm is loaded before the profiling session is started
@Test(sh = "%testbin/non_java_app 1 %s.html", output = true)
@Test(sh = "%testbin/non_java_app 1 %s.jfr", output = true)
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change it to use jfr format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 main reasons,

  • Most other tests use jfr so I changed it to be more inline
  • JFR offers more debug information & is easier to debug in CLI compared to flame-graph

Copy link
Member

Choose a reason for hiding this comment

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

This does not seem correct to me.
Originally, most of tests used collapsed format as it is easiest to parse and human readable at the same time.
Only those tests that require access to individual events used JFR, e.g. multi-event profiling and leak profiling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I revert this to html or convert it to collapsed?

IMO for this context I think collapsed makes more sense than the original html as I'm checking if the stack contains certain function calls

Copy link
Member

Choose a reason for hiding this comment

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

Change it to collapsed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed here a03bba9

@apangin apangin merged commit 0330a6e into async-profiler:master Jul 1, 2025
18 checks passed
visheshruparelia pushed a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
visheshruparelia added a commit to visheshruparelia/async-profiler that referenced this pull request Jul 9, 2025
Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)

Disable JFR OldObjectSample event in jfrsync mode (async-profiler#1350)

Fix invalid alignment in mallocTracer and zero-init buf in getTotalCpuTime (async-profiler#1351)

C++ linting via clang-tidy (async-profiler#1338)

Allow cstack=vmx for native applications (async-profiler#1354)

Correctly unwind stack for malloc events in VM stack walking mode (async-profiler#1357)

Simplify location handling in OTLP (async-profiler#1361)

Suppress javac warnings when compiling tests

Do not include excess files in test.jar

Fix nonjava test failure on Alpine

Auto-generated clang-tidy review comments (async-profiler#1360)

JFR to OTLP converter (async-profiler#1336)

Cancel redundant in-progress GHA runs (async-profiler#1363)

Ensure that only files under `src/` are checked in `cpp-lint-diff` (async-profiler#1365)

Publish clang-tidy comments only for non-draft PRs (async-profiler#1367)

Give tests unique suffix names (async-profiler#1371)

Test OTLP output format (async-profiler#1331)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants