This talk presents a number of conceptual and technical challenges that we discovered while building JRebel. At first, the JVM wasn't designed for live updates, so we will talk about the engine that mitigates the problem. Secondly, the diversity of Java ecosystem, created by the variety of application servers, the frameworks and tools, makes it challenging in creating a generic solution that would fit the majority of developers. We will see, how Java platform itself allows us to develop a solution by applying bytecode instrumentation mechanism.
JRebel does live code reloading to ensure that the developer can keep instantly alternating between the developing environment and the web browser, to save wasted time and increase the productivity flow.
26. public class C extends X {
int y = 5;
int method1(int x) {
return x + y;
}
void method2(String s) {
System.out.println(s);
}
}
27. public class C extends X {
int y = 5;
int method1(int x) {
Object[] o = new Object[1];
o[0] = x;
return Runtime.redirect(this, o, "C", "method1", "(I)I");
}
void method2(String s) {
Object[] o = new Object[1];
o[0] = s;
return Runtime.redirect(
this, o, "C", "method2", "(Ljava/lang/String;)V");
}
}
28. public abstract class C0 {
public static int method1(C c, int x) {
int tmp1 = Runtime.getFieldValue(c, "C", "y", "I");
return x + tmp1;
}
public static void method2(C c, String s) {
PrintStream tmp1 = Runtime.getFieldValue(
null, "java/lang/System", "out", "Ljava/io/PrintStream;");
Object[] o = new Object[1];
o[0] = s;
Runtime.redirect(
tmp1, o, "java/io/PrintStream;", "println",
"(Ljava/lang/String;)V");
}
}
29. public class C extends X {
int y = 5;
int method1(int x) {
return x + y;
}
//...
}
public class C extends X {
int y = 5;
int z() {
return 10;
}
int method1(int x) {
return x + y + z();
}
//...
}
30. public class C1 {
public static int z(C c) {
return 10;
}
public static int method1(C c, int x) {
int tmp1 = Runtime.getFieldValue(c, "C", "y", "I");
int tmp2 = Runtime.redirect(c, null, "C", "z", "(V)I");
return x + tmp1 + tmp2;
}
//...
}
34. static { }
Adding new static fields
Removing static fields
Changing values of static fields
Factories
etc
35. package a;
public class A {
int say() {return 1;}
}
package a;
class Test {
public static void main(String args[]) {
a.A a = new b.B();
System.out.println(a.say());
}
}
package b;
public class B extends a.A {
int say() {return 2;}
}
An Exercise
50. http://zeroturnaround.com/company/case-studies/
“Team velocity was increased by
40.6%, and according to t-test it
was a statistically significant
difference.”
“Netty and Spring together with
JRebel is real pleasure to work
with. The value of time saved is
over 50% of my development
time.”