19
Diego Garbervetsky, LaFHIS, UBA, Argentina - Stefan Marr, JKU, Linz, Austria Building Efficient and Highly Run-Time Adaptable Virtual Machines Guido Chari , LaFHIS, UBA, CONICET, Argentina

Building Efficient and Highly Run-Time Adaptable Virtual Machines

Embed Size (px)

Citation preview

Page 1: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Diego Garbervetsky, LaFHIS, UBA, Argentina - Stefan Marr, JKU, Linz, Austria

Building Efficient and Highly Run-Time

Adaptable Virtual MachinesGuido Chari, LaFHIS, UBA, CONICET, Argentina

Page 2: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Fully-Reflective Execution Environments (FREE)

Every entity at both, the application and the VM-levels, must provide reflective capabilities for its observation and

modification at run time.

MOPFine-Grained Scoping

GlobalMethodObjec

t

Page 3: Building Efficient and Highly Run-Time Adaptable Virtual Machines

point1.setX(2)point2.setX(2)point3.setX(2)

Read-only Exampledef setX(arg) x = arg return x

Point 1

xy

mo

Point 2

xy

mo

Point 3

xy

mo

def fieldWrite(field, value) throw exception()

def fieldWrite(field, value)def returnValue(val) return val + 2

11

11

11

2

2

Ex

3

_NO_METAOBJECT

Page 4: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Starting Point

Extremely slow Smalltalk

interpreter!

Insights for optimizing

reflective systems

What are the fundamental performance overheads of a FREE? How can we optimize them as much as

possible?

Page 5: Building Efficient and Highly Run-Time Adaptable Virtual Machines

def setX(arg) x = arg return x

Difference with Standard VMsdef IntercessionHandling(frame, operation){ if (getGlobalMetaobject(operation)) return delegateToGlobal(operation); if (frame.getMetaobject(operation)) return delegateToFrame(operation); if (rcvr().getMetaobject(operation)) return delegateToRcvr(operation); executeOperationInVM;}

It is hard for the compiler to speculate on the meta behavior because it can not guess the current metaobject for each scope on

each subsequent IH

4 Operations1 Arg Read,1 Field Write,1 Field Read,1 Return

Page 6: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Intercession Handling (IH)✤ Ubiquitous: every

operation must be intercepted.

✤ Complex: every interception must consider scoping conditions.

✤ Tests that depend on run-time values and jeopardize optimizations.

✤ Lookup and marshaling for delegation to language-level.

Page 7: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Conjectures for Optimization

✤ Stable Semantics: Moderated dynamicity at run time.

✤ Low-local metavariability: IH sites similar to call sites: most monomorphic, some polymorphic, few megamorphic.

Page 8: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Optimization Model

✤ Aggressive and exhaustive speculation of the meta-model: speculate on each observed metaobject at every scoping condition for every IH site.

✤ Mitigate as much as possible the overhead of the speculation guards.

Page 9: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Rcvr

Speculate for Each Metaobject + Scope + IH Site

def fieldWrite(field, value) throw writeException()def fieldWrite(field, value)def returnValue(val) return val + 2

def setX(arg) x = arg return x

def fieldWrite(field, value) write in DBdef fieldRead(field) read in DB

2

1

0

3

_NO_METAOBJECT

Field write

Read arg

Global

Frame

30 1 0 1 2

0

Global

Frame Rcvr

0 0 0

Observe the run-time behavior until become stable

Page 10: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Speculate For Each Metaobject + Scope + IH Site

def fieldWrite(field, value) throw writeException()

def fieldWrite(field, value);def returnValue(val) return val + 2

def setX(arg) x = arg return x

def fieldWrite(field, value) write in DBdef fieldRead(field) read in DB

2

1

0

3

_NO_METAOBJECT

Return

Field read

Global

Frame Rcvr

0 0 20

Global

Frame Rcvr

0 0 03

Page 11: Building Efficient and Highly Run-Time Adaptable Virtual Machines

JIT Compiling the Fast Pathdef IntercessionHandling(frame){ executeVMStandardArgRead Globa

lFram

e Rcvr0 0 0

if (globalMO(writeField) == 3) write in DB; else if (frameMO(writeField) == 1 or rcvr.MO(op) == 1) throw writeException() else if (rcvr.MO(writeField) == 2) Nop else executeVMStandardWrite

Global

Frame Rcvr

30 1 0 1 2

0

Global

Frame Rcvr

0 0 03 if (globalMO(readField) == 3) read in DB else executeVMStandardRead

Global

Frame Rcvr

0 0 20

if (rcvr.MO(ret) == 2) return val + 2 else executeVMStandardReturn}

Argument read

Field write

Field read

Return

Global and Frame scoping: optimizable. Instance Scoping: still need to access

memory

Page 12: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Mitigating Speculation Guards: Metaobjects in Layouts

Shapes are usually needed in the context of a method

def setX(arg) x = arg return x

Global

Frame Rcvr

0 0 0

Return

20,0 1,2

if (rcvr.shape == 1) return val + 2; else executeVMStandardReturn

1

No extra memory access for instances

if (rcvr.MO(op) == 2) return val + 2 else executeVMStandardReturn}

1

Page 13: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Inherent Peak Performance Overhead

Mean peak performance overhead: Micro 0.97x

Baseline TruffleSOM: Truffle+ Graal: Java: ~2.7x (~V8)

TruffleMATE: TruffleSOM +

MOP

Page 14: Building Efficient and Highly Run-Time Adaptable Virtual Machines

(+) Inherent Peak Performance Overhead

Mean peak performance overhead: Macro 1.02x

Overall peak

performance overhead:

0.99x

Page 15: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Peak Performance of Using the VM Reflective Capabilities

ExhaustivelyBaseline:

TruffleMATE

Overall mean peak performance overhead: 1-3.4x

Page 16: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Breaking Assumptions

Mega 18.5x, Mono 1.10x

Severe performance degradation when assumptions do not hold

i = 0foreach (point in list) i += point.x

Page 17: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Results

✤ Ran in most cases quite efficiently.

✤ Positive indicator for our optimization model.

✤ Still room for improvements.

✤ High-local meta variability leads to severe performance degradation.

Page 18: Building Efficient and Highly Run-Time Adaptable Virtual Machines

Open Paths

✤ Go deeper into the VM (memory, garbage collection).

✤ Would a reflective compiler enable significant improvements?

✤ Statistics such as code bloat, length of dispatch chains, etc.

TruffleMATE: https://github.com/charig/truffleMate

Page 19: Building Efficient and Highly Run-Time Adaptable Virtual Machines