Non-In trusiv e Ob jet In trosp etion in C++: Ar hiteture - - PowerPoint PPT Presentation

non in trusiv e ob je t in trosp e tion in c ar hite ture
SMART_READER_LITE
LIVE PREVIEW

Non-In trusiv e Ob jet In trosp etion in C++: Ar hiteture - - PowerPoint PPT Presentation

Non-In trusiv e Ob jet In trosp etion in C++: Ar hiteture and Appliation T yng-Ruey Ch uang Institute of Information Siene Aademia Sinia Nank ang, T aip ei 115, T aiw an Join t w ork with Chin-Ch uan


slide-1
SLIDE 1 Non-In trusiv e Ob je t In trosp e tion in C++: Ar hite ture and Appli ation T yng-Ruey Ch uang Institute
  • f
Information S ien e A ademia Sini a Nank ang, T aip ei 115, T aiw an Join t w
  • rk
with Chin-Ch uan Hsu, Ch uan-Chieh Jung, W en-Min Kuan, Y. S. Kuo, W ei-Hsueh Lai, and Chien-Min W ang. 1
slide-2
SLIDE 2 Outline
  • Ob
je t in trosp e tion
  • The
problems with C++
  • Non-in
trusiv e
  • b
je t in trosp e tion in C++
  • Implemen
tation issues
  • Appli ations
2
slide-3
SLIDE 3 Dynami Appli ations
  • They
deal with
  • b
je ts whose t yp es are kno wn
  • nly
at run-time.
  • Examples
in lude dynami library loaders, program debuggers,
  • b
je t serialization routines, et .
  • They
mak e external
  • b
je ts \ ome aliv e" whenev er they are needed, and no matter what they are.
  • Sev
eral OO languages ha v e builtin supp
  • rts,
su h as late-binding, for dev eloping dynami appli ations.
  • CLOS,
Ja v a, Ob je tiv e C, and Smalltalk, for example, all allo w late-binding metho d alls to
  • b
je ts. 3
slide-4
SLIDE 4 Ob je t In trosp e tion
  • It
is the abilit y to query and
  • p
erate an
  • b
je t without kno wing its t yp e stati ally . In trosp e tiv e
  • p
erations are still t yp e- he k ed, ho w ev er, to ex lude illegal a esses.
  • It
greatly helps the dev elopmen t
  • f
dynami appli ations.
  • Example:
Ja v a
  • re
ree tion API.
  • No
builtin supp
  • rt
for
  • b
je t in trosp e tion in C++. C++'s virtual fun tion and Run-Time T yp e Information (R TTI) me hanism an b e to
  • restri tiv
e. 4
slide-5
SLIDE 5 Example
  • C++
  • b
je ts: BSTree *p = new BSTree; p->insert("Sini a ");
  • In
trosp e tiv e C++
  • b
je ts: void *p; Klass bstree = getClass("BSTree" ); p = bstree.new(); Method insert = getMethod(bstree , "insert"); void* argv[℄ = {"Sini a", 0}; bstree.invoke(p, insert, argv); 5
slide-6
SLIDE 6 Curren t C++ Solutions
  • Appli ation
framew
  • rk:
lasses deriv ed from pre-dened framew
  • rk
re eiv e additional in trosp e tiv e supp
  • rts.
Examples: System Ob je t Mo del (SOM) from IBM, and Common Ob je t Mo del (COM) from Mi rosoft.
  • New
language seman ti s and implemen tation: Mak e all
  • b
je ts in trosp e tiv e b y default.
  • Systemati
augmen tation to lass denitions: Instan es
  • f
the augmen ted lasses b e ome in trosp e tiv e. 6
slide-7
SLIDE 7 Issues
  • f
In terop erabilit y
  • T
ypi al problem: Ob je ts pro du ed b y third-part y lass library need in trosp e tion as w ell.
  • Third-part
y library ma y ha v e its
  • wn
lass hierar hi al stru ture (i.e., framew
  • rk).
It is diÆ ult to t it in to another appli ation framew
  • rk.
  • The
library is dev elop ed using
  • ld
seman ti s and implemen tation. New C++ seman ti s and implemen tation do not help.
  • The
augmen ted lass denitions will pro du e
  • b
je ts in ompatible with the existing library (a \bla k b
  • x").
  • Summary:
urren t solutions are in trusiv e to existing lass denitions. 7
slide-8
SLIDE 8 Goals: Non-In trusiv e Ob je t In trosp e tiv e in C++
  • Mak
e
  • b
je ts in trosp e tiv e, as long as
  • ne
has a ess to their lass denitions in adv an e.
  • Non-in
trusiv e. F
  • r
an y giv en lass, its in trosp e tiv e instan es are
  • mpatible
with non-in trosp e tiv e instan es.
  • Easy
to use. Automati to
  • ls
are used to mak e instan es from a lass in trosp e tiv e.
  • Comprehensiv
e supp
  • rts.
The to
  • l
should
  • v
er as man y C++ lass features as p
  • ssible.
8
slide-9
SLIDE 9 A Meta Ob je t Ar hite ture (I)
  • F
  • r
ea h lass, a
  • rresp
  • nding
meta
  • b
je t is reated at run-time with all ne essary information ab
  • ut
the lass.
  • In
trosp e tiv e a esses to instan e
  • f
the lass go through the meta
  • b
je t for help.
  • The
information stored at the meta
  • b
je ts is
  • lle ted
b y parsing the lass denitions in ada v an e. 9
slide-10
SLIDE 10 Comp
  • nen
ts
  • f
the Ar hite ture (I I)
  • Meta
lass supp
  • rting
library: It is not sp e i to an y lass, and is used in user programming.
  • Meta
  • b
je t generation routines: They are sp e i to giv en lasses, and ma y b e in v
  • k
ed in t w
  • stages
at
  • mpile-time
and/or run-time.
  • Tigh
tly- oupled mo del: In trosp e tiv e lasses are kno wn at
  • mpile-time,
but
  • b
je ts ma y from an y
  • f
these lasses.
  • Lo
  • sely- oupled
mo del: In trosp e tiv e lasses are kno wn
  • nly
at run-time.
  • Meta
  • b
je t generations are in v
  • k
ed at dieren t stages for the t w
  • dieren
t mo dels. 10
slide-11
SLIDE 11 Tigh tly-Coupled Mo del

application source application binary application binary class declarations class libraries ("black boxes") class libraries ("black boxes") meta objects (one for each class) Introspective Run-Time Environment Stand-alone Executable Run-Time declarations meta class meta class supporting libraries meta class supporting libraries meta object code generator code to generate meta objects Compile-Time Link-Time

Example: Appli ations that needs C++
  • b
je t input/output. 11
slide-12
SLIDE 12 Lo
  • sely-Coupled
Mo del

application source application binary application binary class declarations class libraries ("black boxes") meta objects (one for each class) class libraries ("black boxes") Compile-Time Run-Time Executable (Client) Dynamically Loaded Libraries (Servers) declarations meta class meta class supporting libraries meta class supporting libraries Link-Time meta objects code to generate Script (Meta Object Generation) meta object code generator

Example: Bro wsers that load and exer ise C++ lasses
  • n
demand. 12
slide-13
SLIDE 13 Meta Class Supp
  • rting
Library
  • Meta
lasses: Klass, Method, et . for represen ting fun tionalit y pro vided b y an y C++ lass and metho d (e.g., ea h meta
  • b
je t an instan e
  • f
Klass). Most metho ds in the meta lasses are virtual fun tions.
  • P
  • lymorphi
  • b
je t referen es: In trosp e tiv e
  • b
je ts all ha v e stati t yp e void*, ho w do es
  • ne
dis o v er their dynami t yp es? W e need virtual
  • nst
har
  • nst
*dynami Type (void
  • nst
*self) { return typeid(*(B *) self).name(); } in the meta
  • b
je t for lass B.
  • Similar
problems with
  • n
v ersion routines b et w een base and deriv ed lasses. 13
slide-14
SLIDE 14 Meta Ob je t Generation Routines
  • They
are automati ally generated b y parsing the lass de larations.
  • They
ma y b e applied in t w
  • stages:
the generator exe ute at appli ation dev elopmen t time, but the
  • de
so generated exe ute at appli ation run-time. Hen e the need for
  • de
lik e
  • ffset_of_a_in_A
= ( har *) &(((A *) 64)->a)
  • ( har
*) ((A *) 64) for prop er memory la y
  • ut
  • f
lass A.
  • Ob
je t
  • mpatibilit
y: W e ma y need to augmen t a lass de laration to gain a ess, but nev er augmen t it in w a ys that will hange its
  • b
je t la y
  • ut.
F
  • r
example, inserting friend fun tions is OK, but adding new virtual fun tions is not. 14
slide-15
SLIDE 15 Tw
  • In
trosp e tiv e Appli ations
  • Obje
tStr e am: A soft w are to
  • l
for pro viding automati I/O supp
  • rts
for
  • mplex
C++
  • b
je ts. Tigh tly- oupled mo del.
  • R
unClass: An appli ation for in tera tiv e exe ution
  • f
dynami ally loaded C++ lass library . Lo
  • sely- oupled
mo del.
  • Ob
je tStream helps sa v e dev elopmen t time and a v
  • id
man ual
  • ding
error.
  • RunClass
helps p erform lass-based soft w are testing, and helps
  • ne
familiarize with new lass library . 15
slide-16
SLIDE 16 RunClass
  • It
allo ws users to reate
  • b
je ts for giv en lasses, exe ute metho ds up
  • n
sp e i
  • b
je ts, and examine their
  • n
ten ts in tera tiv ely .
  • It
has easy-to-use graphi user in terfa e.
  • A
user's
  • mmand
sequen e, and its ee t, an b e logged, and repla y ed later for regression testing
  • n
new er v ersions
  • f
a lass library . 16
slide-17
SLIDE 17 RunClass S reen Shot Note: Being sho wn to exer ise Mi rosoft F
  • undation
Classes. 17
slide-18
SLIDE 18 Ob je tStream
  • C++
I/O
  • p
erators lik e << and >> are made to w
  • rk
  • n
instan es
  • f
an y user-dened lass. In header le
  • f
the supp
  • rting
library: template < lass T> Uostream &operator<<(Uostre am &os, T &obj) { Uwrite(os, (void*) &obj, typeid(T).name()); return
  • s;
} template < lass T> Uistream &operator>>(Uistre am &is, T *&obj){ Uread (is, (void *)
  • bj,
typeid(T).name()); return is; }
  • Ob
je tStream is used to
  • nstru t
an in tera tiv e bro wser for
  • b
je ts stored in external media/format. It is also in orp
  • rated
in to RunClass for
  • b
je t equalit y test. 18
slide-19
SLIDE 19 Design
  • f
Ob je tStream
  • User{pro
vided lass header les are parsed to extra t lass information (su h as
  • b
je t la y
  • ut
and lass hierar h y).
  • Co
de is generated to build up a
  • lle tion
  • f
lass information based
  • n
the extra tions.
  • C++
I/O
  • p
erators, >> and <<, are
  • v
erloaded to supp
  • rt
user-dened lasses.
  • A
generi I/O library is used b y the I/O
  • p
erators to
  • nstru t/tra
v el
  • b
je ts, based
  • n
lass information previously
  • lle ted
and
  • n
run-time t yp e information from C++. 19
slide-20
SLIDE 20 F rom A User's P ersp e tiv e

ObjectStream code generator application source code class declaration augmented class declarations ObjectStream C++ compiler C++ compiler application binary code class-specific class-specific class definition binary code linker stand-alone executable main.cpp class.h main.obj generic I/O library class.obj main.exe

The shell script will automat the working in the dotted box. ObjectStream

class.h initialization binary initialization source classInit.obj classInit.cpp ustream.lib configuration file class.cfg ustream.h ObjectStream header file header file

20
slide-21
SLIDE 21 T e hni al Issues
  • Flexible
and extendible univ ersal stream fa ilit y .
  • A urate
mapping
  • f
p
  • lymorphi
  • b
je ts | an
  • b
je t's dynami (run-time) format not ne essarily depi ted b y its stati ( ompile-time) de laration.
  • Cross{referen es
among and within
  • b
je ts | A graph tra v ersal problem (as in \garbage
  • lle tion").
  • Am
biguities in the language. (void*, union, et .) and anar hi language features (m ultiple inheritan e, lo al lass de larations. et .). 21
slide-22
SLIDE 22 Limitations
  • f
Curren t Approa h
  • Need
a ess to lass de larations.
  • Cannot
deal with am biguities in C++
  • b
je ts: void*, union, et .
  • In ur
run-time
  • v
erhead in t yp e- he king in trosp e tiv e
  • p
erations. 22
slide-23
SLIDE 23 Con luding Remarks
  • Non-in
trusiv ely
  • b
je t in trosp e tion in C++ is p
  • ssible.
  • Our
system ar hite ture is based
  • n
meta
  • b
je ts and is exible.
  • Non-in
trusiv ely
  • b
je t in trosp e tion helps soft w are reuse, esp e ially in the in tegration
  • f
third-part y soft w are in to dynami appli ations.
  • It
has wide appli ation. 23
slide-24
SLIDE 24 More Remarks
  • RunClass
and Ob je tStream w ere separate pro je ts at I IS/AS, ea h started in 1993. W e found
  • ut
later that they b
  • th
w ere ab
  • ut
C++
  • b
je t in trosp e tion.
  • No
eort w as sp en t in re o ding the t w
  • systems
from the rst prin iple. Ho w ev er, a join t pap er w as written around 1998.
  • Ob
je tStream w as implemen ted using G++
  • n
Windo ws 95 under the
  • mmand-line
en vironmen t.
  • Ob
je tStream w as more an in telle tual exer ise than a pro du tion system. W e eased its dev elopmen t in win ter 1998.
  • That
was b efor e ther e was Java! 24