< prev index next >

test/src/jdk/dynalink/test/LinkedCallSiteLocationTest.java

Print this page




  54                         new NamedOperation(CALL_METHOD, "foo"),
  55                         MethodType.methodType(void.class, Object.class)));
  56         linker.link(callSite);
  57 
  58         // Test initial linking
  59         callSite.dynamicInvoker().invoke(new TestClass1()); final int l1 = getLineNumber();
  60         assertLocation(lastLinked[0], l1);
  61 
  62         // Test relinking
  63         callSite.dynamicInvoker().invoke(new TestClass2()); final int l2 = getLineNumber();
  64         assertLocation(lastLinked[0], l2);
  65     }
  66 
  67     private void assertLocation(final StackTraceElement frame, final int lineNumber) {
  68         Assert.assertNotNull(frame);
  69         Assert.assertEquals(frame.getLineNumber(), lineNumber);
  70         Assert.assertEquals(frame.getClassName(), this.getClass().getName());
  71     }
  72 
  73     private static int getLineNumber() {
  74         return StackWalker.getInstance().walk(s -> s.skip(1).findFirst().get().getLineNumber().getAsInt());
  75     }
  76 
  77     public static class TestClass1 {
  78         public void foo() {
  79         }
  80     }
  81 
  82     public static class TestClass2 {
  83         public void foo() {
  84         }
  85     }
  86 }


  54                         new NamedOperation(CALL_METHOD, "foo"),
  55                         MethodType.methodType(void.class, Object.class)));
  56         linker.link(callSite);
  57 
  58         // Test initial linking
  59         callSite.dynamicInvoker().invoke(new TestClass1()); final int l1 = getLineNumber();
  60         assertLocation(lastLinked[0], l1);
  61 
  62         // Test relinking
  63         callSite.dynamicInvoker().invoke(new TestClass2()); final int l2 = getLineNumber();
  64         assertLocation(lastLinked[0], l2);
  65     }
  66 
  67     private void assertLocation(final StackTraceElement frame, final int lineNumber) {
  68         Assert.assertNotNull(frame);
  69         Assert.assertEquals(frame.getLineNumber(), lineNumber);
  70         Assert.assertEquals(frame.getClassName(), this.getClass().getName());
  71     }
  72 
  73     private static int getLineNumber() {
  74         return StackWalker.getInstance().walk(s -> s.skip(1).findFirst().get().getLineNumber());
  75     }
  76 
  77     public static class TestClass1 {
  78         public void foo() {
  79         }
  80     }
  81 
  82     public static class TestClass2 {
  83         public void foo() {
  84         }
  85     }
  86 }
< prev index next >