Java-Level JVM Compiler Interface • JEP 248: Make G1 the Default Garbage Collector • JEP 254: Compact Strings • JEP 280: Indify String Concatenation • JEP 269: Convenience Factory Methods for Collections • JEP 259: Stack-Walking API • New APIs
a compiler written in Java to be used by the JVM as a dynamic compiler. Goals • Allow a Java component programmed against the JVMCI to be loaded at runtime and used by the JVM’s compile broker. • Allow a Java component programmed against the JVMCI to be loaded at runtime and used by trusted Java code to install machine code in the JVM that can be called via a Java reference to the installed code.
class StringLayout { public static void main(String[] args) { String value = "Lorem ipsum ... est laborum."; out.println(VM.current().details()); out.println(ClassLayout.parseClass(String.class).toPrintable()); out.println(GraphLayout.parseInstance(value).toFootprint()); } }
12 (object header) 12 4 char[] String.value 16 4 int String.hash 20 4 (loss due to the next object alignment) Instance size: 24 bytes Space losses: 0 bytes internal + 4 bytes external = 4 bytes total Total size in bytes: 936
char[] data = new char[Integer.MAX_VALUE - 2]; data[0] = '\uD83D'; data[1] = '\uDC7B'; String value = new String(data); System.out.println(value.hashCode()); } } Exception in thread "main" java.lang.OutOfMemoryError: UTF16 String size is 2147483645, should be less than 1073741823 at java.base/java.lang.StringUTF16.newBytesFor(StringUTF16.java:46) at java.base/java.lang.StringUTF16.toBytes(StringUTF16.java:148) at java.base/java.lang.String.<init>(String.java:3023) at java.base/java.lang.String.<init>(String.java:249) at com.vyazelenko.perf.string.StringMaxSize.main(StringMaxSize.java:9)
result = ""; for (int i = 0; i < iterations; i++) { result += (i + " " + log() + "\n"); } return result; } @Benchmark public String proper() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < iterations; i++) { sb.append(i).append(" ").append(log()).append("\n"); } return sb.toString(); } }
List.of() List.of() Collections.emptyList() List.of(1) Collections.singletonList(1) List.of(1,2) new ArrayList(1,2) new LinkedList(1,2) List.of(1..10) new ArrayList(1..10) new LinkedList(1..10) Footprint in bytes
List.of() vs Collections.unmodifiableList() List.of() Collections.emptyList() List.of(1) Collections.singletonList(1) List.of(1,2) new ArrayList(1,2) new LinkedList(1,2) List.of(1..10) new ArrayList(1..10) new LinkedList(1..10) Footprint in bytes
808 656 Set.of() vs Collections.unmodifiableSet() Set.of() Collections.emptySet() Set.of(1) Collections.singleton(1) Set.of(1,2) new HashSet(1,2) new LinkedHashSet(1,2) new TreeSet(1,2) Set.of(1..10) new HashSet(1..10) new LinkedHashSet(1..10) new TreeSet(1..10) Footprint in bytes
help with footprint and startup performance • Compact Strings and optimized String concat make a huge difference • New APIs that improve performance of different tasks (StackWalker, Arrays.mismatch(), etc.)