<<

20 years of

Vladimir Ivanov HotSpot JVM Compile r Twitter: @iwan0www Oracle Corp. OpenJDK: vlivanov

1 28.11.2015 Copyright © 2015, Oracle and/or its affiliates. All rights reserved

20 years of Java (The Platform)

Vladimir Ivanov HotSpot JVM Compile r Twitter: @iwan0www Oracle Corp. OpenJDK: vlivanov

2 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Safe Harbor Statement

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved About me

Joined (SPBDC) to work JDK 1.0 on HotSpot JVM Now 1996 2002 2005 2010 2015 Wrote my first Became part of program in Java. Oracle Corp. after acquisition

4 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1991: Project Green

5 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1991: *7 (StarSeven) Oak

6 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1991: *7 (StarSeven) Duke

7 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1994: WebRunner/HotJava browser

8 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1995: First release: 1.0a2

9 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Intel Pentium P54CS, 0.35µm, 200MHz, 66MHz FSB

10 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 10000 64 UltraSPARC II CPUs, 400 MHz, 16x4GB RAM

11 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1996: JDK 1.0 January, 23

§ 6 packages § # of classes – java. – java/ 225 – java.awt – sun/ 379 – java.io – java.lang – java.net – java.util

12 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1996: picoJava

13 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1997: JDK 1.1 February, 19

14 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1998: J2SE 1.2 December, 8

15 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1999: J2SE, J2ME, J2EE

16 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1999: J2SE, J2ME, J2EE

17 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2000: J2SE 1.3 May, 8

18 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 1998: JCP

19 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2002 February, 6

20 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Java Releases

Inner classes JavaBeans HotSpot JVM JDBC JNDI RMI Java Sound Reflection JVMDI JNI JVMPI

First release JDK 1.1 January, 23 December, 8 J2SE 1.3 February, 6 1995 1996 1997 1998 2000 2002 March February, 19 May, 8 JDK 1.0 J2SE 1.2 J2SE 1.4 AWT Regular Expressions JIT compiler Network IPv6 support Java Plug-in I/O Logging Collections XML, XSLT

21 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2004: J2SE 5.0 September, 30

22 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2004: J2SE 5.0 September, 30

23 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2006: Java SE 6 December, 11

§ Scripting Language Support (JSR 223) § Java Compiler API (JSR 199) § Support for pluggable annotations (JSR 269) § Numerous performance improvements – C1: new linear register allocator – C1: IR in SSA form

24 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Java SE 6u HotSpot Express

§ Escape analysis in C2 – 6u23 § NUMA GC Enhancements – Java SE 6u2 § Compressed OOPs – 6u23 § Tiered compilation

25 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2007 May, 8

26 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2007: May JavaFX 1.0 on December, 2008

27 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 28 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2010

29 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2011: Java SE 7 July, 28

§ JVM support for dynamic languages (JSR 292) § Small language changes – e.g. strings in switch, try-with-resources § New file I/O library (defined by JSR 203)

30 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2014: Java SE 8 March, 18

§ JSR 335: Language-level support for lambda expressions

§ JSR 223: Project Nashorn, a JavaScript runtime § JSR 308: Annotation on Java Types § JSR 310: Date and Time API

§ JEP 122: Remove the permanent generation

31 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2014: Java SE 8 March, 18

32 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 2016: Java SE 9 ETA: September, 22

Scalability Performance Project Jigsaw Security

http://openjdk.java.net

33 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Scalability

34 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Java 8 tools JDK tools.jaxws tools.base JRE corba devtools tools.jre crypto compact3 jaxws compiler rowset compact2 xmldsig desktop rmi naming jaxp jdbc httpserver auth sctp compact1 prefs jx.annotations instrument 54MB 30 16 11 nashorn

35 4 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Performance

rmic xml.ws hotspot.agent

javadoc xml.bind jconsole jcmd jdi smartcardio crypto.ec compiler se aach crypto.pkcs11 xml.ws hpserver compact3 jvmstat hprof.agent jdwp.agent xml.soap corba instrument sql.rowset naming.rmi localedata xml.bind security.acl naming naming sctp compact2 acvaon compiler management zipfs sql security.auth desktop prefs compact1 rmi security.jgss scripting. annotaons.common xml.crypto xml logging scripng security.sasl nashorn

base charsets

36 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw

tools

tools.jaxws tools.base cosnaming management.iiop corba devtools tools.jre crypto management kerberos jaxws compiler rowset jta xmldsig desktop rmi

javafx naming jaxp jdbc logging httpserver tls auth 4 Copyright © 2014, Oracle and/or its affiliates.sctp All rights reserved. prefs jx.annotations instrument base

script nashorn

37 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw

tools

tools.jaxws tools.base cosnaming management.iiop corba devtools tools.jre crypto management kerberos jaxws compiler rowset jta xmldsig desktop rmi

