Java's Not The Only JVM-Based Language
MartinPacker 11000094DH Comments (9) Visits (7606)
JVM-based languages have an interesting property for z/OS programmers: They are zAAP-eligible.
As we all know zAAP Eligibility brings a number of benefits - including the licence charge benefits and the ability to run on a full-speed processor even when your general-purpose processors are subcapacity ones. (I'll briefly mention zAAP-on-zIIP here for completeness, and then move on.)
You probably also know that recent zSeries and System z processor generations have very significantly boosted JVM performance. That's a combination of JVM design improvements, processor speedups and JVM-friendly processor instructions. These are properties of the JVM and processor rather than the language or the javac compiler.
I've carefully avoided saying "Java" so far in this post, apart from obliquely in the previous sentence. That's because this post explores the notion that anything that runs in the JVM can take advantage of all the above. Equally the usual considerations come into play - most notably native code (JNI) affecting eligibility and the startup cost for the JVM.
So what is a JVM? The acronym stands for "Java Virtual Machine". In reality it's a bytecode interpreter - pure and simple. There's nothing that says those bytecodes have to be created using the javac java compiler. Indeed there are a number of languages that create bytecode for the JVM.
And then there's NetRexx. Which we'll come to in a minute.
So, why the fascination with other JVM-friendly languages? First, when people talk about Modernisation on the mainframe there's often a strong component of java in it. My take on Modernisation contains two elements I want to get across:
So, back to NetRexx. It's not the only flavour of REXX available under z/OS Unix System Services. That much is well known. But it does run in the JVM - by compiling NetRexx programs to java source. This is different from the "bytecode" and "interpreted by a java" program approaches. The result is a java class or jar file, just as if you'd written it in java in the first place.
I uploaded the two necessary NetRexx jar files - from the distribution downloadable from here. These are NetRexxC.jar - the compiler - and NetRexxR.jar - the runtime. (I suspect you only really need NetRexxC.jar.) When you compile a NetRexx program you place NetRexxC.jar in you classpath and invoke java program org.
I wrote a simple NetRexx program - which uses (automatically imported) java classes: java
And that really is all there is to it. The "parse arg" and "say" instructions should look familiar to anyone who knows REXX. The rest is just stacked invocations of java classes.
As I read through the NetRexx language definition I could see a lot of advantages over traditional REXX. Two you've already seen - interoperability with java classes and running in the JVM (though the latter isn't really a language definition benefit). Others included object orientation, more sophisticated switch statements, and "--" to start a comment on a line. So I think this is a better REXX. I noted only one incompatibility (and it might not even be incompatible): "loop" instead of "do" to start a loop.
Because Classic REXX can't do Regular Expressions (though "parse" is nice) I experimented with invoking my NetRexx program (above) from classic REXX. I used BPXWUNIX (mentioned before here (and I've now corrected that post which incorrectly mentioned BPXWDYN instead) and in Hackday 9 - REXX, Java and XML ). Because the program uses the JVM I made sure to pass environment statements to BPXWUNIX setting up PATH for the JVM. This worked very well.
I could've used BPXWUNIX to call sed instead - for this use case. That probably would've been cheaper but I was proving I could call a NetRexx program from TSO REXX (in batch), passing in parameters and retrieving the result. Talking of "cheaper" I think it's important to try and avoid transitions across the BPXWUNIX boundary: It'll have a (non-zAAP) CPU cost and, if you're using the JVM as NetRexx does, it'll cost to set up the JVM and tear it down again afterwards. A pair of transitions with meaty application processing in between is going to be the most efficient.
(The previous paragraph was conjectural: It would be nice to run some benchmarks on this one day. Anyone?)
So, I'm impressed (as you can tell) with NetRexx. I think it's worth taking a look at - as indeed are the other JVM-based language implementations I mentioned. The point of this post is to demonstrate (yet again) there are choices - and considerations to go with them.