Using and Extending AspectJ for Separating Concerns in Parallel - - PowerPoint PPT Presentation

using and extending aspectj for separating concerns in
SMART_READER_LITE
LIVE PREVIEW

Using and Extending AspectJ for Separating Concerns in Parallel - - PowerPoint PPT Presentation

Using and Extending AspectJ for Separating Concerns in Parallel Java Code Bruno Harbulot POOSC 2005 Glasgow, UK Bruno Harbulot and John Gurd The University of Manchester POOSC 2005 Glasgow, July 2005 1/26 Presentation Outline


slide-1
SLIDE 1

Bruno Harbulot – POOSC 2005 – Glasgow, UK

1/26

Using and Extending AspectJ for Separating Concerns in Parallel Java Code

Bruno Harbulot and John Gurd

The University of Manchester POOSC 2005 – Glasgow, July 2005

slide-2
SLIDE 2

Bruno Harbulot – POOSC 2005 – Glasgow, UK

2/26

Presentation Outline

  • Problem and Approach
  • Using AspectJ for Parallelisation
  • Extending AspectJ for

Parallelisation

slide-3
SLIDE 3

Bruno Harbulot – POOSC 2005 – Glasgow, UK

3/26

Presentation Outline

  • Problem and Approach
  • Using AspectJ for Parallelisation
  • Extending AspectJ for

Parallelisation

slide-4
SLIDE 4

Bruno Harbulot – POOSC 2005 – Glasgow, UK

4/26

Problem: Code tangling in scientific software

  • Statements for parallelism

tangled within the numerical algorithm

  • Parallelisation cannot be

encapsulated in its own class or procedure

  • Difficult to extract and

reuse numerical algoritm

  • nly, in another context

JGF benchmark suite (Raytracer, MPJ implementation)

JGFRayTracerBenchSizeA.java raytracer/RayTracer.java raytracer/JGFRayTracerBench.java JGFRayTracerBenchSizeB.java

slide-5
SLIDE 5

Bruno Harbulot – POOSC 2005 – Glasgow, UK

5/26

Separation of Concerns

  • Concern: anything about a software system

(feature, requirement, ...)

  • “Separation of concerns”: Dijkstra [Dij76, ch. 27]
  • Designing software: separating concerns into units

such as procedures, classes, methods, libraries, etc.

  • Two concerns crosscut each other when their

relation implies code-tangling.

  • Crosscutting concern: concern that crosscuts the

main purpose of a unit.

slide-6
SLIDE 6

Bruno Harbulot – POOSC 2005 – Glasgow, UK

6/26

Aspect-Oriented Programming (I) Motivation

  • Programming paradigm for encapsulating

crosscutting concerns [KLM+97].

  • AOP builds on top of other programming

paradigms: object-oriented, imperative or

  • functional. It does not supplant them.
  • Encapsulate crosscutting concerns into

aspects.

slide-7
SLIDE 7

Bruno Harbulot – POOSC 2005 – Glasgow, UK

7/26

Aspect-Oriented Programming (II) Concepts

  • Aspects contain statements of the form:

“[...] whenever condition C arises, perform action A.” [FF00]

  • Join point: point in the execution of a program

where an aspect might intervene.

  • Pointcut: expression of a subset of join points

(condition C)

  • Advice: piece of code for action A.
  • Pointcuts and advice encapsulated into aspects.
slide-8
SLIDE 8

Bruno Harbulot – POOSC 2005 – Glasgow, UK

8/26

AspectJ

  • Aspect-Oriented extension to Java
  • Compiles from Java source-code or byte-code
  • Defines new constructs for writing aspects (aspect,

pointcut, ...)

  • Intervenes on object interfaces (field accesses,

method calls, instantiation, ...)

  • Produces Java byte-code (compatible with Java

Virtual Machine specifications)

slide-9
SLIDE 9

Bruno Harbulot – POOSC 2005 – Glasgow, UK

9/26

AspectJ example

/* Java code */ class MyClass { public static final int MAX_VALUE = 2000 ; int a ; /* ... */ } /* AspectJ code */ aspect MyAspect { void around(int val): set (int MyClass.a) && args (val) { if (newval > MyClass.MAX_VALUE) proceed(MAX_VALUE) ; } }

Piece of advice Pointcut

slide-10
SLIDE 10

Bruno Harbulot – POOSC 2005 – Glasgow, UK

10/26

What we would like to do

  • Writing 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-11
SLIDE 11

Bruno Harbulot – POOSC 2005 – Glasgow, UK

11/26

Presentation Outline

  • Problem and Approach
  • Using AspectJ for Parallelisation
  • Extending AspectJ for

Parallelisation

slide-12
SLIDE 12

Bruno Harbulot – POOSC 2005 – Glasgow, UK

12/26

AspectJ for Parallelisation (I)

  • No join point for loops
  • Exposing the iteration space as method parameters

[HG04]

  • void myMethod (..., int iMin, int iMax) {

for (int i=iMin ; i<iMax ; i++) {...} }

  • void around(int min, int max):

