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

SortingBenchmark.ajava

home Home   up Up   ( Download )


import org.taj.ajava.util.*; public actor SortingBenchmark implements Entrypoint { private static final int reptCount = 100; private IntegerArray arrayA, arrayB, arrayC; private long Da = 0, Db = 0, Dc = 0; private IntSorter a; private IntSorterThread b; public react(String[] args) { Stdout <-- "Sorting Benchmark\n"; arrayA = new IntegerArray(10000); arrayB = new IntegerArray(10000); arrayC = new IntegerArray(10000); a = new IntSorter(); b = new IntSorterThread(); this(reptCount); } react (int i) { // seed arrays SorterMethods.seedArray(arrayA); SorterMethods.copyArray(arrayA, arrayB); SorterMethods.copyArray(arrayA, arrayC); // a test long T = System.currentTimeMillis(); a(arrayA); T = System.currentTimeMillis() - T; Da += T; // b test T = System.currentTimeMillis(); b.sort(arrayB); T = System.currentTimeMillis() - T; Db += T; // c test T = System.currentTimeMillis(); SorterMethods.sortArray(arrayC); T = System.currentTimeMillis() - T; Dc += T; // loop... if (i > 1) this <-- (i - 1); else end(); } void end() { System.out.print("Actors: "); System.out.print(Da / reptCount); System.out.println("ms"); System.out.print("Threads: "); System.out.print(Db / reptCount); System.out.println("ms"); System.out.print("Sequential: "); System.out.print(Dc / reptCount); System.out.println("ms"); } } /* System.out.println("Sorting Benchmark"); IntegerArray arrayA = new IntegerArray(10000); IntegerArray arrayB = new IntegerArray(10000); IntSorter a = new IntSorter(); IntSorterThread b = new IntSorterThread(); int reptCount = 20; long Ta, Da = 0, Tb, Db = 0; for (int i = 0; i < reptCount; i++) { // seed arrays SorterMethods.seedArray(arrayA); for (int c = 0; c < arrayA.size(); c++) arrayB.set(c, arrayA.get(c)); // a test Ta = System.currentTimeMillis(); a.deliver(IntSorter.Request.create(, 0, array)) Ta = System.currentTimeMillis() - Ta; Da += Ta; // b test Tb = System.currentTimeMillis(); b.sort(arrayB); Tb = System.currentTimeMillis() - Tb; Db += Tb; } System.out.print("A: "); System.out.print((double)Da / reptCount); System.out.println("ms"); System.out.print("B: "); System.out.print((double)Db/ reptCount); System.out.println("ms"); */