till scheduled release • Now is a good time to plan and prep for it • I am from Azul Systems - maker of compliant JDKs • Observing the process from aside, unbiased view on changes • All sources for this talk are public 2
2016 13:33:06 -0500 From: David M. Lloyd <[email protected]> To: jigsaw-dev <[email protected]> Tools like Maven and JUnit are yet still having a difficult time coping with the oddball module-info.java file. Can we just drop this thing and let the layer provide metadata for the module? This way of defining module metadata is clearly causing trouble. Reference: all previous arguments from non-Oracle people over the last 5 years or so. So far none of our software actually functions with Jigsaw, and the prospect is not improving. In the meantime the EG is alternately completely dead or in a state of we'll-register-your-issue-but-cannot-help-resolve-them mode. I'm highly concerned. Concerns
bigger • Java 8 profiles 1, 2, 3 provide partial solutions • Jar / Classpath Hell • What depends on what .. • Optional dependancies, transitive dependancies • Lazy class loading and initialisation -> NoClassDefFoundError • For code that escapes packages the visibility mechanism is poor - only public • Classes from different packages “see” each other, even from different class loaders • SecurityManager helps to protect, but it is not on by default 16
JDK JEP 220: Modular Run-Time Images JEP 201: Modular Source Code JEP 260: Encapsulate Most Internal APIs JEP 282: jlink: The Java Linker JSR 376: Java Platform Module System JEP 261: Module System Modularity Java Module 17
classpath - going into unnamed modules • Unnamed modules can access all named modules (requires *) /See next slide for a special note/ • The reverse isn’t true - must specify requires unnamed or … • jar file in -mp is being automatically converted to a module with a name matching the name of the jar file • Therefore referred as automodules • Provide transition path to jigsaw modules design • Unnamed modules are being searched for types as a last option 22
true since JDK9 build 118 • These modules are not accessible from unnamed modules: java.activation - java.annotations.common - java.corba java.transaction - java.xml.bind - java.xml.ws • One can still add visibility with a flag like `-addmods java.corba` • Source: May 17th letter from Alan Bateman: http://mail.openjdk.java.net/ pipermail/jdk9-dev/2016-May/004309.html • More info: http://openjdk.java.net/jeps/261 23
might require a different version of a module than loaded before • The extension might require service providers • Layer of modules encapsulates • a module graph • mapping from each module in that graph to a class loader • Boot layer - created by VM at start time and suitable for most apps • App can create a new layer - new universe of modules • Stackable - package resolution starts with the app layer and goes down to the boot layer Layers
jar (Since b109. Bug 8132734) • Packages with the same name possibly leading to NoClassDefFoundException • Layers - new concept for classloaders • New instruments for modules development • <java9_jigsaw>/bin/jdeps -help • IDE are now supporting modules • Classloaders and ways for circular dependancies between modules
listing of dependancies • OSGi compatible and complementary • Will provide new optimisation paths • Compatible with jar/cp • Jigsaw - rough flight all way along, loosing features • Lost ability to match versions 32
all posts before 2014, probably even before 2015 too • State of Jigsaw (March 8 2015) • http://openjdk.java.net/projects/jigsaw/spec/sotms/ • JavaOne 2015 (also Devoxx BE) • http://openjdk.java.net/projects/jigsaw/j1/ • Code was integrated in JDK9 EA build 111 • See also: http://blog.codefx.org/java/dev/features-project-jigsaw-java-9/ • http://blog.codefx.org/java/dev/javaone-2015-under-the-hood-of-project-jigsaw/ 33
String>() { { map.put("key", "value"); } }; } • Using diamond with anonymous classes when actual type may be deduced public class TypeInferrenceTest { Map<String, String> map = new HashMap<> () { { map.put("key", "value"); } }; } Syntax changes - Milling Project Coin 37 Prior to Java 9 ./TypeInferrenceTest.java:7: error: cannot infer type arguments for HashMap<K,V> new HashMap<>() ^ reason: cannot use '<>' with anonymous inner classes where K,V are type-variables: K extends Object declared in class HashMap V extends Object declared in class HashMap 1 error http://c2.com/cgi/wiki?DoubleBraceInitialization
New: • Get pid for this JVM • Get list of processes • Operations on trees of processes Source: http://blog.takipi.com/java-9-the-ultimate-feature-list/ Process proc = Runtime.getRuntime() .exec(new String[]{"/bin/sh", "-c", "echo $PPID"}); if (proc.waitFor() == 0) { InputStream in = proc.getInputStream(); int available = in.available(); byte[] outputBytes = new byte[available]; n.read(outputBytes); String pid = new String(outputBytes); System.out.println("Your pid is " + pid); } System.out.println("Your pid is " + ProcessHandle.current().getPid()); 39
Features: • New method j.l.Thread.onSpinWait() • On x86 - translates into the ‘pause’ instruction • Already used 9 times in JSR 166 for JDK9 • java/util/concurrent/locks/StampedLock.java • java/util/concurrent/Phaser.java • java/util/concurrent/SynchronousQueue.java class EventHandler { volatile boolean eventNotificationNotReceived; void waitForEventAndHandleIt() { while ( eventNotificationNotReceived ) { java.lang.Thread.onSpinWait(); } readAndProcessEvent(); } void readAndProcessEvent() { // Read event from some source and process it . . . } } 40
for 9? • May be not • Just include the agrona library • or look at java/org/agrona/hints/ThreadHints.java • Works for older JDKs 42 https://github.com/real-logic/Agrona/blob/master/src/main/java/org/agrona/hints/ThreadHints.java
JDK 9 EA build 90 • REPL as you know it for other languages • Helps teaching Java class HelloWorld { public static void main(String[] args) { System.out.println("*GNNQ9QTNF"); } } 43
GC in HotSpot (albeit being 10+ years old) • Regional parallel concurrent collector • Targeting both low pause and high throughput • Default => Great number of users => Bugs detecter sooner => G1 will become even more robust shortly • Cons • Due to different characteristics it may reveal synchronisation problems in the code • Eve after 9 years G1 has bugs with Cassandra, Elasticsearch, Lucene, perhaps, other ones are yet not discovered? • source (dated July 2015): https://groups.google.com/forum/#!topic/mechanical-sympathy/ JxsuVtIIOaY 45
no i.e. default GC settings • capture the ergonomics at your deployment sites • consider explicitly setting GC flags in all deployment scripts • If you already had selected and tuned GC flags • No changes, old collectors not phasing out • In any case - keep trying G1 • Understand how GC works • Basic algorithms and associated metrics • More reading: http://www.infoq.com/minibooks/java-garbage-collection 46
JRE Version Selection • 240: Remove the JVM TI hprof Agent • 241: Remove the jhat Tool ——————————— • Because of modules (JEP - 261) • -Xbootclasspath & -Xbootclasspath/p • system property sun.boot.class.path 50
263: HiDPI Graphics on Windows and Linux • 265: Marlin Graphics Renderer • 262: TIFF Image I/O • 257: Update JavaFX/Media to Newer Version of GStreamer (1.4.4) • 251: Multi-Resolution Images 51
• Azul’s innovative Java runtime for business applications • Certified Java SE builds • Removes GC as a factor in your operation • Supports large in-memory data stores • Solves Java’s “warm-up” problem • Runs on distros of RHEL, Ubuntu, SLES and CentOS •Zulu: Java when all you need is Support • Free and Open Source (based on OpenJDK) • Certified Java SE builds • Runs on Windows, Linux & Mac • Performance parity with Oracle Hotspot • Optional customized “embedded” offerings 53