javafx naming jaxp jdbc logging httpserver tls auth 4 Copyright © 2014, Oracle and/or its affiliates.sctp All rights reserved. prefs jx.annotations instrument base

script nashorn

38 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw

tools

tools.jaxws tools.base cosnaming management.iiop corba devtools tools.jre crypto management kerberos jaxws compiler rowset jta xmldsig desktop rmi

javafx naming jaxp jdbc logging httpserver tls auth 4 Copyright © 2014, Oracle and/or its affiliates.sctp All rights reserved. prefs jx.annotations instrument base

script nashorn

39 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw

crypto

javafx

4 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. base

script nashorn

40 Copyright © 2015, Oracle and/or its affiliates. All rights reserved .jmod *.class . *.jar $JRE/bin/java *.jmod jlink /lib/...

JVM image

Fat binary

419 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

rt.jar

crypto nashorn.jar, jfxrt.jar, sunjce_provider.jar javafx base script nashorn myapp.jar

42 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn

43 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn

44 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn § Aggressive inlining

45 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn § Aggressive inlining § Ahead-Of-Time compilation

46 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn § Aggressive inlining § Ahead-Of-Time compilation § JVM-specific memory images – e.g. Application Class Data Sharing (AppCDS)

47 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Opportunities for performance improvements

crypto

§ Improved class loading architecture javafx – fast class lookup base script nashorn § Aggressive inlining § Ahead-Of-Time compilation § JVM-specific memory images – e.g. Application Class Data Sharing (AppCDS) § Removal of unused fields/methods/classes

48 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Security

sun.* *.internal.*

4917 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw Security

sun.misc.Unsafe?!

5017 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw & sun.misc.Unsafe

- How many of you have used the Unsafe API? …

John Rose JVM Architect, @ JVM Language Summit 2014

51 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Jigsaw & sun.misc.Unsafe

- How many of you have used the Unsafe API? … - A lot of you. Gosh, I'm sorry.

John Rose JVM Architect, Oracle Corporation @ JVM Language Summit 2014

52 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 53 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JEP 260: Encapsulate Most Internal APIs

§ Replacement exists in JDK 8 – Encapsulate/remove the method in JDK 9

§ Replacement exists in JDK 9 – Deprecate in JDK9

§ No replacement exists in JDK 9 – (For widely used internal API) Leave accessible

54 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Critical Internal APIs

§ sun.misc.Cleaner § sun.misc.{Signal,SignalHandler} § sun.misc.Unsafe § sun.reflect.Reflection::getCallerClass § sun.reflect.ReflectionFactory

55 Copyright © 2015, Oracle and/or its affiliates. All rights reserved sun.misc.Unsafe

Use case Example methods

Concurrency primitives Unsafe.compareAndSwap*

Unsafe.allocateInstance Serialization (ReflectionFactory.newConstructorForSerialization)

Unsafe.allocate/freeMemory Efficient memory management, Unsafe.get*/put* (and JNI) layout, and access

Interoperate across the JVM Unsafe.get*/put* (and JNI) boundary

56 Copyright © 2015, Oracle and/or its affiliates. All rights reserved sun.misc.Unsafe

Use case Replacement

Concurrency primitives JEP 193 Variable Handles

Reboot JEP 187 Serialization Serialization Improvements

Efficient memory management, Project Panama, Project Valhalla, layout, and access Arrays 2.0, Better GC

Interoperate across the JVM Project Panama, boundary JEP 191 Foreign Function Interface

57 Copyright © 2015, Oracle and/or its affiliates. All rights reserved sun.misc.Unsafe (JDK 9)

Use case Replacement

Concurrency primitives JEP 193 Variable Handles

Reboot JEP 187 Serialization Serialization Improvements

Efficient memory management, Project Panama, Project Valhalla, layout, and access Arrays 2.0, Better GC

Interoperate across the JVM Project Panama, boundary JEP 191 Foreign Function Interface

58 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 59 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JEP 193: Variable Handles

1. Safe, performant, enhanced atomics – access to field and array elements

2. Fence operations for fine-grained control of memory ordering – replacements for Unsafe::{full,store,load}Fence and more

3. Reachability fence – java.lang.ref.Reference::reachabilityFence

60 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Java 7: Method Handles

“The most fundamental change to Java since its inception.”

Charles Oliver Nutter JRuby Lead Developer

61 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Method Handles

62 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (1) Variable Handles

§ like method handles for data – Abstracts over location § static fields, instance fields, arrays, off heap – Supports explicit fences and atomic operations

§ Safer than Unsafe, as fast as method handles

63 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Are sun.misc.Unsafe methods really fast?

§ Not necessarily… – public native Object allocateInstance(Class cls) throws …;

