Getting rid of the “G__” thingies ROOT Team Meeting CERN Diego Marcos && Leandro Franco.

Slides:



Advertisements
Similar presentations
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Advertisements

Part IV: Memory Management
Instruction Set Design
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
The Assembly Language Level
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Pointers Re-introduce Pointer Concepts. Why Pointers  Remember Arrays – try to accommodate user entry by guessing the size.  Usage increases over time.
Chapter 3.2 : Virtual Memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Review of C++ Programming Part II Sheng-Fang Huang.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
CIS Computer Programming Logic
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Pointer. What is pointer ? A Pointer is nothing but a variable that contains an address which is a location of another variable in memory. If one variable.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
CInt Function Stub Removal ROOT Team Meeting CERN Leandro Franco (Joint work with Diego Marcos)
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Topic 2d High-Level languages and Systems Software
Paging Example What is the data corresponding to the logical address below:
CPSC 230 Computers and Programming I Spring 2003 Dr. Lynn Lambert.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
Lecture 5 functions 1 © by Pearson Education, Inc. All Rights Reserved.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
PHY 107 – Programming For Science. Today’s Goal  Learn how arrays normally used in real programs  Why a function returning an array causes bugs  How.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
C++ Functions A bit of review (things we’ve covered so far)
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
User-Written Functions
Andy Wang Object Oriented Programming in C++ COP 3330
The University of Adelaide, School of Computer Science
Other Kinds of Arrays Chapter 11
Student Book An Introduction
Hash table another data structure for implementing a map or a set
CS 2308 Final Exam Review.
More About Data Types & Functions
Register Variables Declaring a variable as a "register" variable is an advisory to the compiler to keep the normal location of the variable in a register,
Lecture Topics: 11/1 General Operating System Concepts Processes
Computer Organization and Design Assembly & Compilation
CISC/CMPE320 - Prof. McLeod
Tutorial 10: Programming with javascript
Data Structures and Algorithms Introduction to Pointers
Data Structures and ADTs
COMP755 Advanced Operating Systems
Virtual Memory and Paging
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
CSE 542: Operating Systems
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Presentation transcript:

Getting rid of the “G__” thingies ROOT Team Meeting CERN Diego Marcos && Leandro Franco

Road Map ● Currents Status – Actual use of the dictionaries. ● Proposal – Removal of stub functions in the dictionaries. – Needed changes ● Advantages – Dictionary size reduction (and its consequences). ● Problems

● Initializing CInt Data structures. – At loading time we have one “G__memfunc_setup” call for each stub function (in a file like G__Hist.cxx). – This function creates a new field in the G__ifunc_table with attributes like name, hash, type, parameters, etc. (Including the pointer to the stub function!) Current status We can see both function in the dictionary... for every single method!!!

Current Status G__G__Hist_118_0_39()

What is a function call in CInt ● A CInt call is something similar to a C/C++ statement that is usually executed from ROOT -2.05b$ root.exe ******************************************* * * * W E L C O M E to R O O T * * * * Version 5.15/03 14 February 2007 * * * * You are welcome to visit our Web site * * * * * ******************************************* FreeType Engine v2.1.9 used to render TrueType fonts. Compiled on 21 February 2007 for linux with thread support. CINT/ROOT C/C++ Interpreter version , February 9, 2007 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] TH1F h1("h1", "h1", 10, 10, 10) root [1] h1.Fill(1); A simple example of function call

