Java and iseries Peter Eibak Peter Eibak Nordic iseries Solution IBM Danmark Specialist A/S IBM Danmark A/S Nordic iseries Solution Specialist Nymøllevej 85 2800 Lyngby Denmark Tel +45 45 23 43 11 (Office) Tel +45 28 80 43 11 (Cell) eibak@dk.ibm.com
Agenda Short introduction How Java and JVM is implemented on iseries iseries System Architecture Review The iseries Program Model Operating Java How do I start a Java application/environment? Garbage Collector Very important to understand iseries Developer Roadmap Positioning Hardware requirements Future? PAGE 2
Short introduction
Introduction At IBM Rochester, we implemented our own JVM This was a big job The decision was not made lightly First JVM on the AS/400 Port of the Sun codebase to ILE/C Common practice among platforms "Technology preview" Project was scrapped Performance was unacceptable Native threads were not (yet) available on the platform These first two sections describe the motivation iseries and AS/400 architecture discussions Show how Java "fits in" PAGE 4
iseries System Architecture Review From 30.000 feet up
iseries System Architecture Review PAGE 6
iseries System Architecture Review PAGE 7
iseries System Architecture Review PAGE 8
iseries System Architecture Review How does Java fit? Java instructions into the MI Java compiled down into bytecode (assembler-like language) Functionality related to Java bytecodes was pushed into the machine itself Result: JVM is below MI PAGE 9
iseries System Architecture Review How does Java fit? Java Developer Kit (JDK), a set of Java APIs, sits above the MI JVM is the bytecode engine that reads, interprets and runs each API element JDK is distributed by Sun. Versions (1.2, 1.3, 1.4, 1.5) PAGE 10
The iseries Program Model From 10.000 feet up
Program Model Architecture PAGE 12
Program Model Architecture Take a typical iseries case, where Thing contains TIMI "OPM (Original Program Model) instructions Key notes: * Of course, we must eventually get some hardware-specific instructions * The iseries architecture incorporates "translation" under the TIMI * The Translator is necessarily (and notoriously) hardware-specific! * The Original translator consisted of tens of thousands of lines of PL code PAGE 13
Program Model Architecture PAGE 14
Program Model Architecture How does Java fit in? PAGE 15
Creating Java Programs Several hundred feet up, falling fast But this is also where we wake up, without hidding the ground Still overview, no syntax
Direct Execution, Interpretation, and JIT PAGE 17
Direct Execution, Interpretation, and JIT PAGE 18
JVAPGM Association How and when does the association between classfile and JVAPGM occur? Explicitly, using the CRTJVAPGM command Implicitly, at "first touch" of the classfile (pre-v4r5) This association is optional PAGE 19
JVAPGM Association Explicit association using CRTJVAPGM Input is Java classfile, JAR file or ZIP file in the IFS Result is a JVAPGM being "associated" with the file JVAPGM is not a regular iseries "object" The CRTJVAPGM command has several options JAR file JVAPGMs contain "guarded" inter-class optimizations Implicitly, at "first touch" of the classfile (unconditional pre-v4r5) Class found without JVAPGM gets one created and associated Optimization level defaults to level 10 (fastest codegen) In JAR files, associations only made for classes actually "used" PAGE 20
JIT with Mixed Mode Interpretation (MMI) In V5R2 a new technology called Mixed Mode Interpretation (MMI) was introduced with JIT V4 on the iseries server. If you look at the execution patterns of the Java classes in any application, you can easily identify a few classes and methods that are executed more frequently than others. Wouldn t it be nice if you could make sure that the methods, that are executed more often, are always on the JIT heap? But how can you do this? The answer is simple: Use a threshold for each method. PAGE 21
JIT with Mixed Mode Interpretation (MMI) The threshold helps to decide if a method should be compiled by the JIT. That is, the first n times, each method is run through the interpreter. On the n+1 invocation of a method, JIT compiles it and saves the compiled version of a method on the heap. With this algorithm, the methods that are executed less than n times are never run through the JIT. And there is a high chance that the method that is invoked the most is always on the JIT heap. The threshold value is modified through the Java System property: os400.jit.mmi.threshold Default Value: 2000 Works together with the Runtime Mode for the JVM java.compiler Default Value: jitc_de (V5R2 or later) PAGE 22
Just In Time Compiler (JIT) Disadvantage that each JVM generates its "own" instructions Advantage that JIT has complete knowledge of runtime environment PAGE 23
Input/Output Structures Now we are entering the rabbit whole, so.
Native methods, the basics Native methods are methods prototyped to Java, but implemented in some other language Java 'native' keyword Native methods are (a necessary) evil Use of native code doesn't "fit" with a key value proposition of Java WORA == Write Once Run Anywhere But, even the JVM has to get down to the "metal" somehow Native methods provide a way to underpin "platform-independent" classes with their necessarily platform-dependent implementation The Java Virtual Machine implementation includes lots and lots of native methods The idea is simple: let the JVM implementation worry about any platform dependencies, so you don't have to PAGE 25
I/O uses "system" native methods PAGE 26
I/O uses "system" native methods (since V4R4) PAGE 27
Operating Java Back to normal behavior
Start of JVM on iseries Use the RUNJVA or JAVA CL command Run the java command in QShell Start a WebSphere Application Server Instance Start a Tomcat Server Note: You may think of a JVM as a special type of operating system. It requires some time to prepare a runtime environment for execution of a Java program. It starts multiple threads, loads multiple Java classes, and so on. PAGE 29
Runtime environment The Java programming language has built-in support for multithreading. This feature implies that JVM on iseries has to run in a job that supports multiple threads, for example batch immediate (BCI). Interactive Job Batc Immediate Job Thread X Thread Y JAVA CLASS ( Hello ) Java Virtual Machine (JVM) Application Code (hello.class) Garbage Collector A Java program creates many objects during its execution. These objects are created in a JVM heap. When an object is dead (meaning that no other object has a reference to this object), garbage collector removes this object from the heap. This function of the Java language and JVM is performed automatically. PAGE 30
Garbage Collection So this is where all those used bits go! Important to understand
Garbage Collection: Background "Garbage collection" (GC): is a built-in attribute of the Java Virtual Machine (JVM) fulfills a requirement of the Java language identifies objects which can no longer be "reached" disposes of "unreachable" objects, making the storage they occupied available for re-use must work correctly, or Bad Things can happen Common GC requirements and features Java objects are typically allocated from a special heap This heap is called the "garbage-collected" heap This heap only contains Java objects The storage occupied by "freed" objects is re-usable The GC typically runs in its own thread The GC is "triggered" either automatically, when an allocation amount crosses a "threshold" manually, using the java.lang.system.gc() call PAGE 32
Garbage Collector There are two operating modes of the garbage collector: Asynchronous: In this mode, the garbage collector tries to clean up the heap without stopping other threads. It runs in the background. Stop-and-copy: In this mode, all active threads are suspended while the garbage collector cleans up the heap. JVM on iseries uses the asynchronous algorithm for the garbage collector. Important: JVM and Java programs create a high number of threads. Make sure that you have an adequate setting for the activity level in the subsystem where you run JVM. Also, the health of JVM and garbage collector plays the most important role in ensuring good performance of your Java and WebSphere applications. PAGE 33
"Synchronous" Garbage Collection Note: This description is just for comparison purposes... It is not the way the iseries JVM's garbage collector works To run a synchronous garbage collection cycle, the garbage collector thread signals all Java threads to stop scans each thread for object "roots" scans for roots in global structures starting with roots, "chases" references to mark all live objects manages object finalizers, as necessary, of unmarked objects collects all unmarked objects, freeing their storage unmarks all marked (live) objects signals all threads to continue All non-gc Java threads are stopped until the collector is finished PAGE 34
Asynchronous Garbage Collection, iseries style To run an asynchronous garbage collection cycle, the garbage collector thread: signals each thread to: stop execution scan themselves for object "roots" queue the roots for return to the GC continue execution scans for roots in global structures starting with roots, "chases" references to mark all live objects manages object finalizers, as necessary, for unmarked objects collects all unmarked objects, freeing their storage unmarks all remaining (live) objects All non-gc Java threads are only interrupted long enough to scan themselves for object roots PAGE 35
Garbage Collection -- comparison diagram PAGE 36
Initial Heap Size Garbage collector execution on the iseries (but not on other platforms) is based on the initial heap size parameter. The initial heap size parameter is a threshold that triggers a garbage collection cycle. PAGE 37
Initial Heap Size It does not trigger a garbage collection cycle based on the absolute size of the heap, but on the amount that the heap has grown since the last cycle (or since startup, if no cycle has yet been run). If you specify an initial heap size of 96 MB, the first cycle runs after the 96 MB of space has been allocated. PAGE 38
Initial Heap Size The garbage collector then frees some of that space for reuse (36 MB in the example). An additional 60 MB are added to the heap to make the size of the free heap equal to the initial heap size, which is 96 MB in our example. Then garbage collection waits until another 96 MB is allocated before running again. PAGE 39
Initial Heap Size Note: The iseries definition of initial heap size is different from other platforms. On other platforms, the initial heap size determines the initial amount of memory to allocate. The maximum heap size has more influence on when garbage collector runs. In most cases, the maximum heap size should not be specified on iseries. PAGE 40
iseries Developer Roadmap Positioning
iseries Developer Roadmap V3 - Architecture 5250 5250 5250 GUI 5250 GUI 5250 GUI 5250 GUI User Interface RPG/COBOL RPG/COBOL Application Technology RPG/COBOL ILE/Java ILE (e.g. CL, RPG, COBOL, ) ILE and Java Java/EJB HTML/JSP HTML/JSP HTML/JSP HTML/JSP Servlets Servlets Servlets Servlets Portlets Portlets Portlets Portlets XML XML XML XML Connectors Process Choreography Web Services Web Services ibm.com/iseries/roadmap DB2 and SQL DB2 and SQL DB2 and SQL PAGE 42
iseries Developer Roadmap WebSphere Development Studio Client for iseries Rational Tools IBM WebFacing Tool HATS WebSphere Application Server WebSphere Portal Java Rich Client RPG IV development Integrated Language Environment (ILE) SQL XML Services Oriented Architecture (SOA) Web Services Java J2EE Business Integration Domino Lotus Workplace Enterprise Generation Language (EGL) WebSphere Business Integration and more PAGE 43
Hardware requirements Materializing the footprint
Characteristics for Java programs Memory consuming Heap size Recommendations for using cache where avilable Processor intensive Binary code JIT Compilation L2/L3 cache recommended Garbage Collection in JVM PAGE 45
What server is needed What do you look for in the Intel world 2-3 GHz processor L2/L3 cache Server technology N-way processor?? Memory 1GB? 2GB? Heap size Initial Heap Size eq. Max Heap Size eq. Physical memory One application One Server Multiple application One Server Do you partition the Intel box? What about fragmenting the processor? PAGE 46
What iseries is needed What do you look for in the iseries world Commercial Processing Workload (CPW)? Processor speed? L2/L3 cache? N-way proccessor One Application One Server Multiple Applications One Server Logical Partitioning? Dedicated/Shared processors? Memory Shared Pool/Dedicated Pool Heap Size Initial Heap Size Normally no need for Max Heap Size No theoretical limit for Heap on iseries In the end it is about Utilization of the processor, and the excess of processor ressources PAGE 47
Future? What will happen? This is not an announcement This is personal thoughts and beleives We can all only just wait and see
What can be expected down the road? It seems there are not much in the pipeline 32-bit JVM Today iseries has a 64-bit JVM Expected to have positive effect on low-end applications Smaller applications, like WebFacing, Web Interaction applications, etc. WebSphere Portal and IBM Workplace have benefits from 64-bit JVM PAGE 49
IBM J9 Technology The future? This is not an announcement It is my personal thoughts and believes High performing and efficient Virtual Machine Today used for Java 2 Micro Edition (J2ME) Mobile devices, PDAs etc. Better implementation for reuse of profiling data in the Java code Smaller footprint for Java code is a high-performance production environment offering adaptive dynamic compilation of Java application bytecodes and superior JIT (Just-In-Time) program execution performance. PAGE 50
The End & PAGE 51