• No results found

Supporting meta types in a compiled, reflective programming language

N/A
N/A
Protected

Academic year: 2020

Share "Supporting meta types in a compiled, reflective programming language"

Copied!
135
0
0

Loading.... (view fulltext now)

Full text

(1)

Terms and Conditions of Use of Digitised Theses from Trinity College Library Dublin

Copyright statement

All material supplied by Trinity College Library is protected by copyright (under the Copyright and Related Rights Act, 2000 as amended) and other relevant Intellectual Property Rights. By accessing and using a Digitised Thesis from Trinity College Library you acknowledge that all Intellectual Property Rights in any Works supplied are the sole and exclusive property of the copyright and/or other I PR holder. Specific copyright holders may not be explicitly identified. Use of materials from other sources within a thesis should not be construed as a claim over them.

A non-exclusive, non-transferable licence is hereby granted to those using or reproducing, in whole or in part, the material for valid purposes, providing the copyright owners are acknowledged using the normal conventions. Where specific permission to use material is required, this is identified and such permission must be sought from the copyright holder or agency cited.

Liability statement

By using a Digitised Thesis, I accept that Trinity College Dublin bears no legal responsibility for the accuracy, legality or comprehensiveness of materials contained within the thesis, and that Trinity College Dublin accepts no liability for indirect, consequential, or incidental, damages or losses arising from use of the thesis for whatever reason. Information located in a thesis may be subject to specific use constraints, details of which may not be explicitly described. It is the responsibility of potential and actual users to be aware of such constraints and to abide by them. By making use of material from a digitised thesis, you accept these copyright and disclaimer provisions. Where it is brought to the attention of Trinity College Library that there may be a breach of copyright or other restraint, it is the policy to withdraw or take down access to a thesis while the issue is being resolved.

Access Agreement

By using a Digitised Thesis from Trinity College Library you are bound by the following Terms & Conditions. Please read them carefully.

(2)

PROGRAMMING LANGUAGE

A t hesis s u b m i t t e d t o t h e U ni v e r s i t y of Du bl i n , T r i n i t y College, in ful fi l l ment o f t h e r e q u i r e m e n t s for t h e d e g r e e of

D o c t o r o f IMiilosophy ( C o m | ) u t e r Science)

' l i l m a n S c h a f e r

D i s t r i b u t e d S y s t e m s ( I r o u p D e i ) a r t i n e i i l o f C o n i p t i t e r S c i e n c e I' rinity Col l e ge , Uiiivei’s i t y of D u b l i n

(3)
(4)

1. t h e u n cl er s i g i i ed , d e c l a r e t h a t t h i s w o r k h a s n o t j ^ r e vi ous l y b e e n s u b m i t t e d t o l l i i s an>' o t h e r U n i v e r s i t y , a n d t l i a t u n l e s s o t h e r w i s e s t a t e d , it is e n t i r e l y m y o w n w o r k .

I ' i l m a n S c h a f e r

(5)

I, t h e u n d e r s i g n e d , a g r e e t h a t T r i n i t y C o l l e g e L i b r a r y m a y l e nd o r c o | ) y t h i s t h e s i s u p o n r ( ' ( | u e s t .

I'iliiian S c h a f e r

(6)

'J’h e w o r k d e s c r i b e d in t h i s t h e s i s w o u l d n e v e r h a v e b e e n p o s s i b l e w i t h o u t t h e h e l p a n d s u i ) ] ) o r t o f a n u m b e r o f p e o p l e . F i r s t o f all, I w o u l d like t o t h a n k m y s u p e r v i s o r . D r . \ ’i n n y C a h i l l , f or p r o v i d i n g d e d i c a t e d a n d p r o f o u n d g u i d a n c e , m o r a l s u p p o r t a n d c o n s t r u c t i v e c r i t i c i s m o v e r t h e e n t i r e t i m e .

I w o u l d a l s o like t o t h a n k t h e p e o p l e in t h e I g u a n a p r o j e c t w h o h a v e b e e n a g r e a t c o m p a n y o v e r t h e l ast co u [ ) l e o f y e a r s a n d w h o c o n t r i b u t e d t o m a n y o f t h e i d e a s p r e s e n t e d in t h i s l li esi s, n a m e l y l \ H e r H a r a s z t i , . )im D o w l i n g a n d l i a r r y l l e d m o n d .

(7)

S o f t w a r e e n g i n e e r i n g in a d i s t r i b u t e d , h e t e r o g e n e o u s e n v i r o n m e n t is faced wi t h a, n u m b e r o f c h a l l en g e s . W i t h d i s t r i b u t i o n c o m e s t h e need for s y n c h r o n i s a t i o n , t r a n s a c t i o n s , a n d f aul t - t o l e r a n c e whi l e s u p p o r t for di fferent o p e r a t i n g s y s t e m s also h a s t o be t a k e n i n t o a c c o u n t . I'he d i s t r i b u t e d a n d d y n a m i c n a t u r e o f a p p l i c a t i o n s in s u c h a n e n v i r o n m e n t al so i m p o s e s s peci al r ec | u i r e m e n t s in t e r m s o f a d a p t a b i l i t y : c o m p o n e n t s b e i n g a d d e d t o or r e m o v e d f r o m t h e s y s t e m m a y recpiire a p p l i c a t i o n s t o a d a p t t h e m s e l v e s t o t h e c h a n g e d e n v i r o n m e n t . i ) ev e l o| )i ne n t s h o ul d m o r e o v e r not be r e s t r i c t e d t o o n e p a r t i c u l a r p r o g r a m m i n g l a n g u a g e . Il s o o n b e c o m e s a p | ) a r e n t t h a t a l ar ge a m o u n t o f effort in t h e d e v e l o p m e n t o f d i s t r i b u t e d a p p l i c a t i o n s is s]>ent on t h e S])ecihcation a n d i m p l e m e n t a t i o n o f t h e s e n o n - f u n c t i o n a l re­ q u i r e m e n t s . .Moreover, t h e a c t u a l f u n c t i o n a l p a r t s o f t h e a])pl i cat i on b e c o m e m o r e a n d inor(' i n t e r t w i n e d wi t h a n d d e p e n d e n t on t h e [)arts that, deal wi t h t h e fulfillment of non- i ' unctional reciuirement.s. As a c o n s e q u e n c e , little cha.nges in t h e desi gn of an aj)])lication m a y I'esult in t h e m o d i f i ca t i o n o f l ar ge a m o u n t s of c o d e t h r o u g h o u t , t h e s y s t e m .

In o r d e r t o t a c k l e t h e s e p r o b l e m s m o d e r n s o f t w a r e e n g i n e e r i n g is cl ear l y a d v a n c i n g t o ­ w a r d s m i d d l e w a r e a n d coni]>onent b a se d s y s t e m s s u c h as t h e C o m m o n O b j e c t Hecpiest B r o k e r . Ar c h i t e c t ur e ( C ' O R B A ) . E n t e r p r i s e .Java B e a n s (H!.]H) a n d t h e S y s t e m O b j e c t .\lf)del ( S O M ) . T h e s e s y s t e m s defi ne a | ) l a t f o r m - i n d e p e n d e n t o b j e c t m o de l , u su a l l y w i t h s u p p o r t for d i s t r i b u t i o n , p e r s i s t e n c e a n d t r a n s a c t i o n s , whi ch allow t h e r ap i d devel o])m(' ut o f a p p l i c a t i o n s in a h e t e r o g e n e o u s , d i s t r i b u t e d e n v i r o n m e n t .

(8)

( ' o i n ] )u t a ti oi ia l r eflection a n d inet a-l evel a r c h i t e c t u r e s offer a n a l t e r n a t i v e a p p r o a c h t o ­ w a r d s t h e d e v e l o ] ) m e n t o f c o m p l e x s y s t e m s in t h a t t h e y p ro v i d e a cl ean s e p a r a t i o n o f c o n c e r n s a n d a s t r u c t u r e d a p p r o a c h o f m a k i n g i m p l e m e n t a t i o n s m o r e o p e n . In o r d e r t o p r o v i d e g e n e r i c l a n g u a g e s u p p o r t for d i s t r i b u t e d c o m p u t i n g a s well as t h e a d v a n t a g e s o f coni|:>onent b a s e d p r o g i ’a m m i n g , we h a v e d e v e l o p e d a c o m p o s a b l e a n d e x t e n s i b l e meta-U' vel a r c h i t e c t u r e for a c o m p i l e d , o b j e c t - o r i e n t e d p r o g r a m m i n g l a n g u a g e . T h e m o d e l p r o p o s e d offers a high d e g r e e o f flexibility a n d can be u s e d t o e x t e n d o b j e c t - o r i e n t e d p r o g r a m m i n g l a n g u a g e s t o s u | ) p o r t a v a ri e t y o f a p p l i c a t i o n - i n d e p e n d e n t b e h a v i o u r s s u c h a s d i s t r i b u ­ ti on. p e r s i s t e n c e , t r a n s a c t i o n s a n d f a u l t - t o l e r a n c e . I ' h e m a i n c o n t r i b u t i o n s o f t h e w o r k d e s c r i b e d in t h i s t h e s i s c o n s i s t of t h e pr ovi si on o f a reflective o b j e c t - m o d e l t h a t is

• C o n i p o s a b l e : W e p r o v i d e a m e c h a n i s m t h a t all ows t h e a u t o m a t i c c o m p o s i t i o n of i n d i v i d u a l l y d e f i ne d o b j e c t b e h a v i o u r s . If t h e d e f a u l t s e m a n t i c s d o e s n o t yield t h e d e si r ed b e h a v i o u r , user def i ned com])Osition r ules c a n be a pp l i e d ma nu al l y .

• D y n a m i c ; l i u n n i n g a p p l i c a t i o n s c an d y n a m i c a l l y s w i t c h b e t w e e n d i f f er e nt o b j e c t m o d e l s , a l lo w i n g o b j e c t s t o evol ve in c h a n g i n g e n v i r o n m e n t s . T h i s kind o f f u n c t i o n ­ a l i ty c o u l d ])reviously o n l y be a c h i e v e d in i n t e r p r e t e d p l a t f o r m s .

