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

Radoslaw Smogura duke at openjdk.org
Mon Aug 8 18:43:21 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

I created test with core method like this

    @CompilerControl(DONT_INLINE)
    private static long sum(MemorySegment in) {
        long sz = in.byteSize() / Integer.BYTES;
        long result = 0L;
        for (long i = 0; i < sz; i += Integer.BYTES) {
            result += (int) JAVA_INT.get(in, i);
        }

        return result;
    }

But results after / before patch does not differs so much. 

Interesting I see some additional optimization turns on after some time (it should be fully JITed during warm-up)

Iteration   3: 228720.552 ns/op
Iteration   4: 220640.677 ns/op
Iteration   5: 12248.776 ns/op
Iteration   6: 9470.916 ns/op
Iteration   7: 9422.982 ns/op


Later I can try a bit with `TypeProfileLevel` looking at code setting it to `2` should enable mentioned profiling always.

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

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


More information about the panama-dev mailing list