Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- On 32-bit Windows, JDK6u26, run this example under OllyDbg,
- ```java
- public class TestUseFastAccessorMethods {
- private static int test(Foo[] objs) {
- int sum = 0;
- for (int i = 0; i < 500000; i++) {
- sum += objs[i % objs.length].foo(); // polymorphic callsite, virtual call not inlined
- }
- return sum;
- }
- public static void main(String[] args) throws Exception {
- Foo[] objs = new Foo[] { new A(), new B(), new C(), new D() };
- for (int i = 0; i < 6; i++) {
- if (i == 5) {
- System.out.println("press enter to continue");
- System.in.read();
- }
- int dummy = test(objs);
- }
- }
- }
- abstract class Foo {
- public abstract int foo();
- }
- class A extends Foo {
- private int a;
- @Override
- public int foo() {
- return a;
- }
- }
- class B extends Foo {
- private int b;
- @Override
- public int foo() {
- return b;
- }
- }
- class C extends Foo {
- private int c;
- @Override
- public int foo() {
- return c;
- }
- }
- class D extends Foo {
- private int d;
- @Override
- public int foo() {
- return d;
- }
- }
- ```
- `java.exe -server -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly TestUseFastAccessorMethods`
- Gets the locations of the `CompiledIC`s we're looking for, set a breakpoint on one of them, and then we get this:
- ```
- call site:
- 009B7D1D 90 nop
- 009B7D1E B8 904DC403 mov eax,3C44D90
- 009B7D23 E8 A4030000 call 009B80CC
- Vtable stub (megamorphic state out-of-line inline cache stub):
- 009B80CC 8B41 04 mov eax,dword ptr ds:[ecx+4] ; load klass ptr
- 009B80CF 8B98 44010000 mov ebx,dword ptr ds:[eax+144] ; load vtable entry of foo
- 009B80D5 FF63 4C jmp dword ptr ds:[ebx+4C] ; jump to its from_compiled_entry (jump to VEP, not unverified entry point)
- ```
Add Comment
Please, Sign In to add comment