cog vm evolution - esug: news the cog vm evolution... · • interpreter • jit ... • first jit...

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

Upload: others

Post on 22-May-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Cog VM Evolution

Clément Béra

Thursday, August 25, 16

Page 2: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Cog VM ?• Smalltalk virtual machine

• Default VM for

• Pharo

• Squeak

• Newspeak

• Cuis

Thursday, August 25, 16

Page 3: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Execution engine

• VM

• Execution engine

• Plugins: graphics, file, etc.

Thursday, August 25, 16

Page 5: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Execution engine

• Interpreter

• JIT

• Memory Manager (including GC)

Thursday, August 25, 16

Page 6: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Evolution

• User and Customer driven

• Where did we start ?

• What problems did we solve ?

Thursday, August 25, 16

Page 7: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Starting blocks

• Interpreter VM

• Made by Dan Ingalls Team

• Simple Interpreter

• Spaghetti stack

• Smart but simple Memory Manager

Thursday, August 25, 16

Page 8: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 9: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Performance !

Short-term delivery

Performance for 3D application

• Fast Interpreter

Thursday, August 25, 16

Page 10: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• 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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Issue• Closure implementation

• No temporaries

• BlockAlreadyEvaluated error

• Non obvious bugs

• New implementation

Thursday, August 25, 16

Page 12: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Binary Tree benchmark

Thursday, August 25, 16

Page 13: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

More Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 14: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

More Performance !

Short-term delivery

Performance for 3D application

• First JIT compiler

Thursday, August 25, 16

Page 15: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Cog VM

• x86 back-end

• Simple machine code generation

• Except inline caches

Thursday, August 25, 16

Page 16: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 17: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

JIT Abstractions

V3

Object Representation

SimpleStackCogit

CogitImplementation

x86

Machine back-end

Thursday, August 25, 16

Page 18: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Yet More Performance !

Short-term delivery

Performance for 3D application

Thursday, August 25, 16

Page 19: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Yet More Performance !

Short-term delivery

Performance for 3D application

• Second JIT compiler

Thursday, August 25, 16

Page 20: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Cog VM

• Machine code generation

• Linear scan register allocation

• Avoids many stack operations

• Register-based calling convention

Thursday, August 25, 16

Page 21: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 22: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

JIT Abstractions

V3

Object Representation

SimpleStackCogitStackToRegisterMappingCogit

CogitImplementation

x86

Machine back-end

Thursday, August 25, 16

Page 23: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Newspeak support ?

Newspeak is Smalltalk-like

New kind of sends

Thursday, August 25, 16

Page 24: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Newspeak support ?

• Multiple bytecode set support

• Newspeak specific operations

• Interpreter

• Machine code generation

Thursday, August 25, 16

Page 25: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 30: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Raspberry Pi performance ?

Scratch support

Thursday, August 25, 16

Page 32: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• ARMv6 support

Raspberry Pi performance ?

Scratch support

Thursday, August 25, 16

Page 33: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

ARMv6 support

• JIT ARMv6 back-end

• JIT abstraction over literal management

• JIT abstraction over CISC / RISC

Thursday, August 25, 16

Page 34: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Ryan (contributor)

Working with the Dart VM

Dart runs on more platform than Newspeak.

Thursday, August 25, 16

Page 36: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Ryan (contributor)

Working with the Dart VM

Dart runs on more platform than Newspeak.

• MIPSEL support

Thursday, August 25, 16

Page 37: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

64 bits support ?

64 bits library binding

Heap over 2Gb

Thursday, August 25, 16

Page 39: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

64 bits support ?

64 bits library binding

Heap over 2Gb

• x64 support

• Immediate float

Thursday, August 25, 16

Page 40: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Yet even more performance !

Computation lasting 3 to 6 hours

Thursday, August 25, 16

Page 42: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Yet even more performance !

Computation lasting 3 to 6 hours

• Speculative optimizations

Thursday, August 25, 16

Page 43: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Sista VM

• The program introspects

• Optimize the code for performance

• Deoptimize when it took incorrect decisions

Thursday, August 25, 16

Page 44: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Issues

• Bytecode set

• Literal mutability

• Closure implementation

Thursday, August 25, 16

Page 45: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Bytecode set limitations ?

Code generator tools

Thursday, August 25, 16

Page 46: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Sista bytecode set

• Lifting encoding limitations

• Encode instructions for the Sista / Lowcode

Thursday, August 25, 16

Page 47: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Efficient modification trackers ?Literal inconsistency ?

Thursday, August 25, 16

Page 48: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• Read-only objects

• IWST talk this afternoon

• Hopefully allows more compiler optimizations

Efficient modification trackers ?Literal inconsistency ?

Thursday, August 25, 16

Page 49: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Closure implementation

• Method and closure get more similar

• Simplifies part of the VM

• Simplifies the runtime compiler

Thursday, August 25, 16

Page 50: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Binary Tree benchmark

0

2

4

6

8

10

12

14

Interpreter Stack CogV1 CogV2 Spur Sista

Thursday, August 25, 16

Page 52: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Image compaction ?

Sometimes, large images when saving

Thursday, August 25, 16

Page 54: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Image compaction ?

Sometimes, large images when saving

• Better compactor

Thursday, August 25, 16

Page 55: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Pauses ?

0.5 second freezes in UI application

Thursday, August 25, 16

Page 56: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Pauses ?

0.5 second freezes in UI application

• Incremental GC

Thursday, August 25, 16

Page 57: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Many hidden parts

...

Thursday, August 25, 16

Page 58: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• C generated from Slang

• Many were fixed

• Towards compilation with -WAll -WError

C compiler warning ?

Thursday, August 25, 16

Page 59: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• LargeInteger plugin more efficient

• Computation moved from 8bits to 32 bits

• Different compilation flags

Faster arithmetic ?

Thursday, August 25, 16

Page 60: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

• Slang-to-C compiler

• Many improvements

• Type inference

Slang ?

Thursday, August 25, 16

Page 61: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

Contribution

Thursday, August 25, 16

Page 62: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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: Cog VM Evolution - ESUG: News The cog vm evolution... · • Interpreter • JIT ... • First JIT compiler Thursday, August 25, 16. Cog VM ... Scratch support Thursday, August 25,

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