call(void *.myMethod(..)) && args(.., min, max) { // int t_min, t_max new Runnable() { public void run() { proceed(t_min, t_max) ; } } // execute each instance concurrently }

  • Similar aspect for using MPI (if data to be sent exposed as well)
slide-13
SLIDE 13

Bruno Harbulot – POOSC 2005 – Glasgow, UK

13/26

AspectJ for Parallelisation (II)

  • AspectJ expects an underlying object-
  • riented design
  • Putting the iteration space outside the

method may require substantial refactoring

  • Although it works on some examples in the

Java Grande Forum benchmark suite, it is almost impossible in others (for example the LU factorisation)

slide-14
SLIDE 14

Bruno Harbulot – POOSC 2005 – Glasgow, UK

14/26

Object-Oriented Models for Loops

  • Object-oriented models for “for”-loops

[HG04]

  • AspectJ can handle these models
  • Consist of encapsulating loop information

into classes: boundaries and loop-body

slide-15
SLIDE 15

Bruno Harbulot – POOSC 2005 – Glasgow, UK

15/26

Object-Oriented Models for Loops

<<Interface>> Runnable2DLoopBody run(i: int,j: int) : void RectangleLoopA loopBody : Runnable2DLoopBody minI : int maxI : int minJ : int maxJ : int run() : void void run () { for (int i = minI; i<=maxI; i++) for (int j = minJ; j<=maxJ; j++) loopBody.run (i,j) ; } RectangleLoopB minI : int maxI : int minJ : int maxJ : int run() : void loopBody(i: int,j: int) : void void run () { for (int i = minI; i<=maxI; i++) for (int j = minJ; j<=maxJ; j++) loopBody (i,j) ; }

slide-16
SLIDE 16

Bruno Harbulot – POOSC 2005 – Glasgow, UK

16/26

Object-Oriented Loops: Overheads

  • Performance results depend on the JVM
  • Cost of refactoring (here: no parallelism)

IBM 142 SUN 142C SUN 142S SUN 150C SUN 150S 10 20 30 40

BasicA BasicB RectangleLoopA RectangleLoopB RectangleLoopC MTRectangleLoopA MTRectangleLoopB MTRectangleLoopC

Time (nanosec) (for size 100)

slide-17
SLIDE 17

Bruno Harbulot – POOSC 2005 – Glasgow, UK

17/26

Presentation Outline

  • Problem and Approach
  • Using AspectJ for Parallelisation
  • Extending AspectJ for

Parallelisation

slide-18
SLIDE 18

Bruno Harbulot – POOSC 2005 – Glasgow, UK

18/26

Join Point for Loops

  • TheClass[] array = /* ... */

for(int i = 0 ; i < array.length ; i++) { TheClass obj = array[i] ; } for (TheClass obj: array) { /* ... */ }

  • Collection c = /* ... */

for(Iterator it=c.iterator() ; it.hasNext() ;) { TheClass obj = (TheClass)it.next() ; /* ... */ } for(TheClass obj: c) { /* ... */ }

slide-19
SLIDE 19

Bruno Harbulot – POOSC 2005 – Glasgow, UK

19/26

Finding loops

  • Analysis of the control flow graph
  • Finding natural and combined loops
  • Based on bytecode representation: it's

about recognising the behaviour, not the coding style (e.g. equivalent “while” and “for” loops)

slide-20
SLIDE 20

Bruno Harbulot – POOSC 2005 – Glasgow, UK

20/26

Context Exposure

  • 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-21
SLIDE 21

Bruno Harbulot – POOSC 2005 – Glasgow, UK

21/26

Context Exposure: Arguments to the loop

  • for (int i = min; i < max ; i+=stride)

– args(min, max, stride)

  • for (int i = 0 ; i < array.length ; i+=stride)

– args(min, max, stride, array)

  • Iterator it ; while (it.hasNext) { it.next() }

– args(it)

  • for (TheClass obj: collec)

– args(iterator, collec)

slide-22
SLIDE 22

Bruno Harbulot – POOSC 2005 – Glasgow, UK

22/26

Aspects for parallelisation

  • void around(int min, int max, int

stride): loop() && args(min, max, stride, ..) { /* create runnables */ }

  • Block scheduling:

proceed(tmin, tmax, stride) ;

  • Cyclic scheduling:

proceed(min+k, tmax, stride*threads);

  • MPI: access to the array + send/recv
slide-23
SLIDE 23

Bruno Harbulot – POOSC 2005 – Glasgow, UK

23/26

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(int min,int max,int

s,byte[] a): loop() && args(min,max,s,a);

slide-24
SLIDE 24

Bruno Harbulot – POOSC 2005 – Glasgow, UK

24/26

Implementation using abc

  • abc: AspectBench Compiler (full AspectJ

compiler),

  • LoopsAJ: our extension for abc that

implements a loop pointcut,

  • Analysis capabilities of Soot
slide-25
SLIDE 25

Bruno Harbulot – POOSC 2005 – Glasgow, UK

25/26

Summary

  • Parallelisation with AspectJ possible but

requires refactoring.

  • Join point for loops: meaningful thanks to

context exposure, which makes it possible to intervene with the iteration space and

  • data. Refactoring not necessary.
  • Both techniques make it possible to have

Java base code for numerical concern and aspects for either MPI or Java threads.

slide-26
SLIDE 26

Bruno Harbulot – POOSC 2005 – Glasgow, UK

26/26

References

  • Aspect-Oriented Software Development

http://www.aosd.net/

  • [HG04] Harbulot and Gurd. Using AspectJ to Separate

Concerns in Parallel Scientific Java Code. AOSD 2005

  • [HG05] Harbulot and Gurd. A join point for loops in
  • AspectJ. FOAL 2005
  • [Dij76] Dijkstra. A Discipline of Programming.
  • [FF00] Filman and Friedman. Aspect-Oriented Programming is

quantification and obliviousness.

  • [KLM+97] Kiczales et. al. Aspect-Oriented Programming.