• Efficient: I5y c h o o s i n g a c o m p i l e d l a n g u a g e we a c hi e ve p e r f o r m a n c e a d v a n t a g e s o v e r i n t e r p r e t e d l a n g u a g e s a n d pr e s e n t a n a r c h i t e c t u r e t h a t is s u i t a b l e for a p | ) l i c at i o n d o m a i n s s u c h as legacy s y s t e m s , o ]) e r a t i u g s y s t e m s a n d e m b e d d e d s y s t e m s .

(9)

1 I n t r o d u c t i o n

1.1 O p e n l n i | ) l e n i e n t a t i o n ... 1.2 I n t r o f l u c t i o n t o R e f l e c t i o n ... 1.2.1 ( ' o r n | > u t a t i o n a l R e f l e c t i o n ... 1.2.2 R e i f i c a t i o n ... 1.2.3 S t i ' u c t n r a l v e r s u s l i e l i a v i o u r a l R e f l e c t i o n . . . . 1.2.1 B a s e M e t a Leve l S e | ; a r a t i o n ... 1. 2.5 M e t a o b j e c t s a n d M e t a o b j e c t C l a s s e s ... 1.2.(i M e t a o b j e c t P r o t o c o l ... 1.2.7 . M e t a c l a s s e s ... I .:5 R e f l e c t i v e P r o g r a i n n i i n g L a n g u a g e s ... 1.1 . Aims a n d O L i j e c t i v e s ... 1.5 I g u a n a ... !.() ( 'out ril>ution o f t h i s I ' l i e s i s ... 1.7 I J o a d i n a p ...

2 R e f l e c t i v e , O b j e c t - O r i e n t e d P r o g r a m m i n g L a n g u a g e s

2.1 ( i c n e r a l o v e r v i e w ... 2. 2 S i n a l l t a l k ... 2.:5 C + + ... 2. 1 ( ) b j e c t i v e - C ... 2 . 5 . Java...

9

10 11 11 12

i;}

i ; 5

i:i

M M M

1 5

1 5

Hi

18

19

21

2.}

2-1

(10)

'2.6 Ope]iC-|--|- v l ...29

2.6.1 T y p e o f R e f l e c t i o n ...29

2.6.2 R eflectiv e F a c i l i t i e s ...29

2.6.3 P r o g r a m m i n g M o d e l ... 30

2.6.4 K n o w n A p p l i c a t i o n s ... 32

2.6.5 P e r f o r m a n c e ... 33

2.6.6 S u p p o r t for M e t a - T y p e s ... 33

2.7 OpenC'-|--|- v 2 ...33

2.7. J 'Fyi^e o f R e f l e c t i o n ... 33

2.7.2 R efle c tiv e F a c i l i t i e s ...34

2.7.3 P r o g r a m m i n g M o d e l ... 35

2.7.4 i^ e if o r m a n c e ... 37

2.7.5 K n o w n .‘\ p p l i c a 1 i o n s ... 3^

2.7.6 .Support for M e t a - T y p e s ... 39

2.8 C'odA ... 40

2.5.1 ry])e o f l i e f l e c t i o u ...40

2.8.2 R eflective F a c i l i t i e s ...40

2.8.3 P r o g r a m m i n g M o d e l ... 42

2.8.4 K n o w n ,‘\ p | ) l i c a t i o n s ... 42

2.8.5 P e r f o r m a n c e ... 43

2.8.6 S u p ])o rt for M e t a - T y p e s ... 43

2.9 A B C I . / R ... 44

2.9.1 4’y])e o f R e f l e c t i o n ...44

2.9.2 R eflective F a c i l i t i e s ... 44

2.9.3 P ro g i'a iiin iiiig M o d e l ... 45

2.9.4 I V r f o r m a n c e ... 47

2.9.5 K n o w n . ' \ p ] ) l i c a t i o n s ... 18

2.9.6 S u p p o r t for M e t a - T y p e s ... 48

(11)

3 T h e I g u a n a R e f l e c t i v e P r o g r a m m i n g M o d e l 5 0

3.1 ( i e n e r a l O v e r v i e w ... 51

3.2 Rei fi cat i on C a t e g o i ' i e s ... 51

3.2.1 S t r u c t u r a l Rei f i cat i on C a t e g o r i e s ... 52

3.2.2 B e h a v i o u r a l Rei fi ca t io n C a t e g o r i e s ... 52

3.2.3 E x t e n t of Refl ect i on ... 53

3.2.4 l)ei)en(lencies b e t we e n I^eification C a t e g o r i e s ... 53

3.2.5 P r o t o c o l s a n d P r o t o c o l S e l e c t i o n ... 54

3.2.6 S h a r e d B e h a v i o u r ... 57

3.3 M e t a o b j e c t C o m p o s i t i o n ... 58

3.3.1 Def aul t C o m p o s i t i o n S e m a n t i c s ... 59

3.3.2 M o d i f y i n g C o m | ) o s i t i o n ... 61

3.3.3 D i s c u s s i o n ... 64

3.3.4 The I g u a n a S y n t a x ... 64

3.4 S u m m a r y ... 65

4 T h e I g u a n a / C + + I m p l e m e n t a t i o n 6 7 1.1 .V|)|)lying tiie iModel ... 67

4.2 ( i e n e r a l O v e r v i e w ... (i8

4.3 4 he I g u a n a Met a - f j evel Cl as s l l i e r a i c h y ... 69

4.4 I ' h e P r e - l ’r o c e s s o r ... 71

4.5 S o u r c e - t o - S o u r c e T r a n s l a t i o n ... 72

4.5.1 P r o t o c o l Def i ni t i ons ... 72

4. 5. 2 A d d i n g I n t r o s p e c t i o n ... 73

4.5. 3 Boot s t , r a p| )i ng ... 74

4.5.4 .Adding i nt er ce ss i on ... 75

4.5. 5 I n s t a n c e p r ot o c ol s e l e c t i o n ... 79

4.5.() R u n - t i me C h e c k s ... 79

(12)

4.6 D y n a m i c M e t a - T y p e S e l e c t i o n ... 81

4.6.1 .Meta-level R e c o n f i g u r a t i o n ... 81

4.7 ' I’he D e f a u l t P r o t o c o l 85 4.7.1 M e t h o d I n v o c a t i o n ... 85

4.7. 2 S t a t e Access ... 85

4.7..’] O b j e c t C r e a t i o n ... 87

4.8 R e s t r i c t i o n s ...87

4.8.1 . • \ ut oni a t i c o b j e c t s ... 87

4.8. 2 . A r r a y s ... 88

4.8. 3 . A l i a s i n g ... 88

4.9 S u m m a r y ... 89

5 R e f l e c t i v e P r o g r a m m i n g w i t h I g u a n a 91 5.1 Usi ng l n t r o s | j e c t i o n ... 91

5.2 B o u n d a r y C h e c k s for . A r r a y s ... 92

5.3 H u n - t i i n e . Ad ap t a t i o n of . Syst ems S o f t w a r e ... 9;}

5.3.1 I he i ni ni ma i Buffer M a n a g e r ... 94

5.3.2 .A(la|)tation us i ng Design P a t t e r n s ... 94

5.3.3 . Ad ap t a t i o n us i ng R e f l e c t i o n ... 95

5.3.1 . State Transfer ... 97

5.3.5 D i s c i h s s i o n ... 98

5.4 .A M e t a - T y | ) e fc;r P e r s i s t e n t O b j e c t s ... 98

5.4.1 O v e r v i e w of O b j e c t P e r s i s t e n c e ... 99

5.4.2 I m p l e m e n t i n g I’e rs i s t e n t O b j e c t s us i n g l g u a n a / C ' - | - - | - ... 99

5.4.3 Us i n g P e r s i s t e n t O b j e c t s ... 101

5.4.4 . Ad ap t i ng t h e M e t a - L e v e l ... 104

5.4.5 D i s c u s s i o n ... 105

5.5 S u m m a r y ... 106

(13)

