The Eclipse Openj9 JVM a Deep Dive! Tobi Ajila Tobi [email protected] Disclaimer
Total Page:16
File Type:pdf, Size:1020Kb
The Eclipse OpenJ9 JVM A deep dive! Tobi Ajila [email protected] Disclaimer • 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 About the speaker • Developer on the OpenJ9 VM team • Worked on: • VM support for Lambda expressions • Java multitenancy incubator • Project Panama experts group Tobi Ajila [email protected] 3 Agenda • What is a JVM? • What is OpenJ9? • How does OpenJ9 work? • What are some interesting features of OpenJ9? 4 5 Compiling a Java application Java source file Java class file JAVAC javac HelloWorld.java 6 Java Class File 7 Java bytecode Java source code Java bytecode JAVAC HelloWorld.class HelloWorld.java 8 kotlinc 9 Running a Java application HelloWorld. Java source file Java class file class JAVAC JAVA Java Runtime Environment Operatiing System javac HelloWorld.java java HelloWorld 10 Launching the jvm java HelloWorld // create the VM JNI_CreateJavaVM(JavaVM **p_vm, JNIEnv **env, . .) // find main class, ‘HelloWorld’ cls = (*env)->FindClass(env, . .); // get main(String[]…) method mid = (*env)->GetStaticMethodID(env, cls, . .); // call it! (*env)->CallStaticVoidMethod(env, cls, mid. .); //shutdown p_vm->DestroyJavaVM(); 11 The JRE Java Runtime Environment (JRE) Java Class Libraries Java Virtual Machine 12 The JRE Java Runtime Environment (JRE) Java Virtual Machine (JVM) Java Class Libraries JCL natives Java Virtual Machine 13 The JRE Java Runtime Environment (JRE) Java Virtual Machine (JVM) Java Class Libraries JCL natives Verifier Classloader Java Virtual Machine 14 The JRE Java Runtime Environment (JRE) Java Virtual Machine (JVM) Java Class Libraries JCL natives Verifier Classloader Interpreter + Garbage JIT collector Java Virtual Machine 15 The JRE Java Runtime Environment (JRE) Java Virtual Machine (JVM) Java Class Libraries JCL natives Verifier Classloader Interpreter + Garbage JIT collector Java Virtual Machine Port/Thread Library 16 Eclipse OpenJ9 Created Sept 2017 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 17 OpenJDK Java language Tools JDK UI Toolkits Base Libraries JRE JVM 18 Building OpenJDK with OpenJ9 OpenJDK OpenJDK Hotspot HotSpot 19 Building OpenJDK with OpenJ9 $ 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 Øhttps://www.eclipse.org/openj9/oj9_build.html 20 The place to get OpenJDK builds For both: • OpenJDK & • OpenJDK with Eclipse OpenJ9 https://adoptopenjdk.net/releases.html?va riant=openjdk9-openj9 21 How does OpenJ9 work? Java class libraries OpenJ9 Core JCL Core Java class libraries • Includes classes that are closely tied to the JCL Natives JVM implementation • These include Verifier Classloader j.l.Object, j.l.Class, j.l.Thread, … Interpreter RAS JIT GC Port/Thread Library 22 How does OpenJ9 work? Java class libraries Reliability, Availability and Serviceability (RAS) OpenJ9 Core JCL • Tools to simplify JVM and application debugging • Trace engine JCL Natives • Verification checking utilities Verifier Classloader Interpreter RAS JIT GC Port/Thread Library 23 OpenJ9 and OMR OpenJ9 VM Classloader Verifier JCL natives Interpreter JAVA RAS JAVA GC JAVA JIT OMR OMR GC OMR JIT OMR RAS Port/Thread Library 24 Eclipse OMR Created March 2016 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 25 OpenJ9: Classloading 26 OpenJ9: Classloading 27 OpenJ9: ROMClass • Keep all the symbolic info from a classfile • Remove variability (where possible) • Position independent: map anywhere in the address space • ROM: written once, only read after • Learn from the Smalltalk/Embedded past ROM Class 28 typedef struct J9ROMClass { U_32 romSize; U_32 singleScalarStaticCount; J9SRP className; J9SRP superclassName; J9ROMClass U_32 modifiers; U_32 extraModifiers; ROM U_32 interfaceCount; Constant pool J9SRP interfaces; U_32 romMethodCount; interfaces J9SRP romMethods; U_32 romFieldCount; J9ROMMethods J9SRP romFields; U_32 objectStaticCount; U_32 doubleScalarStaticCount; . U_32 ramConstantPoolCount; U_32 romConstantPoolCount; ... } J9ROMClass; 29 OpenJ9: Self relative pointers Address of slot + value = target address 0x20 0x20 0x28 0x28 0x30 0x50 0x30 0x20 0x38 0x38 0x40 0x40 0x48 0x48 0x50 0x50 0x58 0x58 0x60 0x60 0x30 + *(0x30) = 0x30 + 0x20 = 0x50 Regular pointer Self relative pointer 30 OpenJ9: Self relative pointers Need to update pointer 0x20 0x70 0x28 0x78 0x30 0x50 0x80 0x50 0x38 0x88 0x40 New address space 0x90 0x48 0x98 0x50 0xA0 0x58 0xA8 0x60 0xB0 Regular pointer 31 OpenJ9: Self relative pointers 0x20 0x70 0x28 0x78 0x30 0x20 0x80 0x20 0x38 0x88 0x40 New address space 0x90 0x48 0x98 0x50 0xA0 0x58 0xA8 0x60 0xB0 self relative pointer 32 Java’s late bound… Isn’t it slow to resolve the fields / methods every time? public static void main(java.lang.String[]) 0 JBgetstatic 2 System.out LPrintStream; 3 JBldc 3 (java.lang.String) "HelloWorld” 5 JBinvokevirtual 4 PrintStream.println(LString;)V 8 JBreturn 33 OpenJ9: ROM to RAM ROMClass Load superclases J9RAMClass Load superinterfaces Calculate vtable Calculate field offsets https://github.com/eclipse/openj9/blob/master/runtime/vm/createramclass.cpp 34 OpenJ9: RamClass typedef struct J9Class { UDATA eyecatcher; struct J9ROMClass* romClass; struct J9Class** superclasses; UDATA classDepthAndFlags; JIT VTable RAM struct J9ClassLoader* classLoader; Constant pool j9object_t classObject; UDATA volatile initializeStatus; struct J9Method* ramMethods; J9Class UDATA* ramStatics; struct J9Class* arrayClass; UDATA totalInstanceSize; VTable UDATA* instanceDescription; UDATA packageID; J9Methods void** iTable; void** jniIDs; struct J9Class* replacedClass; UDATA* ramConstantPool; . } J9Class; 35 OpenJ9: Classloading java.lang.Class java.lang.ClassLoader Heap Native J9ClassLoader ROMClass J9RAMClass 36 OpenJ9: Threading Heap java.lang.Thread java.lang.Thread java.lang.Thread Native J9JavaVM J9VMThread J9VMThread J9VMThread omrthread_t omrthread_t omrthread_t 37 OpenJ9: Threading • Cooperative threading model • Thread states • VM access • Exclusive access • Wait, Sleep, Blocked • Halted (exclusive) 38 • Written in C++ • Switch statement / computed goto • Executes: • bytecodes • INLs • builds stack frames • Transition to the JIT OpenJ9: Interpreter 39 OpenJ9: Interpreter state java.lang.Thread SP A0 PC Method J9VMThread omrthread_t 40 OpenJ9: Interpreter state java.lang.Thread SP A0 PC ROMMethod Method J9VMThread Bytecodes J9Method omrthread_t 41 OpenJ9: Interpreter state 0 Java stack Pending Frame Temps java.lang.Thread Args SP A0 PC ROMMethod Method J9VMThread Bytecodes J9Method omrthread_t 42 OpenJ9: Testarossa JIT 4 3 OpenJ9: Testarossa JIT compiler Profiler Interpreter Profile Info Sampling Thread Profile Manager Hardware counters JIT Profile Info 44 OpenJ9: Testarossa JIT compiler Profiler Interpreter Profile Info Runtime Environment/ Configuration Sampling Thread •Options Profile Manager •Object Model Hardware counters •Memory •Threading •Tracing JIT Profile Info 45 OpenJ9: Testarossa JIT compiler IL Generation Profiler Interpreter Profile Info Runtime Environment/ Configuration Sampling Thread •Options Profile Manager •Object Model Hardware counters •Memory •Threading •Tracing JIT Profile Info 46 ILGen a += b; iload a iload b iadd istore a iload a iload b isub bipush 2 imul istore a 47 ILGen a += b; iload a iload b iadd istore a iadd iload a istore a iload a iload b iload b isub bipush 2 imul istore a 48 ILGen a += b; iload a iload b iadd istore a iadd iload a istore a iload a iload b iload b isub bipush 2 imul istore a 49 IL Generator a += b; iload a iload b iadd treetop istore a iadd iload a istore a iload a iload b iload b isub bipush 2 imul istore a 50 IL Generator treetop treetop treetop treetop treetop treetop treetop treetop treetop treetop treetop 51 OpenJ9: Testarossa JIT compiler IL Generation Profiler Interpreter Profile Info Runtime Optimizer Environment/ cold warm hot very hot profiling scorching AOT FSD Configuration Analyses and Optimizations Sampling Thread •Options Profile Manager •Object Model Hardware counters •Memory •Threading •Tracing