Now... the long history root [1] h1.Fill(1); TCint.cxx ProcessLine() Here it creates a temporal file with the statement and then tries to execute this file. v6_parse.cxx G__exec_statement() Looks for reserved words, if it doesn't find them it tries to execute the statement. v6_parse.cxx G__exec_function() Looks for reserved words, if it doesn't find them it tries to execute the statement. “h1.Fill(1);” “h1.Fill(1)” v6_expr.cxx G__getexpre() Try to find operators inside the string (like “+”, “-”, etc), put things in the stack and evaluate them. G__exec_evalall() G__exec_getitem() v6_var.cxx G__getvariable() It parses the string and looks for a “.” or a “”->” tagname = “h1” membername = “Fill(1)” “h1.Fill(1)” v6_var.cxx G__getstructmem() It tries to find the entry point for the object “h1”, “Fill(1)” v6_var.cxx G__getvariable() Here it finds the name of the variable and calculates its hash (it's only the addition of its chars) “h1” v6_var.cxx G__searchvariable() It looks for all the variables that CInt knows and compares them by hash... returning a G__var_array * “h1”, hash = 153 v6_func.cxx G__getfunction() After finding the object it has to look for the function. To do this it parses the parameters, calling a G__getexpre() for each one keeping them in the struct fpara. “Fill(1)”, ptr to the object At this point we have an object (h1), a list of parameters, and the name of the function (the hash is also calculated)

Almost there..... At this point we have an object (h1), a list of parameters, and the name of the function (the hash is also calculated) “Fill”, &fpara, hash, ptr to object 10 v6_ifunc.cxx G__interpret_function() Here it has to solve overloaded functions. It first tries with the final class and if it can't find the function it tries with its ascendants v6_ifunc.cxx G__overload_match() Here it has to solve overloaded functions. It first tries with the final class and if it can't find the function it tries with its ascendants “Fill”, &fpara, hash, ptr to object v6_newlink.cxx G__call_cppfunc() cppfunc = (GinterfaceMethod)ifunc->pentry[ifn]->p cppfunc --> G__Hist_118_0_39(G__value...) libp (parameters), ifunc (table function pointer) G__hist.cxx G__G__Hist_118_0_39() G__letint(... ((TH1*)G_getstructoffset())->Fill(...) ) funcp, libp, funcname 13 TH1.cxx TH1::Fill() 1 15 Api.cxx G__ExceptionWrapper() return ((*funcp)(result7, funcname, libp, hash) libp, funcname 14 Happy User!!!

Current Status Before Proposal !!!

New Schema Only one calling Function for all methods !! Proposal !!!

Structure Initialization Valid Address

Structure Initialization - Two Strategies “Apriori” Initialization libHist.so Load Time POINTER REGISTRATION TH1::Fill TH1::AddBinContent TH1::FillRandom TH1::GetBin TH1::Chi2Test TH1::ComputeIntegral TH1::Divide Interpreted Function Table (ifunc) - All Pointers for all symbols in the loaded library - Increasing of load time - We register pointers that we will not reference

Structure Initialization - Two Strategies “Lazy” Initialization - On Demand Initialization TH1::Fill() POINTER REGISTRATION ¡¡First Call!! Symbol LookuplibHist.so TH1::Fill TH1::AddBinContent TH1::FillRandom TH1::GetBin TH1::Chi2Test TH1::ComputeIntegral TH1::Divide Interpreted Function Table (ifunc) RegistrationVirtual Address Resolution

Structure Initialization - Two Strategies “Lazy” Initialization - Drawbacks LibHist.so exports 4600 symbols Average Symbol Length = 27 Characters Symbol Lookup = String Comparisons “Lazy” Initialization - Benefits Speed Up - Libraries Load Time

Proposal root [1] h1.Fill(1); Library libHist.so 1 Extract all the symbols (mangled names) and their function pointers Mangled Names _ZN3TH14FillEd _ZN3TH14FillEdd _ZN3TH14FillEPKcd... 2 Demangle them Demangled Names TH1::Fill(double) TH1::Fill(double, double) TH1::Fill(char const*, double)... 3 TCint.cxx RegisterPointer() This will addition the function pointer for the specified methodinside Cint. i.e. it will look for the right i_func_table entry and it will replace “TH1”, “Fill”, “double”, func pointer For Each Class.cxx GetMethod() It looks for the method by name and parses the prototype in case there are multiples methods 4 “Fill”, “double” CallFunc.cxx SetFuncPtr() Adds the new func pointer to the i_func_table: ifunc->funcptr[ifn] = ptr; 5 func pointer v6_newlink.cxx G__call_cppfunc() Here we see if funcptr exists, if it's like that we execute it intead of executing the stub... cppfunc --> ifunc->funcptr[ifn] Unconditional Happiness !! :D 6 7

Intel386 Assembler Direct Calling For each Parameter typ e Passing By Value Passing By Reference Push Value Push Address last No Push “this” pointer Yes Call

Intel386 Method Calling Examples TH1::Fill(Double_t x)TH1::Fill(const char * name, Double_t x) push “this pointer” push “x value” call “Fill” push “this pointer” push “x value” push “name address” call “Fill” ¡¡We have to adapt this calling schema for each processor family!!

Benefits of the stub removal Source Code’s Size reduction 1,56 MB LOC Example: LibHist.so Dictionary G__Hist.cxx Current Status 739,7 KB LOC G__Hist.cxx Future Status Reduction Factor = 2,15

- Compilation Time Decreasing - Disk Space Saving - Memory Use Saving CONSEQUENCES

First problem ● Mangling vs Demangling – Mangling is direct (From the function prototype we can get the function pointer) – But there is no way to do the mangling in a portable way. – Demangling is indirect (Demangle all and do a lookup when a function is needed). – Some effort has been made to have a common demangling scheme.

Second (big) problem... virtuality Based on the Virtual Table Layout from the ABI: ● Category 0: Trivial – No virtual base classes. – No virtual functions. ● Category 1: Leaf – No inherited virtual functions. – No virtual base classes. – Declares virtual functions.

Second (big) problem... virtuality ● Category 2: Non-Virtual Bases Only – Only non-virtual proper base classes. – Inherits virtual functions. ● Category 3: Virtual Bases Only – Only virtual base classes (but those may have non- virtual bases). – The virtual base classes are neither empty nor nearly empty. ● Category 4: Complex

Virtuality ● Categories 0: Trivial – We have the pointer to a function (in the i_func_table) and a pointer to the object so we “just” call the function passing the object as the this parameter. ● Category 1: Leaf – Idem... for the moment we don't need the virtual table.

Virtuality ● Category 2: Non-Virtual Bases Only – Do you meow or bark? Notes: ● C++ can tell dogs and cats apart. ● For an “aniCat” CInt won't be aware that it's a cat, it will just pass the animal to c++. ● Without the stub function it's our problem to differentiate between dogs and cats.

Virtuality ● Category 3: Virtual Bases Only – If you are a mutant... can you really bark? Dog Loyalty Cat Betrayal Objects Mutant Betrayal Loyalty Intelligence Mutant Betrayal Loyalty Intelligence Mutant Betrayal Loyalty Intelligence Dog Loyalty ● A pointer to a mutant points to the beginning of the object. ● In a call mutant->Bark(), c++ can not pass this pointing to “betrayal” because a dog knows nothing about it. ● But without the stubs functions we get a pointer to a Mutant and we have to force it to bark!!!... i.e. turn it to a dog even if it doesn't feel like it.

Virtuality ● Category 4: Complex – Our life is sad enough as it is now :(... we will get back at it after dealing with the other issues.