WIP: default method reloading

This commit is contained in:
Andy Clement
2016-01-18 22:56:27 -08:00
parent f161db7d98
commit bfb55e4c0e
8 changed files with 122 additions and 0 deletions

View File

@@ -244,6 +244,78 @@ public class Java8Tests extends SpringLoadedTests {
assertEquals(44, r.returnValue);
}
// A class implements an interface containing a default method and invokes it.
// That default method is reloaded and modified to do something else.
@Ignore
@Test
public void defaultMethods() throws Exception {
String t = "basic.DefaultMethodsI1A";
String t2 = "basic.DefaultMethodsC1A";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
byte[] ia = loadBytesForClass(t);
ReloadableType rtypeI = typeRegistry.addType(t, ia);
byte[] ca = loadBytesForClass(t2);
ReloadableType rtypeC = typeRegistry.addType(t2, ca);
Class<?> simpleClass = rtypeC.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
// byte[] renamed = retrieveRename(t, t + "2");
rtypeI.loadNewVersion("002", ia);
// ClassPrinter.print(rtypeI.getBytesLoaded());
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
byte[] renamed2 = retrieveRename(t, t + "2");
rtypeI.loadNewVersion(renamed2);
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
assertEquals("FOO", r.stdout);
}
// A class implements an interface. A default method is added to the interface on
// a reload and invoked from a reloaded version of the class.
@Ignore
@Test
public void defaultMethods2() throws Exception {
String t = "basic.DefaultMethodsI2A";
String t2 = "basic.DefaultMethodsC2A";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
byte[] ia = loadBytesForClass(t);
ReloadableType rtypeI = typeRegistry.addType(t, ia);
byte[] ca = loadBytesForClass(t2);
ReloadableType rtypeC = typeRegistry.addType(t2, ca);
Class<?> simpleClass = rtypeC.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
// byte[] renamed = retrieveRename(t, t + "2");
rtypeI.loadNewVersion("002", ia);
// ClassPrinter.print(rtypeI.getBytesLoaded());
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2");
rtypeI.loadNewVersion(renamed);
renamed = retrieveRename(t2, t2 + "2", t + "2:" + t);
rtypeC.loadNewVersion(renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
assertEquals("FOO", r.stdout);
}
@Test
public void multipleLambdasInOneMethod() throws Exception {
String t = "basic.LambdaH";

View File

@@ -0,0 +1,10 @@
package basic;
public class DefaultMethodsC1A implements DefaultMethodsI1A {
public static int run() {
DefaultMethodsC1A instance = new DefaultMethodsC1A();
instance.test();
return 42;
}
}

View File

@@ -0,0 +1,9 @@
package basic;
public class DefaultMethodsC2A implements DefaultMethodsI2A {
public static int run() {
DefaultMethodsC2A instance = new DefaultMethodsC2A();
return 42;
}
}

View File

@@ -0,0 +1,10 @@
package basic;
public class DefaultMethodsC2A2 implements DefaultMethodsI2A2 {
public static int run() {
DefaultMethodsC2A2 instance = new DefaultMethodsC2A2();
instance.test();
return 43;
}
}

View File

@@ -0,0 +1,5 @@
package basic;
public interface DefaultMethodsI1A {
public default void test() {}
}

View File

@@ -0,0 +1,5 @@
package basic;
public interface DefaultMethodsI1A2 {
public default void test() {System.out.println("FOO");}
}

View File

@@ -0,0 +1,4 @@
package basic;
public interface DefaultMethodsI2A {
}

View File

@@ -0,0 +1,7 @@
package basic;
public interface DefaultMethodsI2A2 {
public default void test() {
System.out.println("FOO");
}
}