Top Banner
SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004
30

SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

Dec 18, 2015

Download

Documents

Doreen Daniels
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

SEAL Reflex, the new Reflection Library

Stefan Roiser(for the LCG/SEAL Dictionary work package)

LCG Applications Area Meeting, Oct. 6, 2004

Page 2: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 2

Content

• Reflection and C++

• The Model

• Use Cases

• Producing reflection information

• Current status, future enhancements

• CHEP ‘04

• Conclusion

Page 3: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 3

Definitions

• Reflection is the ability of a language to introspect it’s own structure at runtime and interact with it in a generic way

• A dictionary provides reflection information about types of a certain language to the user

Page 4: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 4

What is Reflection?

class Particle { public: double mass(); private: double m_mass; };

Data & Instructions

Without prior

knowledge about

types

Particle p;

std::cout << p.mass();

ClassBuilder(“Particle”). addDataMember(“m_mass”). addFunctionMember(“mass”);

Dictionary

const Type* t = Type::byName(“Particle”);

Object o = t->construct();

cout << *(double*) o.invoke(“mass”);

t->destruct(o);

Page 5: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 5

Reflection and C++

• Very limited support by the language (RTTI)– Other languages do (e.g. Java, Python,…)

• Several approaches exist, but …– Tied to a system or– Instrumentation of code needed

• Stroustrup proposed XTI (eXtended Type Information)

Page 6: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 6

Goals

• Enhance C++ with reflection capabilities– non intrusive, automated

• Close to the C++ ISO 14882 standard

• Light and standalone system

• Small memory footprint

• Multi platform– Linux, Windows, Mac OSX, …

Page 7: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 7

Reflection Model

Type

TypeBase

Scope

ScopeBase

Member

Class

PropertyList

Function

Typedef

Reference

PointerNamespace

InstTemplate

TemplFamilyInstTFunction

InstTClass

Page 8: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 8

Reflection Use Cases

const Type * t = Type::byName(“Particle”);

size_t s = t->sizeOf();

bool t = t->isClass();

• Types– Retrieve a specific type– Introspect the actual type

Page 9: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 9

Reflection Use Cases (ctd.)

• Classes– Inspect inheritance tree – Create / delete instances

const Class * c = t->asClass();

const Base * b = c->base(0);

Object o = c->construct();c->destruct(o);

Page 10: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 10

Reflection Use Cases (ctd.)

• Data Members– Get / set values– Retrieve offset relative to beginning of class

const DataMember * dm = c->dataMember(0);

double d = *(double*) dm->get(v);

size_t s2 = dm->offset();

Page 11: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 11

Reflection Use Cases (ctd.)

const FunctionMember * fm = c->functionMember(0);

const Type * rt = fm->type()->asFunction()->returnType();

void * r = fm->invoke(o);

• Function Members– Inspect return and parameter types– Invoke a function and retrieve return values

Page 12: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 12

Reflection Use Cases (ctd.)• All Types

– Reference, Pointer, PointerToMember, Array, Enum, Union, Fundamental, Class, Function

• Typedefs• Scopes

– Search scopes– Retrieve scopes

• Additional Properties– For Types, Scopes

and Members– Everything that does

not fit ISO standard– Any type supported

• CV qualifiers• Templates

– Inspect families– Look for instantiations

Page 13: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 13

System Overview

.h_dict.cpp

gcc_xml.xml

gendict.py

lcgdict

.xml

TypeSelection

make.so.cpp _dict.so

make

Reflex.so

UserProgram

Page 14: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 14

[lxplus]~>

Dictionary Creation<lcgdict> <class name=“Particle”/></lcgdict>

#include “Particle.h”class Particle_dict { public: Particle_dict(); };void* stubfun(void* o) { return (void*)((Particle*)o)->mass(); }Particle_dict::Particle_dict() {ClassBuilder<Particle>(“Particle”).addDataMember<double>(”m_mass”,Offset(Particle,m_mass),PRIVATE).addFunctionMember<double(void)>(”mass”,&stubfun,0,0,PUBLIC); }static Particle_dict instance;

[lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl [lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl Parsing File Particle.h with GCC_XML OKGenerating LCG Dictionary (reflex)class Particle[lxplus]~>

[lxplus]~> lcgdict Particle.h -s selection.xml --reflex -I../incl Parsing File Particle.h with GCC_XML OKGenerating LCG Dictionary (reflex)class Particle[lxplus]~> lsParticle.h Particle.xml Particle_dict.cpp[lxplus]~>

Page 15: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 15

gcc_xml

• “[…] generate an XML description of a C++ program from GCC's internal representation.”

• Any gcc compilable program can be used as input

• lcgdict uses the XML file to produce dictionary files

Page 16: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 16

Library Sizes

• SEAL ROOT Dictionary: 405 classes

6657.68 6582.30

0

1000

2000

3000

4000

5000

6000

7000

SealROOTDict (KB)

ReflectionReflex

Page 17: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 17

Library Sizes (ctd.)

CLHEP Dictionary : 56 classes

Page 18: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 18

Status

• Reflex - new version will be released with SEAL 1_4_2 and 1_5_2– In collaboration with the ROOT team– Idea is common LCG & ROOT dictionary– Several enhancements

• References, Enums, Unions, Typedefs, …

– Closer to ISO standard

Page 19: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 19

Future Enhancements

• Template types– Full implementation needed

• Measuring the memory footprint– Instructing new / delete– Counting instances

• Unloading libraries– Proper deletion of types / scopes

Page 20: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 20

Future Enhancements (ctd.)

• Missing Builders – UnionBuilder, EnumBuilder

• STL like iterators– In addition to current implementation

• String parser– Could be used when building types

Page 21: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 21

Integration with LCG SW

• POOL– Reflex provides sufficient functionality– Integration foreseen

• SEAL Scripting– PyLCGDict will become PyReflex– Work has already started

Page 22: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 22

Integration with ROOT

• For ROOT I/O – ROOT Meta Classes (e.g. TClass, TMethod) may

be implemented using Reflex – Check of sufficient functionality needed

• For interactive ROOT (CINT) – Creation of CINT data structures needed– Equivalent to existing CINT/Lcgdict gateway in

POOL• Easy for data members• Function members not so straight forward

Page 23: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 23

Integration with ROOT

.h

lcgdict _dict.so

rootcint CINTcint.so

Reflex

ROOT

CINTDS

TDictionaryCurrent Situation

ReflexDS

Page 24: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 24

Integration with ROOT

.h

lcgdict _dict.so

rootcint CINTcint.so

Reflex

ROOT

CINTDS

Enabling ROOT I/O

ReflexDS

Page 25: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 25

Integration with ROOT

.h

lcgdict _dict.so

rootcint CINTcint.so

Reflex

ROOT

CINTDS

ReflexDS

Enabling ROOT I/O& interactive CINT

Page 26: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 26

Integration with ROOT

.h

lcgdict _dict.so

rootcint CINTcint.so

Reflex

ROOT

CommonDS

Final Goal

Page 27: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 27

CHEP ‘04

• Other projects showed interest– FreeHEP Java Library– Panoramix

• Improving Standard C++ – Compile time reflection wanted feature– No proposal for the time being

• Summary talk of Core Software– Propose reflection as part of ISO standard

Page 28: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 28

SW packages• Reflection library

– Current implementation • Reflection, ReflectionBuilder

– New model• Reflex

• DictionaryGenerator– Produce dictionary files for both versions

• Dictionaries CLHEP, STL, ROOT– Standard dictionaries ready to use

Page 29: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 29

Conclusion• SEAL Dictionaries

– Light, standalone system– Non intrusive, automated code production– Dictionaries for any gcc compileable program

• New system - Reflex - ready for integration– In collaboration with ROOT– Common LCG/ROOT dictionary envisaged– Several enhancements, closer to ISO std– Positive feedback from CHEP’04

Page 30: SEAL Reflex, the new Reflection Library Stefan Roiser (for the LCG/SEAL Dictionary work package) LCG Applications Area Meeting, Oct. 6, 2004.

6. Oct. 2004 Stefan Roiser 30

Pointers

• The SEAL project– http://cern.ch/Seal/

• CVS repository– SEAL.cvs.cern.ch:/cvs/SEAL/Dictionary

• access: kserver, ssh, (anonymous) pserver

• gcc_xml– http://www.gccxml.org