Aosd2009 adams

Post on 12-Apr-2017

121 views 0 download

Transcript of Aosd2009 adams

(Parrot_Interp

d,Parrot_Interp

s,PMC *sub)){

#ifdef

THREAD_DEBUG

PIO_eprintf(s,

"copying over

subroutine [%Ss]

\n",

Parrot_full_sub_

name(S, Sub));

#endif

return

make_local_copy

(d, s, sub);

}

Bram AdamsSAIL

Queen's UniversityCanada

Herman TrompGH-SEL

Ghent UniversityBelgium

Wolfgang De MeuterSOFT

Vrije Universiteit BrusselBelgium

Ahmed E. HassanSAIL

Queen's UniversityCanada

Can we refactor

Conditional Compilation into Aspects?

1. Conditional Compilation vs. Aspects

2. Preprocessor Blueprint Model

3. Parrot VM Case Study

4. Conclusion

#include "parrot/config.h"

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return PARROT_TRANSFER_COPY(d, s, sub);}

The C Preprocessor T n yri it3

#include "parrot/config.h"

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return PARROT_TRANSFER_COPY(d, s, sub);}

The C Preprocessor T n yri it3

THREAD_DEBUG

PARROT_TRANSFER_COPY

2

#include "parrot/config.h"

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return PARROT_TRANSFER_COPY(d, s, sub);}

#ifdef THREAD_DEBUG

#endif

The C Preprocessor T n yri it3

PARROT_TRANSFER_COPY

2

PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));

1#ifdef THREAD_DEBUG

#endif

#include "parrot/config.h"

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return PARROT_TRANSFER_COPY(d, s, sub);}

#ifdef THREAD_DEBUG

#endif

The C Preprocessor T n yri it3

PARROT_TRANSFER_COPY

2

PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));

1 PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub)); PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));

#ifdef THREAD_DEBUG

#endif

#include "parrot/config.h"

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return PARROT_TRANSFER_COPY(d, s, sub);}

The C Preprocessor T n yri it

PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));

1#ifdef THREAD_DEBUG

#endif

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return make_local_copy(d, s, sub);}

Conditional Compilation vs. AOP

PMC* pt_transfer_sub(Parrot_Interp d, Parrot_Interp s, PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return make_local_copy(d, s, sub);}

Conditional Compilation vs. AOP

THREAD_DEBUG

THREAD_DEBUG

+THREAD_DEBUG

syntactical pattern!

Which syntactical patterns of conditional compilation usage can benefit from

refactoring into aspects?

1. Conditional Compilation vs. Aspects

2. Preprocessor Blueprint Model

3. Parrot VM Case Study

4. Conclusion

