[foreign-memaccess+abi] RFR: Prevent maxAlign virtual calls for polluted accesses [v2]

Paul Sandoz psandoz at openjdk.org
Mon Aug 15 19:27:42 UTC 2022


On Wed, 10 Aug 2022 18:01:01 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> @mcimadamore,
>> 
>> I've updated JVM method to allow profiling arguments as you hinted, for vector operations
>> 
>> bool MethodData::profile_unsafe(const methodHandle& m, int bci) {
>>   Bytecode_invoke inv(m , bci);
>>   if (inv.is_invokevirtual()) {
>>     Symbol* klass = inv.klass();
>>     if (klass == vmSymbols::jdk_internal_misc_Unsafe() ||
>>         klass == vmSymbols::sun_misc_Unsafe() ||
>>         klass == vmSymbols::jdk_internal_misc_ScopedMemoryAccess()) {
>>       Symbol* name = inv.name();
>>       if (name->starts_with("get") || name->starts_with("put") || name->starts_with("load") || name->starts_with("store")) {
>>         return true;
>>       }
>>     }
>>   }
>>   return false;
>> }
>> 
>> This improved performance with benchmarks, in same way as a patch:
>> 
>> Before
>> 
>> MixedAccessBenchmarks.directCopy          1048576  avgt   10    22763.442 ±   2145.833  ns/op
>> MixedAccessBenchmarks.pollutedAccessCopy  1048576  avgt   10  3536082.952 ± 309959.183  ns/op
>> 
>> After
>> 
>> Benchmark                                  (size)  Mode  Cnt       Score      Error  Units
>> MixedAccessBenchmarks.directCopy          1048576  avgt   10   23006.005 ± 2497.308  ns/op
>> MixedAccessBenchmarks.pollutedAccessCopy  1048576  avgt   10  254049.440 ± 5218.658  ns/op
>
> Thanks for the experiment - that seems a better way to handle this situation, but I'll leave further comments to @PaulSandoz or @iwanowww.

Expanding the profiling to for method names starting with "loadFrom" and "storeInto" seems reasonable, given the most other access methods are also profiled (although not all the read-modify-write methods are).

I think we should separate out the comparison of method names thereby we don't inadvertently profile other methods just in case new methods get added. Plus we can add some comments to the class doc of `Unsafe` and `ScopedMemoryAccess` to indicate such methods are profiled. Ideally I would prefer an HotSpot-specific annotation indicated that all arguments of an annotated method should be profiled.
 
The profiling of all arguments is a blunter hammer that necessary in this case but so be it.

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

PR: https://git.openjdk.org/panama-foreign/pull/700


More information about the panama-dev mailing list