Created
April 11, 2013 20:15
-
-
Save azolotko/5366808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jvmjit; | |
public class JvmJit { | |
static long startTime = System.nanoTime(); | |
public static void main(String[] args) { | |
Test0 me = new Test0(); | |
while (true) { | |
me.runHello(); | |
} | |
} | |
} | |
interface ICallTarget { | |
void hello(); | |
} | |
class A implements ICallTarget { | |
public void hello() { | |
System.err.println("Hello from A"); | |
} | |
} | |
class B implements ICallTarget { | |
public void hello() { | |
System.err.println("Hello from B"); | |
} | |
} | |
class Test0 { | |
ICallTarget target = new A(); | |
void runHello() { | |
long elapsed = System.nanoTime() - JvmJit.startTime; | |
if (elapsed > 20000000000L && target instanceof A) { | |
target = new B(); | |
} | |
target.hello(); | |
} | |
} | |
/* | |
java -XX:+PrintCompilation jvmjit.JvmJit 2>/dev/null | grep jvmjit | |
404 48 jvmjit.Test0::runHello (37 bytes) | |
405 49 jvmjit.A::hello (9 bytes) | |
473 1 % jvmjit.JvmJit::main @ 8 (15 bytes) | |
20082 48 jvmjit.Test0::runHello (37 bytes) made not entrant <---- JVM сделала недоступной старую версию с заинлайненым вызовом A | |
20117 55 jvmjit.Test0::runHello (37 bytes) <---- Скомпайлила новую с вызовом B | |
20119 56 jvmjit.B::hello (9 bytes) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment