changeset 6069:2e5b62d880a1

Summary: New covar return, concrete method matching, and access flags tests
author kamg
date Tue, 09 Oct 2012 07:54:56 -0400
parents a0513c13c10e
children d30d2d58baa5
files test-ng/tests/org/openjdk/tests/separate/TestHarness.java test-ng/tests/org/openjdk/tests/vm/DefaultMethodsTest.java test-ng/tests/org/openjdk/tests/vm/StrictfpDefault.java test-ng/tests/org/openjdk/tests/vm/SynchronizedDefault.java
diffstat 4 files changed, 162 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/test-ng/tests/org/openjdk/tests/separate/TestHarness.java	Mon Oct 08 16:20:42 2012 -0700
+++ b/test-ng/tests/org/openjdk/tests/separate/TestHarness.java	Tue Oct 09 07:54:56 2012 -0400
@@ -158,7 +158,8 @@
             String.format("((%s)(new %s())).%s(%s)", iface.toString(),
                 specimen.getName(), method.getName(), params));
         sm.suppressWarnings();
-        Class ii = new Class("II_" + specimen.getName(), sm);
+        Class ii = new Class("II_" + specimen.getName() + "_" + 
+            iface.getType().getName(), sm);
         ii.addCompilationDependency(istub);
         ii.addCompilationDependency(cstub);
         ii.addCompilationDependency(method);
--- a/test-ng/tests/org/openjdk/tests/vm/DefaultMethodsTest.java	Mon Oct 08 16:20:42 2012 -0700
+++ b/test-ng/tests/org/openjdk/tests/vm/DefaultMethodsTest.java	Tue Oct 09 07:54:56 2012 -0400
@@ -657,4 +657,156 @@
             new ConcreteMethod("int", stdMethodName, "return -1;", s), 
             "-1", "\"string\"");
     }
