Re:Unrolling Java Loops at Runtime with Byte Buddy
by RyanZAG on Thursday October 22, 2015 @01:56AM
(#10430606)
Instead of manipulating byte code at runtime, wouldn't it make more sense to use an annotation processor to just create a specialized UnsafeArrayList for each input type you need?
With something like JavaPoet, it's fairly easy to do as well. It feels a lot safer than manually creating byte code like that. Let javac do that for you.
Re:Unrolling Java Loops at Runtime with Byte Buddy
by MrBuddyCasino on Thursday October 22, 2015 @01:40AM
(#10430567)
tl;dr: HotSpot doesn't seem to optimize a data copying loop for code that uses sun.misc.Unsafe, due to unknown reasons. Thus, we can generate bytecode at runtime to unroll said loop to make things go twice as fast.
Does anyone know if Unsafe is indeed blacklisted for JIT optimisations?
Re:Unrolling Java Loops at Runtime with Byte Buddy
by Apanatshka on Thursday October 22, 2015 @02:04AM
(#10430631)
No, Unsafe is not blacklisted from JIT afaik. Although be careful that a helper method using Unsafe usually doesn't get inlined.
The problem in this case is the loop. It ranges over a long, and where int loops get a lot of optimisations, long loops don't (yet, they're aware of the issue)
With something like JavaPoet, it's fairly easy to do as well. It feels a lot safer than manually creating byte code like that. Let javac do that for you.
EDIT: If you're not familiar with JavaPoet, check it out here: https://corner.squareup.com/2015/01/javapoet.html
Does anyone know if Unsafe is indeed blacklisted for JIT optimisations?