– Array index vs raw offset long[] base = new long[…]; int idx = …; long offset = (((long) idx) << SCALE + OFFSET) long value = Unsafe.getLong(base, offset);

– JDK-8078629: “VM should constant fold Unsafe.get*() loads from final fields”

64 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (1) Variable Handles

65 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (2) Memory Fences

Thread #1 Thread #2

a = ?, b = ?

66 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (2) Memory Fences

Thread #1 Thread #2

[a,b] = [0,0], [0,1], [1,0], [1,1]

67 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (2) Memory Fences

Thread #1 Thread #2

[a,b] = [0,0], [0,1], [1,0], [1,1]

68 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (3) Finalization

69 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (3) Premature Finalization

70 Copyright © 2015, Oracle and/or its affiliates. All rights reserved (3) Premature Finalization

71 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Beyond Java 9

72 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Specialized Generics Project Valhalla Value Types

Foreign Function Interface Project Panama Data Layout Control Arrays 2.0

http://openjdk.java.net

73 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Valhalla “The hall of valor value”

74 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value-based Class @since 8

final class Point { “Use of identity-sensitive operations public final int x; on instances of value-based classes public final int y; may have unpredictable effects and should be avoided.” } ValueBased javadoc

75 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value-based Class Arrays

Point[] points = headerh

x y x y x y x y x y x y

76 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value-based Class Arrays

Point[] points = headerh

x y x y x y for (Point p : points) { x y sum += p.x + p.y; x y } x y

77 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value-based Class Arrays

int[] xPoints = headerh x x x x x x

int[] yPoints = headerh y y y y y y

assert(xPoints.length == yPoints.length);

for (int i = 0; i < xPoints.length; i++) { sum += xPoint[i] + yPoint[i]; }

78 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value-based Class Arrays

int[] points = headerh x y x y x y x y x y x y

assert(points.length % 2 == 0);

for (int i = 0; i < points.length; i+=2) { sum += points[i] + points[i+1]; }

79 Copyright © 2015, Oracle and/or its affiliates. All rights reserved “Codes like a class, works like an int!”

John Rose, Brian Goetz, Guy Steele

“State of the Values”

80 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value Types Arrays

Point[] points = headerh x y x y x y x y x y x y

value class Point { for (Point p : points) { public final int x; sum += points.x + points.y; } public final int y; }

81 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Motivation Value Types

§ Smaller footprint – no object header § Better locality – no dereference § Simpler semantics – no identity, no aliasing § No object allocation

82 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value Types Concurrent side effects

Rectangle r = value class Point { header y y public final int x; h x x public final int y; } Rectangle r = header h class Rectangle { public final Point corner1; x y public final Point corner2; y } x

83 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Value Types Concurrent side effects

Rectangle r = value class Point { header y y public final int x; h x x public final int y; } Rectangle r = header h class Rectangle { public Point corner1; x y public volatile Point corner2; y } x

84 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Use cases

§ Numerics: complex, decimal, rarely-big-num, etc. § Native types: int128_t, vectors, unsigned, safe native pointers § Algebraic data: optional (no box), choice-of, unit (no bits) § Tuples: multiple-value return! (requires specialization machinery also) § Cursors: unboxed iterators, STL-style bounds § Flat data: values naturally represent pointer-poor data structures

85 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Selected details

Point[] <:? Object[]

86 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Selected details

Point[] points = headerh x y x y x y x y x y x y

Point[] <: Object[]

87 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization Motivation

ArrayList

88 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization Motivation

ArrayList

89 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Objects vs Primitives

§ Object, String, …, MyClass, …, – 8 primitive types (+ reference)

Integer, Long, … § boolean, byte, short, char, int, long, float, double

90 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Objects vs Non-objects

§ Object, String, …, MyClass, …, – 8 primitive types (+ reference)

Integer, Long, … § boolean, byte, short, char, int, long, float, double

– Value types

§ User-defined (!!!)

91 Copyright © 2015, Oracle and/or its affiliates. All rights reserved

Generic Specialization Motivation

ArrayList

92 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box { T val;

public Box(T val) { this.val = val; } public T get() { return val; } }

93 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box { T val;

public Box(T val) { this.val = val; } public T get() { return val; } }

94 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box { Object val;

public Box(Object val) { this.val = val; } public Object get() { return val; } }

95 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box< int> { int val;

public Box(int val) { this.val = val; } public int get() { return val; } }

96 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box { T val;

public Box(T val) { this.val = val; } public T get() { return val; } }