(i.l O v e r h e a d , W h e r e a n d W h y ...108

(i.l.J Desi gn Level ... 109

6.1. 2 I m p l e m e n t a t i o n Level ...109

G.1.3 l l o s t - L a n g u a g e L e v e l ... I l l 6.1. 4 A p p l i c a t i o n L e v e l ... 112

6.2 D i s c u s s i o n ...113

6.3 O t h e r 0|:>tiuiisation T e c h n i ( | u e s ... 114

6.3.1 P a r t i a l E v a l u a t i o n ...114

6.-3.2 P a r t i a l E v a l u a t i o n o f l g u a n a / C ' + + ... 116

6.3.3 E l i m i n a t i o n o f R u n - T i m e C h e c k s ... 117

6.1 S u m m a r _ y ... 117

7 C o n c l u s i o n a n d F u t u r e W o r k 1 1 8 7.1 U n d e r s t a n d i n g Ref l ect i ve P r o g r a m m i n g ... 120

7.2 P e r f o r m a n c e a nd O p t i m i s a t i o n ...121

7.-3 L' uture W o r k ...121

7.3.1 Ref l ect i on a n d De si gn P a t t e r n s ... 121

7.3.2 ( 'omi^osition o f M e t a - T y [ ) e s ... 121

7.3.3 C o m | ) i l e r S u | ) p o r t for Ref l ect i ve P r o g r a m m i n g L a n g u a g e s ... 122

7.3.4 I ' or ma J i s at i o n of M e t a - T y p e s ... 122

(14)

I n t r o d u c t i o n

R E F L E C T I O N , n . A n a c t i o n o f t h e m i n d w h e r e b y we o b t a i n a c l e ar e r \'iew of o u r r e l a t ion t o t h e t h i n g s o f y e s t e r d a y a n d a r e abl e t o avoi d t h e |)erils t h a t we shall n o t ag a i n e n c o u n t e r . A m b r o s e Bierce. The D e v il's DictioiKirij.

. Modern s o f t w a r e e ng i n e e r i n g h a s t o keep p a c e w i t h ever e vol vi ng r u n t i m e c n v i r o u n i e n t s t h a l pl ace new d e m a n d s on t h e d e v e l o p m e n t o f c o m p u t e r a] ) pl i cat i ons. Si nce t h e ad- \ e n t a n d p o p u l a r i t y o f t h e I n t e r n e t , for e x a m p l e , a c o m p l e t e l y different | ) r o g r a m m i n g e n \ ii'onmen1 h a s e m e r g e d , i n t i ' o d u c i n g a f l e m a n d foi' d i s t r i b u t e d a n d c o n c u r r e n t a])i)lica- l i o n s . I.ong- i ' unni ng s y s t e m s such as o ] ) e r a t i n g s y s t e m s a re m o r e o v e r faced w i t h d y n a m i c c h a n g e s t a k i n g |)lace at r u n - t i m e , w i t h c o n i | ) o n e n t s be i ng a d d e d t o o r r e m o v e d f r om t he ( ' i i v i r on me n t , recpiiring t h e s y s t e m t o ada|)t, itself t o t h e c h a n g e d s u r r o u n d i n g s . .As s ys ­ t e m s g r ow l a r g e r a n d b e c o m e i n c re as in g l y c o m p l e x , t h e q u e s t i o n a r i ses as t o w h a t e x t e n t a p r o g r a m m i n g l a n g u a g e c an assist dev e l oj ie r s in t h e t a s k of d e v e l o p i n g s u c h a p p l i c a t i o n s . O n e ai^proach is t o | jr ovi de d i r e c t s np] ) or t for s o m e e l e m e n t of d i s t r i b u t e d c o m p u t i n g IVom witliin t h e | ) r o g r a m m i n g l a n g u a g e . I']xam])les of t h o s e l a n g u a g e s i n c l u d e ( ' * * [Tay93, \' ( ' (1P93] , I'Jiierald [.)LI1B88] a n d .Java [CJ.IS96]. C'** is an e x t e n s i o n o f C++ a n d |:>rovides I l u ' a| )| )lication p r o g r a m m e r wi t h s u | ) p o r t for p e r si st e n c e , d i s t r i b u t i o n , a n d t r a n s a c t i o n s , h j ii e r ak i p r ov i de s object, m i g r a t i o n a n d an e x t e n d e d e x c e p t i o n h a n d l i n g m e c h a n i s m to rf'cover fr om p a r t i a l failures [Hut9()]. .Java on t h e o t h e r h a n d f e a t u r e s built-in s u p i )o r t for m u l t i - t h r e a d i n g a n d s t a n d a r d l i br ar i es for r e m o t e m e t h o d i n v o c a t i o n , m a k i n g t h e d e v e l ­ o p m e n t of c o n c u r r e n t , d i s t r i b u t e d a p p l i c a t i o n s easier.

(15)

s u p p o r t e d f e a t u r e usu a l l y recpiires a specific s y n t a x a n d / o r r u n - t i m e s u p p o r t , m a k i n g t h e l a n g u a g e m o r e c o m p l e x a n d difficult t o i m p l e m e n t .

A different a p p r o a c h t h a t a d d r e s s e s t h e s e p r o b l e m s is e x e mpl i f i ed by c o m p o n e n t - b a s e d s y s t e m s s uch as S u n ’s E n t e r p r i s e J a v a B e a n s ( E J B ) [MicOl], t h e C o m m o n O b j e c t Recpiest B r o k e r A r c h i t e c t u r e ( C O I i B A ) [Gro95] a n d I B M ’s S y s t e m O b j e c t M o d e l ( S O M ) [Lau94], f h e s e s y s t e m s p r o v i d e a p l a t f o r m - i n d e p e n d e n t f r a m e w o r k for b u i l d i n g a p p l i c a t i o n s in a d i s t r i b u t e d e n v i r o n m e n t a n d u s u a l l y c o m e w'ith bui l t -i n s u p p o r t for d i s t r i b u t i o n , p er si s­ t e n c e a n d t r a n s a c t i o n s , f ^ r o g r a m m e r s s i m p l y sel ect o r d e p l o y a pr e - d e f i n e d c o m p o n e n t i nt o t h e i r aj ^plication. s u b j e c t t o s o m e p r o g r a m m i n g c o n v e n t i o n s t h a t o n e h a s t o obey. Ho we v e r , t h e s e s y s t e m s a r e p r i m a r i l y t a r g e t e d t o w a r d s t h e d e v e l o p m e n t of b us i n e s s a p p l i ­ c a t i o n s a n d can h a r d l y be e mp l o y e d for t h e d e v e l o p m e n t o f low-level, p e r f o r m a n c e critical a p p l i c a t i o n s s u c h as o p e r a t i n g s y s t e m s a n d e m b e d d e d s y s t e m s . M o r e o v e r , t h e s e s y s t e m s a r e ' c l o s e d ’ s y s t e m s , m e a n i n g t h a t u s e r s d o n o t h a v e d i r e c t c o n t r o l ov e r t h e i m p l e m e n t a ­ t i on of t h e v ar io u s facilities a n d c a n in g e n e r a l not p r o v i d e c u s t o m i s e d s er vi ces. S u p p o r t for di l ferent o p e r a t i n g s y s t e m s , a m a j o r prerecpiisite for t h e d e v e l o p m e n t in a h e t e r o g e ­ neous. d i s t r i b u t e d e n v i r o n m e n t , m i gh t also n o t a l w a y s be avai l abl e. I nt er ope r a . bi l it y b e ­ t ween t h e s e s y s t e m s d o e s e x i s t t o s o m e e x t e n t , for exam])le. in t h e f o r m o f C ' O R B A - C O M briflges. but t h e s e c o m e a t t h e price o f i n c r e as e d c o m p l e x i t y a n d i n t r o d u c e c o m | ) a t i b i l i t y p r o b l e m s .

Si nce t h e p r ov i d e r o f a s o f t w a r e c o m p o n e n t c a n in g en er a l not foresee all p o s s ib l e us a g e s c e n a r i o s a n d s y s t e m r ecpi i r ement s , a new p r o g r a m m i n g mo de l is n e ed e d t h a t is in s o m e seiis(' " o p e n " a n d d o e s not restrict, its u s e r s by t h e de c i s i ons m a d e by its d e s i g n e i ’s.

1.1

O pen Im p lem e n ta tio n

(16)

I'he o p e n i ni ] ) le n i e n t a t io n a p p r o a c h sli oul d n o t be seen as a c o n t r a d i c t i o n t o t h e cla.ssicai l)lack b ox a p ] ) r oach. I n s t e a d, it s h o ul d be u n d e r s t o o d as an e x t e n s i o n t o t h e f o r m e r . a d \ o c a t i n g a fai r er t r a d e - o f f b e t w e en p e r f o r m a n c e on t h e o n e h a n d a n d a b s t r a c t i o n on t h e o t h e r , l a k e t h e U n i x s y s t e m call m a d v i s e as a n e x a m p l e . It allow's ] ) r o gr a m n ) e rs t o ‘a d v i s e ’ t h e u n d e r l y i n g v i r t u a l m e m o r y m a n a g e r a b o u t t h e u s a g e p a t t e r n o f a block of m e m o r y m a p p e d i n t o t h e a p p l i c a t i o n ’s a d d r e s s s p a ce . It t h e r e f o r e e x p o s e s s o m e h i d de n f u n c t i o n a l i t y o f t h e u n d e r l y i n g o p e r a t i n g s y s t e m t o t h e user, r e s u l t i n g in a m o r e efficient i n i | ) l e m e n t a t i o n .

Ho we v e r , t h i s e x a m p l e c an m e r e l y be r e g a r d e d as an a d hoc a p p r o a c h t o oj)en i m p l e m e n ­ t a t i o n s a n d o n l y al l ows ve r y r e s t r i c t e d ac c e s s t o t h e o p e r a t i n g s y s t e m ’s i n t e r n a l s . W h a t

is t her ef or e ne e de d is a m e t h o d o l o g y t h a t al l ows a m o r e r i g o r o u s a n d s t r u c t u r e d access t o a c o m p o n e n t ’s i n t e r n a l s . C o m p u t a t i o n a l reflection, as d e s c r i b e d in t h e f ol lowing s e ct io n s , c a n s e r ve as an u n d e r l y i n g t e c h n o l o g y for b u i l d i n g o p e n i n i ] ) l e m e n t a t i o n s in t h a t it e q u i p s a c o m p u t a t i o n a l s y s t e m w i t h a s e j i a r a t e r e p r e s e n t a t i o n of itself.

I nevi tabl y, a n u m b e r o f issues arise, n a m e l y t o w h a t e x t e n t i n t e r n a l i m p l e m e n t a t i o n d e t a i l s s h o u l d or c a n be e x p o s e d t o t h e user a n d how t h e e r r o n e o u s o r d e l i b e r a t e m i s u s e o f s uch i n f o r m a t i o n can be | )r ev en t e d . T h e s e issues will follow us t h r o u g h t h i s t h e si s a n d will be d('alt w i t h m o r e t h o r o u g h l y as t h e y arise.

1.2

I n t r o d u c t i o n t o R e f l e c t i o n

' f h i s s e c t i on i n t r o d u c e s s o m e o f t h e m a i n c o n c e p t s a n d t e r m i n o l o g y used t h r o u g h o u t t h e r e m a i n d e r of t his t hesi s. In m o s t c a s e s t h e c o n c e p t s a n d t e r m i n o l o g y p r e s e n t e d her e a r e not. specific t o t h e a u t h o r ’s view a n d a r e wi del y used in t h e reflection c o m m u n i t y a t large. I nf oi ' t una t e l y, t h e r e is n o t c o m p l e t e c o n s e n s u s on t h e use o f all o f t h e s e t e r m s even w i t h i n t h e I ' cf l e c t i o n c o m n u i n i t y .

1. 2.1

C o m p u t a t i o n a l R e f l e c t i o n

(17)

it i l l u s t r a t e s s o m e of t h e f e a t u r e s t h a t a r e c h a r a c t e r i s t i c o f a reflective s y s t e m , n a m e l y:

I n t r o s p e c t i o n : Int r o s p e c t i o n is t h e p r oc e s s o f o b s e r v i n g o n e ’s i n t e r n a l s t a t e o r s t r u c ­ t u r e . Kor a s y s t e m t o be a bl e t o i n t r o s p e c t a n d r e as o n a b o u t itself it n e e d s a s e l f repre.se n ta tio n .

S e l f r e p r e s e n t a t i o n : In t h e e x a m p l e a bo v e , ’I ’ r e p r e s e n t s D e s c a r t e s himself, his n o t i o n o f himself.

C a u s a l c o n n e c t i o n : A c o m p u t a t i o n a l s y s t e m c o n t a i n s an i n t e r n a l r e p r e s e n t a t i o n of s o m e ])art of t h e e x t e r n a l wor l d, its d o m a i n (for e x a m p l e in f o r m o f d a t a a n d c o d e ) . A s y s t e m is said t o be c au s a l l y c o n n e c t e d t o its d o m a i n if t h e i n t e r n a l s t r u c t ur es a n d t he d o m a i n t h e y r e p r e s e n t a r e linked in s u c h a w a y t h a t if o n e o f t h e m c h a n g e s , t hi s l e a d s t o a c o r r e s p o n d i n g effect u p o n t h e o t h e r [Mae87]. A reflective s y s t e m is o n e w h o s e s e l f - r e| ) r es en t a t i o n is c au s a l l y c o n n e c t e d t o itself, o r whi ch is s el f - r ef erent i al . A g a i n , as D e s c a r t e s d e d u c e s “t h e r e f o r e I a m ” , he g e n e r a t e s n e w k n o w l e d g e wh i c h in t u r n feeds back i nt o his s e l f - r e p r e s en t a t i o n in a c a u sa l l y c o n n e c t e d way.

