the cog vm evolution

63
Cog VM Evolution Clément Béra Thursday, August 25, 16

Upload: esug

Post on 13-Jan-2017

288 views

Category:

Software


2 download

TRANSCRIPT

Page 1: The Cog VM evolution

Cog VM Evolution

Clément Béra

Thursday, August 25, 16

Page 2: The Cog VM evolution

Cog VM ?• Smalltalk virtual machine

• Default VM for

• Pharo

• Squeak

• Newspeak

• Cuis

Thursday, August 25, 16

Page 3: The Cog VM evolution

Cog Philosophy

• Open source (MIT)

• Simple

• Is the optimization / feature worth the added complexity ?

• Cross-Platform (Processors, OS, 32/64 bits)

Thursday, August 25, 16

Page 4: The Cog VM evolution

Execution engine

• VM

• Execution engine

• Plugins: graphics, file, etc.

Thursday, August 25, 16

Page 5: The Cog VM evolution

Execution engine

• Interpreter

• JIT

• Memory Manager (including GC)

Thursday, August 25, 16

Page 6: The Cog VM evolution

Evolution

• User and Customer driven

• Where did we start ?

• What problems did we solve ?

Thursday, August 25, 16

Page 7: The Cog VM evolution

Starting blocks

• Interpreter VM

• Made by Dan Ingalls Team

• Simple Interpreter

• Spaghetti stack

• Smart but simple Memory Manager

Thursday, August 25, 16

Page 8: The Cog VM evolution

Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 9: The Cog VM evolution

Performance !

Short-term delivery

Performance for 3D application

• Fast Interpreter

Thursday, August 25, 16

Page 10: The Cog VM evolution

• Context-to-stack Mapping

• 85% of context allocation removed

• No copying of arguments

• New hash logic

• Primitive function caching

Stack VM

Thursday, August 25, 16

Page 11: The Cog VM evolution

Issue• Closure implementation

• No temporaries

• BlockAlreadyEvaluated error

• Non obvious bugs

• New implementation

Thursday, August 25, 16

Page 12: The Cog VM evolution

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Binary Tree benchmark

Thursday, August 25, 16

Page 13: The Cog VM evolution

More Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 14: The Cog VM evolution

More Performance !

Short-term delivery

Performance for 3D application

• First JIT compiler

Thursday, August 25, 16

Page 15: The Cog VM evolution

Cog VM

• x86 back-end

• Simple machine code generation

• Except inline caches

Thursday, August 25, 16

Page 16: The Cog VM evolution

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 17: The Cog VM evolution

JIT Abstractions

V3

Object Representation

SimpleStackCogit

CogitImplementation

x86

Machine back-end

Thursday, August 25, 16

Page 18: The Cog VM evolution

Yet More Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 19: The Cog VM evolution

Yet More Performance !

Short-term delivery

Performance for 3D application

• Second JIT compiler

Thursday, August 25, 16

Page 20: The Cog VM evolution

Cog VM

• Machine code generation

• Linear scan register allocation

• Avoids many stack operations

• Register-based calling convention

Thursday, August 25, 16

Page 21: The Cog VM evolution

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 22: The Cog VM evolution

JIT Abstractions

V3

Object Representation

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86

Machine back-end

Thursday, August 25, 16

Page 23: The Cog VM evolution

Newspeak support ?

Newspeak is Smalltalk-like

New kind of sends

Thursday, August 25, 16

Page 24: The Cog VM evolution

Newspeak support ?

• Multiple bytecode set support

• Newspeak specific operations

• Interpreter

• Machine code generation

Thursday, August 25, 16

Page 25: The Cog VM evolution

64 bits ? Images larger than 1 or 2 Gb ?

Moving objects during FFI call-backs ?Even more performance !

Ephemerons ?Become is so slow it cannot be used.

Thursday, August 25, 16

Page 26: The Cog VM evolution

64 bits ? Images larger than 1 or 2 Gb ?

Moving objects during FFI call-backs ?Even more performance !

Ephemerons ?Become is so slow it cannot be used.

Short-term delivery

Thursday, August 25, 16

Page 27: The Cog VM evolution

64 bits ? Images larger than 1 or 2 Gb ?

Moving objects during FFI call-backs ?Even more performance !

Ephemerons ?Become is so slow it cannot be used.

Short-term delivery

• New Memory Manager

Thursday, August 25, 16

Page 28: The Cog VM evolution

Spur Memory Manager

• Class-table (efficient caches and compactness)

• Efficient scavenging

• Fast become

• New object layouts (Ephemerons, ShortArrays)

• Memory representation 64-bits compatible

• Pinned objects

• Segmented Memory

Thursday, August 25, 16

Page 29: The Cog VM evolution

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 30: The Cog VM evolution

JIT Abstractions

V3Spur32

Spur64

Object Representation

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86

Machine back-end

V3Spur32

Spur64

Object Representation

x86

Machine back-end

32 bits 64 bits

Thursday, August 25, 16

Page 31: The Cog VM evolution

Raspberry Pi performance ?

Scratch support

Thursday, August 25, 16

Page 32: The Cog VM evolution

• ARMv6 support

Raspberry Pi performance ?

Scratch support

Thursday, August 25, 16

Page 33: The Cog VM evolution

ARMv6 support

• JIT ARMv6 back-end

• JIT abstraction over literal management

• JIT abstraction over CISC / RISC

