a compiler infrastructure for high-performance java€¦ · zresearch goal: to investigate...
TRANSCRIPT
A Compiler Infrastructure for High-Performance Java
Neil V. Brewster and Tarek S. Abdelrahman
The Edward S. Rogers, Sr. Department of Electrical and Computer Engineering
University of Toronto
{brewste|tsa}@eecg.toronto.edu
Brewster & Abdelrahman 2
Outline
Motivation and objectives.
Infrastructure architecture and design.
An example of use.
Implementation status.
Related work.
Conclusions and future work.
Brewster & Abdelrahman 3
Motivation
Research goal: to investigate automatic parallelization of Java programs.
Automatic parallelization: the use of the compiler to detect, extract and generate parallelism from a sequential program.– Maintains familiar programming model.– Promotes portability.
Existing parallelizing compiler technology not adequate for Java:– Focus has been on extracting parallelism from counted loops that
use arrays.– Java programs use pointer-based dynamic data structures, and use
recursion.
A fresh approach is needed ⇒⇒⇒⇒ The zJava System.
Brewster & Abdelrahman 4
The zJava System
We focus on method-level parallelism:– A method invocation creates an independent thread.– The thread may invoke more methods creating more threads.– Threads execute in parallel.
Data dependences among methods require that threads synchronize to maintain sequential execution semantics.
Difficult to determine data dependences at compile-time.
Combined compile-time and run-time approach:– A compiler analyzes methods to symbolically summarizes the data
accessed by each method.– A run-time system receives data access summaries and uses it to
detect and enforce dependences among executing threads.
Require a compiler infrastructure to prototype our analyses.
Brewster & Abdelrahman 5
The zJava Compiler Infrastructure
HLIR
javac
zJavafrontend BCIR
High-levelpasses
Low-levelpasses
.class.java
.class
.java
HLIR: High Level Intermediate RepresentationBCIR: Bytecode Level Intermediate Representation
Brewster & Abdelrahman 6
Compilation Unit
ClassesFilenamePackage nameImport declarations
HLIR ArchitectureProgram
Method
NameArgumentsReturn typeBody
Statement
Expressions
Symbol Table
Symbol Symbol
Compilation Unit
Class Class
Name, Superclass
Methods Fields
Method
Expression
SubexpressionsStatement
Statement List
Statements Expression
ExpressionExpression Expression
Symbols
Compilation Units
Brewster & Abdelrahman 7
HLIR Features
Syntactic consistency enforcement.– Prohibit the representation of syntactically incorrect Java code.
Internal consistency enforcement.– Prohibit changes to the IR which break the relationships between
internal structures.
Automatic internal structure maintenance.– Incrementally update symbol and scope information when the IR is
modified.– Hooks for user structure updates.
Enable rapid prototyping of compiler analyses through a robust intermediate representation
Brewster & Abdelrahman 8
HLIR Features
Compiler analyses may be designed in a modular fashion: an analysis pass can build on the results of passes run previously,without re-running these passes.– Source code directives.– Bytecode attributes.
Framework for interprocedural analysis.– Bytecode attributes.– External class resolution.
Implicit code representation.– Represent the entire program, including code which is present, but
not explicit in the source.
Brewster & Abdelrahman 9
System.out.println(“I can’t be here!”);
Syntactic Consistency
Prohibit creation and/or transformation of IR which results in the representation of syntactically incorrect Java code.
Primarily enforced by the representation of statements.– Individual class constructors.– Statement list constructors.– Statement list modifiers.
try {myFile.write(“Hello”);
}
catch (IOException ioe) {System.out.println(“Error on write.”);
}
Brewster & Abdelrahman 10
;
System.out.println(“Error.”);
try
myFile.write(“Hello”){
}
{
}
catch (IOException ioe)
Syntactic Consistency
tryStatement
fieldAccess
blockStatement
endStatement
catchStatementvarExpression
endStatement
endStatement
stmtList
exprStatement
endStatement
blockStatement
exprStatement
Brewster & Abdelrahman 11
Internal Consistency – Object Sharing
Note that a and b could be in different source files!
Simplified case to demonstrate problem
Prohibit object sharing.– Collections, with ownership.
asym
bsym
csym
t_floattypeaSymref
Type of a changedto t_int
asym bsym csym
t_floattype t_floattype t_floattype
Brewster & Abdelrahman 12
Internal Consistency – Statements
catchStatement
stmtList
endStatement
tryStatement
fieldAccessexprStatement
tryBlockStatement
endStatement
varExpression
endStatement
exprStatement
endStatement
blockStatement
Brewster & Abdelrahman 13
Automatic IR Maintenance
{foo(0);
if (i < 12){
++i;int j = i;foo(j);
}else{
foo(i);}i = 0;
} statement-symtab link
symtab-parent link
symtab# symbol table
4
3
2
1int m;
5
Brewster & Abdelrahman 14
Modular Analysis
Modular compiler analyses.– Later stages in analysis can build on previous results, without
repeating the analysis.– Manually insert directives while the previous analysis stage is being
developed.
//zj Loop i parallelfor (i=1; i<n; ++i) {
}
for (i=1; i<n; ++i) {
}
original .java Loop-levelparallelism
.java withdirectives Locality
Analysis
optimizedcode
Brewster & Abdelrahman 15
Implicit Code Representation
Simplifies compiler passes.
Maintained automatically.
class Foo {int local = 10;int instanceVar;{
local = 99;}Foo() {
int i = 3;
this.instanceVar = i;}
}
<object_init>();
private void <object_init>() {local = 10;{
local = 99;}
}super();
i = 3;
Brewster & Abdelrahman 16
Examples
Control Flow Graph.
Software Architecture Visualization.
Data Structure Visualization.
N. V. Brewster. A Compiler Infrastructure for Research on High-Performance Java. M.A.Sc. Thesis. Department of Electrical and Computer Engineering. University of Toronto, 2001.
http://www.eecg.toronto.edu/zjava/
Brewster & Abdelrahman 17
Data Structure Visualizer
Node Node
current
head
head = new Node();head.next = new Node();head.next.next = new Node();
current = head;while (current != null){current = current.next;
}
Node
Brewster & Abdelrahman 18
Data Structure Visualizer
Compiler directives used to give hints to HLIR pass.
HLIR pass instruments code to insert calls to the DSV library.
Augmented program interfaces with DSV at runtime.
original .javawith DSVdirectives
HLIR
.java augmentedto interface withDSV
Javacompiler
JVM
DSVLibrary Screen
.class
Brewster & Abdelrahman 19
javaType int_t = new javaType(javaType.t_int);varSymbol loopVar = new varSymbol("i", int_t, new fieldModifier());loopVar.setInitializer(new varExpression(“0"));LinkedList declsList = new LinkedList(); declsList.addLast(loopVar);declStatement dStmt = new declStatement(declsList);
LinkedList argsList = new LinkedList();argsList.addLast(new StringLiteralExpression("Hello World!"));naryExpression arguments = new naryExpression(argsList);varExpression methExpr = new varExpression("System.out.println");methodInvocation invokeExpr =
new methodInvocation(methExpr, arguments);stmtList bodyList = new stmtList(new exprStatement(invokeExpr));
++i;
Loop Insertion
Create individual components, assemble into list, insert into method.
while ( ){
}
int i = 0;i < 10
System.out.println("Hello World!");
stmtList newList = new stmtList(new declStatement(declsList));newList.addLast(new stmtList(whileStmt, bodyList));method_body.add(idx, newList);
varExpression leftExpr = new varExpression(new String("i"));intLiteralExpression rightExpr = new intLiteralExpression(10);binaryExpression conditionalExpr = new binaryExpression(leftExpr,
binaryExpression.op_lessthan, rightExpr);whileStatement whileStmt = new whileStatement(conditionalExpr);
preUnaryExpression incrExpr = new preUnaryExpression(unaryExpression.op_plusplus, new varExpression("i"));
bodyList.addLast(new stmtList(new exprStatement(incrExpr)));bodyList = new stmtList(new blockStatement(), bodyList);
Brewster & Abdelrahman 20
Implementation status
Successfully implemented the source-level restructuring sub-system of zJava, using the JDK1.2.2 from Sun.– ~ 27 000 lines of text.– ~ 9 000 executable statements.– 110 classes.
Testing and verification.– Self-compile.– SPECjvm98.– Examples.
Released.– http://www.eecg.toronto.edu/zjava/– Licensing.
Brewster & Abdelrahman 21
Related Work
Cecil, C++, M3, Javabytecode
••οοοVortex
Fortran, C, C++οο••οSage++
Oberon-2ο•οοοOOC2
IC++•οο•οConcert
Fortran, Cοο•οοParaphrase-2
N/Aο•οοοScore
Fortranο••••Polaris
Fortran, C, C++••••οSUIF
Java•ο•••zJava HLIR
Languages Supported
IPAFram
ework
High and Low
Level
Source-to-Source
Modular Analysis
Automatic
Consistency
Brewster & Abdelrahman 22
Conclusions and future work
Achieved goal of providing a robust system to promote rapid development of compiler passes.– Enforces syntactic and internal consistency.– Represents and incrementally maintains symbol and scope
information.– Ready to use to prototype analyses in the zJava system.
Future Work:– Semantic consistency.– Precise modeling of exception flow.– Extensions for Java1.1.– Builder methods.– Link high and low level representations in zJava.