RFR: 8336489: Track scoped accesses in JVMCI compiled code [v3]

Carlo Refice duke at openjdk.org
Fri Jul 26 17:05:36 UTC 2024


On Tue, 23 Jul 2024 13:02:03 GMT, Carlo Refice <duke at openjdk.org> wrote:

>> This PR adds JVMCI support to scoped access tracking introduced in #20158.
>> 
>> In this PR:
>> * The `Method::is_scoped` flag is now exposed in JVMCI as `HotSpotResolvedJavaMethod.isScoped()`, and serialized to / deserialized from the JVMCI compiled code stream as a boolean flag.
>> * To determine whether a compiled method has a scoped access, we simply check `HotSpotResolvedJavaMethod.isScoped()` returns `true` for the root method or any of the methods that were inlined in the compilation.
>> * The above check is implemented as the method `HotSpotCompiledNMethod.hasScopedAccess()`, instead of as an explicit flag set in a the constructor of `HotSpotCompiledNMethod`. This keeps the change isolated to JVMCI, without requiring coordinated changes to the Graal compiler. No other changes in the compiler are necessary to benefit from the optimization.
>
> Carlo Refice has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
> 
>   Clarify HotSpotResolvedJavaMethod#isScoped javadoc

I figured out what went wrong with the `is_scoped` flag in JVMCI. The implementation of `HotSpotResolvedJavaMethodImpl#getConstMethodFlags` was as follows:

    private int getConstMethodFlags() {
        return UNSAFE.getChar(getConstMethod() + config().constMethodFlagsOffset);
    }
    
    public boolean isScoped() {
        // constMethodFlagsIsScoped == 1 << 16
        return (getConstMethodFlags() & config().constMethodFlagsIsScoped) != 0;
    }
 ```
 
 However, `ConstMethod::_flags` is a `u4`, not a `u1`. This caused only the least significant byte of the flags (or most, depending on endianness) to be read in JVMCI code. A similar problem also occurred with `Method::_flags`, though for that one two bytes were read.
 
 I suppose we didn't really care about flags with bit indexes past 8 before now, hence why the tests never failed before. Nevertheless, I fixed both and `isScoped()` now behaves as expected (and tested)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/20256#issuecomment-2253147625


More information about the hotspot-compiler-dev mailing list