Reflection c a n be d i ve rs a n d o c c u r s in m a n y different d o m a i n s . So h o w d o e s t h e a b o v e re l a t e t o o b j e c t - o r i e n t e d |)rogi’amiriiiig l a n g u a g e s ? An o b j e c t - o r i e n t e d p r o g r a m m i n g l a n ­ g u a g e (o o il) p r ov i d es c o u ce | ) t s s uch as classes, i n h e r i t a n c e , m e t h o d i n v o c a t i o n a n d s t a t e acc('ss. Ap | ) l i c a t i o n s w r i t t e n in such a l a n g u a g e coiice]>tually consi st o f a set o f o b j e c t s e x c h a n g i n g m e s s a g e s a n d p e r f o r m i n g c om] Mi t a t i ons u])on r e ce pt i o n o f m e s s a g e s . In a re- flec'tive p r o g r a m m i n g l a n g u a g e , i nt r osj^ection e n a b l e s o b j e c t s t o q u e r y t h e i r o w n s t a t e , for e x a m p l e t o h n d o u t a b o u t t h e i r class, t h e m e t h o d s a n d a t t r i b u t e s t h e y ])rovide, e t c . ' .Moi'co\'er, t h e self r e p r e s e n t a t i o n m a y also p ro vi d e a descri])tion of t h e o b j e c t ' s b e h a v i o u r , i.e.. c o d e t h a t d e s c r i b e s t h e o b j e c t sjjccific s e m a n t i c of m e s s a g e s e n d i n g / r e c e i v i n g , m e t h o d d i s | ) a t c hi n g , etc.

1. 2 .2

R e i f i c a t i o n

.Any O O l ' L s u p p o r t s a n u m b e r o f f e a t u r e s such as o b j e c t c r e a t i o n , m e t h o d i n v o c a t ion, s t a t e access a n d i n h e r i t a n c e . A p r o g r a m m i n g l a n g u a g e t h e r ef or e p r ov i d e s a s y n t a x t h a t is used l)y t h e | > r o g r a m m e r t o e x p r e s s a p a r t i c u l a r conce])t as well as a s e m a n t i c t h a t d e s c r i b e s how t h e concej j t is i n t e r p i ’e t e d o r e x e c u t e d . In t r a d i l i o n a J O O P L s t h e s y n t a x / s e m a n t i c s rel at i onshi ]) is fixed, m e a n i n g t h a t t h e r e is no (easy) wa y for a | ) r o g r a m n i e r t o m o d i f y t h e

(18)

s y n t a x o f t h e l a n g u a g e o r t o mo di f y t h e wa y a s p e ci h c l a n g u a g e c o n s t r u c t is i n t e r p r e t e d . lk:iJication refers t o t h e p r o ce ss o f m a k i n g t h e i m p l e m e nt a . t i o n o f t h e s e f e a t u r e s ex|)licit. w i t h i n t h e l a n g u a g e so t h a t t h e y c a n be reflected u p o n . In p a r t i c u l a r , r ei f i cat i on allows t h e i m p l e m e n t a t i o n o f t h e s e f e a t u r e s t o be modi f i ed f r o m w i t h i n t h e l a n g u a g e .

1 . 2 . 3

S t r u c t u r a l v e r s u s B e h a v i o u r a l R e f l e c t i o n

S t r u c t u r a l reflection is t h e abi l i t y o f a l a n g u a g e t o p ro v i d e a c o m p l e t e rei fi cat i on o f b o t h t h e p r o g r a m c u r r e n t l y b e i n g e x e c u t e d as well as c o m p l e t e reifi cat i on o f its a b s t r a c t d a t a tyi )es (e.g. its classes) [DM95]. l i e h a v i o u r a l reflection on t h e o t h e r h a n d is t h e ability' o f t h e l a n g u a g e t o |)rovi de a coni]>lete r eification of its s e m a n t i c s . 13ehavioural reflection r e q u i r e s a m e c h a n i s m t o i n t e r v e n e in t h e e x e c u t i o n o f t h e c u r r e n t p r o g r a m in o r d e r t o ( ' x e c u t e s o m e reflective c o d e t h a t will an.alyse o r m o d i f y t h e c o u r s e o f e ve nt s.

1 . 2 . 4

B a s e - M e t a L e v e l S e p a r a t i o n

In g e n e r a l we c an d i s t i n g u i s h b e t we e n t h e base-level o f a s y s t e m a n d its m e t a - l e v e l . 'I'he base-level c o n t a i n s t h e c o d e a n d d a t a c o n c e r n e d wi t h t h e ap])l i cat i on d o m a i n whi l e t h e n u ' t a- l evel c o n t a i n s t h e c o d e a n d f la t a c o n c e r n e d wi th t h e base-level. We c a n t a l k ai ) out a s y s t e m e x e c u t i n g at t h e base-level w h e n p e r f o r m i n g d o m a i n - s p ec i f i c c o m p u t a t i o n a n d e x e c u t i n g at t h e me t a- le v e l w h en c a r r y i n g o u t c o m ] ) u t a t i o n a b o u t t h e base-level. ' Fhus 1 h(' ( s e l f -) re | ) re se nt a t i o n o f t h e base-level e xi s ts as t h e d a t a o f t he me ta -l e v e l a n d reflective c o m| ) U t a t i o n is p e r f o r m e d wh e n e x e c u t i n g at t h e me t a - le v e l . T h e t r a n s i t i o n f r o m p e r ­ f o r m i n g d o m a i n c o m p u t a t i o n t o | ) e r f o r m i n g reflective c o m p u t a t i o n is c h a r a c t e r i s e d as a t i a n s i t i o n f r om b a s e t o me t a - le v e l e x e c u t i o n .

1 . 2 . 5

M e t a o b j e c t s a n d M e t a o b j e c t C l a s s e s

In a I'eflective OOIM,, a ni et aobj er t (also k n o w n as a ni ( ta - l e v el objcrt) is a n object, t h a t liolds i n f o r m a t i o n a b o u t t h e i m p l e m e n t a t i o n a n d i n t e r p r e t a t i o n o f s o m e o b j e c t [Mae87]. r i i e set of n i e t a o b j e c t s t h a t r e pr es e nt a p a r t i c u l a r o b j e c t t o g e t h e r f o r m i t s incia-level. T h e set o f m e t a o b j e c t s r e p r e s e n t i n g all t h e base-level o b j e c t s t h a t m a k e u p a n a]j|)lica1ion t o g e t h e r f o r m t h e a p | ) l i c a t i o n ’s rneta-level.

(19)

even t h e c o d e of its m e t h o d s . O n t h e o t h e r h a n d , b e h a v i o u r a l n i e t a o b j e c t s a r e used t o i m p l e m e n t v ar io u s as i )e c t s o f an o b j e c t ’s b e h a v i o u r . F o r e x a m p l e , b e h a v i o u r a l m e t a o b j e c t s m i g h t be used t o i m| > l eme nt o b j e c t c r e a t i o n or m e t h o d i n vo c at i o n .

1 . 2 . 6

M e t a o b j e c t P r o t o c o l

M e t a o b j e c t s |)rovide t h e n e c e s s a r y f u n c t i o n a l i t y t o c o n t r o l a n d re]>resent base-level o b j e c t s . C o m m u n i c a t i o n b e t w e e n b a s e a n d me t a -l e v e l o b j e c t s t a k e s ])lace t h r o u g h a well def i ned s e t o f i n t e r f ac e f u n c t i o n s . ' Fhe set o f t h e s e i n t e r f ac e f u n c t i o n s is r ef e r r ed t o as t h e m e tn o b je c t p rotocol [KP96] , or M O P for s h o r t .

1. 2.7

M e t a c l a s s e s

S o m e o b j e c t - o r i e n t e d p i ' o g r a n i m i n g e n v i r o n m e n t s , i n c l u d i n g S m a l l t a l k a n d S O M . p r ov i d e n u t a r la s s e s as t h e n a t u r a l b a s e o f t h e i r o b j e c t m o d e l: m e t a c l a s s e s a r e c l asses w h o s e i n­ s t a n c e s a r e t h e m s e l v e s cl asses. I ' h e y defi ne tlie c o m m o n |>ro])erties t h a t all cl as s e s s ho u l d proN'ide. for exairi|)le. how me t h o d s a r e d i s p a t c h e d . In S m a l l t a l k t h e r e is a fixed o n e - t o - o n e r e l a t i o n s h i p b e t w e en a c l ass a n d i t s m e t a c l a s s , e v e ry met acla,ss is def i ned by t h e S m a l l t a l k r u n - t i m e envii-onnuMit a n d c a n n o t be a l t e r e d by t h e a]:>plication ] >r ogr a mme r . S O M on t h e o t h e r h a n d allows t h e (levelojMnent a n d c o m p o s i t i o n of i n d e p e n d e n t met acl a. sses [l''l)M!)4].