+
+    /**
+     * interface I { Integer m() default { return new Integer(88); } }
+     * class C { Number m() { return new Integer(99); } }
+     * class D extends C implements I {}
+     * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger;
+     * TEST: S s = new S(); s.foo() == new Integer(99)
+     */
+    public void testCovarBridge() {
+        Interface I = new Interface("I", new DefaultMethod(
+            "Integer", "m", "return new Integer(88);"));
+        Class C = new Class("C", new ConcreteMethod(
+            "Number", "m", "return new Integer(99);"));
+        Class D = new Class("D", I, C);
+
+        ConcreteMethod DstubMethod = 
+            new ConcreteMethod("Integer", "m", "return null;");
+        Class Dstub = new Class("D", DstubMethod);
+
+        ConcreteMethod toCall = new ConcreteMethod(
+            "Object", "foo", "return (new D()).m();");
+        Class S = new Class("S", D, toCall);
+        S.addCompilationDependency(Dstub);
+        S.addCompilationDependency(DstubMethod);
+
+        assertInvokeVirtualEquals(new Integer(99), S, toCall, "null");
+    }
+
+    /**
+     * interface I { Integer m() default { return new Integer(88); } }
+     * class C { int m() { return 99; } }
+     * class D extends C implements I {}
+     * class S { Object foo() { return (new D()).m(); } // link sig: ()LInteger;
+     * TEST: S s = new S(); s.foo() == new Integer(88)
+     */
+    public void testNoCovarNoBridge() {
+        Interface I = new Interface("I", new DefaultMethod(
+            "Integer", "m", "return new Integer(88);"));
+        Class C = new Class("C", new ConcreteMethod(
+            "int", "m", "return 99;"));
+        Class D = new Class("D", I, C);
+
+        ConcreteMethod DstubMethod = 
+            new ConcreteMethod("Integer", "m", "return null;");
+        Class Dstub = new Class("D", DstubMethod);
+
+        ConcreteMethod toCall = new ConcreteMethod(
+            "Object", "foo", "return (new D()).m();");
+        Class S = new Class("S", D, toCall);
+        S.addCompilationDependency(Dstub);
+        S.addCompilationDependency(DstubMethod);
+
+        assertInvokeVirtualEquals(new Integer(88), S, toCall, "null");
+    }
+
+    /**
+     * interface J { int m(); }
+     * interface I extends J { int m() default { return 99; } }
+     * class B implements J {}
+     * class C extends B implements I {}
+     * TEST: C c = new C(); c.m() == 99
+     *
+     * The point of this test is that B does not get default method analysis, 
+     * and C does not generate any new miranda methods in the vtable.  
+     * It verifies that default method analysis occurs when mirandas have been
+     * inherited and the supertypes don't have any overpass methods.
+     */   
+    public void testNoNewMiranda() {
+        Interface J = new Interface("J", new PresentMethod());
+        Interface I = new Interface("I", J, DefaultMethod.returns("99"));
+        Class B = new Class("B", J);
+        Class C = new Class("C", B, I);
+        assertInvokeVirtualEquals(99, C);
+    }
+    
+    /**
+     * interface I<T,V,W> { int m(T t, V v, W w); }
+     * interface J<T,V> implements I<T,V,String> { int m(T t, V v, String w); }
+     * interface K<T> implements J<T,String> { 
+     *     int m(T t, String v, String w); { return 99; } }
+     * class C implements K<String> {
+     *     public int m(Object t, Object v, String w) { return 77; }
+     * }
+     * TEST C = new C(); ((I)c).m(Object,Object,Object) == 99
+     * TEST C = new C(); ((J)c).m(Object,Object,String) == 77 
+     * TEST C = new C(); ((K)c).m(Object,String,String) == 99 
+     *
+     * Test that a erased-signature-matching method does not implement
+     * non-language-level matching methods
+     */
+    public void testNonConcreteFill() {
+        PresentMethod ipm = new PresentMethod("int", "m", 
+            new MethodParameter("T", "t"),
+            new MethodParameter("V", "s"), 
+            new MethodParameter("W", "w")); 
+        Interface I = new Interface("I", 
+            new TypeParameter("T"), 
+            new TypeParameter("V"), 
+            new TypeParameter("W"), ipm);
+
+        PresentMethod jpm = new PresentMethod("int", "m", 
+            new MethodParameter("T", "t"),
+            new MethodParameter("V", "s"), 
+            new MethodParameter("String", "w")); 
+        Interface J = new Interface("J", 
+            new TypeParameter("T"), 
+            new TypeParameter("V"), 
+            I.with("T", "V", "String"), jpm);
+
+        PresentMethod kpm = new PresentMethod("int", "m", 
+            new MethodParameter("T", "t"),
+            new MethodParameter("String", "s"), 
+            new MethodParameter("String", "w")); 
+        Interface K = new Interface("K", 
+            new TypeParameter("T"), 
+            J.with("T", "String"),
+            new DefaultMethod("int", "m", "return 99;",
+                new MethodParameter("T", "t"),
+                new MethodParameter("String", "v"),
+                new MethodParameter("String", "w")));
+
+        Class C = new Class("C",
+            K.with("String"),
+            new ConcreteMethod("int", "m", "return 77;",
+                new MethodParameter("Object", "t"),
+                new MethodParameter("Object", "v"),
+                new MethodParameter("String", "w")));
+
+        String a = "\"\"";
+        assertInvokeInterfaceEquals(99, C, 
+            K.with("String"), kpm, a, a, a);
+        assertInvokeInterfaceEquals(77, C, 
+            J.with("String", "String"), jpm, a, a, a); 
+        assertInvokeInterfaceEquals(99, C, 
+            I.with("String", "String", "String"), ipm, a, a, a);
+    }
+
+    public void testStrictfpDefault() {
+        try {
+            java.lang.Class.forName("StrictfpDefault"); 
+        } catch (Exception e) {
+            fail("Could not load class", e);
+        }
+    }
+
+    public void testSynchronizedDefault() {
+        try {
+            java.lang.Class.forName("SynchronizedDefault"); 
+        } catch (Exception e) {
+            fail("Could not load class", e);
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-ng/tests/org/openjdk/tests/vm/StrictfpDefault.java	Tue Oct 09 07:54:56 2012 -0400
@@ -0,0 +1,4 @@
+
+interface StringfpDefault {
+    strictfp void m() default {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-ng/tests/org/openjdk/tests/vm/SynchronizedDefault.java	Tue Oct 09 07:54:56 2012 -0400
@@ -0,0 +1,4 @@
+
+interface SynchonizedDefault {
+    synchronized void m() default {}
+}