Getting ready for java 9
About me
@arnaudroger
https://arnaudroger.github.io/blog/
http://simpleflatmapper.org/
https://github.com/arnaudroger/NoopFactory
About me
What do I know about java 9?
- SimpleFlatMapper modularized since August 2016
- wrote one article for site point
- spend too much time following java 9 devs
Java 9
- early-access available
- http://jdk.java.net/9/
- Still suggested to changes
- last proposed change was on 5th of June
- impact mainly integration of old jar as a module
- apart from Jigsaw very stable
@arnaudroger https://arnaudroger.github.io/blog/
Java 8 EOL
see Oracle Java SE Support Roadmap
- Three years after the general availability date (GA) of a major release
- One year after the GA of a subsequent major release
- Six months after a subsequent major release has been established as the default Java Runtime Environment (JRE) for end-user desktops on java.com
@arnaudroger https://arnaudroger.github.io/blog/
@arnaudroger https://arnaudroger.github.io/blog/
@arnaudroger https://arnaudroger.github.io/blog/
Why the delay?
- Blame Jigsaw JEP 200*
- JSR 277 Early draft review was 11 Oct, 2006 targeting JDK 7
* JEP : JDK Enhancement Proposal
@arnaudroger https://arnaudroger.github.io/blog/
Let's talk about JPMS aka Jigsaw
Why? Why? Why?
What is all that module system about?
Why did it take more than 11 years to do?
@arnaudroger https://arnaudroger.github.io/blog/
Jigsaw why?
- Security
- enforce encapsulation
- 3 out of 5 zero-day since jdk7 would have been prevented
- Scalability
- jlink distribute only necessary module
- Compile time, startup time dependency check
@arnaudroger https://arnaudroger.github.io/blog/
What's a module
It's mostly a jar
with a module-info.class
- required modules
- visible packages
- services exported
- services used
But no version information.
Only a module if on the module path.
module simpleflatmapper.converter { requires simpleflatmapper.util; exports org.simpleflatmapper.converter; uses org.simpleflatmapper.converter.ConverterFactoryProducer; }
@arnaudroger https://arnaudroger.github.io/blog/
What's a module
- Reflection restriction
- setAccessible on private field
- unless module is open
- can --add-open on command line
-
Does not apply to classpath code
-
recent change, was dissallowed before
-
--illegal-access=permit is the default
-
-> old code breaking encapsulation will work,
for now. but security is compromised...
run with --illegal-access=deny if you can.
@arnaudroger https://arnaudroger.github.io/blog/
Why did it take so long?
- Java SE code was ugly... non sense dependency chain
- loads of rework to end up with :
@arnaudroger https://arnaudroger.github.io/blog/
Why is still being delayed
- Migration concern
- automatic module name
- reflection access for non module
- Meta module concern
- no version
- no cyclic dependencies
- no access to internal module api
@arnaudroger https://arnaudroger.github.io/blog/
What to be concerned about
- do you use jvm internal api sun.*
- sun.misc.BASE64Decoder
- you can find out with jdep
The following are still accessible
-
sun.misc.{Signal,SignalHandler}
-
sun.misc.Unsafe
-
sun.reflect.Reflection::getCallerClass(int)
-
sun.reflect.ReflectionFactory.newConstructorForSerialization
Same applies to your dependency.
Other impactful changes
- G1 becomes the default GC
- different latency
- different tuning strategies
- String compaction
- lower memory footprint
- might incur higher cpu
@arnaudroger https://arnaudroger.github.io/blog/
Is Java9 just about pain?
91 JEPs
@arnaudroger https://arnaudroger.github.io/blog/
Compact String
- NO API CHANGE
- stored as byte[]
- encoded as LATIN-1 or UTF-16
- better jit/intrinsic to mitigate cost
- some operation faster/some slower
- disable latin-1 compression using -XX:-CompactStrings
@arnaudroger https://arnaudroger.github.io/blog/
@arnaudroger https://arnaudroger.github.io/blog/
@arnaudroger https://arnaudroger.github.io/blog/
Spin-Wait Hint
- Smallest JEP ever
- java.lang.Thread.onSpinWait()
- transformed into a PAUSE instruction on x86
- useful for busy spin
@arnaudroger https://arnaudroger.github.io/blog/
Stack-Walking API
- Faster than new Throwable()
- Cost proportional to amount traversed
- Access to getCallerClass
- new Throwable() can be faster if
- full traversal
- access to debug info - line number.
more details https://www.sitepoint.com/deep-dive-into-java-9s-stack-walking-api/
@arnaudroger https://arnaudroger.github.io/blog/
Variable Handles
- Partial safe unsafe replacement
- No memory address
- on fields and array elements
- memory fences
-
Reachability fence
- CAS
@arnaudroger https://arnaudroger.github.io/blog/
@arnaudroger https://arnaudroger.github.io/blog/
Java next
- use release train
ship what's ready at a specified date
- Interesting work
- Valhalla, value types
- Panama, native code interaction
- Intel vectorization API!!!
-
Shenandoah, ultra-low pause time garbage collector
-
Graal, JIT compiler, potential C2 replacement
@arnaudroger https://arnaudroger.github.io/blog/
Questions?
@arnaudroger https://arnaudroger.github.io/blog/
nidevconf-java9
By Arnaud Roger
nidevconf-java9
- 733