Are all the “Magic” methods on the JVM marked as Native?

穿精又带淫゛_ 提交于 2020-01-02 03:50:11

问题


By "Magic" I mean the methods which have semantics which are not expressed in pure Java.

I know all native methods are magic, in that their implementation is provided by the underlying runtime and not by Java bytecodes.

Is the reverse true? Are all magic methods native, or are there some magic methods apparently implemented in pure Java, but with some extra help from some JVM-special-casing?

The use case is that I want to modify the semantics of Java by instrumenting its bytecodes. All these magic methods are special cases which I will have to handle some way or another. The native ones are all obvious, but I was wondering if there are any unmarked magic methods I have to watch out and special case for.


回答1:


Unfortunately there are "magic" methods outside of native methods. Take a look at intrinsic methods - these methods are known to the JIT, which uses hand rolled implementations when a method is compiled, and include heavily called methods such as String.indexOf, Integer.numberOfLeadingZeros, etc.

Take a look at here, under Intrinsics, for some details and how to determine which methods are intrinsified on your JVM. I'm not sure if injecting bytecode will turn off intrisification, but there is a DisableIntrinsic XX option you can use to disable selected intrinsics.




回答2:


You may find that a lot of details have already been handled in AspectJ. I would take a look at it before doing manual bytecode manipulation.



来源:https://stackoverflow.com/questions/13244898/are-all-the-magic-methods-on-the-jvm-marked-as-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!