Top Banner
20 years of Java Vladimir Ivanov HotSpot JVM Compile r Oracle Corp. Twitter: @iwan0www OpenJDK: vlivanov 28.11.2015
133

Владимир Иванов (Oracle): Java: прошлое и будущее

Jan 22, 2018

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Владимир Иванов (Oracle): Java: прошлое и будущее

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

20 years of Java

Vladimir Ivanov HotSpot JVM Compile r Oracle Corp.

Twitter: @iwan0www OpenJDK: vlivanov

28.11.2015

Page 2: Владимир Иванов (Oracle): Java: прошлое и будущее

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

20 years of Java (The Platform)

Vladimir Ivanov HotSpot JVM Compile r Oracle Corp.

Twitter: @iwan0www OpenJDK: vlivanov

Page 3: Владимир Иванов (Oracle): Java: прошлое и будущее

3 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.

Page 4: Владимир Иванов (Oracle): Java: прошлое и будущее

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

About me

1996 2002 2010 2015 2005

JDK 1.0

Wrote my first program in Java.

Joined Sun Microsystems

(SPBDC) to work on HotSpot JVM Now

Became part of Oracle Corp.

after acquisition

Page 5: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1991: Project Green

Page 6: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1991: *7 (StarSeven) Oak programming language

Page 7: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1991: *7 (StarSeven) Duke

Page 8: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1994: WebRunner/HotJava browser

Page 9: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1995: First release: 1.0a2

Page 10: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Intel Pentium P54CS, 0.35µm, 200MHz, 66MHz FSB

Page 11: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Sun Enterprise 10000 64 UltraSPARC II CPUs, 400 MHz, 16x4GB RAM

Page 12: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1996: JDK 1.0

§ 6 packages –  java.applet –  java.awt –  java.io –  java.lang –  java.net –  java.util

January, 23

§ # of classes –  java/ 225 –  sun/ 379

Page 13: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1996: picoJava

Page 14: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1997: JDK 1.1 February, 19

Page 15: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1998: J2SE 1.2 December, 8

Page 16: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1999: J2SE, J2ME, J2EE

Page 17: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1999: J2SE, J2ME, J2EE

Page 18: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2000: J2SE 1.3 May, 8

Page 19: Владимир Иванов (Oracle): Java: прошлое и будущее

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

1998: JCP

Page 20: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2002 February, 6

Page 21: Владимир Иванов (Oracle): Java: прошлое и будущее

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

First release

1995 1997 2002

Java Releases

1996 1998

JDK 1.0

JDK 1.1

J2SE 1.2

2000

J2SE 1.3

J2SE 1.4

Inner classes JavaBeans

JDBC RMI

Reflection JNI

Swing JIT compiler Java Plug-in Collections

HotSpot JVM JNDI

Java Sound JVMDI JVMPI

Regular Expressions IPv6 support

Logging XML, XSLT

Java Web Start

January, 23

February, 19

December, 8

May, 8

February, 6

March

AWT Network

I/O

Page 22: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2004: J2SE 5.0 September, 30

Page 23: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2004: J2SE 5.0 September, 30

Page 24: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2006: Java SE 6

§ 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

December, 11

Page 25: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Java SE 6u

§ Escape analysis in C2 –  6u23

§ NUMA GC Enhancements –  Java SE 6u2

§ Compressed OOPs –  6u23

§ Tiered compilation

HotSpot Express

Page 26: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2007 May, 8

Page 27: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2007: May JavaFX 1.0 on December, 2008

Page 28: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Page 29: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2010

Page 30: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2011: Java SE 7

§  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)

July, 28

Page 31: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2014: Java SE 8

§  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

March, 18

Page 32: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2014: Java SE 8 March, 18

Page 33: Владимир Иванов (Oracle): Java: прошлое и будущее

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

2016: Java SE 9 ETA: September, 22

Project  Jigsaw   Scalability  Performance  Security  

http://openjdk.java.net  

Page 34: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw Scalability

Page 35: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Java 8

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

authjdbc jaxpnaming

jaxwscompiler

rowsetxmldsig

crypto

corba

desktop

tools.jre

httpserver

tools

tools.jaxws tools.base

devtools

javafx

prefssctp jx.annotationsinstrument

54MB 30 16 11 nashorn

rmi

compact1

JRE

compact3

compact2

JDK

Page 36: Владимир Иванов (Oracle): Java: прошлое и будущее

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

naming.rmi  

base  charsets  

se  

