A presentation for PL/I and COBOL developers about Java. Not a course, but a technical deep dive. Parts are reused from an earlier Jave on Mainframe presentations, but most is new stuff.
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Java on the Big Iron: Why, What and How
1. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Java is a new Language
on the Mainframe
Copenhagen, 8th January 2016
Michael Erichsen,
Xact Consulting A/S,
michael.erichsen@xact.dk
2. Agenda
• Why Java on z?
• Which kind of language is Java?
• How is Java implemented on z?
• How do I develop mixed language Java applications on z?
• What is the security setup?
• What do I need to learn?
3. Second Slot after Lunch?
This is surely the Graveyard Shift!
• What do you think
System.exit()
will do?
• What do you think it will do in
CICS?
4. Second Slot after Lunch?
This is surely the Graveyard Shift!
• Exactly the same as a
COBOL STOP RUN in CICS!
5. System.exit() in CICS
13.16.28 STC00106 +DFHSJ0214 CICSTS51 019
13:16:28 CICSTS51 A class in a JVM Server has invoked System.exit(). CICS will shut down immediately.
13.16.28 STC00106 +DFHDU0201 CICSTS51 ABOUT TO TAKE SDUMP. DUMPCODE: ASJS , DUMPID:
1/0023
13.16.50 STC00106 +DFHTM1703 CICSTS51 CICS is being terminated by userid CICSUSER in transaction
HT01 at netname SC0TCP29.
13.16.50 STC00106 +DFHMQ0410 I 01/05/2016 13:16:50 CICSTS51 CICS immediate shutdown detected.
Adapter terminated.
13.16.52 STC00106 BPXP018I THREAD 1F8EBC0000000000, IN PROCESS 67174429, ENDED WITHOUT
BEING UNDUBBED WITH COMPLETION CODE 0033E000, AND REASON CODE 00000000.
…
13.17.03 STC00106 +DFHDU0303I CICSTS51 Transaction Dump Data set DFHDMPA closed.
13.17.03 STC00106 +DFHKE1799 CICSTS51 TERMINATION OF CICS IS COMPLETE.
13.17.12 STC00106 $HASP395 CICSTS51 ENDED
6. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Why Java on z?
7. Java on the Big Iron
• Open the mainframe to a new generation of developers
• Portability of applications
• Wide choice of open and closed source packages
• Typical use: Non-mixed, Java only
– E.g. in WebSphere, batch, CICS, IMS, or DB2 Stored procedures
10. Old or New?
• OO is just a way to do some
categories of computing
– Not something given to Moses on
tablets
• The first OO language, Simula,
was formalized in 1962-1965
– Last version 1986
– Latest Java version 8: 2014
• COBOL was formalized in 1959-60
– Latest ISO standard: COBOL 2014
– Latest version 5.2: 2015
10
11. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
What Kind of Language is Java?
12. COBOL and other 3GL* Words
• The Compiler creates an object
from a source
*) 3GL: Third Generation
Language, like PL/I and COBOL
13. COBOL and other 3GL Words
• A pseudo-assembler listing is
produced on the way
14. COBOL and other 3GL Words
• The Binder (Linker) binds the
object into a program object or
load module
.0..............................................................................
0F000000000000000000000000000000000000000000000000000000000000000000000000000000
30000000000000000000000000000000000000000000000000010000000000000000000000000000
------------------------------------------------------------------------------
...............................................................-........HELLOCOB
000000000000000000000000000000000000000000000000000000000000000600000000CCDDDCDC
30000001000000000000000000000000000000000000000000000000000000000000000885336362
------------------------------------------------------------------------------
.........................................@.......................@......C_CEESG0
000000000000000000000000000000000000000008000000000000000000100008000000C6CCCECF
310100020001000000000000000000000000000010000000000000000000030A0030000A3D355270
------------------------------------------------------------------------------
...03...........................................................................
000FF000000000000000000000000000000000000000000000000000000000000000000000000000
32003000000000000000000000000000000000000000000000000000000000000000000000000000
------------------------------------------------------------------------------
...........................ì.............@..............................C_CODE..
000000000000000000000000000500000000000008000000000000000000100000000000C6CDCC00
300100030001000000000000008800000000000010000000000000000000030A003000063D364500
------------------------------------------------------------------------------
........................................................................HELLOCOB
000000000000000000000000000000000000000000000000000000000000100000000000CCDDDCDC
31020004000300000000000000000000000000001000000000000000000000020300000A85336362
16. Java Source
• The Compiler compiles source
into bytecode
• There is no linking/binding for
Java
– Each class is loaded separately on
demand
17. Java Bytecode
• Java bytecode is the instruction
set of the Java virtual machine
• This is a symbolic representation
Compiled from "Hello.java"
public class dk.xact.michael.BatchHello.Hello {
public dk.xact.michael.BatchHello.Hello();
Code:
0: aload_0
1: invokespecial #8 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #16 // Field
java/lang/System.out:Ljava/io/PrintStream;
3: ldc #22 // String Hello from batch
5: invokevirtual #24 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
19. Java at Runtime
• The Java Classloader executes these steps for each class:
– Load
• Loading brings the bytecode into the JVM
– Link
• Verification ensures the class/interface is structurally correct
• Preparation involves allocating memory needed by the class/interface
• Resolution resolves symbolic references
– Initialize
• Initialization gives the proper initial values to the class variables
20. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
How is Java implemented on z?
22. Java Native Interface (JNI) is the Bridge
• JNI enables Java code running in a JVM to call and be called by
native applications and libraries written in other languages
• Functionality implemented in separate C or C++ files
– Convert native arrays to/from Java arrays, native strings to/from Java
strings, instantiate objects, throw exceptions, etc.
23. Sample COBOL JNI Program
PROGRAM-ID. "DBBATCOB" RECURSIVE.
REPOSITORY.
Class DbBatchJava is "DbBatchJava"
Class jstring is "jstring".
WORKING-STORAGE SECTION.
01 parmString OBJECT REFERENCE jstring.
LINKAGE SECTION.
COPY JNI.
PROCEDURE DIVISION.
Set address of JNIEnv to JNIEnvPtr
Set address of JNINativeInterface to JNIEnv
CALL "NewStringPlatform” USING BY VALUE JNIEnvPtr ADDRESS OF input-string
ADDRESS OF parmString 0 RETURNING RC.
INVOKE DbBatchJava "sayHello” USING BY VALUE parmString RETURNING RC.
24. Sample called Java Program
public class DbBatchJava {
public static int sayHello(String inputString) {
System.out.println("DB Batch Java received " +
inputString);
return 4711;
}
}
25. JDBC
• JDBC (Java Data Base Connection)
• Lower part implemented as C++
program objects
• Upper part implemented as Java
classes calling through JNI
• Note that the jar files in the
figure are really symbolic links to
the program objects in the /IBM
folder
26. Which Runtimes?
• Batch
– BPX
– C:OZ
– JZOS
– BCD
• CICS
– JVMServer
• JCICS
• OSGi
• JDBC Type 2 (Local)
• SQLJ (Static)
– Liberty
• PHP
• Mobile
• Servlets
• JSP
• SAML
• JDBC Type 4 (Over TCP/IP)
• DB2
– Stored procedures
• IMS
– JMP
– JDBC
• MQ
– WMQ API
– jms
• WAS
– ”Classic”
– Liberty
• zLinux
All of them!
27. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Challenges
28. Theory and Practice
• Processor been optimized for the
JVM
• JVM has been optimized for the
processor
• You should be at the highest level
of both
– Z13 boxes
– Java 8
• In theory performance
comparable between Java and
3GL
29. Theory and Practice
• In theory, there is no difference between theory and practice
• But, in practice, there is
30. Theory and Practice
• Theory
– You understand everything
– Nothing works
• Practice
– Everything works
– Nobody knows why
• Here we unite theory and
practice
– Nothing works
– Nobody understands why
32. Virtualization Conflicts
• Mainframe has excelled in virtual storage and virtual machines
since the 1960’es
– Based on a set of civilized traffic rules in a multi-tenant system
• Java has its own Virtual Machine
– Raised as a spoiled only child with no manners
– Grabs all the storage it can immediately
• Has been handled on z in different ways over time
• JVM on top of Virtual Storage on top of z/OS perhaps on top of
z/VM on top of PR/SM...?
33. JVM Load and Initialization
• Can take a lot of MIPS
– You should minimize loads
– You should reuse JVM’s
34. Shared Class Cache
• A shared class area for one or more JVM’s improves startup time
– Lots of classes are already preloaded
• Switch on shared classes with the -Xshareclasses command-line option
– Virtual memory footprint reduction when using more than one JVM
– Loading classes from a populated cache is faster than loading classes from disk
– Improved startup
– Classes are already in memory and partially verified
– Benefits applications that regularly start new JVM instances doing similar tasks
– Cost to populate an empty cache with a single JVM is minimal
• Both relevant for CICS and batch
35. CICS OSGi middleware bundles
• JVMProfile option OSGI_BUNDLES
• Middleware bundles installed and activated in the OSGi
framework when JVM is initialized
• OSGI_BUNDLES=/u/example/pathToBundleDirectory/B1.jar,
/u/example/pathToBundleDirectory/B2.jar
36. Storage Differences
• Storage is static in COBOL,
HLASM, PL/I etc.
• Storage is dynamic in Java
• You should not call from Java to
COBOL with an area that has
not yet been allocated by Java
– Storage violations
– Null pointer exceptions
37. COBOL Storage Allocation
• WORKING-STORAGE normally
allocated from LE heap storage
– If you declare it, it is being
allocated
• LOCAL-STORAGE allocated from
LE stack storage
• External variables allocated from
LE heap storage
• LE stack storage is automatically
created by LE and is used for
routine linkage and automatic
storage
• LE heap storage is dynamically
allocated at a routine's first
request for storage that has a
lifetime not related to the
execution of the current routine
38. Java Storage Allocation from LE Heap
• The Java heap that garbage collection manages is allocated
during JVM startup as a contiguous area of memory
– Its size is that of the maximum Java heap size parameter
– Allocate for the maximum heap size to ensure that one contiguous
area will be available should heap expansion occur
• Explicit calls to malloc() by the JVM, or by any native JNI (Java
Native Interface) code that is running under that Java process
– This includes application JNI code, and vendor-supplied native
libraries; for example, JDBC drivers
39. Garbage Collection
• Java normally does not do explicit
allocation and deallocation
• Deallocation done as Garbage
Collection (GC)
– All active objects marked and copied
away
– All unused deleted by compacting
storage
– Done in different pools to handle
short and long lived objects
separately
40. Garbage Collection Issues
• Pause time
• Pause predictability
• CPU usage
• Memory footprint
– Virtual footprint
– GC interaction with paging and
swapping
• The unimaginable memory leaks
– Unintended object retention
41. IBM JVM Garbage Collection Policies
• -Xgcpolicy:optthruput
– For “batch” type apps
• -Xgcpolicy:optavgpause
– For apps with responsiveness
criteria
• -Xgcpolicy:gencon
– Highly transactional workloads
• -Xgcpolicy:subpools
– Large systems with allocation
contention
42. Heap size tuning
• Java heap size tuning is an art
– Small heaps get filled up quickly
• GC runs often
– Large heaps hold a lot of objects
• Each GC takes a long time (”Stop the World”)
– Need tools, measurements, statistics and tuning
• Java heaps lives on top of Language Environment heaps and z/OS
virtual storage
– LE heaps can be measured and tuned
– Paging and swapping can be the result of overallocating heaps
44. Health Center
• An agent is included in the IBM JVM in recent versions, so you
don’t have to install anything
• A server is part of IBM Support Assistant Team Server
– If you have the authority you can alternatively install it and run it on
your own workstation
• A client can run in a browser or in Eclipse
52. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Development
53. Plain Java Development
• All Java tools can be used
• Rational Developer for z has
support for special API’s like
JCICS and for OSGi
• The IBM JVM is 100%
compatible with Sun/Oracle
from the development side
– Differences only in JVM
implementation and in toolbox
54. Addressing Modes
• COBOL runs in 31 bit mode
• Java can run in 31 or 64 bit
mode
• Calling between 31 and 64 bit
programs can yield interesting
results
55. Java in Batch
• BPX
– Unix batch launcher
• Co:Z
– Executes the Unix program or shell in the same address space, which
simplifies job accounting and allows for the use of resources such as DD
statements by the Unix program
• JZOS
– Java batch launcher
• BCD
– Managed environment for Java
– Allows interoperability with COBOL and PL/I
56. BPXBATCH and BPXBATSL
• USS batch launcher facilities
– Can launch a JVM in a batch job
• BPXBATCH Limitations
– No flexible configuration of the USS environment for each job
– No condition codes passed
– Separate address space
– No use of DD statements
– Stderr and stdout not written before the step has finished
• BPXBATSL supports DD statements
• C:OZ is an improved solution, supplied as Freeware from Dovetailed
Technologies
57. JZOS
• Java batch launcher
– Written in Java by Dovetailed Technologies and acquired by IBM
• Call the JZOS batch launcher load module from JCL to create a JVM under
UNIX System Services
• DD statements
– Java main class
– Java version that is needed for this job
– Classpath
– Libpath
– Additional JVM arguments, also from a PDSE member
– JVM Encoding
58. JZOS Advantages
• Launcher and JVM run in the same address space
• Makes job accounting easier
• Allows the use of DD statements
• System.out.println() and System.err.println() redirected to
SYSOUT and SYSERR
• Easier to integrate in a scheduling environment
59. z/OS Batch Runtime (BCD)
• Java-focused, platform-neutral programming model
• Managed environment for Java
– Allows interoperability with COBOL and PL/I
– Supports DB2 hybrid applications
• Initialization
– Set up the job step under a Resource Recovery Services (RRS)
managed global transaction
– Call the primary COBOL or Java application after initialization of the
environment
60. z/OS Batch Runtime (BCD)
• Mixed COBOL/PL/I and Java batch application with a shared
DB2 connection
– Coexistence of SQL, JDBC and SQLJ
– Updates to DB2 are committed in the same unit of work
• Consistent with IBM WebSphere-based batch
• Must run in 31 bit mode, because COBOL and PL/I are 31 bit
• JZOS launches the Java program
com.ibm.zos.batch.container.BCDBatchContainer
that invokes your Java, COBOL and PL/I programs
61. Seamless Debug in CICS
• COBOL & PL/I
– Connect to DTCN in Host Connections
– Create a DTCN Server Profile
• Java
– Open RDz Debug Configurations
– Start the Remote Java Application pointing to the Java project and
CICS
• Run the transaction in CICS
65. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Security
66. Batch and CICS Liberty
• EJBROLE
– Member class for Enterprise Java
Beans authorization roles
• GEJBROLE
– Grouping class for Enterprise Java
Beans authorization roles
• JAVA
– Contains profiles that are used by
Java for z/OS applications to
perform authorization checking for
Java for z/OS resources
69. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Education
70. What do I need to learn?
• Object Orientation
– Inheritance
– Encapsulation
– Polymorphism
• Java syntax & semantics
• Libraries
– Supplied with Java
– Supplied by IBM
– Open source
• Development tools
– Eclipse
– RDz
– Mapping tools
– ...
• Performance tools
• Site & business specific
knowledge
71. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Moderniza-
tion
Conversion
Business
Software
Consultants
72. FOR MORE INFORMATION PLEASE CONTACT
Xact Consulting A/S
Arnold Nielsens Boulevard 68A
DK-2650 Hvidovre
+45 7023 0100
info@xact.dk
www.xact.dk
Enterprise Modernization
Thank you for your attention