Yes, HotSpot JVM is kind of “cheating”, because it has a special version of some BigInteger
methods that you won’t find in Java code. These methods are called JVM intrinsics.
In particular, BigInteger.multiplyToLen
is an intrinsic method in HotSpot. There is a special hand-coded assembly implementation in JVM source base, but only for x86-64 architecture.
You may disable this intrinsic with -XX:-UseMultiplyToLenIntrinsic
option to force JVM to use pure Java implementation. In this case the performance will be similar to the performance of your copied code.
P.S. Here is a list of other HotSpot intrinsic methods.