RFR: 8329331: Intrinsify Unsafe::setMemory [v5]
Scott Gibbons
sgibbons at openjdk.org
Fri Apr 5 22:07:23 UTC 2024
On Fri, 5 Apr 2024 21:53:50 GMT, Scott Gibbons <sgibbons at openjdk.org> wrote:
>> This code makes an intrinsic stub for `Unsafe::setMemory` for x86_64. See [this PR](https://github.com/openjdk/jdk/pull/16760) for discussion around this change.
>>
>> Overall, making this an intrinsic improves overall performance of `Unsafe::setMemory` by up to 4x for all buffer sizes.
>>
>> Tested with tier-1 (and full CI). I've added a table of the before and after numbers for the JMH I ran (`MemorySegmentZeroUnsafe`).
>>
>> [setMemoryBM.txt](https://github.com/openjdk/jdk/files/14808974/setMemoryBM.txt)
>
> Scott Gibbons has updated the pull request incrementally with one additional commit since the last revision:
>
> Fixed generate_fill when count > 0x80000000
Thanks for all your thoughtful feedback. I would very much like to take "the right approach"(tm) but I don't have the skill to write IR, especially given that this is an Unsafe block, which is restricted by atomicity and alignment. I would not know how to prevent the C2 optimizer from vectorizing, or indeed replacing my code with a call to memset(). I'm not sure it would go this far, but in order to remain compliant with the spec I have to prevent it in the future.
This was modeled after the existing implementation of copyMemory, gives good performance (3-5x), and can serve as a template for other platform developers to follow. They have the expertise for their specific platform(s) which I do not have.
Again, thank you.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18555#issuecomment-2040688225
More information about the core-libs-dev
mailing list