CCR2JR(1)

NAME
ccr2jr - CCR notation to JR code preprocessor

SYNOPSIS
ccr2jr file.ccr

DESCRIPTION

Ccr2jr converts a program written in CCR (Conditional Critical Region) notation into an equivalent one written in the JR language. The JR program is placed in file.jr, which may then be translated using jr(1).

The exact syntax of the CCR notation can be discerned by examining the CCR programs in the examples directory. Each CCR-notation construct begins with an underscore; CCR code is mixed with regular JR code.

Ccr2jr translates a CCR resource into a JR class and translates a CCR region statement into code that uses Rem's algorithm. Typically, the rest of the user's code will be a single JR class; that code needs to instantiate an instance or instances of the CCR resource (class). Variables declared within CCR resources can be used only within region statements.

Variables (data fields) declared in the CCR resource are replicated when instantiated. Variables in the CCR resource should be declared public, but they must not be declared as static; however, constants can be declared in the CCR resource as static final. The CCR resource can use static {...} and {...} initializers. Variables (and constants) declared in resources must have names distinct from names used elsewhere in the CCR program. (The same field name may appear in multiple resources, though.)

Arrays of CCR resources are supported using JR notation (i.e., Java array notation). In conventional CCR notation (e.g., see Andrews's book), each variable declared within a CCR resource is replicated within each element of the CCR resource array. In ccr2jr notation, such replication occurs due to instantiation.

The region statement has four components: classname, thisname, instance, and when. Classname is the name of the CCR resource (i.e., JR class). Thisname is a name chosen to refer to the CCR resource instance (i.e., JR object) for this region statement. when is the boolean expression controlling access to the region. Thisname is not allowed to be altered within the region statement.

A typical ccr2jr program will be placed in one file that consists of a single CCR resource followed by code that instantiates that resource and uses the resource instance. A ccr2jr program may also be divided into several files. (If necessary, the Java keyword public can precede _resource.) For example, the CCR resource might be placed in a separate file from the CCR code that uses it. For a multi-file program, all files must be presented to ccr2jr together, with their names listed on the command line such that files containing CCR resources appear before any files containing CCR region statements.

A few limitations exist to ease the implementation. Do not use names of JR predefined functions or reserved words (e.g., cap) as variable names within CCRs. Do not use identifiers beginning with r_ within CCR code. Do not use any other JR synchronization or return/reply within a CCR program.

The predefined Java method Thread.sleep, which puts the currently executing process to sleep for a while and performs a context switch to another process, is useful in CCR programs to alter the interleaving of process execution. For example, it can be used with the random number functions to obtain different interleavings to test whether a critical section algorithm works. See the programs in the examples directory for examples.

QUICK REFERENCE
_resource name { field declarations }

_region classname _with thisname = instance _when when { code }

_region classname _with thisname = instance { code }

FILES
file.ccr    CCR source file
file.jr    generated JR source file

SEE ALSO
Ronald A. Olsson and Aaron W. Keen, The JR Programming Language: Concurrent Programming in an Extended Java. Kluwer Academic Publishing (now part of Springer), 2004, ISBN 1-4020-8085-9. (see http://www.cs.ucdavis.edu/~olsson/research/jr).

Gregory R. Andrews and Ronald A. Olsson, The SR Programming Language: Concurrency in Practice. Benjamin/Cummings, 1993, ISBN 0-8053-0088-0.

Gregory R. Andrews, Concurrent Programming: Principles and Practice. Benjamin/Cummings, 1991, ISBN 0-8053-0086-4.

jr(1), ccr2sr(1), csp2sr(1), m2sr(1), csp2jr(1), m2jr(1)

DIAGNOSTICS

Some erroneous CCR code will cause errors from ccr2jr. These line numbers generally correspond to the ones in the .ccr file.

Other errors in CCR code are detected by the JR or Java compilers. The line numbers for these errors will not correspond to those in the original source file, but they can be mapped back by looking in the generated code file. The generated code file contains as comments the original lines of source code along with the source file name and source line number. Thus, the line in the original source file can be located fairly easily. If, for example, the JR compiler reports an error on line 38, then look at line 38 of the generated JR file. Above that line, you might find a comment
// a.ccr, line 12  x = y+2;
This is the line that immediately caused the error.