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

Radoslaw Smogura duke at openjdk.org
Wed Aug 10 17:44:01 UTC 2022


On Mon, 8 Aug 2022 17:39:18 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Exactly!
>
> I guess which solution is taken depends on how deep of a problem this is. I suggest writing a benchmark using e.g. bulk copy between segments, and see if the same issue occurs. We do have tests for polluted memory segment access and we have not seen issues with maxAlignMask showing up there, so I'm curious as to why the vector use-site seems to be more problematic. I wonder if part of the issue is the lack of argument type profiling - e.g. profile info based on the type of arguments in a static call. I think Method/VarHandle have that enabled by default (for obvious reasons) and there are hacks in the JVM to allow that for Unsafe as well. But that support is not enabled for this particular vector call, and I wonder if that could lead to the problem you describe.
> 
> https://github.com/openjdk/jdk/blob/master/src/hotspot/share/oops/methodData.cpp#L1583

@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

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

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


More information about the panama-dev mailing list