View
217
Download
0
Category
Tags:
Preview:
Citation preview
Multi-Method Dispatch Using Multiple RowDisplacement
Candy Pang, Wade Holst, Yuri Leontiev, and Duane SzafronECOOP’99
Presented by: Irene ChengDate: 7 November 2002
AxA
AxB BxA
AxC BxB CxA
BxC CxB
CxC
1
2
3
4
• Review of Terminology
• Review of Row Displacement Dispatchfor Single-Receiver
• Multiple Row Displacement (MRD)
• Optimizations
• Performance Results and Conclusion
Presentation Topics
Review of Terminology
• Single-receiver dispatch uses the dynamic type of a receiver object and the method name to determine which method to execute at run-time,
e.g. aPerson.id();
• Multi-method dispatch uses the dynamic types of the arguments and the method name to determine the method to execute,
e.g. shape.intersect( rectangle, circle );
Review of Terminology (cont)
What is a call-site ?• In single-receiver languages - viewed as a
message sent to the receiver object.e.g.
• In multi-method languages - viewed as the execution of a behavior on a set of arguments.
e.g.
The run-time determination of the method to invoke at a call-site is called method dispatch.
aPerson.id()
shape.intersect( rectangle, circle )
Review of Terminology (cont)
Dispatch strategy:• Cache-based (global or local)• Table-based -
Pre-determine the method for every possible call-site, and record these methods in a table.
When a method is defined, each argument has a specific static type. However, at a call-site, the dynamic type of each argument can either be the static type, or any of its subtypes, e.g.
Person (id1)
Student (id2)
Person aPerson;if (…) aPerson = new Person();else aPerson = new Student();aPerson.id( );
id1 id2
Product-Type Graph (for 2 arguments)
AxA
AxB BxA
AxC BxB CxA
BxC CxB
CxC
1
2
3
4
The underlying Inheritance Hierarchy, H The 2-arity product-type graph, H2
A
B
C
A product-type graph hierarchy contains all the possible call-sites
Inheritance Conflicts
AxC
AxD BxC
AxE BxD ExC
BxE ExD
ExE
1
2
General DefinitionA conflict occurs when a product-type can see 2 different method definitions by looking up different paths in the induced product-type graph.
RelaxationLet = { P1 … Pn } and P < P1 … Pn, the methods in Pi and Pj do not conflict in P if :
i.e. 1 <= i, j, k <= n
• Pi < Pj or
• Pj < Pi or
• { Pk | Pk Pi Pk Pj }
2 2
2
Review of single-receiver Row displacement Dispatch (RD)
Example: E anE = new E();anE.();
1 + 4 = 5 D::
A0 D3
B1 C2 , E4
4
MRD Dispatch Table for method with 2 arguments
AA
AB BA
AC BB CA
AD BC CB DA
AE BD CC DB EA BE CD DC EB
CE DD EC
DE ED
EE
1 2
3
AA
AB BA
AC BB CA
AD BC CB DA
AE BD CC DB EA BE CD DC EB
CE DD EC
DE ED
EE
1
2
MRD Dispatch Table for method with 2 arguments
Data Structure per Behavior - Array of pointers to arrays
A0 B1 C2 D3 E4 A0 B1 C2 D3 E4
• ( Level-0 array ) L0 - indexed by the 1st argument type• ( Level-1 array ) L1 - indexed by the 2nd argument type and
contains method addresses
Compressing the Data Structure for
M - Global Master Array I0 - Global Index Array B - Global Behavior Array
Compressing the Data Structure for and
M - Global Master Array I0 - Global Index Array B - Global Behavior Array
Example: Dispatch a call-site (anE, aD) M [ I0 [5 + 4 = 9 ] + 3 = 14 ]
MRD is designed for n-dimensional dispatch tables
1
BDBBDEBEBBEEEDBEDEEEBEEE
2
DBDDBEDEDDEEEBDEBEEEDEEE
Example: dispatch a call-site (anE, aD, aB)
M [I1 [I0 [ B [] +4] +3] +1]= M [I1 [I0 [ 7+4] +3] +1]= M [I1 [ 5+3] +1]= M[ 15+1]
BD DB EE
Optimizations
Single I - One Global Index Array, I, to store all L0 to Lk-2 arrays
I00 0 1 1 5 8 11 - - 11
- - 14 15 15 14 14 - 15 19
L0 - 8 - 9 13
0 5 17B
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
M [ I0 [ I0 [ B[] +4] +3] +1]= M [ I0 [ I0 [ 17+4] +3] +1]= M [ I0 [ 13+3] +1]= M [ 15+1]
Example: (anE, aD, aB)
I1
Optimizations (cont)
Row-matching instead of row-shifting (additional 10-14% )
Row-shifting
Row-matching
Row-matching cannot be used in single-receiver RD because different rows contain different behavior, and thus different method addresses.
Before displacement
Optimizations (cont)
Byte vs. Word Storage (MRD-B)
• M is the most memory consuming data structure (duplicate 4-byte method address)
• Use method-map per behavior (each method address is stored only once)
• Only 1 byte (max. 256 methods) is used in M to store the index of the corresponding method in the method-map.
• Size of M is reduced to 1/4 but extra redirection time at dispatch.
Timing results
Noop - dummy function to time the overhead incurredMRD - multiple row displacement MRD-B - MRD using byte instead of word for Master arrayCNT - Compressed N-Dimensional TablesSRP - Single Receiver ProjectionsLUA - Lookup Automata
Memory Utilization
LUA - Lookup AutomataMRD - multiple row displacementMRD-B - MRD using byte instead of word for Master arrayCNT - Compressed N-Dimensional TablesSRP - Single Receiver Projections
Conclusion
• A new multi-method dispatch technique is introduced to compress an n-dimensional table by row displacement.
• The first time a comparison of multi-method techniques has appeared in the literature.
• Experimental results shows that when comparing with other table-based multi-method techniques, MRD has the fastest dispatch time and the second smallest per-call-site code size.
Recommended