RFR: 8355369: Remove setAccessible usage for setting final fields in java.util.concurrent
    Viktor Klang 
    vklang at openjdk.org
       
    Wed Apr 23 12:23:55 UTC 2025
    
    
  
On Wed, 23 Apr 2025 10:44:05 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> This Pull Request replaces the uses of Field + setAccessible to modify final fields in java.util.concurrent with Unsafe.
>
> src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java line 534:
> 
>> 532:         U.putReference(
>> 533:             this,
>> 534:             U.objectFieldOffset(ConcurrentSkipListSet.class, "m"),
> 
> Would it make sense to compute the offset once and for all and put it in a `static final long` field?
Yeah, I originally did that, but the following patch is the "smallest change".
Given that the "original code" obtained the Field instance each call, this is still likely a performance improvement.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24821#discussion_r2055927582
    
    
More information about the core-libs-dev
mailing list