compact3  

compact2  

compact1  

logging   scrip:ng  

security.acl  

security.sasl    

sql  rmi  

xml  xml.crypto  

prefs  desktop  

ac:va:on  

corba  

compiler   management  

sql.rowset  

security.jgss  

instrument  

naming  

xml.ws  

xml.soap  

xml.bind  

annota:ons.common  

hBpserver  

rmic  

javadoc  

xml.ws  

xml.bind  

compiler  

hotspot.agent  

jconsole   jcmd  jdi  

aBach  

jvmstat  

naming  

smartcardio  crypto.ec  

crypto.pkcs11  

hprof.agent  jdwp.agent  

localedata  sctp  

zipfs  security.auth  

scripting. nashorn

Project Jigsaw Performance

Page 37: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

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

tlslogging

authjdbc

jta

jaxpnaming

jaxwscompiler

rowset

kerberosmanagement

xmldsig

crypto

cosnaming management.iiop

corba

desktop

tools.jre

httpserver

tools

tools.jaxws tools.base

devtools

javafx

prefssctp jx.annotations

nashorn

instrument base

script

rmi

Page 38: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

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

tlslogging

authjdbc

jta

jaxpnaming

jaxwscompiler

rowset

kerberosmanagement

xmldsig

crypto

cosnaming management.iiop

corba

desktop

tools.jre

httpserver

tools

tools.jaxws tools.base

devtools

javafx

prefssctp jx.annotations

nashorn

instrument base

script

rmi

Page 39: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

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

tlslogging

authjdbc

jta

jaxpnaming

jaxwscompiler

rowset

kerberosmanagement

xmldsig

crypto

cosnaming management.iiop

corba

desktop

tools.jre

httpserver

tools

tools.jaxws tools.base

devtools

javafx

prefssctp jx.annotations

nashorn

instrument base

script

rmi

Page 40: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

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

crypto

javafx

nashorn

base

script

Page 41: Владимир Иванов (Oracle): Java: прошлое и будущее

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

j l i n k

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

*.jmod $JRE/bin/java

/ l i b / . . .

* . j a r

* .c lass

JVM image

. j a r

.jmod

Fat binary

Page 42: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw Opportunities for performance improvements

rt.jar

nashorn.jar, jfxrt.jar,sunjce_provider.jar

myapp.jar

crypto

javafx

nashornbase

script

Page 43: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 44: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 45: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

§ Aggressive inlining

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 46: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

§ Aggressive inlining § Ahead-Of-Time compilation

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 47: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

§ Aggressive inlining § Ahead-Of-Time compilation §  JVM-specific memory images

–  e.g. Application Class Data Sharing (AppCDS)

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 48: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Jigsaw

§  Improved class loading architecture –  fast class lookup

§ Aggressive inlining § Ahead-Of-Time compilation §  JVM-specific memory images

–  e.g. Application Class Data Sharing (AppCDS)

§ Removal of unused fields/methods/classes

Opportunities for performance improvements crypto

javafx

nashornbase

script

Page 49: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.* * . in te rna l .*

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

Project Jigsaw Security

Page 50: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.misc.Unsafe?!

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

Project Jigsaw Security

Page 51: Владимир Иванов (Oracle): Java: прошлое и будущее

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

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

John Rose JVM Architect, Oracle Corporation

Project Jigsaw & sun.misc.Unsafe

@ JVM Language Summit 2014

Page 52: Владимир Иванов (Oracle): Java: прошлое и будущее

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

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

- A lot of you. Gosh, I'm sorry.

John Rose JVM Architect, Oracle Corporation

Project Jigsaw & sun.misc.Unsafe

@ JVM Language Summit 2014

Page 53: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Page 54: Владимир Иванов (Oracle): Java: прошлое и будущее

54 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

Page 55: Владимир Иванов (Oracle): Java: прошлое и будущее

55 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

Page 56: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.misc.Unsafe

Use case Example methods

Concurrency primitives Unsafe.compareAndSwap*

Serialization Unsafe.allocateInstance (ReflectionFactory.newConstructorForSerialization)

Efficient memory management, layout, and access

Unsafe.allocate/freeMemory Unsafe.get*/put* (and JNI)

Interoperate across the JVM boundary

Unsafe.get*/put* (and JNI)

Page 57: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.misc.Unsafe

Use case Replacement

Concurrency primitives JEP 193 Variable Handles

Serialization Reboot JEP 187 Serialization Improvements

