- A Concurrent Affair - https://www.concurrentaffair.org -

New Mint Release: r15858

I made a new release of Mint [1] and DrJava with Mint [2] yesterday: September 29, 2010 (r15858). The latest release is, as always, available from the Mint implementation [3] page:

We have added the [cci lang=”java”]edu.rice.cs.mint.runtime.CodeFree[/cci] interface and the [cci lang=”java”]edu.rice.cs.mint.runtime.CheckedExceptionInCode[/cci] exception class.

The [cci lang=”java”]CodeFree[/cci] interface provides a different, more transparent way of specifying separable classes that can be used for non-local assignments and CSP. When a class is declared to implement the [cci lang=”java”]CodeFree[/cci] interface, the class is guaranteed to be code-free, provided a number of static checks are passed:

  1. All field types and method return types are code-free, either using the old definition that required the types to be [cci lang=”java”]final[/cci], or by themselves implementing the [cci lang=”java”]CodeFree[/cci] interface.
  2. The same applies to all subtypes of types implementing the [cci lang=”java”]CodeFree[/cci] interface. It is an error to extend a class declared to be code-free using the [cci lang=”java”]CodeFree[/cci] interface and then to add a field containing or a method returning code.

This new rule makes it simpler to work with non-primitive types since the classes do not have to be [cci lang=”java”]final[/cci] anymore. In the past, lifting had to be done instead of using CSP; that is not necessary anymore. Consider the old code with the required [cci lang=”java”]lift[/cci] method and its application instead of straight-forward CSP:

[cc lang=”java”]public abstract class Value {
public separable int intValue() { throw new WrongTypeException(); }
public separable boolean booleanValue() { throw new WrongTypeException(); }
public separable abstract boolean valueEq(Value other);
public separable abstract Code lift();
}

public class IntValue extends Value {
private int _data;
// …
public separable Code lift() {
final int lfData = _data; // hack to help the Mint compiler
return <| (Value) new IntValue(lfData) |>;
}
}

public class BooleanValue extends Value {
private boolean _data;
// …
public separable Code lift() {
final boolean lfData = _data; // hack to help the Mint compiler
return <| (Value) new BooleanValue(lfData) |>;
}
}

// …

public class Val implements Exp {
private Code _value;
public Val(final Value value) {
_value = value.lift(); // lifting here
}
// …
}[/cc]
and the new code that doesn’t require the [cci lang=”java”]lift[/cci] method anymore:

[cc lang=”java”]public abstract class Value implements CodeFree, Serializable {
public separable int intValue() { throw new WrongTypeException(); }
public separable boolean booleanValue() { throw new WrongTypeException(); }
public separable abstract boolean valueEq(Value other);
}

public class IntValue extends Value {
private int _data;
// …
}

public class BooleanValue extends Value {
private boolean _data;
// …
}

// …

public class Val implements Exp {
private Code _value;
public Val(final Value value) {
_value = <| value |>; // straight-forward CSP
}
// …
}
[/cc]

Please note that a class used in CSP still needs to be serializable if the code object it is used in is to be saved using [cci lang=”java”]MintSerializer.save[/cci]. That means that whenever you implement [cci lang=”java”]CodeFree[/cci], you should consider also implementing the [cci lang=”java”]java.io.Serializable[/cci] interface.

The second change involves the way checked exceptions are thrown inside a code object. In the past, checked exceptions were not allowed, because the [cci lang=”java”]Code.run()[/cci] method did not have a [cci lang=”java”]throws Throwable[/cci] clause.

We still didn’t add such a clause, because it would essentially require a try-catch construct around every call to [cci lang=”java”]Code.run()[/cci]. Instead, checked exceptions are caught and rethrown wrapped in a [cci lang=”java”]edu.rice.cs.mint.runtime.CheckedExceptionInCode[/cci] unchecked exception. Here is an example:

[cc lang=”java”]public static separable void m() throws IOException {
new File(“/this/is/a/bad/path”).createNewFile(); // throws IOException
}

// …

SafeCode c = <| { m(); } |>;
try {
c.run();
}
catch(CheckedExceptionInCode ce) {
Throwable cause = ce.getCause();
// …
}[/cc]

We also improved error checking for calls to separable methods and fixed a bug that required [cci lang=”java”]SafeCode[/cci] in too many places.

The version of DrJava with Mint is based on the current trunk (and therefore is newer than the updated stable release of DrJava that was recently made available).

(Re-posted from The Java Mint Blog [7].)

[8] [9]Share [10]