Beispiel #1
0
  public void testTightenDependsOnTightenedMethods() throws Exception {
    addSnippetClassDecl("abstract static class A {}");
    addSnippetClassDecl("static class B extends A {}");
    addSnippetClassDecl("static A test() { return new B(); }");
    // test should be tightened to be static EntryPoint$B test();

    addSnippetClassDecl("static class C {A a;}");
    addSnippetClassDecl("static void fun1(A a) {if (a == null) return;}");
    addSnippetClassDecl("static A fun2() { return test(); }"); // tighten method return type
    Result result =
        optimize(
            "void",
            "A a = test();" // tighten local varialbe.
                + "C c = new C(); c.a = test();" // tighten field
                + "fun1(test());" // tighten parameter
            );
    assertEquals("static EntryPoint$B fun2();\n", result.findMethod("fun2").toString());
    assertEquals(
        "EntryPoint$B a",
        OptimizerTestBase.findLocal(result.findMethod(MAIN_METHOD_NAME), "a").toString());
    assertEquals(
        "EntryPoint$B a",
        OptimizerTestBase.findField(result.findClass("EntryPoint$C"), "a").toString());
    assertEquals("static void fun1(EntryPoint$B a);\n", result.findMethod("fun1").toString());
  }
Beispiel #2
0
  public void testMethodBasedOnLeafType() throws Exception {
    addSnippetClassDecl("abstract static class A { void makeSureFunIsCalled() {fun(this);} }");
    addSnippetClassDecl("static class B extends A {}");
    addSnippetClassDecl("static A fun(A a) {return a;}");

    Result result = optimize("void", "");
    assertEquals("static EntryPoint$B fun(EntryPoint$B a);\n", result.findMethod("fun").toString());
  }
Beispiel #3
0
 public void testTightenParameterBasedOnAssignment() throws Exception {
   addSnippetClassDecl("static class A { }");
   addSnippetClassDecl("static class B extends A { }");
   addSnippetClassDecl("static class C extends B { }");
   addSnippetClassDecl("static class D extends B { }");
   addSnippetClassDecl("static void test(A a) { }");
   Result result = optimize("void", "C c = new C(); D d = new D(); test(c); test(d);");
   assertEquals("static void test(EntryPoint$B a);\n", result.findMethod("test").toString());
 }
Beispiel #4
0
 public void testMethodBasedOnReturns() throws Exception {
   addSnippetClassDecl("static class A {}");
   addSnippetClassDecl("static class B extends A {}");
   addSnippetClassDecl("static class C extends B {}");
   addSnippetClassDecl("static class D extends B {}");
   addSnippetClassDecl(
       "A fun(int a) { if(a<0) return new B(); else if(a==0) return new C(); return new D();}");
   Result result = optimize("void", "");
   assertEquals("EntryPoint$B fun(int a);\n", result.findMethod("fun").toString());
 }