97 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box extends Object { private final Object t;

public Object get() { 0: aload_0 1: getfield #2 //Field t:LObject; 4: areturn } }

98 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box extends Object { private final int t;

public int get() { 0: aload_0 1: getfield #2 //Field t:I; 4: ireturn } }

99 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

class Box extends Object { private final Object*T t;

public Object*T get() { 0: aload_0 1: getfield #2 //Field t:Lobject*T; 4: areturn*T } }

100 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

Box :> Box

101 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

Box :>? Box

102 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Generic Specialization

Box :> Box

Box :> Box Box :> Box Box :> Box

103 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Project Panama “Bridging the gap”

104 Copyright © 2015, Oracle and/or its affiliates. All rights reserved “If non-Java programmers find some library useful and easy to access, it should be similarly accessible to Java programmers.”

John Rose, JVM Architect,

Oracle Corporation

105 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JNI @since 1.1

106 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JNI

A victim of its own success?

107 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JNI Usage scenario

108 Copyright © 2015, Oracle and/or its affiliates. All rights reserved JNI

Java: public class GetPid { public static native long getpid(); }

C/++: get_pid.h: JNIEXPORT jlong JNICALL Java_GetPid_getpid (JNIEnv *, jclass);

get_pid.c: jlong JNICALL Java_GetPidJNI_getpid(JNIEnv *env, jclass c) { return getpid();

109 } Copyright © 2015, Oracle and/or its affiliates. All rights reserved JNI: Method Invocation

Runtime checks before and after native call

1. if (GC_locker::needs_gc()) 1. call native entry point SharedRuntime::block_for_jni_critical() 2. check for safepoint in progress 2. transition to thread_in_native 3. check if any thread suspend flags are set 3. unpack array arguments – call into JVM and possibly unlock the 4. call native entry point JNI critical if a GC was suppressed while in the critical native 4. transition to thread_in_Java 5. return

110 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI

Easier, safer, faster!

111 Copyright © 2015, Oracle and/or its affiliates. All rights reserved sun.misc.Unsafe

§ Anti-JNI

112 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Unsafe.getUnsafe().

putInt(new Object(), 0, 0)

113 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Unsafe.getUnsafe().

putInt(null, 0, 0)

114 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI

Easier, safer, faster!

115 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI

pid_t get_pid();

116 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Easier

public interface GetPid { long getpid(); }

117 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Easier

public interface GetPid { long getpid(); }

GetPid getpid = Library.load(GetPid.class, “c” /* lib_name */ );

118 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Easier

public interface GetPid { long getpid(); }

GetPid getpid = Library.load(GetPid.class, “c” /*lib_name*/ );

getpid.getpid();

119 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Faster

callq 0x1057b2eb0 ; getpid entry

120 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI gettimeofday

/* time.h */

struct { struct { time_t tv_sec; int tz_minuteswest; suseconds_t tv_usec; int tz_dsttime; } timeval; } timezone;

int gettimeofday(struct timeval* tv, struct timezone* tz);

121 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI $ jextract time.h

interface Time {

interface Timeval { interface Timezone { long tv_sec$get(); long tz_...$get(); void tv_sec$set(long); void tz_...$set(long); long tv_usec$get(); long tz_...$get(); void tv_usec$set(long); void tz_...$set(long); } }

int gettimeofday(Timeval, Timezone);

122 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Runtime Library lib = Library.create(“c”);

Time time = lib.create(Time.class);

Timeval tval = lib.create(Timeval.class); Timezone tzone = null;

int res = time.gettimeofday(tval, tzone); if (res == 0) { long tv_sec = tval.tv_sec$get(); long tv_usec = tval.tv_usec$get(); }

123 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Resources Timeval tval; try { tval = lib.create(Timeval.class);

int res = time.gettimeofday(tval, null); if (res == 0) { long tv_sec = tval.tv_sec$get(); long tv_usec = tval.tv_usec$get(); } } finally { lib.free(tval); tval = null; }

124 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Resources

try (Timeval tval = lib.create(Timeval.class)) { int res = time.gettimeofday(tval, null); if (res == 0) { long tv_sec = tval.tv_sec$get(); long tv_usec = tval.tv_usec$get(); } }

125 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI Safer

§ no crashes § no leaks § no hangs § no privilege escalation § no unguarded casts

126 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Better JNI

127 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Specialized Generics Project Valhalla Value Types

Foreign Function Interface Project Panama Data Layout Control Arrays 2.0

http://openjdk.java.net

128 Copyright © 2015, Oracle and/or its affiliates. All rights reserved [email protected] Project Valhalla http://hg.openjdk.java.net/valhalla/valhalla

[email protected] Project Panama http://hg.openjdk.java.net/panama/panama

http://openjdk.java.net

129 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Duke

1995 2015

130 Copyright © 2015, Oracle and/or its affiliates. All rights reserved 131 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Safe Harbor Statement

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

132 Copyright © 2015, Oracle and/or its affiliates. All rights reserved Graphic Section Divider

133 Copyright © 2015, Oracle and/or its affiliates. All rights reserved