Efficient memory management, layout, and access

Project Panama, Project Valhalla, Arrays 2.0, Better GC

Interoperate across the JVM boundary

Project Panama, JEP 191 Foreign Function Interface

Page 58: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.misc.Unsafe (JDK 9)

Use case Replacement

Concurrency primitives JEP 193 Variable Handles

Serialization Reboot JEP 187 Serialization Improvements

Efficient memory management, layout, and access

Project Panama, Project Valhalla, Arrays 2.0, Better GC

Interoperate across the JVM boundary

Project Panama, JEP 191 Foreign Function Interface

Page 59: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Page 60: Владимир Иванов (Oracle): Java: прошлое и будущее

60 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

Page 61: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Charles Oliver Nutter JRuby Lead Developer

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

Java 7: Method Handles

Page 62: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Method Handles

Page 63: Владимир Иванов (Oracle): Java: прошлое и будущее

63 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

Page 64: Владимир Иванов (Oracle): Java: прошлое и будущее

64 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”

Page 65: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(1) Variable Handles

Page 66: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(2) Memory Fences

a = ?, b = ?

Thread #1 Thread #2

Page 67: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(2) Memory Fences

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

Thread #1 Thread #2

Page 68: Владимир Иванов (Oracle): Java: прошлое и будущее

68 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]

Page 69: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(3) Finalization

Page 70: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(3) Premature Finalization

Page 71: Владимир Иванов (Oracle): Java: прошлое и будущее

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

(3) Premature Finalization

Page 72: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Beyond Java 9

Page 73: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Valhalla

Project Panama

Specialized Generics Value Types

Foreign Function Interface Data Layout Control Arrays 2.0

http://openjdk.java.net  

Page 74: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Valhalla “The hall of valor value”

Page 75: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value-based Class

final  class  Point  {          public  final  int  x;          public  final  int  y;  }      

@since 8

“Use of identity-sensitive operations on instances of value-based classes may have unpredictable effects and should be avoided.”

ValueBased javadoc

Page 76: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value-based Class

Point[] points =

Arrays

h header

x y

x y

x y

x y

x y

x y

Page 77: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value-based Class

Point[] points =

Arrays

h header

x y

x y

x y

x y

x y

x y

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

Page 78: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value-based Class

int[]  xPoints  =  

Arrays

h header

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

h header

x x x x x x

y y y y y y int[]  yPoints  =  

Page 79: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value-based Class

int[]  points  =  

Arrays

h header

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

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

Page 80: Владимир Иванов (Oracle): Java: прошлое и будущее

80 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”

Page 81: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value Types Arrays

value  class  Point  {          public  final  int  x;          public  final  int  y;  }  

Point[]  points  =   h header x y x y x y x y x y x y

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

Page 82: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Motivation

§ Smaller footprint –  no object header

§ Better locality –  no dereference

§ Simpler semantics –  no identity, no aliasing

§ No object allocation

Value Types

Page 83: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value Types

value  class  Point  {          public  final  int  x;          public  final  int  y;  }    class  Rectangle  {          public  final  Point  corner1;          public  final  Point  corner2;  }    

Concurrent side effects

x xy yh header  

Rectangle  r  =    

x y

x y

h header  

Rectangle  r  =    

Page 84: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Value Types

value  class  Point  {          public  final  int  x;          public  final  int  y;  }    class  Rectangle  {          public                    Point  corner1;          public  volatile  Point  corner2;  }    

Concurrent side effects

x xy yh header  

Rectangle  r  =    

x y

x y

h header  

Rectangle  r  =    

Page 85: Владимир Иванов (Oracle): Java: прошлое и будущее

85 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

Page 86: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Selected details

Point[] <:? Object[]

Page 87: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Selected details

Point[] <: Object[]

Point[]  points  =   h header x y x y x y x y x y x y

Page 88: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization Motivation

ArrayList<Integer>

Page 89: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization Motivation

ArrayList<int>

Page 90: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Objects

§ Object, String, …, MyClass, …, Integer, Long, …

–  8 primitive types (+ reference)

§  boolean, byte, short, char, int, long, float, double

vs Primitives

Page 91: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Objects

§ Object, String, …, MyClass, …, Integer, Long, …

–  8 primitive types (+ reference)

§  boolean, byte, short, char, int, long, float, double

–  Value types

§  User-defined (!!!)

vs Non-objects

Page 92: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization Motivation

ArrayList<Point>

Page 93: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

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

Page 94: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

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

