12. NoEscape
class Cursor {
String icon;
int x;
public void create() {
Cursor c = new Cursor(); //HEAP
c.icon = null; //HEAP
c.x = 0; //HEAP
}
}
13. NoEscape → scalar replacement
class Cursor {
String icon;
int x;
public void create() {
String icon = null; //ref on stack frame
int x = 0; //int on stack frame
}
}
23. -XX:-OptimizeStringConcat
String twenty = «12345678901234567890»;
String sb = new StringBuilder()
.append(twenty).append(twenty)
.append(twenty).append(twenty).toString();
new char[16];
new char[34];
new char[70];
new char[142];
24. -XX:+OptimizeStringConcat
String twenty = «12345678901234567890»;
String sb = new StringBuilder()
.append(twenty).append(twenty)
.append(twenty).append(twenty).toString();
new char[80];
25. -XX:+OptimizeStringConcat
String twenty = «12345678901234567890»;
StringBuilder sb1 = new StringBuilder();
sb1.append(new StringBuilder()
.append(twenty).append(twenty)
.append(twenty).append(twenty)
);
new char[80];