Wednesday, October 20, 2010

New Mint Release: r15952

I made a new release of Mint and DrJava with Mint yesterday: October 19, 2010 (r15952). The latest release is, as always, available from the Mint implementation page:

There were several bug fixes regarding assignment to variables declared as CodeFree, the places where SafeCode is required, treatment of type variables with bounds in escapes, and array types, which were erroneously printed as '[Lfoo/bar;' or '[B'.

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).

Sunday, October 10, 2010

GPCE'10 Tutorial Slides

The slides for our GPCE 2010 tutorial presentation "Agile and Efficient Domain-Specific Languages using Multi-Stage Programming in Java Mint" are available now as PowerPoint and PDF file.

The zip file with the source code for our GPCE 2010 tutorial is available too.

The simplest way to experiment with Mint is to download the latest version of DrJava with Mint.

GPCE'10 Tutorial Source

Here is a zip file with the source code for our GPCE 2010 tutorial.

The simplest way to experiment with Mint is to download the latest version of DrJava with Mint.

Thursday, September 30, 2010

New Mint Release: r15858

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

We have added the edu.rice.cs.mint.runtime.CodeFree interface and the edu.rice.cs.mint.runtime.CheckedExceptionInCode exception class.

The CodeFree 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 CodeFree 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 final, or by themselves implementing the CodeFree interface.
  2. The same applies to all subtypes of types implementing the CodeFree interface. It is an error to extend a class declared to be code-free using the CodeFree 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 final 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 lift method and its application instead of straight-forward CSP:

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<Value> lift();
}

public class IntValue extends Value {
private int _data;
// ...
public separable Code<Value> 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<Value> lift() {
final boolean lfData = _data; // hack to help the Mint compiler
return <| (Value) new BooleanValue(lfData) |>;
}
}

// ...

public class Val implements Exp {
private Code<Value> _value;
public Val(final Value value) {
_value = value.lift(); // lifting here
}
// ...
}
and the new code that doesn't require the lift method anymore:

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> _value;
public Val(final Value value) {
_value = <| value |>; // straight-forward CSP
}
// ...
}


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 MintSerializer.save. That means that whenever you implement CodeFree, you should consider also implementing the java.io.Serializable 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 Code.run() method did not have a throws Throwable clause.

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

public static separable void m() throws IOException {
new File("/this/is/a/bad/path").createNewFile(); // throws IOException
}

// ...

SafeCode<Void> c = <| { m(); } |>;
try {
c.run();
}
catch(CheckedExceptionInCode ce) {
Throwable cause = ce.getCause();
// ...
}
We also improved error checking for calls to separable methods and fixed a bug that required SafeCode<T> 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).

Thursday, September 16, 2010

New Mint Release: r15772

We have just made a new release of Mint and DrJava with Mint: September 16, 2010 (r15772). The latest release is, as always, available from the Mint implementation page:


We have added the edu.rice.cs.mint.runtime.MintSerializer class to it that can write code object, including CSP data, to a jar file (or whatever stream you like), and then restore it again. Here is a very simple example:

Code c = <|123|>;
File f = new File(dir, "IntegerCode1.jar");
MintSerializer.save(c, "IntegerCode1", f);

Integer s = MintSerializer.load(f);
System.out.println(s);


The version of DrJava with Mint is based on the current trunk (and not on updated stable release of DrJava that was made available this week).

Wednesday, September 1, 2010

Mint on the Mac

I guess I'm a bit behind the technology curve. The MacBook that I'm using as one of my development machines is one of the original white Intel MacBooks with a Core Duo CPU (not Core 2 Duo). It's a 32-bit machine, and Apple doesn't offer Java 6 for 32-bit computers.

Mint, however, requires a version of Java 6, which is why we recommended using SoyLatte to run Mint. That comes with all kinds of inconveniences because SoyLatte uses X11 for its GUIs, which means DrJava needs to run under X11.

Yesterday I tested Mint and DrJava with Mint using Apple's Java SE 6.0 Release 1 Developer Preview 6 (file name: javase6release1dp6.dmg), which I still had floating around and which is the last version of Apple's Java 6 that still runs on 32-bit Macs. It works! SoyLatte is only required if you don't have a version of Java 6 (either Apple's official version on 64-bit Macs, or Apple's Java SE 6.0 Release 1 Developer Preview 6 on 32-bit Macs) on your Mac.

