简体   繁体   中英

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM