ActiveJava

Copyright Tristan Aubrey-Jones May 2008.

Abstract: A project investigating and developing an implicitly concurrent programming language, based on a metaphor taken from the physical world is reported. Uses a programming paradigm where programs consist of systems of autonomous agents, or active objects which communicate via message passing. A language enhancing Java with actors and linear types is presented. Example programs are written, compiled, and executed to evaluate the usefulness of the language. The language found to provide a familiar notation for implicit parallelism, and a compelling new model for concurrency, combining the performance of shared variables with the elegance of message passing.

Introductory Slides (PDF), Report (PDF),
ActiveJava compiler prototype (ajavac), ActiveJava runtime library (ajava_lang).

Examples:

calc - pocket calculator actor program
dining - dining philosophers actor program (never deadlocks)
sort - parallel quicksort implementation ("SortBenchmark" sorts 10,000 random integers using actors, java threads, and sequentially and compares)
To compile examples use:
compile.bat ./calc
compile.bat ./sort
compile.bat ./dining
To run examples use:
run ./calc Main
run ./dining Main
run ./dining Main fast
run ./sort Main
run ./sort SortingBenchmark

DebugIntSorter.ajava

home Home   up Up   ( Download )


import org.taj.ajava.util.*; /** Sorter, performs quicksort on integer arrays using array partitioning */ public aclass DebugIntSorter returns IntegerArray { private static final int MIN_PARTITION_SIZE = 200; private int depth; public DebugIntSorter() { this(0); } public DebugIntSorter(int depth) { this.depth = depth; } // sorts an integer array, using // quicksort public react(IntegerArray array) { // check base case if (array.size() <= MIN_PARTITION_SIZE) { // sort this section sequentially SorterMethods.sortArray(array); // return return array; } else { // inductive case // partition array int pivotIndex = SorterMethods.choosePivotIndex(array); int pivotNewIndex = SorterMethods.partitionArray(array, pivotIndex); Stdout <-- Integer.toString(depth) + ": Pivot Index: " + Integer.toString(pivotNewIndex) + "\n"; Stdout <-- Integer.toString(depth) + ": Split : " + array.toString() + "\n"; // split array at partition int[] indices = new int[1]; indices[0] = pivotNewIndex; IntegerArray[] parts = array.split(indices); Stdout <-- Integer.toString(depth) + ": Split into: " + parts[0].toString() + " and " + parts[1].toString() + "\n"; // sort left and right concurrently DebugIntSorter lhs = new DebugIntSorter(depth+1); DebugIntSorter rhs = new DebugIntSorter(depth+1); // (need semi colons at end of fork statements fork ( parts[0] = lhs(parts[0]); parts[1] = rhs(parts[1]); ) { Stdout <-- Integer.toString(depth) + ": Merging: " + parts[0].toString() + " and " + parts[1].toString() + "\n"; // merge them back together array.merge(parts); Stdout <-- Integer.toString(depth) + ": Merged into: " + array.toString() + "\n"; // return sorted list // (having the return shared at the end // wouldnt currently work...) return array; } } } }