Java 9 新特性

Cartel

2017/10/18 发布于 技术 分类

Java 9 新特性

QCon  QCon2017 

文字内容
6. What is cool in Java 8 and new in 9 Felix Yang Java Java Platform, Oracle Leader Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
7. Oracle Oracle Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
8. – Principal Member of Technical Staff, OpenJDK Committer, Oracle Java – Java Java – IBM – Java Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
9. : OpenJDK 9 API 1 2 3 4 JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
10. Java 9 API 1 2 3 4 JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11. Project Jigsaw Java • JEP 261: Module System • JEP 200: The Modular JDK • JEP 201: Modular Source Code • JEP 220: Modular Run-Time Images • Plus – JEP 260: Encapsulate Most Internal APIs – JEP 282: jlink: The Java Linker Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12. JEP 269: Convenience Factory Methods for Collections core-libs / java.util:collections Set set = new HashSet<>(); set.add("a"); set.add("b"); set.add("c"); set = Collections.unmodifiableSet(set); // Set alphabet = Set.of("a", "b", "c"); Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
13. JEP 102: Process API Updates core-libs / java.lang • API ProcessHandle current = ProcessHandle.current(); current.info() .totalCpuDuration() .ifPresent(d -> System.out.println("Total cpu duration :" + d)); current.children() .forEach(p -> System.out.println("Pid:" + p.getPid())); Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
14. JEP 259: Stack-Walking API core-libs API • – filtering – Lazy access stack traces – API VM stack stack snapshot caller class • – exception stack trace // Stack-Walking API new – StackWalker().walk( SecurityManager. getClassContext() (s) ->s.map(StackFrame::declaringClass).skip(2).findFirst()); – API Reflection.getCallerClass() Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
15. JEP 193: Variable Handles core-libs / java.lang API • – java.util.concurrent.atomic sun.misc.Unsafe fence operations • – • object fields, array elements sun.misc.Unsafe reachability fence operation Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
16. JEP 266: Java ( Concurrency)API core-libs / java.util.concurrent API • Reactive Stream – Flow API (Publisher, Subscriber, Processor) – Stream – – Memory-efficient CompletableFuture API • – – time-based executor Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
17. JEP 222: jshell: The Java Shell (Read-Eval-Print Loop -REPL) tools / jshell Java • • command-line jdk-9\bin\jshell : Jshell>/help jshell> ProcessHandle ph = ProcessHandle.current(); jshell> ph.getPid(); jshell> ph.info().command(); Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
18. JEP 238: Multi-Release JAR Files tools / jar • • JAR class JDK Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
19. JEP 247: Compile for Older Platform Versions tools / javac • Javac --release N • • Javac -source N -target N -bootclasspath rtN.jar • Javac – – API API Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
20. Java 9 API 1 2 3 4 JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
21. Java • JEP 219: Datagram Transport Layer Security (DTLS) • JEP 229: keystore JKS PKCS12 • JEP 244: TLS Application-Layer Protocol Negotiation(ALPN) Extension HTTP/2 – • JEP 249: • JEP 273: – OCSP Stapling for TLS DRBG SecureRandom Deterministic Random Bit Generator (DRBG) NIST 800-90Ar1 • JEP 287: SHA-3 Hash Algorithms Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
22. JEP 110: HTTP/2 Client core-libs / java.net HTTP client API • – – HTTP/2 WebSocket HttpURLConnection API • – – • HttpClient client = HttpClient.newBuilder() Reactive style incubator .sslContext(sslContext) .version(HTTP_2) .build(); HttpRequest req = HttpRequest.newBuilder(uri) .POST() .build(); client.sendAsync(req, abodyhandler) .thenApply(…); Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
23. core-libs / java.lang • Java SE 9 – JEP 227: Unicode 7.0 – JEP 267: Unicode 8.0 • JEP 226: UTF-8 Property Files – – ISO-8859-1 ResourceBundle API UTF-8 Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
24. Java 9 API 1 2 3 4 JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
25. JEP 254: Compact Strings core-libs / java.lang • String – • • String API byte[] char[] (16 bits) Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
26. JEP 280: Indify String Concatenation tools / javac Javac • StringBuilder – – StringBuilder – invokedynamic • – – JDK . java.lang.invoke.StringConcatFactory , JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved. .
27. • JEP 232: – security manager – Java 9 • JEP 246: 10-15% CPU GHASH and RSA SPARC and Intel x64 CPU – – • JDK 8 AES 8 Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
28. JEP 143: Contended Locking hotspot / runtime high-contended • – – • Java Object Monitor Java monitor enter, exit, notify/notifyAll internal VM monitors/mutex, Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
29. JEP 285: Spin-Wait Hints core-libs / java.lang • Thread.onSpinWait() • Hint JVM it is in a spin loop (busy locking), no semantic behaviour requirements • x86 CPU pause spin wait Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
30. Java 9 API 1 2 3 4 JVM Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
31. JEP 295: Ahead-of-Time Compilation hotspot / compiler (library-like mechanism) • : jaotc • • : – Compile: jaotc --output libHelloWorld.so HelloWorld.class – Run: java -XX:AOTLibrary=./libHelloWorld.so HelloWorld Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
32. JEP 248: G1 hotspot / gc G1 • server Parallel GC • • G1 – – – : SLAs CMS ( Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
33. JVM GC hotspot / gc • JEP 214: GC Incremental CMS (iCMS) • JEP 291: Deprecate CMS Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
34. JEP 158/ JEP 271: JVM/GC hotspot / gc, svc • JVM jvm • • “-Xlog:gc” ”-XX:PrintGC” Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
35. JEP 165: Compiler Control hotspot / compiler • JVM (JIT) JVM • (C1 and C2) • – Directive file – jcmd • -XX:CompilerDirectivesFile= JIT Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
36. JEP 250: Store Interned Strings in CDS Archives hotspot / runtime JVM • – – CDS G1 • pinned region – • G1 pinning 64-bit Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
37. hotspot/compiler • JEP 197: Segmented Code Cache – code cache segments • JEP 243: Java-Level JVM Compiler Interface – – Java based JVM compiler interface (JVMCI) JVM Graal Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Java
38. Q&A Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 34