1.3

R e fle c tiv e P r o g r a m m in g L a n g u a g e s

R a t h e r t h a n s u p p o r t i n g a fixed s e t o f facilities for a specific p r o g r a m m i n g e n v i r o n m e n t , F('liective i i r o g r a m m i n g l a n g u a g e s a r e d e s i g n e d so t h a t t h e i r i m p l e m e n t a t i o n is m o r e o p e n , al l owi ng a d a p t a t i o n of t he l a n g u a g e t o v a r yi n g , n o n - f u n c t i o n a l r ec i ui r ement s . In a reflective | ) r o gr a ni i n i n g l a n g u a g e , p r o g r a m m e r s c a n a l t e r t h e s y n t a x a n d s e m a n t i c s of t h e l a n g u a g e itself a n d t her eb y a d j u s t t he b e h a v i o u r o f t h e l a n g u a g e c o n s t r u c t s t o build a | ) r o g r a m m i n g e n v i r o n m e n t t h a t best fits t h e i r needs. F o r e x a m p l e , if t h e l a n g u a g e d o e s n o t h a v e bui l t -i n suppor t , foi', l e t ' s sa\'. d i s t r i b u t i o n , it c a n be e x t e n d e d t o allow t h e i n v o c a t i o n o f r e m o t e m e t h o d s by m o d i f yi n g t h e s e m a n t i c s o f a n o r m a l m e t h o d call.

I.isp for exani])le is a f u nc t i o n a l p r o g r a m m i n g l a n g u a g e w i t h reflective facilities: f u n c t i o n s a re first class e n t i t i e s t h a t c a n be mani | Mi l at ed a s c a n a n y o t h e r val ues. T h i s is a c h i e v e d

(20)

1.4

A im s and O b jec tiv es

( i e i i e r a l l y s j ^ e a k i n g , w e w a n t t o e x t e n d t l i e e x i s t i n g o b j e c t - m o d e l o f a p r o g r a m m i n g l a n ­ g u a g e ill s u c h a w a y t h a t it is p o s s i b l e t o i n t r o d u c e n e w o b j e c t s e m a n t i c s t o t h a t l a n g u a g e .

I'his e x t e n s i o n s h o u l d ( f r o m t h e a p p l i c a t i o n p r o g r a m m e r ’s ] )oi nt o f v i e w ) be:

• I ' r a n s p a r e n t : t h e r e f l e c t i v e e x t e n s i o n s h o u l d b e a s t r a n s p a r e n t a s p o s s i b l e , w i t h o u t t h e n e e d f o r a p p l i c a t i o n p r o g r a m m e r s t o e x p l i c i t l y i n v o k e m e t a - l e v c l c o m p u t a t i o n .

• C ' o m p o s a b l e : it s h o u l d b e p o s s i b l e t o c o m b i n e a n d a u g m e n t o b j e c t b e h a v i o u r s in a m e a n i n g f u l w a y , s o f o r e x a m p l e t o a l l o w t h e c o n s t r u c t i o n o f b o t h p e r s i s t e n t a n d r e m o t e l y a c c e s s i b l e o b j e c t s .

• D y n a m i c : t h e o b j e c t m o d e l s h o u l d b e a b l e t o e v o l v e o v e r t i m e , e n a b l i n g o b j e c t s t o a d a p t t h e m s e l v e s t o a c h a n g i n g e n v i r o n m e n t .

• K x t e n s i b l e : t h e r e s h o u l d b e n o f i xed s e t o f o b j e c t b e h a v i o u r s . It s h o u l d b e p o s s i b l e t o d e v e l o p n e w oi' m o d i f y e x i s t i n g o b j e c t m o d e l s .

[DM9.5] d e s c r i b e s w h a t a n i d e a l r e f l e c t i v e l a n g u a g e s h o u l d offer:

" I d e a l l y , a r e f l e c t i v e l a n g u a g e s h o u l d s u j ) p o r t a m e t h o d o l o g y o f r e ( l e c t i \ e c o m p u t a t i o n s g i v i n g i t s u s e r s a s m u c h f l e x i b i l i t y a s p o s s i b l e , it s h o u l d b e |)0s s i b l e t o m o d i f y t h e b e h a v i o u r o f s o m e c o n s t r u c t f o r t h e w h o l e e x e c u t i on o f a p r o g r a m , o r f or s h o r t p e r i o d o f ( e x e c u t i o n ) t i m e . It s h o u l d a l s o b e | ) o s s i b l e t o m o d i f y t h e b e h a v i o u r o f s o m e c o n s t r u c t f o r all t h e p r o g r a m o r o n l y for s o m e o f i t s s u b p a r t s . N o n e o f t h e l a n g u a g e s c u r r e n t l y p r o | ) o s e d a. chi eves t h i s level o f ffexi bi l i t y"

M a i n l y b e c a u s e o f e f f i c i e n c y r e a s o n s , p r o v i d i n g all o f t h e f u n c t i o n a l i t i e s a s d e s c r i b e d a b o v e m a y n o t b e feasil)le. W e t h e r e f o r e h a v e t o f i nd a g o o d c o m p r o m i s e b e t w e e n f u n c t i o n a l i t y o n t h e o n e h a n d a n d p e r f o r m a n c e o n t h e o t h e r h a n d .

1.5

Iguana

(21)

w i t h e v o l v i n g r u n - t i m e e n v i r o n m e n t s , r e q u i r i n g t h e a p p l i c a t i o n t o a d a p t itself t o t h e mnv e n v i r o n m e n t , s uch as o p e r a t i n g s y s t e m s a n d m i d d l e w a r e .

A desi gn pri nci pl e t h a t h a s b e e n i n f lu e n c i n g t h e I g u a n a m o d e l t o a g r e a t e x t e n t w a s t h e idea o f a coni | ) l et e decom]:)osition o f t h e u n d e r l y i n g o b j e c t m o de l , al lowi ng a ver y fine g r a i n e d c o n t r o l over t h e reification o f l a n g u a g e f e a t u r e s . Ho we v e r , in p r a c t i c a l t e r m s t hi s a p | ) r o a c h h a s been foujid as t o be t o o c o m p l i c a t e d , l e ad i n g t o a n o v e r s pe c i a l i s a t i o n of M O l ' s [Pa,w98]. T h e following is a c r i t i q u e t h a t s u m m a r i s e s t h e m a i n deficiencies o f t h e I g u a n a mo d e l in its pi' evious version:

• C o m p l e x i t y : T h e m o d e l w a s t o o c o m p l e x , c o n f r o n t i n g t h e u s e r w i t h a n u m b e r of f e a t u r e s w h o s e s e m a n t i c s we r e n o t fully u n d e r s t o o d a n d / o r p r a c t i c a l . It also r e qu i r e d a k n ow l e d ge of t h e i nt r i ns i c m e c h a n i s m s o f t h e h o s t p r o g r a m m i n g l a n g u a g e wh i c h d e f e a t e d l a n g u a g e i n d e p e n d e n c e a n d e as e o f use.

• S a f e t y a n d r o b u s t n e s s : M a n y issues c o n c e r n i n g s a f e t y a n d r o b u s t n e s s in reflective p r o g r a m m i n g ha.d n o t been a d d r e s s e d sufficiently. O p e n i n g u p a l a n g u a g e a n d ;il- l owi ng t h e p r o g r a m m e r t o i n t e r c e d e wi t h t h e u n d e r l y i n g o b j e c t mo de l recpiii'es a p r o f o u n d u n d e r s t a n d i n g o f t h e l a n g u a g e ’s i n t r in s i c m e c h a n i s m s . Us e r s o f a r eflective s y s t e m not onl>’ h a \ e t o m a k e s u r e t h a t t h e i r base-level a p p l i c a t i o n is s e m a n t i c a l l y cori' ect. t h e y must also ensui' e t h a t t h e c o d e at. t h e met a- l evel is c o n s i s t e n t . T h e t h o u g h t l e s s use o f reflection c a n easily affect t h e e n t i r e s y s t e m a n d m a k e s d e b u g g i n g ( ' \ en hai'd('r as e r r o r s c a n o c c u r at b o t h t h e b a s e a n d me t a- l evel .

• r ia ns ] ) a r e i i cy: The | )r evi ons ver si on di d n o t s e ] ) a r a t e sufficiently b e t w e e n base a n d m e t a - l e \ ’el cotie a n d e x p o s e d t o o m a n y i m p l e m e n t a t i o n d e t a i l s t o t h e api^licjiticin | ) r o g r a m m e r . .'Vgain, t h i s rai ses t h e issue as t o w h a t e x t e n t a n i m ] ) l e m e n t a t i o n c a n be o| )ened up w i t h o u t l e a di n g t,o an o v er l oa d o f accessi bl e f e a t u r e s . M o r e o v e r , it w a s not possi bl e t o use reflective a n d n o n - re fl ec ti ve o b j e c t s i n t e r c h a n g e a b l y .

• I m p l e m e n t a t i o n : O n l y a p a r t i a l i m p l e m e n t a t i o n e x i s t e d . 'Flie f e a s a b i li t y a n d aj j pl i - c ab i l i ty o f t h e I g u a n a m o d e l in p r a c t i c a l t e r m s still h a d t o be p r ov e n .

1.6

C ontribution o f this T h esis

(22)

T h e c h a l l e n ge w a s t o m a i n t a i n t h e flexibility or i gi nal l y e nv i s a g e d a n d t o find a user i n­ t e r f a c e whi ch is a t t h e s a m e t i m e s i mp l e , r o b u s t a n d ex p r es s i v e . A s a n o u t c o m e of o u r wo r k we i n t r o d u c e t h e c o n c e p t of a m e t a - t y p e as s uch a n i n t e r f ac e t h a t s e rv e s o u r p u r p o s e , ' f i l e m e t a - t y p e o f a n o b j e c t c h a r a c t e r i s e s its o b j e c t m o d e l a n d as s u c h its n o n - f u n c t i o n a l ij e h a v i o u r . F o r e x a m p l e , a m e t a - t y ] ) e Persi st ent m i g h t c o r r e s p o n d t o an o b j e c t - m o d e l si i p] ) or t i ng o b j e c t j^ersistence whi l e a di f f e r e nt m e t a - t y p e R e mo t e m i g h t s u p p o r t r e m o t e m e t h o d i nv o c a t i o n . W e also p r o v i d e a s e m a n t i c for c o m b i n i n g mul t i | )l e m e t a - t y p e s by a m e c h a n i s m s i mi l a r t o class i n h e r i t a n c e . .4s will b e c o m e c l ea r e r l a t e r , met a- t y] >es differ fr om i n e t a c l a s s e s as d e s c r i b e d a b o v e in t h a t we allow' m e t a - t y p e s t o be d y n a m i c a l l y se­ lected by i n s t a n c e s o f p o t e n t i a l l y a n y class, s u b j e c t t o a few r es t r i c t i o n s . M e t a c l a s s e s on t h e o t h e r h a n d defi ne t h e b e h a v i o u r of a class a n d t h e r e b y t h e b e h a v i o u r o f all i n s t a n c e s of t h a t class.

By a p p l y i n g tlie I g u a n a m o d e l t o a com| )i l ed l a n g u a g e , in t h i s c as e C+ + , we al so d e m o n ­ s t r a t e d t h a t c o m p i l e d p l a t f o r m s c an e xh i b i t a flexibility c o m p a r a b l e t o inter]M'eted l a n ­ g u a g e s , while at t h e s a m e t i m e i n t r o d u c i n g on l y lit t l e o r no o v e r h e a d w h e n t h e reflective f e a t u r e s a re not used.

We h a v e chosen C++ a s a h o s t l a n g u a g e for a c ou p l e o f r ea s o n s . F i r s t , it is w id e ly used. Se co nd , it allows low-level a ccess a n d is highl y p e r f o r m a n t , b o t h cr uci al p r o p e r t i e s for t h e de\-elo|)inent o f o | ) e r a t i n g s y s t e m s a n d emi ^edded s y s t e m s . T h e ,A.pertos o | ) e r a t i n g s y s t e m as (h' scri bed in [’N'KI.94, LYil9-5] for exani])le uses reflection as a n u n d e r l y i n g de s i gn p r i n ­ ciple'. i'lfliciency h a s been re c ogni se d as a m a j o r c o n c e r n . Su[)|>orting r u n - t i m e I'eflection in a coiii|)iled l a n g u a g e c a n a d v a n c e t h e r es e a r ch in t h a t a r e a by p r o v i d i n g a d e v e l o p m e n t p l a t f o r m for efficient a n d low-level | ) r o g r a m m i n g .

It s h o u l d l>e n o t e d h o w e ve r t h a t t h e ] ) r o g r a m m i n g m od e l descrii)ed in t h i s t h es i s is i n t e n d e d t(j be l a n g u a g e i nde i )e n d e n t a n d not. r e s t r i c t e d t o C++ in ] )ar t i cul ar. In f act , c u r r e n t w o r k is invest i g a t i n g t he i m p l e m e n t a t i o n o f t h e I g u a n a m o d e l in .Java [RCOO]. M o r e specifically, we a d d r e s s e d t h e follow'ing issues in o u r i m p l e m e n t a t i o n of m e t a - t y p e s :

M e t a o b j e c t c o m p o s i t i o n : I g u a n a ’s m o d u l a r desi gn al l ows t h e c o m p o s i t i o n o f m e t a ­ level o b j e c t s in o r d e r t o c o m b i n e t w o or m o r e b e h a v i o u r s . ,‘\ s a n e w f e a t u r e , we p r o v i d e a u t o m a t i c m e t a o b j e c t c on i | ) o s it i on . If t h e d ef a u l t s e m a n t i c s d o e s not. yield t h e de s i r e d b e h a \ ' i o u r . user defi ned com| )Osi t i on r ules c a n be a pp l i ed easily.

(23)

a s i g n i fi c a n t i m p r o v e m e n t t o e a rl ie r ve r si o n s o f I g u a n a , we n o w p r o v i d e a saf e t r a n s i ­ t i on b e t w e e n d i ff er en t me ta -l e ve l c o n f i g u r a t i o n s , a c c o m p l i s h e d by a c o m b i n a t i o n o f s t a t i c s u b - t y p i n g rules a n d r u n - t i m e m e t a - t y p e ciiecking.

U n d e r s t a n d i n g m e t a - l e v e l p r o g r a m m i n g : in c o n t r a s t t o o b j e c t - o r i e n t a t i o n , reflec­ t ion r e m a i n s a r a t h e r e so t e r ic p r o g r a m m i n g p a r a d i g m a n d h a s n o t f o u n d its w a y i n t o e x i s t i n g c o m p i l e r t ecluiologies. In a n u m b e r of cas e s t u d i e s we s h o w h o w me t a -l e v el p r o ­ g r a m m i n g c a n p r o v i d e a g e ne r ic f r a m e w o r k for b u i l d i n g c e r t a i n t y p e s of a p p l i c a t i o n s , for exam])l e, s y s t e m s t h a t need t o d y n a m i c a l l y a d a p t t o c h a n g i n g recj ui r ement s .

O p t i m i s a t i o n : T h e flexibility g a i n e d by e x t e n d i n g t h e l a n g u a g e a n d g i vi ng t h e users liie o p p o r t u n i t y t o a d a p t t h e l a n g u a g e t o t h e i r n e ed s u su a l l y i n c u r s s u b s t a n t i a l i n t e r p r e ­ t a t i v e o v e r h e a d . A l t h o u gi i t h i s issue h a s been a d d r e s s e d by a n u m b e r o f r e s e a r c h er s , it h a s not sufficiently been sol ved in a wa y t h a t it wo u l d h a v e i n c re as ed t h e accei:>tance of r ellective | :)rogrammi ng. We ident i f y | )rofi t abl e t a r g e t s a n d technic[ues for o ] ) t i m i s a t i o n . a l l owi ng a m o r e efficient i m] ) le me n t a 1 i on o f t h e reflective p r o g r a m m i n g f e a t u r e s . P r a c t i c a l e x p e r i e n c e s w i t h usi ng reflection a s a t ool for p r o v i d i n g pr o] ) er t i es s u c h as f a u l t - t o l e r a n c e a n d group-l.iased d i s t r i b u t e d s y s t e m s h o we v e r h a v e s h o w n t h a t t h e c o s t s d u e t o t h e use of a iiiet aol )j ect ])rotocol a r e negligible wi t h r e sp e ct t o t h e e xe c u t i o n c o s t s o f t h e ni et a- Ini i ct i oual | )ro| )ert i es [I''P98].

1.7

R o a d m a p

(24)

R e fle c tiv e , O b j e c t - O r ie n t e d P r o g r a m m in g

L a n g u a g e s

R E V I E W , v . t . T o s e t y o u r w i s d o m ( h o l d i n g n o t a d o u b t o f it. A l t h o u g h in t r u t h t l i e r e ' s n e i t h e r b o n e n o r skin t o it)

At wo r k u])on a b o o k , a n d so r ead o u t o f it r ii e ( | ualities t h a t you h av e first r ead i n t o it.

At i i bro. ‘<f H i e i r f . I'hf D e v / T s J ) i r t i o n a r i / .

W ith t r a d i t i o n a l , o l) j e c t - o r i e n t e d l a n g u a g e s , t h e d e v e l o | ) me nt o f s y s t e m s t h a t a r e c h a r ­ a c t e r is e d by a st r o n g i n t e r d e p e n d e n c y of f u nc t i o n a l a n d n o n - f u n c t i o n a l r e q u i r e m e n t s can lesult in c o d e w h e r e p a r t s d e a l i n g w i t h t h e f u n c t i o n a l a s p e c t s of t h e a | ) pl i c at i o n a r e t o a large e x t e nt i n t e r t w i n e d w i t h p a r t s t h a t deal wi t h t h e n o n - f u n c t i o n a l a s | )ect s . T a k e r e m o t e m e t h o d i n v o c a t i o n s as an e x a m p l e . I m p l e m e n t i n g r e m o t e o b j e c t s us i n g an a r c h i t e c t u r e such as C ' O R l i A r e qui r e s t h a t a r g u m e n t s t o r e m o t e m e t h o d s a r e w r a p p e d in s peci al w r a p - pei- o b j e c t s ' . A l t h o u g h m u c h o f t h e f u n c t i o n a l i t y u n d e r l y i n g r e m o t e o b j e c t s c a n be h i d d e n by us i ng n o r m a l class i n h e r i t a n c e , t h e a p p l i c a t i o n now c o n t a i n s cocie t o w r a p a n d u n w r aj ) a r g u m e n t s a n d r e t u r n val ues of r e m o t e m e t h o d s .

Reflective p r o g r a m m i n g l a n g u a g e s |)rovi de a n a l t e r n a t i v e a|:)|:)roach in t h e d e v e l o | ) m e n t of such s y s t e m s in t h a t t h e y allow t h e i m j ^ l e m e nt a t i o n of t h e h o s t l a n g u a g e ’s o b j e c t m o d e l t o be m a d e moi ’(' o| )en. a ll o wi n g d i f f er en t o b j e c t m o d e l s t o be s u p p o r t e d s i m u l t a n e o u s l y wi t hi n a single l an g u a g e . In a r eflective a r c h i t e c t u r e , c o d e d e al i n g w i t h t h e f u n c t i o n a l I ' c q u i r eme n t s resides a t t h e base-level w h e r e a s c o d e d e a l i n g w i t h n o n - f u n c t i o n a l recpiire- m e nt s , such as |X’r si s t e n c e a n d d i s t r i b u t i o n , resides a t a s e p a r a t e m e ta l e v e l. C o m r n u

(25)

ni cat i oi i b e t w e e n b a s e a n d me t a - l e ve l is a ch i e v e d by i n t e r c e d i n g w i t h t h e e x e c u t i o n or i n t e r | ) r e t a t i o n of l a n g u a g e o p e r a t i o n s .

