JDK-8149163 : Unsafe.addressSize() does not optimize
  • Type: Enhancement
  • Component: core-libs
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2016-02-05
  • Updated: 2016-07-28
Related Reports
Relates :  
Description
I noticed as part of my work on JDK-8141491 that the addressSize() method isn't an intrinsic, and so if somebody accidentally uses that method instead of the ADDRESS_SIZE field in Unsafe the resulting code will always call into the VM.

Yes, I'm using Unsafe. Yes, I should know better. That said, it would be nice if we could either make addressSize() do the right thing, OR at least make it private, OR at least document that it shouldn't be used directly and that ADDRESS_SIZE is what should be used instead - *even* if this is "just" Unsafe.

I also noticed that there's at least one place in the JDK where addressSize() is used - sun/nio/ch/NativeObject calls addressSize() instead of using the ADDRESS_SIZE field, so it will not be fully optimized.