I have updated the instructions on how to install Java Mint on the Mac and how to run DrJava with Mint accordingly.

Monday, August 30, 2010

New Mint Release: r15716

As mentioned before, Eddy and I discovered a problem with type variables in code generated by the Mint compiler. We have now fixed this problem in the new release of Mint and DrJava with Mint: August 30, 2010 (r15716). The latest release is, as always, available from the Mint implementation page:
The problem occurred when the programmer used a type variable inside a bracket. An example of this would be a generic method like this:
public separable <X> Code<X> fun(Code<X> c1, Code<X> c2) {
return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ?
`c2 : `c1 ) |>;
}
This caused Mint to generate 2nd stage code that contained the type variable X unbound. Unfortunately, the types are erased, and there is no way to find out what type X actually refers to at runtime, e.g. by writing something like X.class (this generates the Java compiler error "cannot select from a type variable").

To get around this problem, we now require a final instance of type Class<X> to be in scope for every type variable X. For example, in the generic method above, there is a type variable X that is being used in the bracket. Therefore, we now have to have a final instance of Class<X>somewhere in scope, for example as a method parameter.
public separable <X> Code<X> fun(Code<X> c1, Code<X> c2,
final Class<X> xc) {
return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ?
`c2 : `c1 ) |>;
}
That's all that is necessary. The variable xc is not actually used in the code, it just needs to be in scope.

Tuesday, August 24, 2010

New Mint Release: r15707

When working on our GPCE tutorial, Eddy and I discovered a small bug in the Mint compiler which I have now fixed in the new release of Mint and DrJava with Mint: August 24, 2010 (r15707). The latest release is, as always, available from the Mint implementation page:
The only change I made was to fix the let expression pretty printer when the expression contained more than one declaration.

The problem never came up before because we only had one declaration per let expression, and it was always possible to rewrite

let int x = 1, y = 2; x+y


as

let int x = 1; let int y = 2; x+y


We are pushing the Mint compiler more, and we have discovered another problem with generic methods. Currently, Mint generates a class extending Code<X> with X occurring unbound when this method is called:

public separable abstract <X> Code<X> fun(Code<X> c1, Code<X>
c2, Object... param);


We are looking at making another bugfix soon.

Friday, August 20, 2010

New Mint Release: r15700

On Friday, I created a new release of Mint and DrJava with Mint: August 20, 2010 (r15700). The latest release is, as always, available from the Mint implementation page:
The only changes that we made were a small change to the build process on Mac OS, and the addition of the Range and Lift utility classes.

The Lift class allows the user to manually lift primitive values and strings when the compiler did not do that already, for example when working with arrays.

The Range class provides methods that allow many for loops to be written as foreach loops with a final loop variable that can be used across bracket boundaries immediately. Consider this example of a staged sparse matrix multiplication:

public static separable
Code<Void> smmult(final double[][] a,
Code<double[][]> b,
Code<double[][]> output,
int l, int m, int n) {
Code<Void> stats = <| { } |>;
for(final int i: range(0, l)) {
for(final int j: range(0, m)) {
Code<Double> c = <| 0.0 |>;
for(final int k: range(0, n)) {
if(a[i][k] == 0.0)
continue;
else if(a[i][k] == 1.0)
c = <| `c + (`b)[k][j] |>;
else
c = <| `c + (`(lift(a[i][k])) * (`b)[k][j]) |>;
}
stats = <| { `stats; (`output)[i][j] = `c; } |>;
}
}
return stats;
}


is a lot cleaner than

public static separable
Code<Void> smmult(final double[][] a,
Code<double[][]> b,
Code<double[][]> output,
int l, int m, int n) {
Code<Void> stats = <| { } |>;
for(int i = 0; i < l; i++) {
for(int j = 0; j < m; j++) {
final int ii = i;
final int jj = j;
Code<Double> c = <| 0.0 |>;
for(int k = 0; k < n; k++) {
final int kk = k;
if(a[i][k] == 0.0)
continue;
else if(a[i][k] == 1.0)
c = <| `c + (`b)[kk][jj] |>;
else
c = <| `c + (`(lift(a[ii][kk])) * (`b)[kk][jj]) |>;
}
stats = <| { `stats; (`output)[ii][jj] = `c; } |>;
}
}
return stats;
}


The ii, jj, and kk variables aren't necessary anymore.

Monday, August 16, 2010

GPCE'10 Tutorial Lecture: Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint

Eddy, Walid, and I proposed a tutorial lecture for GPCE'10, and we're delighted to report that it has been accepted for presentation on Sunday, October 10, 2010.

Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint

Domain-specific languages (DSLs) are a powerful productivity tool because they allow domain experts, who are not necessarily programming experts, to quickly develop programs. DSL implementations have unique constraints for programming languages because they must be efficient, in order to ensure high productivity, but they must also be agile, in order to meet the rapidly changing demands of their domains. In this tutorial we show how multi-stage programming (MSP) can be used to build staged interpreters, which combine the agility of interpreters with the efficiency of compilers. The tutorial is conducted in Java Mint, an multi-stage Java based on recent work incorporating MSP into imperative object-oriented languages. In the first half of the tutorial, we introduce MSP by demonstrating how to write a staged interpreter for a number of basic language constructs, such as recursive functions, conditionals, and let expressions. In the second half, we extend our staged interpreter to take advantage of several well-known compiler optimizations, including type inference, constant folding, and static parallel loop scheduling. We highlight the opportunities afforded by using MSP with object-oriented design to quickly create efficient DSL implementations.



Brief Outline of Tutorial

This tutorial uses Java Mint to introduce MSP in imperative,
object-oriented languages. We will progress as follows:


  1. Introduction to MSP, the three language constructs "bracket",
    "escape" and "run", and their use in Java Mint.
  2. Brief overview of MSP applications other than interpreters.
  3. Development of a staged interpreter for a small DSL. We incrementally add:
    1. Arithmetic expressions
    2. Conditionals
    3. Recursive functions
    4. Let expressions
  4. Application of compiler optimizations in the interpreter for our DSL. We discuss:
    1. Extending the interpreter with multiple data types
    2. Type inference
    3. Constant folding
    4. Static parallel loop scheduling


Biographies

Mathias Ricken is a doctoral candidate in the Programming Languages Team at Rice University and one of the principal developers of the DrJava integrated development environment. His research interests include concurrent programming, extending the Java language, and computer science education. He is the developer of the Concutest concurrent unit testing framework and has created various experimental extensions of Java to address, for instance, programming with meta-data. Currently, Mathias is contributing to Java Mint, a multi-stage extension of Java that allows safe and expressive statically typed program generation and specialization in an imperative language setting.

Edwin Westbrook is a post-doctoral researcher at Rice University. His primary interests are in developing techniques for implementing and verifying properties of domain-specific languages (DSLs). He has worked on a number of projects in this area, including: Cinic, a type theory for building machine-checked proofs of properties of DSLs using a new approach to higher-order abstract syntax; Java Mint, a multi-stage version of Java used for efficient implementations of DSLs; and Acumen, a DSL for designing cyber-physical systems.

Walid Taha is an professor at Halmstad University. His current interest is in modeling and simulation of cyberphysical systems. He was the principal investigator on a number of research awards and contracts from the National Science Foundation (NSF), Semi-conductor Research Consortium (SRC), and Texas Advanced Technology Program (ATP). He received an NSF CAREER award to develop Java Mint. He is the principle designer Java Mint, Acumen, MetaOCaml, and the Verilog Preprocessor. He founded the ACM Conference on Generative Programming and Component Engineering (GPCE), the IFIP Working Group on Program Generation (WG 2.11), and the Middle Earth Programming Languages Seminar (MEPLS). In 2009, he chaired the IFIP Working Conference on Domain Specific Languages (DSLs).

New Version of DrJava with Mint: drjava-r5366-mint-r15665

The DrJava team released a new stable version of DrJava today, drjava-stable-20100816-r5366.

I therefore created a new release of DrJava with Mint: August 16, 2010 (drjava-r5366-mint-r15665.jar). The latest release is available from the Mint implementation page:
Nothing has changed on the Mint language side.

Thursday, July 29, 2010

New Mint Release: r15665

I just created a new release of Mint and DrJava with Mint: July 28, 2010 (r15665). It's been over a year since we made the first version of Mint available! The latest release is, as always, available from the Mint implementation page:
Nothing really changed in the Mint language or in the way Mint is implemented; however, we moved our modified javac compiler into subpackages of the edu.rice.cs.mint.comp package, which means that the compiler is now invoked using the edu.rice.cs.mint.comp.com.sun.tools.javac.Main class.

The package and class names got a bit long, but by not using the same class names as Sun/Oracle, we can use our compiler together with other compilers or the original compiler if we want to, and there won't be any class name clashes.

Thursday, July 22, 2010

New Mint Release: r15637

I just created a new release of Mint and DrJava with Mint: July 22, 2010 (r15637). It's been over a year since we made the first version of Mint available! The latest release is, as always, available from the Mint implementation page:

The DrJava team released a third beta version of DrJava almost two weeks ago, drjava-beta-20100711-r5314.

The only thing that changed on the Mint language side is the implementation of the toString() method for brackets.

There have a been plenty of new features and bugfixes for DrJava, and they have been integrated into DrJava with Mint. In fact, DrJava with Mint includes a few bugfixes that are not yet in the latest beta of DrJava.

Sunday, July 11, 2010

New Version of DrJava with Mint: drjava-r5246-mint-r15405

The DrJava team released a third beta version of DrJava today, drjava-beta-20100711-r5314.

I therefore created a new release of DrJava with Mint: May 8, 2010 (r15405). The latest release is available from the Mint implementation page:
Nothing has changed on the Mint language side.

Thursday, April 15, 2010

New Mint Release: r15405

I just created a new release of Mint and DrJava with Mint: May 8, 2010 (r15405). The release is available from the Mint implementation page:

The DrJava team released a second beta version of DrJava yesterday, drjava-beta-20100507-r5246.

Nothing has changed on the Mint language side, but there have been minor changes in the Mint build process, and several examples have been added.

There have been plenty of new features and bugfixes for DrJava, and they have been integrated into DrJava with Mint. Most importantly, DrJava with Mint will now automatically select the Mint compiler on start-up.

Wednesday, March 24, 2010

Camera-Ready Version of PLDI Paper Submitted

This afternoon, I submitted the final camera-ready version of our Mint paper that was accepted to PLDI 2010, Mint: Java Multi-stage Programming Using Weak Separability.

Eddy and I incorporated some more suggestions we had received from Julia Lawall and Sam Kamin, who sacrificed their valuable pre-OOPSLA submission time to proof-read our paper again. Thank you so much!

I'm glad that I could sign the copyright release form by myself, and that I didn't need to get the signatures of my five co-authors. That could have been a big headache: Walid is here, but I didn't see him today; Eddy and Jun are in Oxford; Yilong is an undergrad at Rice, and I haven't seen him in months; and Tamer is in Egypt. I enjoy signing other people's rights away.

All of that is done now. I think the paper got better still, and we even managed to stay six lines under the limit of twelve pages!

Camera-ready version: Mint: Java Multi-stage Programming Using Weak Separability (PDF)

Thursday, March 4, 2010

Mint Talk at Purdue

I'm visiting my friend Luke at Purdue after SIGCSE, and we arranged for me to give a talk to the CS department.

If you have the chance, come grill me on Monday, March 15, 2010 at 3:30 PM.

Computer Science Colloquia
Mint: A Multi-stage Extension of Java
Mr. Mathias Ricken
Rice University
LWSN 3102 A/B
Monday, March 15, 2010
3:30 p.m. - 4:30 p.m.

Complete Description:
Abstract:
Multi-stage programming (MSP) provides a safe way of generating code at run-time. In mostly-functional languages like MetaOCaml, this has been used to reduce the performance penalties of abstractions such as loops, recursion or interpretation. The main advantage of MSP compared to other techniques, such as string or LISP quotations, is that MSP guarantees type safety for the generated code statically, at the time the program is compiled.

Unfortunately, MSP is difficult to combine with imperative features found in most mainstream languages like Java. The central problem is "scope extrusion", which may accidentally move variables outside the scopes in which they are bound, leading to run-time errors in the generated code. This problem can be prevented if code in escapes (or "anti-quotes") is "weakly separable", i.e. the computational effects occurring inside an escape that are visible from the outside do not involve code.

We have formalized a type system, based on Lightweight Java, that uses weak separability to prevent scope extrusion, and we have proved that the type system is sound. We have also developed an implementation called Mint to demonstrate the expressivity of the type system and the performance benefits MSP can provide in an imperative setting. Since our implementation extends the Java language, our work is accessible to mainstream programmers.

This talk is based on work will be presented at the Conference on Programming Language Design and Implementation (PLDI 2010). More information is available at http://mint.concutest.org/


Bio:
Mathias Ricken is a doctoral candidate in the Programming Languages Team at Rice University and one of the principal developers of the DrJava integrated development environment. His research interests include concurrent programming, extending the Java language, and computer science education. He is the developer of the Concutest concurrent unit testing framework and has created various experimental extensions of Java to address, for instance, programming with meta-data. Currently, Mathias is contributing to Mint, a multi-stage extension of Java that allows safe and expressive statically typed program generation and specialization in an imperative language setting.

Faculty and students wishing to speak privately with Mr. Ricken should contact Jan Vitek at jv@cs.purdue.edu.


This is going to be exciting!

Monday, February 22, 2010

Mathias' Mint Talk

On February 8, Mathias gave a talk about Mint in the COMP 600 graduate seminar at Rice. The slides for "Mint: A Multi-stage Extension of Java" and the video recording are available now:

Slides (PDF)
Slides (PowerPoint)
Video Recording (on vimeo, requires Flash)

Abstract:

Multi-stage programming (MSP) provides a safe way of generating code at run-time. In mostly-functional languages like MetaOCaml, this has been used to reduce the performance penalties of abstractions such as loops, recursion or interpretation. The main advantage of MSP compared to other techniques, such as string or LISP quotations, is that MSP guarantees type safety for the generated code statically, at the time the program is compiled.

Unfortunately, MSP is difficult to combine with imperative features found in most mainstream languages like Java. The central problem is "scope extrusion", which may accidentally move variables outside the scopes in which they are bound, leading to run-time errors in the generated code. This problem can be prevented if code in escapes (or "anti-quotes") is "weakly separable", i.e. the computational effects occurring inside an escape that are visible from the outside do not involve code.

We have formalized a type system, based on Lightweight Java, that uses weak separability to prevent scope extrusion, and we have proved that the type system is sound. We have also developed an implementation called Mint to demonstrate the expressivity of the type system and the performance benefits MSP can provide in an imperative setting. Since our implementation extends the Java language, our work is accessible to mainstream programmers.

This talk is based on work done in collaboration with Edwin Westbrook, Jun Inoue, Yilong Yao, Tamer Abdelatif, and Walid Taha. A paper titled Mint: Java Multi-stage Programming Using Weak Separability has been accepted for publication in the Proceedings of the 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2010).

Wednesday, February 17, 2010

New Mint Release: r15116

I just created a new release of Mint and DrJava with Mint: February 17, 2010 (r15116). The release is available from the Mint implementation page:
There were some small changes in the approximation of weak separability to make the implementation match improvements in the paper more closely. It also disallows stitching in a Code<?> as a statement, because we can't statically know if we have to discard the result in a statement context or not.

Friday, February 12, 2010

New Mint Release: r15085

I just created a new release of Mint and DrJava with Mint: February 12, 2010 (r15085). The release is available from the Mint implementation page:
The two changes since the last release involve CSP values and escapes in bracket statements. Instead of storing CSP values in a CSP table, we now store CSP values in individual fields. This reduces the overhead by eliminating an array lookup. The serializer benchmark benefited from this, for example.

We now also allow non-void escapes in bracket statements. For example, the following code is now allowed:

Code<Integer> x = <| 1 |>;
Code<void> c = <| { `x } |>;


In the past, this caused an error because 1 was not a statement. The Mint compiler now accepts this and discards the result of the escape if it is used in statement form, but it does emit a warning.

Monday, February 8, 2010

Great News

Our paper, "Mint: Java Multi-stage Programming Using Weak Separability" (pre-print PDF), has been accepted to PLDI 2010. We look forward to spreading the word about Mint in Toronto!

Mathias just gave the first presentation about Mint in the COMP 600 graduate seminar at Rice. The slides for "Mint: A Multi-stage Extension of Java" are available (PDF).

Finally, you may already have noticed that the blog has a new URL: www.javamint.org. We currently also have some problems with the implementation URL; for now, you can use http://mint.concutest.org as a resource hub for everything Mint-related.