Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Dan Heidinga,
OpenJ9 Project Lead
IBM Runtimes J9 Interpreter Lead
Daniel_Heidinga@ca.ibm.com
@DanHeidinga
Oct 3, 2017
Ope...
Important disclaimers
§ THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.
§ WHIL...
Who am I?
§ I've been involved with virtual machine development at IBM
since 2007 and am now the J9 Virtual Machine Team L...
Dan Heidinga,
OpenJ9 Project Lead
IBM Runtimes J9 Interpreter Lead
Daniel_Heidinga@ca.ibm.com
@DanHeidinga
Oct 3, 2017
Ecl...
http://www.eclipse.org/openj9
https://github.com/eclipse/openj9
Dual License:
Eclipse Public License v2.0
Apache 2.0
Users...
https://adoptopenjdk.net/nightly.html?variant=openjdk9-openj9
$ git clone https://github.com/ibmruntimes/openj9-openjdk-jdk9
$ cd openj9-openjdk-jdk9
$ bash ./get_source.sh
$ bash ./co...
Wait… OpenJDK with OpenJ9?
8
9
10 http://docs.oracle.com/javase/8/docs/index.html
11
The VM has connections into the rest of the JDK
12
OpenJDK with Eclipse OpenJ9
To build OpenJDK with OpenJ9 requires patches
• Build process
• Class libraries
OpenJ9 Communities
Open	
JDK
HotSpot
Eclipse	OMR
Open	
JDK
Eclipse	
OpenJ9
Eclipse	
OMR
Proven	adaptable	technology	in	the...
Build an open reusable language runtime foundation for cloud platforms
– To accelerate advancement and innovation
– In ful...
http://www.eclipse.org/omr
https://github.com/eclipse/omr
https://developer.ibm.com/open/omr/
Dual License:
Eclipse Public...
public class HelloService {
public static void main(…) {
System.out.println(“Hello”);
}
}
17
$ java -jar uber.jar
18
$ java -jar uber.jar
19
Hello
$
20
What’s a JVM
actually doing
here?
21
22
Classfile
23
Classfile
Inputs Outputs
24
Classfile
Inputs Outputs
$ java -jar uber.jar
25
Hello
$
$ java –verbose:class
-jar uber.jar
26
27
…
class load: jdk/internal/org/objectweb/asm/FieldVisitor from: jrt:/java.base
class load: jdk/internal/org/objectweb/a...
“Data dominates.
If you've chosen the right data structures and
organized things well, the algorithms will almost
always b...
29
public class HelloService {
public static void main(…) {
System.out.println(“Hello”);
}
}
30
What does the JVM do to find ...
31
J9ROMClass: a better classfile
§ Keep all the symbolic info from a classfile
§ Remove variability (where possible)
§ Posit...
Conversion to ROM
33
Classfile Static
Verification
ROMClassROM Class
Builder
https://github.com/eclipse/openj9/tree/master...
Regular pointers
34
0x50
0x20
0x28
0x30
0x38
0x40
0x48
0x50
0x58
0x60
Self-relative pointers
35
0x20
0x20
0x28
0x30
0x38
0x40
0x48
0x50
0x58
0x60
0x30 + *(0x30) = 0x30 + 0x20 = 0x50
Address of...
typedef struct J9ROMClass {
U_32 romSize;
U_32 singleScalarStaticCount;
J9SRP className;
J9SRP superclassName;
U_32 modifi...
37
public static void main(java.lang.String[])
0 JBgetstatic 2 System.out LPrintStream;
3 JBldc 3 (java.lang.String) "Hell...
From ROM to RAM
38
RAM class creation
Load superclases
Load superinterfaces
Calculate vtable
ROMClass J9RAMClass
https://g...
typedef struct J9Class {
UDATA eyecatcher;
struct J9ROMClass* romClass;
struct J9Class** superclasses;
UDATA classDepthAnd...
ShareClasses: ROM pays off
JVM 1 JVM 2 JVM 3
ShareClasses: ROM pays off
JVM 1 JVM 2 JVM 3
ShareClasses: ROM pays off
JVM 1 JVM 2 JVM 3
Shared Classes
Cache
Faster startup, Smaller footprint
43
ROMClass J9RAMClass
Cool native memory!
How does this show
up for my Java code?
Classloading: tying it all together
44
ROMClass J9RAMClass
J9ClassLoader
java.lang.Class java.lang.ClassLoader
Heap
Native
45
public static void main(java.lang.String[])
0 JBgetstatic 2 System.out LPrintStream;
3 JBldc 3 (java.lang.String) "Hell...
Execution context: the Thread
46
J9VMThreadJ9VMThreadJ9JavaVM
omrthread_t omrthread_t omrthread_t
Heap
Native
java.lang.Th...
SP
A0
PC
Method
Per-Thread Interpreter State
47
J9VMThread
omrthread_t
java.lang.Thread
J9Method
ROMMethod
Bytecodes
SP
A0
PC
Method
Per-Thread Interpreter State
48
J9VMThread
omrthread_t
java.lang.Thread
J9Method
ROMMethod
Bytecodes
SP
A0
PC
Method
Per-Thread Interpreter State
49
J9VMThread
omrthread_t
java.lang.Thread
Pending
Frame
Temps
Args
Java stac...
Interpreter
§ Written in C++
§ Switch statement / computed goto
§ Executes:
– bytecodes
– INLs
– builds stack frames
§ Tra...
JIT Compilation
ARM
Optimizer
Analyses	and	Optimizations
cold warm hot FSDscorching AOT
IL	Generation
x86
POWER
Z
Code	Gen...
Adaptive JIT Compilation
52
§ Methods start out running bytecode form directly
§ After many invocations (or via sampling) ...
53
+ (cold) jdk/internal/reflect/NativeConstructorAccessorImpl.newInstance0(…
+ (cold) java/lang/Module.defineModule0(…
+ ...
“Dynamic” AOT through ShareClasses
Shared Classes
Cache
AOTROM Classes
$ java –Xshareclasses -jar uber.jar
55
Cool!
How can I get
involved?
Wrap-up: Want to get involved?
§ Download OpenJDK with OpenJ9 and try it out!
– https://adoptopenjdk.net/releases.html?var...
Learn more at Java One!
§ Have even more questions? Dan Heidinga, Mark Stoodley, John Duimovich
Ask the OpenJ9 Architects ...
Questions?
58
Dan Heidinga
daniel_heidinga@ca.ibm.com
@DanHeidinga
59
Legal Notice
IBM and the IBM logo are trademarks or registered trademarks of IBM Corporation, in the United States, oth...
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
Upcoming SlideShare
Loading in …5
×

JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM

1,163 views

Published on

An updated version of my "OpenJ9: Under the hood of the next open source JVM" that covers where it was open sourced (github.com/eclipse/openj9), how to build it, and then deep dives into the ROM/RAM divide before touching on interpreter, JIT and AOT.

Published in: Software
  • Be the first to comment

JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM

  1. 1. Dan Heidinga, OpenJ9 Project Lead IBM Runtimes J9 Interpreter Lead Daniel_Heidinga@ca.ibm.com @DanHeidinga Oct 3, 2017 OpenJ9: Under the Hood of the Next Open Source JVM
  2. 2. Important disclaimers § THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. § WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. § ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES. § ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE. § IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE. § IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. § NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF: – CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS 2
  3. 3. Who am I? § I've been involved with virtual machine development at IBM since 2007 and am now the J9 Virtual Machine Team Lead. J9 is IBM's independent implementation of the JVM. § I've represented IBM on both the JSR 292 ('invokedynamic') and JSR 335 ('lambda') expert groups and lead J9's implementation of both JSRs. § I’ve also maintain the bytecode verifier and deal with various other parts of the runtime. § Now one of the Project Leads for the Eclipse OpenJ9 JVM. 3
  4. 4. Dan Heidinga, OpenJ9 Project Lead IBM Runtimes J9 Interpreter Lead Daniel_Heidinga@ca.ibm.com @DanHeidinga Oct 3, 2017 Eclipse OpenJ9: Under the Hood of the Next Open Source JVM
  5. 5. http://www.eclipse.org/openj9 https://github.com/eclipse/openj9 Dual License: Eclipse Public License v2.0 Apache 2.0 Users and contributors very welcome https://github.com/eclipse/openj9/blob/master/CONTRIBUTING.md Eclipse OpenJ9 Created Sept 2017
  6. 6. https://adoptopenjdk.net/nightly.html?variant=openjdk9-openj9
  7. 7. $ git clone https://github.com/ibmruntimes/openj9-openjdk-jdk9 $ cd openj9-openjdk-jdk9 $ bash ./get_source.sh $ bash ./configure --with-freemarker-jar=freemarker.jar $ make images $ cd build/linux-x86_64-normal-server-release/images/ $ ./jdk/bin/java -version 7 Building OpenJDK with OpenJ9
  8. 8. Wait… OpenJDK with OpenJ9? 8
  9. 9. 9
  10. 10. 10 http://docs.oracle.com/javase/8/docs/index.html
  11. 11. 11 The VM has connections into the rest of the JDK
  12. 12. 12 OpenJDK with Eclipse OpenJ9 To build OpenJDK with OpenJ9 requires patches • Build process • Class libraries
  13. 13. OpenJ9 Communities Open JDK HotSpot Eclipse OMR Open JDK Eclipse OpenJ9 Eclipse OMR Proven adaptable technology in the open for rapid innovation and collaboration across multiple language communities OpenJDK IBM SDK for Java Java community open innovation and collaboration Ruby? OMR Communities Beyond Java COBOL PL/I Emulator Python? OMR JS? OMR Swift? OMR … Long term support, quick response for problems, and other forms of IBM customer specific engagement + IBM isms Open JDK Eclipse OpenJ9 Eclipse OMR
  14. 14. Build an open reusable language runtime foundation for cloud platforms – To accelerate advancement and innovation – In full cooperation with existing language communities – Engaging a diverse community of people interested in language runtimes • Professional developers • Researchers • Students • Hobbyists Eclipse OMR Mission
  15. 15. http://www.eclipse.org/omr https://github.com/eclipse/omr https://developer.ibm.com/open/omr/ Dual License: Eclipse Public License v2.0 Apache 2.0 Users and contributors very welcome https://github.com/eclipse/omr/blob/master/CONTRIBUTING.md Eclipse OMR Created March 2016
  16. 16. public class HelloService { public static void main(…) { System.out.println(“Hello”); } } 17
  17. 17. $ java -jar uber.jar 18
  18. 18. $ java -jar uber.jar 19 Hello $
  19. 19. 20 What’s a JVM actually doing here?
  20. 20. 21
  21. 21. 22 Classfile
  22. 22. 23 Classfile Inputs Outputs
  23. 23. 24 Classfile Inputs Outputs
  24. 24. $ java -jar uber.jar 25 Hello $
  25. 25. $ java –verbose:class -jar uber.jar 26
  26. 26. 27 … class load: jdk/internal/org/objectweb/asm/FieldVisitor from: jrt:/java.base class load: jdk/internal/org/objectweb/asm/FieldWriter from: jrt:/java.base class load: java/lang/ClassLoader$$Lambda$3/00000000702E91F0 class load: HelloService from: file:/openj9/uber.jar class load: jdk/internal/reflect/UnsafeFieldAccessorFactory from: jrt:/java.base class load: jdk/internal/reflect/FieldAccessor from: jrt:/java.base class load: jdk/internal/reflect/FieldAccessorImpl from: jrt:/java.base class load: jdk/internal/reflect/UnsafeFieldAccessorImpl from: jrt:/java.base class load: jdk/internal/reflect/UnsafeObjectFieldAccessorImpl from: jrt:/java.base class load: java/lang/Class$ReflectCache from: jrt:/java.base class load: java/lang/annotation/Annotation from: jrt:/java.base class load: jdk/internal/reflect/CallerSensitive from: jrt:/java.base ….
  27. 27. “Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.” –Rob Pike (known for Plan 9, UTF-8, Go) 28
  28. 28. 29
  29. 29. public class HelloService { public static void main(…) { System.out.println(“Hello”); } } 30 What does the JVM do to find that main method?
  30. 30. 31
  31. 31. J9ROMClass: a better classfile § Keep all the symbolic info from a classfile § Remove variability (where possible) § Position independent: map anywhere in the address space § ROM: Read only once written – Learn from the Smalltalk past 32 ROMClass
  32. 32. Conversion to ROM 33 Classfile Static Verification ROMClassROM Class Builder https://github.com/eclipse/openj9/tree/master/runtime/bcverify https://github.com/eclipse/openj9/tree/master/runtime/bcutil
  33. 33. Regular pointers 34 0x50 0x20 0x28 0x30 0x38 0x40 0x48 0x50 0x58 0x60
  34. 34. Self-relative pointers 35 0x20 0x20 0x28 0x30 0x38 0x40 0x48 0x50 0x58 0x60 0x30 + *(0x30) = 0x30 + 0x20 = 0x50 Address of slot + value = target address
  35. 35. typedef struct J9ROMClass { U_32 romSize; U_32 singleScalarStaticCount; J9SRP className; J9SRP superclassName; U_32 modifiers; U_32 extraModifiers; U_32 interfaceCount; J9SRP interfaces; U_32 romMethodCount; J9SRP romMethods; U_32 romFieldCount; J9SRP romFields; U_32 objectStaticCount; U_32 doubleScalarStaticCount; U_32 ramConstantPoolCount; U_32 romConstantPoolCount; ... } J9ROMClass; J9ROMClass ROM Constant pool interfaces J9ROMMethods . . .
  36. 36. 37 public static void main(java.lang.String[]) 0 JBgetstatic 2 System.out LPrintStream; 3 JBldc 3 (java.lang.String) "Hello” 5 JBinvokevirtual 4 PrintStream.println(LString;)V 8 JBreturn Java’s late bound… Isn’t it slow to resolve the fields / methods every time?
  37. 37. From ROM to RAM 38 RAM class creation Load superclases Load superinterfaces Calculate vtable ROMClass J9RAMClass https://github.com/eclipse/openj9/blob/master/runtime/vm/createramclass.cpp
  38. 38. typedef struct J9Class { UDATA eyecatcher; struct J9ROMClass* romClass; struct J9Class** superclasses; UDATA classDepthAndFlags; struct J9ClassLoader* classLoader; j9object_t classObject; UDATA volatile initializeStatus; struct J9Method* ramMethods; UDATA* ramStatics; struct J9Class* arrayClass; UDATA totalInstanceSize; UDATA* instanceDescription; UDATA packageID; void** iTable; void** jniIDs; struct J9Class* replacedClass; UDATA* ramConstantPool; . . . } J9Class; J9Class VTable JIT VTable RAM Constant pool J9Methods
  39. 39. ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3
  40. 40. ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3
  41. 41. ShareClasses: ROM pays off JVM 1 JVM 2 JVM 3 Shared Classes Cache Faster startup, Smaller footprint
  42. 42. 43 ROMClass J9RAMClass Cool native memory! How does this show up for my Java code?
  43. 43. Classloading: tying it all together 44 ROMClass J9RAMClass J9ClassLoader java.lang.Class java.lang.ClassLoader Heap Native
  44. 44. 45 public static void main(java.lang.String[]) 0 JBgetstatic 2 System.out LPrintStream; 3 JBldc 3 (java.lang.String) "Hello” 5 JBinvokevirtual 4 PrintStream.println(LString;)V 8 JBreturn That’s all good but what about actually running my code???
  45. 45. Execution context: the Thread 46 J9VMThreadJ9VMThreadJ9JavaVM omrthread_t omrthread_t omrthread_t Heap Native java.lang.Thread java.lang.Thread java.lang.Thread
  46. 46. SP A0 PC Method Per-Thread Interpreter State 47 J9VMThread omrthread_t java.lang.Thread J9Method ROMMethod Bytecodes
  47. 47. SP A0 PC Method Per-Thread Interpreter State 48 J9VMThread omrthread_t java.lang.Thread J9Method ROMMethod Bytecodes
  48. 48. SP A0 PC Method Per-Thread Interpreter State 49 J9VMThread omrthread_t java.lang.Thread Pending Frame Temps Args Java stack J9Method ROMMethod Bytecodes 0
  49. 49. Interpreter § Written in C++ § Switch statement / computed goto § Executes: – bytecodes – INLs – builds stack frames § Transition to the JIT 50 https://github.com/eclipse/openj9/blob/master/runtime/vm/BytecodeInterpreter.hpp
  50. 50. JIT Compilation ARM Optimizer Analyses and Optimizations cold warm hot FSDscorching AOT IL Generation x86 POWER Z Code Generators Runtime Environment/ Configuration •Options •Object Model •Memory •Threading •Tracing codeMetadataRuntimeRT Helpers very hot profiling Profile Manager Hardware counters Sampling Thread Interpreter Profile Info JIT Profile Info Profiler
  51. 51. Adaptive JIT Compilation 52 § Methods start out running bytecode form directly § After many invocations (or via sampling) code get compiled at ‘cold’ or ‘warm’ level § Low overhead sampling thread is used to identify hot methods § Methods may get recompiled at ‘hot’ or ‘scorching’ levels (for more optimizations) § Transition to ‘scorching’ goes through a temporary profiling step cold hot scorching profiling interpreter warm
  52. 52. 53 + (cold) jdk/internal/reflect/NativeConstructorAccessorImpl.newInstance0(… + (cold) java/lang/Module.defineModule0(… + (cold) java/lang/Module.addReads0(Ljava/lang/Module;Ljava/lang/Module;)V + (cold) java/lang/Module.addExports0(… + (cold) java/lang/Module.addExportsToAll0(Ljava/lang/Module;Ljava/lang/String;)V + (warm) java/util/HashMap.hash(Ljava/lang/Object;)I + (warm) java/util/HashMap.putVal(… + (cold) java/lang/Thread.setNameImpl(JLjava/lang/String;)V + (warm) java/lang/Math.floorMod(II)I + (warm) java/lang/Math.floorDiv(II)I $ java –Xjit:verbose -jar uber.jar
  53. 53. “Dynamic” AOT through ShareClasses Shared Classes Cache AOTROM Classes $ java –Xshareclasses -jar uber.jar
  54. 54. 55 Cool! How can I get involved?
  55. 55. Wrap-up: Want to get involved? § Download OpenJDK with OpenJ9 and try it out! – https://adoptopenjdk.net/releases.html?variant=openjdk9-openj9 – Run on your favourite Java application and let us know how it went! § Interact with our community via Github issues – https://github.com/eclipse/openj9 – Ask questions, report problems, report Amazing Results – Download the code, build it yourself, play around! – Submit pull requests, see them tested on multiple platforms in the open § Whatever you think will make Eclipse OpenJ9 better, we’d love to hear it 56
  56. 56. Learn more at Java One! § Have even more questions? Dan Heidinga, Mark Stoodley, John Duimovich Ask the OpenJ9 Architects [CON2672] Wednesday, Oct 04, 8:30 a.m. - 9:15 a.m. | Moscone West - Room 2011 § Learn about microservices for open testing with Shelley Lambert Cloud-Based Test Microservices [CON2789] Thursday, Oct 05, 11:45 a.m. - 12:30 p.m. | Marriott Marquis (Yerba Buena Level) - Salon 12 § Debugging runtimes with Dan Heidinga for Bjørn Vårdal Secrets of Building a Debuggable Runime [CON4081] Thursday, Oct 05, 12:45 p.m. - 1:30 p.m. | Marriott Marquis (Yerba Buena Level) - Salon 15 § Visit the Eclipse Foundation booth (6140) Dan Heidinga & Mark Stoodley today from 4:00 - 5:45 Mark Stoodley on Wednesday from 2:30 - 4:30 57
  57. 57. Questions? 58 Dan Heidinga daniel_heidinga@ca.ibm.com @DanHeidinga
  58. 58. 59 Legal Notice IBM and the IBM logo are trademarks or registered trademarks of IBM Corporation, in the United States, other countries or both. Java and all Java-based marks, among others, are trademarks or registered trademarks of Oracle in the United States, other countries or both. Other company, product and service names may be trademarks or service marks of others. THE INFORMATION DISCUSSED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION, IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, AND IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, SUCH INFORMATION. ANY INFORMATION CONCERNING IBM'S PRODUCT PLANS OR STRATEGY IS SUBJECT TO CHANGE BY IBM WITHOUT NOTICE.

×