Page 95: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

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

Page 96: Владимир Иванов (Oracle): Java: прошлое и будущее

96 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;  }    }      

Page 97: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

class  Box<any  T>    {      T            val;        public  Box(T            val)  {  this.val  =  val;  }      public  T            get()        {  return  val;  }    }      

Page 98: Владимир Иванов (Oracle): Java: прошлое и будущее

98 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          }  }  

Page 99: Владимир Иванов (Oracle): Java: прошлое и будущее

99 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          }  }  

Page 100: Владимир Иванов (Oracle): Java: прошлое и будущее

100 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          }  }  

Page 101: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

Box<Integer> :> Box

Page 102: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

Box<int> :>? Box

Page 103: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Generic Specialization

Box<int> :> Box

Box<int> :> Box<?> Box<Object> :> Box<?>

Box :> Box<?>

Page 104: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Panama “Bridging the gap”

Page 105: Владимир Иванов (Oracle): Java: прошлое и будущее

105 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

Page 106: Владимир Иванов (Oracle): Java: прошлое и будущее

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

JNI @since 1.1

Page 107: Владимир Иванов (Oracle): Java: прошлое и будущее

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

JNI

A victim of its own success?

Page 108: Владимир Иванов (Oracle): Java: прошлое и будущее

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

JNI Usage scenario

Page 109: Владимир Иванов (Oracle): Java: прошлое и будущее

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

JNI

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

C/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(); }

Page 110: Владимир Иванов (Oracle): Java: прошлое и будущее

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

JNI: Method Invocation

1.  if (GC_locker::needs_gc()) SharedRuntime::block_for_jni_critical()

2.  transition to thread_in_native 3.  unpack array arguments

4.  call native entry point

Runtime checks before and after native call

1.  call native entry point 2.  check for safepoint in progress

3.  check if any thread suspend flags are set –  call into JVM and possibly unlock the

JNI critical if a GC was suppressed while in the critical native

4.  transition to thread_in_Java

5.  return

Page 111: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI Easier, safer, faster!

Page 112: Владимир Иванов (Oracle): Java: прошлое и будущее

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

sun.misc.Unsafe § Anti-JNI

Page 113: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Unsafe.getUnsafe().

putInt(new Object(), 0, 0)

Page 114: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Unsafe.getUnsafe().

putInt(null, 0, 0)

Page 115: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI Easier, safer, faster!

Page 116: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

pid_t get_pid();

Page 117: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

public  interface  GetPid  {          long  getpid();  }    

Easier

Page 118: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

public  interface  GetPid  {          long  getpid();  }    GetPid  getpid  =  Library.load(GetPid.class,  “c”  /*  lib_name  */  );  

Easier

Page 119: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

public  interface  GetPid  {          long  getpid();  }    GetPid  getpid  =  Library.load(GetPid.class,  “c”  /*lib_name*/  );    getpid.getpid();  

Easier

Page 120: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI Faster

callq 0x1057b2eb0 ; getpid entry

Page 121: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI gettimeofday

/*  time.h  */    struct  {          time_t            tv_sec;              suseconds_t  tv_usec;    }  timeval;    

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

   struct  {          int  tz_minuteswest;              int  tz_dsttime;    }  timezone;    

Page 122: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI $ jextract time.h

interface  Time  {    interface  Timeval  {          long  tv_sec$get();          void  tv_sec$set(long);          long  tv_usec$get();          void  tv_usec$set(long);      }    

int  gettimeofday(Timeval,  Timezone);  

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

Page 123: Владимир Иванов (Oracle): Java: прошлое и будущее

123 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();  }  

Page 124: Владимир Иванов (Oracle): Java: прошлое и будущее

124 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;  }  

Page 125: Владимир Иванов (Oracle): Java: прошлое и будущее

125 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();      }  }  

Page 126: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

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

Safer

Page 127: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Better JNI

Page 128: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Valhalla

http://openjdk.java.net  

Project Panama

Specialized Generics Value Types

Foreign Function Interface Data Layout Control Arrays 2.0

Page 129: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Project Valhalla

http://openjdk.java.net  

valhalla-­‐[email protected]  http://hg.openjdk.java.net/valhalla/valhalla  

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

Page 130: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Duke

1995 2015

Page 131: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Page 132: Владимир Иванов (Oracle): Java: прошлое и будущее

132 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.

Page 133: Владимир Иванов (Oracle): Java: прошлое и будущее

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

Graphic Section Divider