Efficient Compilation of .NET Programs for Embedded Systems Olivier - - PowerPoint PPT Presentation

efficient compilation of net programs for embedded
SMART_READER_LITE
LIVE PREVIEW

Efficient Compilation of .NET Programs for Embedded Systems Olivier - - PowerPoint PPT Presentation

Efficient Compilation of .NET Programs for Embedded Systems Olivier Sallenave Roland Ducournau Cortus SA LIRMM (France) MASPEGHI/ICOOOLPS 2010 Maribor, Slovenia Outline Motivation 1 Type analysis 2 Coloring 3 Evaluation 4


slide-1
SLIDE 1

Efficient Compilation of .NET Programs for Embedded Systems Olivier Sallenave Roland Ducournau

Cortus SA – LIRMM (France) MASPEGHI/ICOOOLPS 2010 Maribor, Slovenia

slide-2
SLIDE 2

Outline

1

Motivation

2

Type analysis

3

Coloring

4

Evaluation

2 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-3
SLIDE 3

Outline

1

Motivation

2

Type analysis

3

Coloring

4

Evaluation

3 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-4
SLIDE 4

Embedded systems Long development cycles

Specific constraints Increasing design complexity

Low-end systems

Still programmed in C or assembly

The problem

High-level languages poorly adapted for constrained devices

4 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-5
SLIDE 5

Approach

Global compilation

Closed-world assumption

Knowledge of the whole program ⇒ more efficient implementation

Implications

Disable dynamic loading and reflection

5 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-6
SLIDE 6

Objective

Enable .NET for devices with <100KB memory

Target architecture

Cortus APS3 (32-bit RISC processor) Small size Low power consumption

6 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-7
SLIDE 7

Compilation scheme

Ahead-of-time compilation

C# code bytecode CIL Microsoft C# compiler C# code CIL bytecode code C

code machine APS3

aps3−gcc Global compilation

No runtime penalty (no JIT) Compile under the closed-world assumption Focus on optimizing object mechanisms

7 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-8
SLIDE 8

Outline

1

Motivation

2

Type analysis

3

Coloring

4

Evaluation

8 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-9
SLIDE 9

Type analysis Type analysis

Constructs a call graph of the program Approximates dynamic types Many algorithms exist (+/- precision)

Optimizations

Monomorphic method calls → implement as static calls Safe subtype checks → remove Unreachable members/code → remove

9 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-10
SLIDE 10

Implementation details Our algorithm

Based on RTA (maintain a set of instantiated classes) Meta-model to represent classes/members Takes into account .NET specificities

Meta-model

Distinguishes identity/implementations of methods Dead identity → remove entry in method tables Dead implementation → remove code

Stack state simulation

.NET VM is stack-based ⇒ static type of operands ? Compute stack state for each instruction

10 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-11
SLIDE 11

Array covariance (Java/.NET) Principle

B <: A ⇒ B[] <: A[] <: subtyping relationship

class B : A { } ... void meth(A[] tab, A x, int i) { tab[i] = x ; }

Drawback

Array assignments are unsafe → need subtype check

11 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-12
SLIDE 12

Eliminating subtype checks

P(x) = {possible types of x} approximate x’s type

x isa t ?

True if ∀p ∈ P(x), p <: t False if ∀p ∈ P(x), ¬(p <: t) <: subtyping relationship Otherwise, need subtype check

The problem for array assignments

t is unknown at compile-time (element type of the assigned array) ⇒ approximate it as well

12 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-13
SLIDE 13

Optimizing array covariance

P(x) = {possible types of x} approximate x’s E(tab) = {possible element types for tab} and tab’s types

tab[i] = x

Safe if ∀p ∈ P(x), ∀e ∈ E(tab), p <: e Error if ∀p ∈ P(x), ∀e ∈ E(tab), ¬(p <: e) Otherwise, need subtype check

Effectiveness

Efficient if a few array types are instantiated

13 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-14
SLIDE 14

Outline

1

Motivation

2

Type analysis

3

Coloring

4

Evaluation

14 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-15
SLIDE 15

Single subtyping Virtual method tables

Straightforward extensions of the superclass table

No binary tree dispatch

No branch prediction Tends to increase code size

15 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-16
SLIDE 16

Multiple subtyping Insert empty entries in method tables

Maintain single subtyping invariants Drawback is additional space cost Minimize the number of holes is NP-hard

16 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-17
SLIDE 17

Coloring interfaces Abstract types

Their method tables do not exist at runtime Consider it in the coloring algorithm → allocate holes in abstract tables first

17 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-18
SLIDE 18

Implementation details What remains in method tables

Only necessary data Methods called polymorphically at least once Type IDs for subtype check targets (Cohen test) Some holes

Fill empty entries

Insertion of holes is the drawback of coloring ⇒ use them to store static fields

18 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-19
SLIDE 19

Outline

1

Motivation

2

Type analysis

3

Coloring

4

Evaluation

19 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-20
SLIDE 20

Program reduction Dead types

reduction classes 552 57% interfaces 24 54%

Dead members

non-virtual reduction fields 795 33% methods 886 41% virtual methods (id) 384 66% methods (impl) 651 69% bytecode size 82KB 26%

20 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-21
SLIDE 21

Object mechanisms Compile-time resolution

method calls resolved static 2999 – virtual 599 85% subtype checks downcasts 84 11% array assignments 199 81%

Runtime structures

entries in reduction method tables 2974 82% instance layouts* 707 15%

* one layout per class

21 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-22
SLIDE 22

Summary Summary

Noticeable reduction of the programs Array covariance is almost safe (almost no overhead)

Bench programs (.NET Micro Framework)

Only a few holes should result from coloring : Most classes do not implement interfaces Average method table size is small Holes can be filled with static fields

22 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-23
SLIDE 23

Future work Future work

Null check elimination Genericity (mixed implementation) Evaluate on bigger programs Profiling Garbage collection

Additional features

Generate debug informations Multithreading

23 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems

slide-24
SLIDE 24

Thank you !

http://www.cortus.com

24 Motivation Type analysis Coloring Evaluation Efficient Compilation of .NET Programs for Embedded Systems