Why is String.equals() faster than itself?

前端 未结 3 1972
你的背包
你的背包 2021-02-04 05:42

I was attempting to create a faster version of String.equals() method and started by simply copying it. The result I found was quite confusing. When I ran the copy pasted versio

3条回答
  •  借酒劲吻你
    2021-02-04 06:21

    Hotspot allows developers to provide a native implementation of a method in addition of the Java implementation. The Java code is swapped out at runtime and replaced by the optimized version. It is called an intrinsic. Few hundred of methods from base classes are optimized by intrinsics.

    By looking at the OpenJDK source code you can see the x86_64 implementation of String.equals. You can also look into vmSymbols to get the list of all instrinsics (search for do_intrinsic)

提交回复
热议问题