H o w e ve r , d e s p i t e i t s o b v i o u s a d v a n t a g e s , reflective p r o g r a m m i n g r e m a i n s t o be a r a t h e r ne gl ec te d | > r o g r a n i mi n g p a r a d i g m a n d h a s n ’t f ou n d its w a y i n t o m a i n s t r e a m s o f t w a r e d e ­ sign a n d i m p l e m e n t a t i o n techniciues. T h i s lack o f p o p u l a r i t y s t e m s f r o m t h e f a c t t h a t wi t h t lie a d d i t i o n a l f u n c t i o n a l i t y c o m e s c om p l e x i t y , l e a di n g t o tlie p e r c e p t i o n t h a t niet a-l evel ]:>rogramming is h a r d a n d c o m p l i c a t e d . In f ac t , o u r view is t h a t me ta -l e v e l p r o g r a m m i n g is n o t t r i vi al a n d r eq ui r e s a t h o r o u g h u n d e r s t a n d i n g o f t h e s e m a n t i c s o f b o t h t h e u n d e r ­ lyi ng o b j e c t m o d e l a n d t h e n o n - f u n c t i o n a l r e q u i r e m e n t s t h a t a r e t o be e m b e d d e d i n t o t h e l a n g u a g e ’s o b j e c t m od e l . O n t h e o t h e r h a n d , o n ce t h i s s e p a r a t i o n h a s been a c h i e ve d , t h e le.ss e x p e r i e n c e d base-level p r o g r a m m e r c a n g a i n f r om t h e cl ean s e p a r a t i o n of c o n c e r n s a nd s h o u l d be a b l e t o a p p l y t h e e x t e n d e d o b j e c t b e h a v i o u r w i t h o u t o t h e r w i s e b e i n g c o n c e r n e d a b o u t t h e e x i s t e n c e of t h e me t a -l e v e l a r cl i i t e ct u r e.

W h a t is t h e r e f o r e n e e de d is a n e w level o f a b s t r a c t i o n t h a t e n c a p s u l a t e s m o s t o f t h e ini])le- m e i i t a t i o n d e t a i l s o f reflective pi’o g r a m m i n g for bot h t h e b a s e a n d me ta -l ev e l j i r o g r a m m e r . I'o d r a w an a n al o g y, t h e conce])t o f i n h e r i t a n c e in OOPLs p r ov i d es a power f ul t o o l for e n ­ c a p s u l a t i n g a n d c o m b i n i n g s o f t w a r e c o m p o n e n t s . I n h e r i t a n c e as a conce| )t wo u l d n o t have been s uccessful if p r o g r a m m e r s w e r e n ’t sufficiently shi el ded f r om its i m p l e m e n t a t i o n d e ­ tails. so for e x a m] ) le if t h e y h a d t o ex])licitly acce.ss attd initialise v i r t u a l f u n c t i o n t a b l e s . I nfort uiiately, t h i s is e x a c t l y w h a t a n u m b e r o f reflective p r o g r a m m i n g l a n g u a g e s reciuire. n a m e l y t h e di r e c t anti ex])licit a c c e s s of met a- l evel i n f o r m a t i o n .

In oi'dc'r t o a d d r e s s t h e p r ol j l ems d e s c r i b e d a bo v e , w’e a d v o c a t e a s t r o n g s e ] )a r at i o n of t h e roles of base-level (or aj^plication | ) r o g r a m m e r ) a n d me t a -l e v e l p r o g r a m m e r . T h e l)ase-level p r o g r a m m e r s h o u l d |>rimarily be c o n c e r n e d w i t h t h e i m p l e m e n t a t i o n of t h e f u n c t i o n a l re­ q u i r e m e n t s o f an a p| ) l ic a t i o n a n d s h o u l d t o a g r e a t e s t e x t e n t be u n a w a r e of t h e e x i s t e n c e of t h e I'ellective l a n g u a g e e x t e n s i o n . 'Idie ( m o r e e x p e r i e n c ed ) me t a - l e ve l p r o g r a m m e r s ho u l d l)e a bl e t o p r o v i d e t h e n o n - f u n c t i o n a l re c i ui re men t s i n d e | ) e n d e n t o f t h e a c t u a l base-level c o d e . . \ s an i n t e r f a c e for b o t h t h e a p p l i c a t i o n a n d me t a - l e v el p r o g r a m m e r , we i n t r o d u c e d t h e c o n c e p t o f a m e t a - t y p e . F r om t h e a])pl i cat i on p r o g r a m m e r p o i n t of view, m e t a - t y p e s e n c a | ) s u l a t e m o s t o f t h e f u n c t i o n a l i t y of reflective p r o g r a m m i n g a n d c o n s t i t u t e s i m p l y c o i i q ) o n e n t s t h a t c a n be sel e c t e d i n t o a n a p p l i c a t i o n . F r o m t h e e x p e r i e n c e d niet a-l evel p r o g r a m m e r p o i n t of view, m e t a - t y p e s build a f r a me w’o r k for d e si g n i n g , c o m | ) o s i n g a nd i m p l e m e n t i n g o b j e c t mo d e l s. C o n c e p t u a l l y , m e t a - t y p e s s h o u l d be t r a n s p a r e n t , e x t e n s i b l e a n d efficient in t h e i r i m p l e m e n t a t i o n .

(26)

2.1

G eneral overview

Keflective facilities c a n be f o u n d t o a g r e a t e r o r lesser e x t e n t in m o s t o b j e c t - o r i e n t e d |>ro- g i ' a ni ni i n g l a n g ua ge s . C++ for e x a m p l e o n l y p r o v i d e s r u d i m e n t a r y i n t r o s | j e c t i o n in t h e i'orm o f r u n - t i m e ty])e i n f o r m a t i o n ( i n ' T l ) [Str91], w h e r e a s .Java is e q u i p p e d w i t h a full i nt r os ] ) ect i on AIM [Mic99]. However , m a i n s t r e a m [ )rogra. mming l a n g u a g e s o nl y p r o v i de basic reflective f e a t u r e s , in g en e r a l on l y s t r u c t u r a l r eflection, whi ch is n o t e n o u g h t o s u p - pcM't m e t a - t y p e s . T h e r e f o r e , a n u m b e r of o b j e c t - o r i e n t e d l a n g u a g e s h a v e been e x t e n d e d in or t l er t o j jrovide a m o r e r i g o r o us sup] ) or t for r eflection.

Pi ' ovi di ng full s t r u c t u r a l a n d b e h a v i o u r a l r eflection is a t a s k t h a t largel y d e p e n d s on w h e t h e r t h e u n d e r l y i n g p r o g r a m m i n g l a n g u a g e is i n t e r p r e t e d o r c o m p i l e d . In a n i n t e r ­ p r e t e d l a n g u a g e for e x a m p l e , t h e i n t e r p r e t e r a l r e a d y c o n s t r u c t s a s u b s t a n t i a l a m o u n t of meta.-level i n f o r m a t i o n a b o u t t h e pi’o g r a m t o be i n t e r p r e t e d . E x t e n d i n g t h e l a n g u a g e t o be r('Ilective onl>' i nvolves t h e e x p o s i t i o n of t h i s me t a -l e v e l i n f o r m a t i o n a n d t h e i n t e r p r e t a t i o n m e c h a n i s m t o t h e a p p l i c a t i o n p r o g r a m m e r .

In a t y p i c a l c o m p i l e d l a n g u a g e ( m o s t n o t a b l y C+ + ) on t h e o t h e r h a n d l i ttle or no m e t a - level i n f o r m a t i o n is k e p t in t h e r u n - t i m e i m a g e . A d d i n g reflection is d o m i n a t e d by t h e pi'oljlem of m a i n t a i n i n g t h e s t r u c t u r a l i n f o r m a t i o n b e y o n d t h e c o m p i l a t i o n ])rocess a n d of ( ' x t e n d i n g t h e c o d e wi t h t h e a p i >r o p r ia t e h o o k s t o expl oi t t h e me t a - l e v e l i n f o r m a t i o n . h'igure 2.1 de])icts t h e t a x a n o m y o f r eflective p r o g r a n i i i i i n g l a n g ua ge s . D e | ) e n d i n g on 1 Ik' t>'pe of p r o g r a m m i n g l a n g u a g e , c o m p i l e d o r inter]>reted, we c an d i s t i n g u i s h b e t w e en v a r i ous t y p e s of r efh' ction: com| )il(' -time, r u n - t i m e a n d l o a d - t i m e reflection.

W’itii c o m | ) i l e - t i m e reflection, t h e comj ) il a t i o n ])rocess o f a p r o g r a m is c o n t r ol kx i by a cor- r c' spondi ng met a- l evel p r o g r a m . It c a n be vi ewed a s a kind o f ’s m a r t p r e- | ) r o c es s i n g' wiiere th(' s e m a n t i c s o f tlu' a p p l i c a t i o n c o d e a r e mo d i f i e d in a c o n t e x t s e ns i ti v e way. E x a m | ) l e s o f t h e s e a r c h i t e c t u r e s a r e ( ) p e n C + + v2 [Chi96] a n d O p e n . I a v a [Chi9-5].

H u n - t i m e reflection all ows t h e i n t e r p r e t a t i o n / e x e c u t i o n o f l a n g u a g e c o n s t r u c t s t o i)e m o d ­ ified at r u n - t i m e . T h i s is in g en e r a l ac hi e ve d by i n t e r c e d i n g w i t h t h e e x e c u t i o n of l a n g u a g e o p e i' a t io n s . R u n - t i m e reflection offers t h e h i g h e s t d e g r e e o f flexibility b u t u su a l l y inciirs 1 he m o s t o v e r h e a d .

(27)

Object-Oriented Programming Languages

Interpreted (Java, Smalltalk, ABCL/1)

OpenC++ v2 OpenJava

Compiled (C++, Objective C)

Compile- Time

OpenC++ v1 Iguana

Metaxa Guarana ABCL/R CodA

Binary Component Adaptation (BCA) Javassist

l''ig n re 2.1: I'a x a n o in y o f re fle c tiv e , o b je c t-o rie n te d p r o g r a iiin iin g languages.

a fivanced lin k e r /lo a d e r th a t in s p e c ts m od ule s to be d y n a m ic a lly lin k e d in to a ])])lic a tio n s . Taking a p p lic a tio n specific b e h a v io u r in to a c c o u n t^, it is jio s s ib le to load specialised im ­ p le m e n ta tio n s o f syste m ca lls such as f o r k and m a llo c .

