Guest User

Untitled

a guest
Aug 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. On 32-bit Windows, JDK6u26, run this example under OllyDbg,
  2.  
  3. ```java
  4. public class TestUseFastAccessorMethods {
  5. private static int test(Foo[] objs) {
  6. int sum = 0;
  7. for (int i = 0; i < 500000; i++) {
  8. sum += objs[i % objs.length].foo(); // polymorphic callsite, virtual call not inlined
  9. }
  10. return sum;
  11. }
  12.  
  13. public static void main(String[] args) throws Exception {
  14. Foo[] objs = new Foo[] { new A(), new B(), new C(), new D() };
  15. for (int i = 0; i < 6; i++) {
  16. if (i == 5) {
  17. System.out.println("press enter to continue");
  18. System.in.read();
  19. }
  20. int dummy = test(objs);
  21. }
  22. }
  23. }
  24.  
  25. abstract class Foo {
  26. public abstract int foo();
  27. }
  28.  
  29. class A extends Foo {
  30. private int a;
  31.  
  32. @Override
  33. public int foo() {
  34. return a;
  35. }
  36. }
  37.  
  38. class B extends Foo {
  39. private int b;
  40.  
  41. @Override
  42. public int foo() {
  43. return b;
  44. }
  45. }
  46.  
  47. class C extends Foo {
  48. private int c;
  49.  
  50. @Override
  51. public int foo() {
  52. return c;
  53. }
  54. }
  55.  
  56. class D extends Foo {
  57. private int d;
  58.  
  59. @Override
  60. public int foo() {
  61. return d;
  62. }
  63. }
  64. ```
  65.  
  66. `java.exe -server -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly TestUseFastAccessorMethods`
  67.  
  68. Gets the locations of the `CompiledIC`s we're looking for, set a breakpoint on one of them, and then we get this:
  69.  
  70. ```
  71.  
  72. call site:
  73.  
  74. 009B7D1D 90 nop
  75. 009B7D1E B8 904DC403 mov eax,3C44D90
  76. 009B7D23 E8 A4030000 call 009B80CC
  77.  
  78. Vtable stub (megamorphic state out-of-line inline cache stub):
  79.  
  80. 009B80CC 8B41 04 mov eax,dword ptr ds:[ecx+4] ; load klass ptr
  81. 009B80CF 8B98 44010000 mov ebx,dword ptr ds:[eax+144] ; load vtable entry of foo
  82. 009B80D5 FF63 4C jmp dword ptr ds:[ebx+4C] ; jump to its from_compiled_entry (jump to VEP, not unverified entry point)
  83. ```
Add Comment
Please, Sign In to add comment