RFR: 8372410: ThreadFactory used by Thread.Builder::factory uses non-optimal VarHandle

Alan Bateman alanb at openjdk.org
Tue Nov 25 07:51:38 UTC 2025


On Tue, 25 Nov 2025 03:38:41 GMT, Francesco Nigro <duke at openjdk.org> wrote:

>>> This has bitten me lot of times @liach 😢 Including others while reading/writing oop fields into arrays too; it would be nice to get an option to fail fast with an exception enabled via diagnostic args eg EnableStrictPolymorphicSignature Although Javac should be able to detect it too, thinking about it twice
>> 
>> This can be done using [`VarHandle::withInvokeExactBehavior`](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/invoke/VarHandle.html#withInvokeExactBehavior()) on a per var handle basis. C2 can constant fold the type-check away as well.
>
> @JornVernee thanks 🙏 I admit it's the first time I see this method, wow

@franz1981 You can type "/integrate" into a comment and I will sponsor. I ran tests with the change yesterday and all good.

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

PR Comment: https://git.openjdk.org/jdk/pull/28475#issuecomment-3574186718


More information about the core-libs-dev mailing list