InfoQ

News

Longjumps, Tailcalls, Tuples for the JVM

Posted by Geoffrey Wiseman on Sep 19, 2007 08:30 AM

Community
Java
Topics
Dynamic Languages
Tags
JVM ,
Functional Programming

This summer, John Rose made a series of posts that Charles Nutter described as "some exciting articles about the future of the JVM and a number of changes potentially for the next Java version." Although John does occasionally touch on the impact to the Java language, the emphasis here is clearly on the VM, and many of these could be seen as important for supporting other languages on the JVM, including both functional and dynamic languages.

In the first of these posts, John Rose described longjumps, or non-local exits that may be necessary for some kinds of closures within the Java language. By using exception-handling mechanics with pre-allocated (e.g. cloned) stack traces, it's possible to get a non-local exit without paying the heavy price of exceptions for flow control. Done well, this can be less than three times the cost of a local exit/return and can be optimized to a machine-level goto instruction. This is particularly performant with a build of Java 7 that optimizes the cost of Object.clone().

Next, John tackles tail calls in the JVM: the ability to compress tail recursion in an explicit, guaranteed fashion ('hard tail calls') or as a compiler optimization ('soft tail calls'). This post evoked a lively discussion in the comments about approaches and uses, but tail calls would likely be of help to functional languages — or languages with some functional-language features — on the JVM, as well as dynamic languages that would benefit from invokedynamic (JSR-292):

It would apply to invokedynamic along with the others. Having hard tailcall would give you more options for implementing dynamic calls: You could branch to a dispatch routine, which would then tailcall the normal routine. (In fact, that's how java.lang.reflect.Method.invoke could work today, at least if return values are not to be boxed.) Since Scheme is a dynamic language, tailcalls are loosely related to JSR 292.

Finally, he looks at Tuples, raising a proposal that dates from 2004 and which describes both 'pure' tuple types (plain tuples) value classes with tuple semantics, which do not need to retain identity (tagged tuples). This can also encompass support for methods with multiple return values. Again, the emphasis on the JVM rather than the Java language is clear here:

It is likely that the tuple-enhanced language will provide a canonical translation between groups of typed values and references to heap objects carrying those values. For example, each value class is likely to support a constructor whose argument signature is the tagged tuple for that class. A tuple is likely to be representable on the heap as a fixed-length Object array or as a generic immutable utility class, with primitive component values in wrapper classes (as in varargs).

And again, in the lively comment thread:

Actually integrating value-like types into Java raises difficult design issues, as you point out clearly. My purpose for this post is to indicate that adding tuples to the JVM is fairly simple, and does not require solution of the language design problems.

Do these proposals strike a chord with you? Are you more interested in seeing the JVM increase support for different languages, or the evolution of the Java language, or are these non-conflicting goals? We'll try and keep you informed on all these topics at InfoQ.

Yes, please! by Tom Nichols Posted Sep 19, 2007 10:06 AM
Re: Yes, please! by Michael Neale Posted Sep 19, 2007 6:07 PM
They are better than non-conflicting goals by Ricky Clarkson Posted Sep 19, 2007 10:41 AM
Advance the VM by Michael Krumlauf Posted Sep 20, 2007 10:26 AM
  1. Back to top

    Yes, please!

    Sep 19, 2007 10:06 AM by Tom Nichols

    Java is not necessarily the best tool for every job, but the real value is in the JVM and all of the libraries and frameworks built for it. To get the most out of the Java platform (and the JVM) it seems apparent that they should do their best to support other (read: dynamic) languages. .NET already has a head start with the DLR.

  2. Back to top

    They are better than non-conflicting goals

    Sep 19, 2007 10:41 AM by Ricky Clarkson

    Java's improvements will drive the JVM forward, and the JVM's improvements will make it easier to improve Java. Adding guaranteed tail calls and closures in the same release of Java would be a great step.

  3. Back to top

    Re: Yes, please!

    Sep 19, 2007 6:07 PM by Michael Neale

    Absolutely. Its good to see people looking at enhancements to the JVM that aren't driven with a short term view of what just the Java language spec has to do (which is much smaller then what the JVM can do).

  4. Back to top

    Advance the VM

    Sep 20, 2007 10:26 AM by Michael Krumlauf

    Of course. To constrain the VM merely to conform to the constraints of the Java language would be short-sighted. There don't seem to be any backwards-compatibility issues, so there doesn't seem to be any reason not to proceed with improvements to the VM.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.