A join point for loops in AspectJ Bruno Harbulot and John Gurd - - PowerPoint PPT Presentation

a join point for loops in aspectj
SMART_READER_LITE
LIVE PREVIEW

A join point for loops in AspectJ Bruno Harbulot and John Gurd - - PowerPoint PPT Presentation

A join point for loops in AspectJ Bruno Harbulot and John Gurd Bruno Harbulot AOSD 2006 Bonn, 22/03/2006 The University of Manchester AOSD 2006 Bonn, March 2006 1/19 What we would like to do Write aspects that represent the


slide-1
SLIDE 1

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

1/19

A join point for loops in AspectJ

Bruno Harbulot and John Gurd

The University of Manchester AOSD 2006 – Bonn, March 2006

slide-2
SLIDE 2

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

2/19

What we would like to do

  • Write aspects that represent the concern:

– “parallelise all the loops iterating from 0 to the

length of an array of int using MPI”,

– or “parallelise all the loops iterating over a

Collection using Java Threads”.

  • Write (aspect) code that does not invade

the readability of the numerical code.

slide-3
SLIDE 3

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

3/19

Previously, on loops and AspectJ...

  • “Using AspectJ to Separate Concerns In

Parallel Scientific Java Code” (AOSD 2004)

  • Parallelisation of loops using aspects:

– by making the iteration space visible as

parameters to the methods

– by turning loops into self-contained objects

(loop body and boundaries)

  • Both require refactoring the base code
slide-4
SLIDE 4

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

4/19

Presentation Outline

  • Loop join point model and objectives
  • Finding the loops
  • Context exposure
  • LoopsAJ: prototype implementation
  • Related topics
slide-5
SLIDE 5

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

5/19

Objective (“strong” form)

  • Analogy with Java 5 (Tiger) constructs.
  • Collection collec = ...

for (Object item: collec) { ... }

  • Object[] array = ...

for (Object item: array) { ... }

  • Syntactic sugar for this form:

Object[] array = ... for (int i=0; i<array.length; i++) { ... }

slide-6
SLIDE 6

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

6/19

Objective (“weak” form)

  • Exposing the data not always necessary.
  • Iterator (object or int) may be sufficient.
  • for (int i=min ; i<max ; i+=stride)
  • Iterator iter = ... ;

while (iter.hasNext()){ ... iter.next() ... }

slide-7
SLIDE 7

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

7/19

Finding the loops

  • Analysis of the control flow graph, based on

bytecode representation.

  • Finding natural and combined loops
  • Classification of loops according to their

weaving and analysis capabilities:

– General loops – Loops with unique successor – Loops with unique exit node

slide-8
SLIDE 8

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

8/19

Control-flow graph, dominators and natural loops (I)

  • A node is a basic block (only entry via its

head and only exit via its tail).

  • Node d dominates node n if every path from

the beginning to n goes through d.

  • A back edge (a -> b) is an edge whose head

(b) dominates its tail (a).

  • Given a back edge n -> d, the natural loop is

d plus the set of nodes that can reach n without going through d.

slide-9
SLIDE 9

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

9/19

Control-flow graph, dominators and natural loops (II)

for (int i = 0 ; i<MAX ; i ++) { /* A */ } int j = 0 ; int STRIDE = 1 ; for (; j < MAX ; j+=STRIDE) { /* A */ } int k = 0 ; while (k < MAX) { /* A */ k ++ ; }

1 2 3 4

i=0; if (i<MAX) /* A */ i++; return;

1 2 3 4 Control-flow graph Dominator tree

Back edge

Natural Loop Header

slide-10
SLIDE 10

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

10/19

Loop categories (I) General case

  • Always possible to define “before”
  • Inserting a pre-header

header pre-header header

slide-11
SLIDE 11

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

11/19

Loop categories (II) Successor(s) and exit(s)

  • iloop:

for (int i=0; i<MAXI; i++) { for (int j=0; j<MAXJ; j++) { if (c(i,j)) break iloop; } }

slide-12
SLIDE 12

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

12/19

Loop categories (III) Successor(s) and exit(s)

  • Unique successor:

unique point after (around possible).

  • Multiple successors:

multiple points after (around impossible).

  • Loops with unique exit

node allow further behaviour prediction (context exposure).

i=0; 1 if(i<MAXI) 2 j=0; 3 if(j<MAXJ) if(c(i,j)) j++; i++ /* A */ 4 6 5 7 8

slide-13
SLIDE 13

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

13/19

Context Exposure (I)

  • For method calls (for example), the context

exposed comprises the target, the caller

  • bject and the arguments.
  • Need similar data for loops to exploit the

loop join point potential.

  • Otherwise, only able to recognise that there

is a loop, but no extra information on what it does.

slide-14
SLIDE 14

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

14/19

Context Exposure (II)

  • Exposing data processed and guiding the

execution.

  • “Arguments” to the loop.
  • Integer range and Iterators.
  • Arrays and Collections.
  • (Only loop with unique exit nodes to avoid

“break” statements and irregular iterations)

slide-15
SLIDE 15

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

15/19

Loop selection

  • In AspectJ, the selection is (ultimately) based on a

name pattern, for example on the method name or an argument type,

  • Loops haven't got names,
  • Selection to be made on argument types and on

data processed: integer range and Iterators; and especially arrays and Collections. (+cflow,

within and withincode)

  • pointcut bytearrayloop(byte[] a):

loop() && args(..,a);

slide-16
SLIDE 16

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

16/19

LoopsAJ Implementation using abc

  • abc: AspectBench Compiler (full AspectJ

compiler).

  • LoopsAJ, our extension for abc, provides

the loop() pointcut.

  • Analysis capabilities of Soot.
  • Limitation: only one “after” point possible,

but could certainly be overcome.

slide-17
SLIDE 17

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

17/19

Reflection and analyses

  • Further analyses of the code, the result of

which could be access via reflection

  • thisJoinPoint.isArrayBoundSafe()
  • thisJoinPoint.isParallelisable()
  • (Could probably be optimised with SCoPE if

in the pointcut description and static part)

  • Potential for further results if whole-

application analysis.

slide-18
SLIDE 18

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

18/19

Related topics: loop-body join point

  • It would be possible to insert a node similar

to the “pre-header”, but for edges coming from the loop.

  • This would comprise the evaluation of the

condition within the definition of the “loop- body”.

  • What context could be exposed?
slide-19
SLIDE 19

Bruno Harbulot – AOSD 2006 – Bonn, 22/03/2006

19/19

Summary

  • Loop join point: a join point based on the

recognition of a complex behaviour.

  • Meaningful thanks to context exposure.
  • Problem of loop selection would probably

benefit from more advanced pointcut mechanisms.

  • LoopsAJ:

http://www.cs.manchester.ac.uk/cnc/projects/loopsaj/