Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 968
Li Haoyi Avatar asked Nov 06 '12 05:11

Li Haoyi


1 Answers

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.

like image 130
BeeOnRope Avatar answered Sep 22 '22 22:09

BeeOnRope