H o a d m a p

In th e re m a in d e r o f th is c h a |)te r we w ill firs t b rie fly review som e o f th e m ore co m m o n o b je c t-o rie n te d ])ro g ra m m in g languages and discuss th e in h e re n t re fle c tiv e fe a tu re s th e y pi'ovid e. 'Then we w ill e x a m in e in t \irn a n u m b e r o f re fle c tiv e e x te n s io n s u n d e r th e fo llo w in g aspects:

T y p e o f r e f l e c t i o n : D escribes w h e th e r th e |)la tfo rm |)ro vid e s c o m p ile -tim e , r u n -tim e or lo a d -tim e re fle c tio n .

R e f le c t iv e f a c i li t i e s : T h is section describes w h ich fe a tu re s o f th e la n gu ag e are reified and how th e y can be accessed.

P r o g r a m m i n g m o d e l: 'T his se ction describes th e user in te rfa c e ]>rovided by each la n ­ guage. M o re s p e c ific a lly , it describes how th e p ro g ra m m e r can d efin e a new m o p im p le m e n ta tio n and how it can be a ])p lie d to th e a p ])lic a tio n .

(28)

P e r f o r m a n c e : In t h i s s ec t i on we d i s c us s t h e p e r f o r m a n c e t r ad e -o f fs whi ch a r e i n c u r r e d w i t h t h e use o f reflection.

K n o w n a p p l i c a t i o n s : Descri l j es c o n c r e t e a j j p l i c at i o n s t h a t h a v e b e e n w r i t t e n in t h e s p e ­ cific l a n g u a g e .

S u p p o r t f o r m e t a - t y p e s : 13iscusses t o w h a t e x t e n t t h e l a n g u a g e s u p p o r t s t h e c o n c e p t o f n i e t a - t y p e s . M o r e specifically, we d i s c u s s w h e t h e r t h e reflective l a n g u a g e e x t e n s i o n a ll ows t o c o m p o s e a n d d y n a m i c a l l y reselect niet a-l evel c o n f i g u r a t i o n s , h o w t r a n s p a r ­ e n t l y t h e e x t e n s i o n c a n be a pp l i e d a n d w h e t h e r t y p e o r t h o g o n a l i t y is a c h i e v e d .

2.2

S m a llta lk

S m a l l t a l k [GRS.'j] w a s d e ve l o p e d in t h e Xe ro x P a l o A l t o R e s e a r c h C e n t e r a n d w a s first released in 1980. It is an inter|M’e t e d , fully o b j e c t - o r i e n t e d p r o g r a m m i n g l a n g u a g e f e a t u r i n g w e a k t y p i n g , m u l t i p l e i n h e r i t a n c e a n d a u t o m a t i c g a r b a g e col l ect i on).

I n h e r e n t r e f l e c t i v e f e a t u r e s

S m a l l t a l k c o n t a i n s m a n y e l e m e n t s t h a t c an o n l y be d e s c r i b e d as reflective. I ' h i s can lie s('('n f r om its conseciuent- u n d e r l y i n g p r o g r a m m i n g p a r a d i g m : e v e r y t h i n g is an o b j e c t . C l a s s e s in S m a l l t a l k a r e first, c l ass e nt i t i e s , i n s t a n c e s o f a s u b c l a s s o f Met aCl ass. l i v er y met acla.ss has e x a c t l y o n e i n s t a n c e , n a m e l y t h e class o f t h e s a m e n a m e .

riie class i n t e r f a c e de f i n e s a n u m b e r of m e t h o d s t h a t m a k e it v e r y e a s y t o i n t r o s p e c t on cl asses a n d m e t h o d s , a s t h e f ol lowing e x a m p l e i l l us tr at e s .

[ 0 1 ] l i s t M e t h o d s : t a r g e t O b j e c t [ 0 2 ] I c l m I

[ 0 3 ] c l := t a r g e t O b j e c t c l a s s . [ 0 4 ] m := c l m e t h o d D i c t i o n a r y . [ 0 5 ] m i n s p e c t .

f i g u r e 2.2'. I n t r o s p e c t i o n in S m a l l t a l k : t h e f u n c t i o n l i s t M e t h o d s lists all m e t h o d s of t h e o b j e c t t a r g e t O b j e c t .

(29)

objeci targetObject. f i r s t , t he class ( ni ct a- ) obj ec t is looked u|) an d stored (line [0.'3]). 'I’lie me t h od methodDictionary c o m p u t e s an orde red collection of all m e t h o d s of t h a t class, which is finally printed o u t in line [05].

[l'.J89] discusses how fur the r reflective features, such as cust omi sed m e t h o d di spat chi ng, could be i nc or por at ed into Smalllalk.

2. 3

C + +

('++ is an object- oriented extension of the C p r o g r a m m i n g l anguage and was designed l)y Bj arne S t r o u s t r u p . it was s t an da r d i se d by t he ISO C++ s t a n d a r d s c o m m i t t e e in 1997. Because it originated from C, C++ is a hybrid language t h a t s u p p o r t s t he full r ange of low- level p ro g r a mmi ng , jjrocedural | )r ogrammi ng, obj ect -ori ent ed p r o g r a m m i n g up t o generic p r o g r a m m i n g using temi)lates.

I n l i e r e n t r e f l e c t i v e f e a t u r e s

('++ allows t he redefinition or o \ er l o a d i ug of specific oi>erators. "Fhe new o | ) e r at or for i nst ance is a special met hod t hat is called whenever a new object is to be cr ea t ed on the lu'a|). Its task is to allocate t he ap p io |) r ia t e a m o u n t of raw m e mo r y to contain t he ol)ject' s att riliutes. 'I’iie delete o|>eratoi' on t he o t he r hand is invoked when an object is deletf'd in

O l d e r to free t he memor y held by t he object.

Ov('rloadiiig t h e n e w / de le t e o| ) e r at or can be viewed as reifying t he m e m o r y m a n a g e m e n t of o b j ec t s and provides a me a ns of interceding in t h e c r e at i o n / d e l e t i o n mecha ni sm of ol)jects. riiis can l>e useful t o im|)lement g a r b a g e collection or to allow o b j ec t s t o be

l o c a t e d at specific addresses in memory. C hoices [MKIC'92] for ex a mp l e is a f r ame wor k loi' c o n s t r u c t i n g object - ori ented o | ) e r a t i n g s y st e m s t h a t uses a reified heap m a n a g e r which

c a n l)e replaced in a I ' u n n i n g s yst em. T h e code in figure 2.3 is an ex amp l e of a customi sed new o |) e ra l or t h a t |)rints out a message every ti me an o bj e c t is cr eat ed, sz c on t a i ns t he size (in bytes) of t h e object.

RTTI

(30)

t o |)ei'forin o p t i m i s e d o p e r a t i o n s on o b j e c t s , t o realise o b j e c t - o r i e n t e d d a t a b a s e s o r for d e b u g g i n g p u r p o s e s . In t h e e x a m p l e bel ow, t h e s e ri a li s a ti on o f a d a t a s t r u c t u r e c a n be iini)ieiriented in d i f fe r en t w a y s if t h e a c t u a l t y p e o f t h e s t r u c t u r e is k n ow n :

c l a s s list {

/ / i n i p l e m e n t a t i o n o f a list };

c l a s s linkecLlist : p u b l i c list {

/ / i i n p l e m e n t a t i o n o f a lin k e d list

i n t seri al i ze(l i st *ls, o s t r e a m *os) { / / d u m p a list to a n o u t p u t s t r e a m c o n s t t y p e J n f o & t i = t y p e i d ( * l s ) ; / / *ls can b( o f type list o r l i n k e d J i s t i f (ti = = t y | ) e i d ( l i n k e d _ l is t ) ) {

/ / d o l i n k e d J i s t stufj' } e l s e {

/ / do list s t u f f }

}

l']\| )loiting t y p e i n f o r m a t i o n as in t h e e x a mj j l e a b o v e h o we ve r s h o u l d be a^’oi d e d as it d e f e a t s t r a n s | ) a r e n c y a n d i n h i b i t s s o f t w a r e reuse. I n s t e a d , p o l y m o r p h i c m e m b e r f u n c t i o n s woul d be b e t t e r used t o i m p l e m e n t ty|:>e si)ecific o p e r a t i o n s .

c l a s s V e rb os e {

v o i d * o | ) e r a t o r n e w ( s i z e _ t sz){

c o u t < < ’’C a l l i ng V e r b o s e : : n e w ( ” < < sz < < ” ) ” < < endl; r e t u r n inal l oc(sz);

}

Figure

Figure 2.12: W ritin g  an ap|)lication in Open C'-|--|- v2.
Figure 2.13: Code modifications performed by the O p e n C + +  M O P in order to trap invo­cations on an object.
Figure 3.1: Dependencies between reification categories in Iguana.
Figure 3.2: M etalevel configuration w ith  local and shared m etaobjects.
+7

References

Related documents

We compared the impact of COX-2 versus mPGES-1 inhibition on human experimental tumor- associated immunity in an authentic in vitro tumor model composed of human

, sen- sitized erythrocytes bearing complement components as designated by numerical subcripts; E*, red cells irre- versibly damaged by the action of complement; S*, red cell

This intermediate complex was formed by the reaction of EA (sensitized in Na3HEDTA-BBS, washed and resuspended in BBS) with R4 (14). The cells were then washed 3 times in the cold

To search for geographical and temporal patterns in the phylogeny of Nigerian strains in more detail, a large number of partial GP, NP, and L gene sequences of Lassa virus

The rates of synthesis of heme and globin within the erythroid cell maturation period are defined in these studies by the daily incremental incorpora- tion of glycine-2-C14

Genotype resistance profiles also indicate that mutations conferring INH resistance in Nigeria occur at a similar rate in the inhA promoter and the katG S315T region, in contrast

10 7 fibroblasts and 1 in 10 5 epithelial cells) escapes crisis through spontaneous activation of a telomere lengthening mechanism (TLM), and the cell culture becomes

Matrix-assisted laser desorption ionization–time of flight mass spectrometry (MALDI-TOF MS) is a rapid bacterial identification technique that is increasingly used in