KEMBAR78
Test `comptask` feature by fandreuz · Pull Request #1293 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

@fandreuz
Copy link
Contributor

Description

Add a test to check that the method being compiled appears correctly in the profile when features=comptask is used.

Related issues

Will be useful to test changes related to #1260

Motivation and context

We don't have an integration test for features=comptask yet.

How has this been tested?

GHA


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

@fandreuz fandreuz force-pushed the test-comptask branch 4 times, most recently from 498af69 to ce9b53b Compare May 16, 2025 07:52
src/vmStructs.h Outdated
Comment on lines 378 to 381
if (goodPtr(env)) {
const char* task = (const char*) SafeAccess::load((void**) (env + _comp_task_offset));
if (goodPtr(task)) {
return (VMMethod*) SafeAccess::load((void**) (task + _comp_method_offset));
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 this?
compiledMethod() is called at a known location where all pointers should be valid. If it's not the case, there must be a bug somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check this segfault stacktrace: https://github.com/fandreuz/async-profiler/actions/runs/15069387768/job/42361695062#step:16:164

In the same run, I also added some debug print statements:

    VMMethod* compiledMethod() {
        const char* env = *(const char**) at(_comp_env_offset);
        if (env != NULL) {
            const char* task = *(const char**) (env + _comp_task_offset);
            if (task != NULL) {
+               fprintf(stderr, "env: %p, taks_ptr: %p, task_offset: %d, method_ptr: %p, method_offset: %d\n", 
+                  env, task, _comp_task_offset, task + _comp_method_offset, _comp_method_offset);
                return *(VMMethod**) (task + _comp_method_offset);
            }
        }
        return NULL;
    }

and these are the last few lines before the segfault:

env: 0x7f6014cf9a10, taks_ptr: 0x7f60310208d0, task_offset: 112, method_ptr: 0x7f60310208e0, method_offset: 16
env: 0x7f6014cf9a10, taks_ptr: 0x7f60310208d0, task_offset: 112, method_ptr: 0x7f60310208e0, method_offset: 16
env: 0x7f6014cf9a10, taks_ptr: 0x7f60310208d0, task_offset: 112, method_ptr: 0x7f60310208e0, method_offset: 16
env: 0x7f6014cf9a10, taks_ptr: 0x1, task_offset: 112, method_ptr: 0x11, method_offset: 16

It seems that the dereferenced pointer to CompileTask points to some random location. In a different run, I also got a valid task_ptr and an invalid method_ptr.

Do we have any strong guarantee about the memory we're reading? I guess we don't, the JVM seems to be free to reuse it however it likes. My theory here is that the CompileTask completed successfully, and we're just getting access to some memory which has been recycled.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so your test found a real bug, and that's actually a good news.
The reason is, CompilerThread::_env is initialized inside invoke_compiler_on_method. This means, it's not always safe to access _env inside invoke_compiler_on_method, we should check the presence of another frame like compile_method.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@fandreuz fandreuz marked this pull request as draft May 19, 2025 14:37
@fandreuz fandreuz marked this pull request as ready for review May 20, 2025 09:49
@fandreuz
Copy link
Contributor Author

@apangin all comments have been addressed

@apangin apangin merged commit ed57317 into async-profiler:master May 20, 2025
17 checks passed
roy-soumadipta pushed a commit to roy-soumadipta/async-profiler that referenced this pull request Jun 20, 2025
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.

3 participants