Thursday, August 25, 16

Page 34: The Cog VM evolution

JIT Abstractions

V3Spur32

Spur64

Object Representation

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86

Machine back-end

V3Spur32

Spur64

Object Representation

x86ARMv6MIPSEL

Machine back-end

32 bits 64 bits

Inline

Outline

Literal Manager

Thursday, August 25, 16

Page 35: The Cog VM evolution

Ryan (contributor)

Working with the Dart VM

Dart runs on more platform than Newspeak.

Thursday, August 25, 16

Page 36: The Cog VM evolution

Ryan (contributor)

Working with the Dart VM

Dart runs on more platform than Newspeak.

• MIPSEL support

Thursday, August 25, 16

Page 37: The Cog VM evolution

JIT Abstractions

V3Spur32

Spur64

Object Representation

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86

Machine back-end

V3Spur32

Spur64

Object Representation

x86ARMv6MIPSEL

Machine back-end

32 bits 64 bits

Inline

Outline

Literal Manager

Thursday, August 25, 16

Page 38: The Cog VM evolution

64 bits support ?

64 bits library binding

Heap over 2Gb

Thursday, August 25, 16

Page 39: The Cog VM evolution

64 bits support ?

64 bits library binding

Heap over 2Gb

• x64 support

• Immediate float

Thursday, August 25, 16

Page 40: The Cog VM evolution

JIT Abstractions

V3Spur32

Spur64

Object Representation

Inline

Outline

Literal Manager

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86ARMv6MIPSEL

x64

Machine back-end

32 bits 64 bits

Thursday, August 25, 16

Page 41: The Cog VM evolution

Yet even more performance !

Computation lasting 3 to 6 hours

Thursday, August 25, 16

Page 42: The Cog VM evolution

Yet even more performance !

Computation lasting 3 to 6 hours

• Speculative optimizations

Thursday, August 25, 16

Page 43: The Cog VM evolution

Sista VM

• The program introspects

• Optimize the code for performance

• Deoptimize when it took incorrect decisions

Thursday, August 25, 16

Page 44: The Cog VM evolution

Issues

• Bytecode set

• Literal mutability

• Closure implementation

Thursday, August 25, 16

Page 45: The Cog VM evolution

Bytecode set limitations ?

Code generator tools

Thursday, August 25, 16

Page 46: The Cog VM evolution

Sista bytecode set

• Lifting encoding limitations

• Encode instructions for the Sista / Lowcode

Thursday, August 25, 16

Page 47: The Cog VM evolution

Efficient modification trackers ?Literal inconsistency ?

Thursday, August 25, 16

Page 48: The Cog VM evolution

• Read-only objects

• IWST talk this afternoon

• Hopefully allows more compiler optimizations

Efficient modification trackers ?Literal inconsistency ?

Thursday, August 25, 16

Page 49: The Cog VM evolution

Closure implementation

• Method and closure get more similar

• Simplifies part of the VM

• Simplifies the runtime compiler

Thursday, August 25, 16

Page 50: The Cog VM evolution

Integration

• Closed alpha version

• Integrating dependencies:

• Bytecode set integrated

• Read-only objects integrated (but disabled)

• Closure implementation in progress

Thursday, August 25, 16

Page 51: The Cog VM evolution

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 52: The Cog VM evolution

JIT Abstractions

V3Spur32

Spur64

Object Representation

Inline

Outline

Literal Manager

SimpleStackCogitStackToRegisterMappingCogit

RegisterAllocatingCogitSistaCogit

CogitImplementation

x86ARMv6MIPSEL

x64

Machine back-end

32 bits 64 bits

Thursday, August 25, 16

Page 53: The Cog VM evolution

Image compaction ?

Sometimes, large images when saving

Thursday, August 25, 16

Page 54: The Cog VM evolution

Image compaction ?

Sometimes, large images when saving

• Better compactor

Thursday, August 25, 16

Page 55: The Cog VM evolution

Pauses ?

0.5 second freezes in UI application

Thursday, August 25, 16

Page 56: The Cog VM evolution

Pauses ?

0.5 second freezes in UI application

• Incremental GC

Thursday, August 25, 16

Page 57: The Cog VM evolution

Many hidden parts

...

Thursday, August 25, 16

Page 58: The Cog VM evolution

• C generated from Slang

• Many were fixed

• Towards compilation with -WAll -WError

C compiler warning ?

Thursday, August 25, 16

Page 59: The Cog VM evolution

• LargeInteger plugin more efficient

• Computation moved from 8bits to 32 bits

• Different compilation flags

Faster arithmetic ?

Thursday, August 25, 16

Page 60: The Cog VM evolution

• Slang-to-C compiler

• Many improvements

• Type inference

Slang ?

Thursday, August 25, 16

Page 61: The Cog VM evolution

Contribution

Thursday, August 25, 16

Page 62: The Cog VM evolution

Cog VM team• Started with Eliot Miranda

• Many more contributors now:

• Tim Rowledge

• Clément Béra (myself)

• Nicolas Cellier

• Fabio Niephaus & Tim Felgentreff

• Ryan Macnak

Thursday, August 25, 16

Page 63: The Cog VM evolution

Conclusion• Lots of new features and improvements over years

• A lot more is incoming

• If you want to support, talk to us !

• ARMv8 ?

• Incremental GC ?

• Performance (escaping, floats) ?

Thursday, August 25, 16