void Parrot_setenv(. . . name,. . . value){#ifdef PARROT_HAS_SETENV my_setenv(name, value, 1);#else int name_len=strlen(name); int val_len=strlen(value); char* envs=glob_env; if(envs==NULL){ return; } strcpy(envs,name); strcpy(envs+name_len,"="); strcpy(envs+name_len + 1,value); putenv(envs);#endif}

#ifdef LINUXextern int Parrot_signbit(double x){ union{ double d; int i[2]; } u; u.d = x;# ifdef BIG_ENDIAN return u.i[0] < 0;# else return u.i[1] < 0;# endif}#endif

endif

else

PARROT_HAS_SETENV

endif

endif

LINUX

else

BIG_ENDIAN

endif

else

PARROT_HAS_SETENV

endif

endif

LINUX

else

BIG_ENDIAN

PARROT_HAS_SETENV

LINUX

BIG_ENDIAN

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

PARROT_HAS_SETENV

LINUX

BIG_ENDIAN

Preprocessor Blueprint Model

Declarative Pattern Matching

PMC* pt_transfer_sub(Parrot_Interp d,Parrot_Interp s,PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return make_local_copy(d, s, sub);}

matched bysub filter_before_execution{ my ($seq)=@_; my $clone=$seq; my $seq2=$seq;

while ($seq =~ m/;fu(\d+)\@(\d+)/g) { my $function=$1;

while ($seq2 =~ m/;fu${function}\@1(?!\d)(?:;fu${function}(,co\d+)+(?:,(?:ac|in|ma)\d+)?\@\d+)+(;fu${function}(?:,(?:ac|in|ma)\d+)?\@\d+)+(?!\d)/g) { my $match=$&; my $pre=$`; my $post=$'; if ($pre !~ /fu${function}/ and $post !~ /fu${function}/) { ! my $tmp=$clone;! $clone =~ s/${match}//;! if ($clone ne $tmp) {! $nr_of_occurrences_of_before_execution++;! } } } } if ($clone ne $seq) { $nr_of_sequences_with_before_execution++; } return filter_out_non_conditional_parts($clone);}

Declarative Pattern Matching

wildcardproc. or

data

definition

LEGEND cond.

region

PMC* pt_transfer_sub(Parrot_Interp d,Parrot_Interp s,PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s,"copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return make_local_copy(d, s, sub);}

matched bysub filter_before_execution{ my ($seq)=@_; my $clone=$seq; my $seq2=$seq;

while ($seq =~ m/;fu(\d+)\@(\d+)/g) { my $function=$1;

while ($seq2 =~ m/;fu${function}\@1(?!\d)(?:;fu${function}(,co\d+)+(?:,(?:ac|in|ma)\d+)?\@\d+)+(;fu${function}(?:,(?:ac|in|ma)\d+)?\@\d+)+(?!\d)/g) { my $match=$&; my $pre=$`; my $post=$'; if ($pre !~ /fu${function}/ and $post !~ /fu${function}/) { ! my $tmp=$clone;! $clone =~ s/${match}//;! if ($clone ne $tmp) {! $nr_of_occurrences_of_before_execution++;! } } } } if ($clone ne $seq) { $nr_of_sequences_with_before_execution++; } return filter_out_non_conditional_parts($clone);}

Pattern Identification

Fact DB

Pattern Identification

Fact DB

(a) Multiple Inclusion Pro-tection

(b) Conditional Defini-tion

!

"

(c) Partitioned

!

"

#

(d) Semi-partitioned

!"#$%&'$

(

(

(

)

*

+,-,./

(e) Conditional Signa-ture

!"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..

(f) Simple (before)

!""#

$

$

%

&

(g) Simple Return

!

!

"

#

(h) Simple Declaration

!

"#

(i) Scattered

!

(j) Invasive (before)

!"

(k) General Fine-grained

!"#$%&'$

(

(

(

)

*

+,-,./

(e) Conditional Signa-ture

!"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..

(f) Simple (before)

!""#

$

$

%

&

(g) Simple Return

!

!

"

#

(h) Simple Declaration

!

"#

(i) Scattered

!

(j) Invasive (before)

!"

(k) General Fine-grained

150

120

20

35sub filter_before_execution{ my ($seq)=@_; my $clone=$seq; my $seq2=$seq;

while ($seq =~ m/;fu(\d+)\@(\d+)/g) { my $function=$1;

while ($seq2 =~ m/;fu${function}\@1(?!\d)(?:;fu${function}(,co\d+)+(?:,(?:ac|in|ma)\d+)?\@\d+)+(;fu${function}(?:,(?:ac|in|ma)\d+)?\@\d+)+(?!\d)/g) { my $match=$&; my $pre=$`; my $post=$'; if ($pre !~ /fu${function}/ and $post !~ /fu${function}/) { ! my $tmp=$clone;! $clone =~ s/${match}//;! if ($clone ne $tmp) {! $nr_of_occurrences_of_before_execution++;! } } } } if ($clone ne $seq) { $nr_of_sequences_with_before_execution++; } return filter_out_non_conditional_parts($clone);}

1. Conditional Compilation vs. Aspects

2. Preprocessor Blueprint Model

3. Parrot VM Case Study

4. Conclusion

1. Syntactical patterns of conditional compilation?

2. Evolution of the patterns?

3. Refactorability of the patterns into aspects?

Research Questions

Case Study

Syntactical patterns of conditional compilation?

1

Fine-grained26%

Coarse-grained74%

1. Syntactical Patterns

39%

15% 5%7%

14%

13%

8%2%6%

70%

22%

Multiple InclusionConditional DefinitionPartitionedSemi-partitioned

Conditional Signature SimpleSimple Return Simple DeclarationScattered InvasiveOther

1a. Coarse-grained 1b. Fine-grained

1a. Conditional Definition

#ifdef YY_NEED_STRLENstatic int yy_flex_strlen(yyconst char * s, yyscan_t yyscanner){! register int n;! for (n = 0; s[n]; ++n) {! ! ;! }! return n;}#endif

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

70%

30%

1a. Partitioned

INTVAL fetch_iv_le(INTVAL w){#if !PARROT_BIGENDIAN return w;#else INTVAL r;

r = w << 56; r |= (w & 0xff00) << 40; r |= (w & 0xff0000) << 24; r |= (w & 0xff000000) << 8; r |= (w & 0xff00000000) >> 8; r |= (w & 0xff0000000000) >> 24; r |= (w & 0xff000000000000) >> 40; r |= (w & 0xff00000000000000) >> 56; return r;#endif}

(a) Multiple Inclusion Pro-tection

(b) Conditional Defini-tion

!

"

(c) Partitioned

!

"

#

(d) Semi-partitioned

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

94%

6%

1b. Simple

wildcardproc. or

data

definition

LEGEND cond.

region

wildcardproc. or

data

definition

LEGEND cond.

region

PMC* pt_transfer_sub(Parrot_Interp d,Parrot_Interp s,PMC *sub)){#ifdef THREAD_DEBUG PIO_eprintf(s, "copying over subroutine [%Ss]\n", Parrot_full_sub_name(S, Sub));#endif return make_local_copy(d, s, sub);}

13%

87%

static void compact_pool(PARROT_INTERP, ARGMOD(Memory_Pool *pool)){ INTVAL j; UINTVAL total_size;

...

{ Memory_Block *cur_block = pool->top_block; ... }

#if WE_WANT_EVER_GROWING_ALLOCATIONS total_size += pool->minimum_block_size;#endif

alloc_new_block(interp, total_size, pool, "inside compact");

new_block = pool->top_block; ...}

!"#$%&'$

(

(

(

)

*

+,-,./

(e) Conditional Signa-ture

!"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..

(f) Simple (before)

!""#

$

$

%

&

(g) Simple Return

!

!

"

#

(h) Simple Declaration

!

"#

(i) Scattered

!

(j) Invasive (before)

!"

(k) General Fine-grained

1b. Invasive

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

proc. or

data

definition

call or

access

15%

85%

static int largebin_index(unsigned int sz) { unsigned int x = sz >> SMALLBIN_WIDTH; unsigned int m; if (x >= 0x10000) { return NBINS - 1; }#if defined (__GNUC__) && defined (i386) __asm__("bsrl %1,%0\n\t" : "=r" (m) : "g" (x));#else { unsigned int n = ((x - 0x100) >> 16) & 8; x <<= n; m = ((x - 0x1000) >> 16) & 4; n += m; x <<= m; m = ((x - 0x4000) >> 16) & 2; n += m; x = (x << m) >> 14; m = 13 - n + (x & ~(x >> 1)); }#endif return NSMALLBINS + (m << 2) + ((sz >> (m + 6)) & 3);}

!"#$%&'$

(

(

(

)

*

+,-,./

(e) Conditional Signa-ture

!"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..

(f) Simple (before)

!""#

$

$

%

&

(g) Simple Return

!

!

"

#

(h) Simple Declaration

!

"#

(i) Scattered

!

(j) Invasive (before)

!"

(k) General Fine-grained

1b. Other

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

!"#$%&'$()*)+, !"#$%&#"&

'()(&

'*!+,),#+

$(--&#"&

($$*..!""#

39%61%

Evolution of the patterns?

2

0.001!

0.01!

0.1!

1!

01/09/01!

01/03/02!

01/09/02!

01/03/03!

01/09/03!

01/03/04!

01/09/04!

01/03/05!

01/09/05!

01/03/06!

01/09/06!

01/03/07!

01/09/07!

01/03/08!

#p

att

ern

s/fi

le (

10

log)!

inclusion!

cond def!

part!

semi-part!

cond-sign!

invasive!

gen fine!

2. Evolution of Pattern Usage

Simple (Return/Decl.) and Scattered

0.001!

0.01!

0.1!

1!

10!

01

/0

9/0

1!

01

/0

3/0

2!

01

/0

9/0

2!

01

/0

3/0

3!

01

/0

9/0

3!

01

/0

3/0

4!

01

/0

9/0

4!

01

/0

3/0

5!

01

/0

9/0

5!

01

/0

3/0

6!

01

/0

9/0

6!

01

/0

3/0

7!

01

/0

9/0

7!

01

/0

3/0

8!

#p

att

ern

s/fi

le (

10

log)!

inclusion!

cond def!

part!

semi-part!

cond-sign!

invasive!

other!

Refactorability of the patterns into aspects?

3

AOP refactoring ! modules quantified around empty around before after call advice" pattern ITD execution execution execution execution

coar

se-g

rain

ed multiple inclusion - - - - - - -conditional • build know-

ledge needed• combinatorial

module increase

+ • larger binary• not for data

- - - -definition

partitionedduplication

+ - - - -semi-partitioned + - join point context - -

fine-

grai

ned

cond. signature duplication - - - - -simple - precedence - • fine-grained join point context passing needed

• precedence of conditional regions at same join point-

simple return - - - - - • choose one re-gion as base code

• join point context

-

simple declaration - - - join point context - -scattered - - - - - - • heterogeneity

• prepare base code

invasive - - - - - - join point contextgeneral fine- - - - - - - • fragile advice

• prepare base codegrained other

3a. Refactoring using Static Crosscutting

other

AOP refactoring ! modules quantified around empty around before after call advice" pattern ITD execution execution execution execution

coar

se-g

rain

ed multiple inclusion - - - - - - -conditional • build know-

ledge needed• combinatorial

module increase

+ • larger binary• not for data

- - - -definition

partitionedduplication

+ - - - -semi-partitioned + - join point context - -

fine-

grai

ned

cond. signature duplication - - - - -simple - precedence - • fine-grained join point context passing needed

• precedence of conditional regions at same join point-

simple return - - - - - • choose one re-gion as base code

• join point context

-

simple declaration - - - join point context - -scattered - - - - - - • heterogeneity

• prepare base code

invasive - - - - - - join point contextgeneral fine- - - - - - - • fragile advice

• prepare base codegrained

AOP refactoring ! modules quantified around empty around before after call advice" pattern ITD execution execution execution execution

coar

se-g

rain

ed multiple inclusion - - - - - - -conditional • build know-

ledge needed• combinatorial

module increase

+ • larger binary• not for data

- - - -definition

partitionedduplication

+ - - - -semi-partitioned + - join point context - -

fine-

grai

ned

cond. signature duplication - - - - -simple - precedence - • fine-grained join point context passing needed

• precedence of conditional regions at same join point-

simple return - - - - - • choose one re-gion as base code

• join point context

-

simple declaration - - - join point context - -scattered - - - - - - • heterogeneity

• prepare base code

invasive - - - - - - join point contextgeneral fine- - - - - - - • fragile advice

• prepare base codegrained

3b. Refactoring using Dynamic Crosscutting

other other

3c. Refactorability of the patterns into aspects?

Other, Simple, Invasive, ...

3c. Refactorability of the patterns into aspects?

YES78%

NO22%

Cond. Def. & (Semi)-Partitioned

MultipleInclusion

MAYBE92%

NO8%

Coarse-grained Fine-grainedCond.

Signature

1. Conditional Compilation vs. Aspects

2. Preprocessor Blueprint Model

3. Parrot VM Case Study

4. Conclusion

QUESTIONS?

0.001!

0.01!

0.1!

1!

01/09/01!

01/03/02!

01/09/02!

01/03/03!

01/09/03!

01/03/04!

01/09/04!

01/03/05!

01/09/05!

01/03/06!

01/09/06!

01/03/07!

01/09/07!

01/03/08!

#p

att

ern

s/fi

le (

10lo

g)!

inclusion!

cond def!

part!

semi-part!

cond-sign!

invasive!

gen fine!

2. Evolution of Pattern Usage

Simple (Return/Decl.) and Scattered

0.001!

0.01!

0.1!

1!

10!

01/09/01!

01/03/02!

01/09/02!

01/03/03!

01/09/03!

01/03/04!

01/09/04!

01/03/05!

01/09/05!

01/03/06!

01/09/06!

01/03/07!

01/09/07!

01/03/08!

#p

att

ern

s/fi

le (

10

log)!

inclusion!

cond def!

part!

semi-part!

cond-sign!

invasive!

other!

env.c:1:16

env.c:53:67

strlen

LINUX env.c:19:30

SET

ENV

strcpy

putenv

strlen

strcpy

strcpy

u

BIG

function

definition

cond.

region

call

opaquedata

def. global var.

access

+

-

+

+

-

-

+

glob.c:14

LEGEND

PARROT_HAS_SETENV

LINUX

BIG_ENDIAN

Preprocessor Blueprint Modelvoid Parrot_setenv(. . . name,. . . value){

#ifdef PARROT_HAS_SETENV

my_setenv(name, value, 1);

#else

int name_len=strlen(name);

int val_len=strlen(value);

char* envs=glob_env;

if(envs==NULL){

return;

}

strcpy(envs,name);

strcpy(envs+name_len,"=");

strcpy(envs+name_len + 1,value);

putenv(envs);

#endif

}

#ifdef LINUX

extern int Parrot_signbit(double x){

union{

double d;

int i[2];

} u;

u.d = x;

# ifdef BIG_ENDIAN

return u.i[0] < 0;

# else

return u.i[1] < 0;

# endif

}

#endif

endif

else

PARROT_HAS_SETENV

endif

endif

LINUX

else

BIG_ENDIAN

PMC* pt_transfer_sub(Parrot_Interp d,

Parrot_Interp s,

PMC *sub)){

#ifdef THREAD_DEBUG

PIO_eprintf(s,"copying over subroutine [%Ss]\n",

Parrot_full_sub_name(S, Sub));

#endif

return make_local_copy(d, s, sub);

}

Conditional Compilation vs. AOP

THREAD_DEBUG

THREAD_DEBUG

+

THREAD_DEBUG

!

syntactical pattern!

Other, Simple, Invasive, ...

3c. Refactorability of the patterns into aspects?

YES78%

NO22%

Cond. Def. & (Semi)-Partitioned

MultipleInclusion

MAYBE92%

NO8%

Coarse-grained Fine-grainedCond.

Signature