how to build a high-performance vm for squeak/smalltalk in your spare time: an experience report of...
TRANSCRIPT
![Page 1: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/1.jpg)
RSqueak/VM
Building a fast, malleable VM with students
Hasso-Plattner-Institut Potsdam
Software Architecture Group
Tim Felgentreff, Tobias Pape, Patrick Rein, Robert
Hirschfeld
http://www.hpi.uni-potsdam.de/swa/
![Page 2: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/2.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Goals
2
• No C or assembler– Useful for teaching
• Good performance– Think about abstractions and how to lower them
• Small codebase– Easy to introduce new students
• Lots of tests– Experiments can rely on tests to catch errors
![Page 3: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/3.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
A VM WITHOUT LL CODE
3
![Page 4: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/4.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Background: the RPython Toolchain
4
![Page 5: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/5.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2008: Back to the Future in 1 Week
• Spy VM – a Smalltalk-80 VM in
RPython
• Interpreter-only
• 1 week
• Mostly people with no prior
RPython and little Python
experience
5
VM HLL-Code
Squeak VM 8900
Spy VM 2600
![Page 6: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/6.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
•
.
• Fast enough to run
many primitives
from Slang
2013: Tracing Algorithmic Primitives
• Lars Wassermann for his Master’s thesis transforms
Spy VM into RSqueak/VM
• Adds an FFI interface to native Squeak plugins
• Adds JIT annotations
• Supports Closures
6
![Page 7: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/7.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 7
![Page 8: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/8.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2014: Software Transactional Memory
• 5 students, 3 months
8
![Page 9: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/9.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2014: Software Transactional Memory
– Threads see different memory until they commit
– Automatically re-execute conflicts
9
![Page 10: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/10.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
• 3 students, 3 months
2014: Tagged vs Boxed Integers
10
![Page 11: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/11.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
• 3 students, 3 months
2015: Objects as Methods
11
![Page 12: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/12.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2015: Allocation Removal Strategies
• 1 student, 6 months
• adds a generic interface in RPython (and uses it in
RSqueak) to avoid allocations of special objects in
homogeneous objects
12
BitBlt benchmark in C in Smalltalk
Interpreter VM 650ms 389,660ms
1 x C 599 x C
Cog JIT VM 790ms 336,490ms
1 x C 423 x C
R/SqueakVM 880ms 20,310ms
1 x C 23 x C
![Page 13: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/13.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
SmallInteger
value: 456
SmallInteger
value: 789
...
...
SmallInteger
value: 123
value: 123
value: 456
...
...
value: 789
Collection Collection
<SmallIntegers>
Optimization
Storage Strategies
![Page 14: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/14.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
...
...
SmallInteger
value: 123
value: 123
value: 456
...
...
value: 789
Collection Collection
<SmallIntegers>
Deoptimizatio
nPoint
x
y
...
...
SmallInteger
value: 456
col at: 3 put: 1@2
Storage Strategies
![Page 15: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/15.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Collection
storage
...
...
...
...
read
write
Storage Strategies
![Page 16: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/16.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Collection
storage
...
...
...
...
StorageStrategy
read
write
StorageStrategyA
Storage Strategies
![Page 17: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/17.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Increment size of OrderedCollection
i215 = int_add_ovf(i213, 1)p227 = new_with_vtable(ConstClass(W_SmallInteger))setfield_gc(p227, i215, W_SmallInteger.inst_value)setarrayitem_gc(p147, 2, p227)
Store new value in Array
i204 = int_add_ovf(i189, 2)i219 = int_ne(i204, 2147483647)guard_true(i219)setarrayitem_gc(p211, i213, i204)
Store new value in Array
i207 = int_add_ovf(i194, 2)p231 = new_with_vtable(ConstClass(W_SmallInteger))setfield_gc(p231, i207, W_SmallInteger.inst_value)setarrayitem_gc(p220, i222, p231)
Without
Strategie
s
With
Strategie
s
![Page 18: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/18.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Strategy
Transitions
(Big picture)
Scenario:
● Open image
● Use browser
● Close image
![Page 19: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/19.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Evaluation: Performance
![Page 20: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/20.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Architecture
AbstractStrategy
SingleValueStrategy
EmptyStrategy
GenericStrategy
SingleTypeStrategy
TaggedStrategy
StrategyFactory
StrategyLogger
LogParser
Logfil
e
jpg
svg
![Page 21: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/21.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Usage
SingleValueStrategy
AllNilStrategy
SingleValueStrategy
value = nil
SmallIntegerStrategy
SingleTypeStrategy
type = SmallInteger
SingleTypeStrategy
StrategyFactory
RSqueakStrategyFact
orycreate_strategy()...
switch_strategy()...
![Page 22: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/22.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Usage
@rstrat.strategy(generalize=[
SmallIntegerOrNilStrategy,
FloatOrNilStrategy,
ListStrategy])
class AllNilStrategy(AbstractStrategy):
repr_classname = "AllNilStrategy"
import_from_mixin(rstrat.SingleValueStrategy)
def value(self): return self.space.w_nil
![Page 23: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/23.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
SIDETRACK
The tracing JIT optimizations from up high
23
![Page 24: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/24.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
BitBlt
24
![Page 25: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/25.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Algorithm Structure
25
![Page 26: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/26.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Type Specialization
26
![Page 27: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/27.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Type Specialization
27
![Page 28: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/28.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Inlining
28
![Page 29: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/29.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Folding
29
![Page 30: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/30.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Loops
30
![Page 31: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/31.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Loops
31
![Page 32: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/32.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Branch Pruning
32
![Page 33: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/33.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Branch Pruning
33
![Page 34: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/34.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2016: RSqueak + SQLite
• Joint-execution JIT and shared object space for
SQLite and RSqueak
• 5 students, 3 months
• ~25% speed-up
34
JIT
RSqueak
+ SqPyte
![Page 35: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/35.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2016: RSqueak + Topaz Ruby
• Joint-execution JIT and shared object space for
Topaz and RSqueak
• me, 2 days
35
JIT
RSqueak
+ Topaz
![Page 36: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/36.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
THE (SMALL-ISH) CODEBASE
36
![Page 37: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/37.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Absolute Size of Codebases
37
0
100
200
300
400
500
600
OST-VM RSqueak/VM
x 1
000
VMs including Translation Toolchains
HLL-Code LL-Code Test-Code
![Page 38: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/38.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
38
0
50
100
150
200
250
300
350
400
450
500
OST-VM RSqueak/VM
x 1
000
VMs without Toolchains
HLL-Code LL-Code Test-Code
![Page 39: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/39.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
39
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
OST-VM RSqueak/VM
VMs without Toolchains
HLL-Code LL-Code Test-Code
![Page 40: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/40.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
40
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
OST-VM RSqueak/VM
VMs without Toolchains
HLL-Code LL-Code Test-Code
35% Tests =>
![Page 41: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/41.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Performance Tests
41
![Page 42: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/42.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Performance Tests
42
![Page 43: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/43.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
IMPRESSIONS FROM
STUDENTS
43
![Page 44: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/44.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Taking advantage of the (R)Python standard library is enjoyable (compared to C-based projects)
PyPy source documentation very helpful
Feedback
44
![Page 45: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/45.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Feedback
45
![Page 46: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/46.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Feedback
46
DETAILS ON THE PROJECT SETUP
From a non-technical perspective, a problem we
encountered was the huge roundtrip times (on our
machines up to 600s, 900s with JIT enabled). This led
to a tendency of bigger code changes ("Before we
compile, let's also add this"), lost flow ("What where we
doing before?") and different compiled interpreters in
parallel testing ("How is this version different from the
others?") As a consequence it was harder to test and
correct errors. While this is not as much of a problem for
other RPython VMs, RSqueakVM needs to execute the
entire image, which makes running it untranslated
even slower.
![Page 47: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/47.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 47
![Page 48: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/48.jpg)
![Page 49: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/49.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 49
![Page 50: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/50.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 50
INT TAGGING ALLOCATION REMOVAL
![Page 51: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/51.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 51
FLOAT WORDS ALLOCATION REMOVAL
![Page 52: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/52.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 52
BITBLT PLUGIN AGGRESSIVE INLINING
![Page 53: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/53.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
BitBlt>>benchmark
Rule Depth VM copy 1x1warp 2x2warp 3x3warp
Rule 25 8 C 10 11 37 59
R 455 763 2703 2831
16 C 15 19 42 56
R 736 719 2223 2525
32 C 4 7 26 44
R 624 640 2191 2669
Rule 3 8 C 4 5 23 40
R 70 95 1650 2518
16 C 6 6 27 49
R 115 108 1497 1799
32 C 1 6 22 48
R 18 92 1586 2029
53
![Page 54: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/54.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rule Depth VM copy 1x1warp 2x2warp 3x3warp
Rule 25 8 C 10 11 37 59
R 455 763 2703 2831
16 C 15 19 42 56
R 736 719 2223 2525
32 C 4 7 26 44
R 624 640 2191 2669
Rule 3 8 C 4 5 23 40
R 70 95 1650 2518
16 C 6 6 27 49
R 115 108 1497 1799
32 C 1 6 22 48
R 18 92 1586 2029
54
~ Factor <50
![Page 55: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/55.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rule Depth VM copy 1x1warp 2x2warp 3x3warp
Rule 25 8 C 10 11 37 59
R 455 763 2703 2831
16 C 15 19 42 56
R 736 719 2223 2525
32 C 4 7 26 44
R 624 640 2191 2669
Rule 3 8 C 4 5 23 40
R 70 95 1650 2518
16 C 6 6 27 49
R 115 108 1497 1799
32 C 1 6 22 48
R 18 92 1586 2029
55
~ Factor <50 Factor 100+
![Page 56: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/56.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Growing the method dictionary copies
56
![Page 57: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/57.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Removing methods creates copies
57
![Page 58: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/58.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Points to Consider
• No interrupts in VM-level primitives
• Performance critical code may still have to be
optimized
• GC interaction with user code, but not primitives
• Simulating C semantics impacts results
58
![Page 59: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/59.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Array filling
| index repOff |
repOff := repStart - start.
index := start - 1.
[(index := index + 1) <= stop] whileTrue: [
self at: index
put: (replacement at: repOff + index)]
59
![Page 60: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/60.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Array filling
| index repOff |
repOff := repStart - start.
index := start - 1.
[(index := index + 1) <= stop] whileTrue: [
self at: index
put: (replacement at: repOff + index)]
Needs bounds checks
– interrupting threads may modify the replacement array
60
![Page 61: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/61.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Mandala
self isDefined: 'ENABLE_FAST_BLT'
inSmalltalk: [false
"there is no current fast path
specialisation code in-image"]
ifTrue:[self copyBitsFastPathSpecialised]
ifFalse: [self copyBitsLockedAndClipped].
No Slang code for this – just plain C. Optimization on
Smalltalk level required.
61
![Page 62: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/62.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Secure Hash Algorithm
self primHasSecureHashPrimitive
ifTrue: [
^ self
processBufferUsingPrimitives:
aByteArray]
ifFalse: [totals := nil].
"... 26 lines of code using instances of
ThirtyTwoBitRegister"
62
![Page 63: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/63.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Secure Hash Algorithm
self primHasSecureHashPrimitive
ifTrue: [
^ self
processBufferUsingPrimitives:
aByteArray]
ifFalse: [totals := nil].
"... 26 lines of code using instances of
ThirtyTwoBitRegister"
OO-Abstraction of words (with high and low parts stored
separately). Instances escape loops and cause GCs
63
![Page 64: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/64.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 64
![Page 65: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/65.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rendering Fonts
65
![Page 66: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/66.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rendering Fonts
66
Simulating C pointer arithmetic, casts, …
![Page 67: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/67.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 67
![Page 68: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/68.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Our Takeaway
• Useable Performance
reduces the need for
primitives
• Debugging in practical
applications feasible
• Writing new primitives
in Smalltalk from the
start is an option
68
![Page 69: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/69.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 69
(#('VMMaker-Translation to C' 'VMMaker-Building' 'VMMaker-
InterpreterSimulation'
'VMMaker-JITSimulation' 'VMMaker-SpurMemoryManagerSimulation' 'VMMaker-
PostProcessing')
gather: [:cat | (Smalltalk organization listAtCategoryNamed:
cat) collect: [:s | (Smalltalk at: s) linesOfCode]]) sum
22171
(#('VMMaker-Interpreter' 'VMMaker-JIT' 'VMMaker-Multithreading' 'VMMaker-
Plugins' 'VMMaker-Plugins-FFI' 'VMMaker-SmartSyntaxPlugins'
'VMMaker-SpurMemoryManager' 'VMMaker-Support')
gather: [:cat | (Smalltalk organization listAtCategoryNamed:
cat) collect: [:s | (Smalltalk at: s) linesOfCode]]) sum
118738
sloccount platforms/
ansic: 263736
cpp: 46791
objc: 13036
asm: 9753
-------------------------
(#('VMMaker-Tests') gather: [:cat | (Smalltalk organization
listAtCategoryNamed: cat) collect: [:s | (Smalltalk at: s) linesOfCode]]) sum
3837
![Page 70: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/70.jpg)
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 70
find rpython/ -not -path "*test*" -not -path "*_cache*" -not -name "*.pyc" | tr '\n' ' ' |
xargs sloccount
python: 345405
ansic: 8090
asm: 213
sloccount rsdl/
python: 822
find rsqueakvm/ -type f -not -path "*test*" -not -path "*_cache*" -not -name "*.pyc" | tr
'\n' ' ' | xargs sloccount
python: 11823
-------------------------
find rpython -type f -path "*test*" -not -path "*_cache*" -not -name "*.pyc" | tr '\n' ' '
| xargs sloccount
python: 134942
asm: 4956
ansic: 574
sloccount rsdl/test
python: 513
find rsqueakvm/ -type f -path "*test*" -not -path "*_cache*" -not -name "*.pyc" | tr '\n' '
' | xargs sloccount
python: 6786
![Page 71: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/71.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
• A kind of Allocation Removal Optimization
– Less overhead due to memory management
– Less pressure on garbage collector (less GCs, shorter GCs)
– Smaller memory footprint of application
• Based on heuristics/speculations
– Slow deoptimizations possible
![Page 72: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/72.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
SmallInteger
value: 456
SmallInteger
value: 789
...
...
SmallInteger
value: 123
value: 123
value: 456
...
...
value: 789
Collection Collection
<SmallIntegers>
Optimization
![Page 73: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/73.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
...
...
SmallInteger
value: 123
value: 123
value: 456
...
...
value: 789
Collection Collection
<SmallIntegers>
Deoptimizatio
nPoint
x
y
...
...
SmallInteger
value: 456
col at: 3 put: 1@2
![Page 74: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/74.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Collection
storage
...
...
...
...
read
write
![Page 75: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/75.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Collection
storage
...
...
...
...
StorageStrategy
read
write
StorageStrategyA
![Page 76: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/76.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Increment size of OrderedCollection
i215 = int_add_ovf(i213, 1)p227 = new_with_vtable(ConstClass(W_SmallInteger))setfield_gc(p227, i215, W_SmallInteger.inst_value)setarrayitem_gc(p147, 2, p227)
Store new value in Array
i204 = int_add_ovf(i189, 2)i219 = int_ne(i204, 2147483647)guard_true(i219)setarrayitem_gc(p211, i213, i204)
Store new value in Array
i207 = int_add_ovf(i194, 2)p231 = new_with_vtable(ConstClass(W_SmallInteger))setfield_gc(p231, i207, W_SmallInteger.inst_value)setarrayitem_gc(p220, i222, p231)
Without
Strategie
s
With
Strategie
s
![Page 77: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/77.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Strategy
Transitions
(Big picture)
Scenario:
● Open image
● Use browser
● Close image
![Page 78: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/78.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Evaluation: Performance
![Page 79: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/79.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
rstrategies: Architecture
AbstractStrategy
SingleValueStrategy
EmptyStrategy
GenericStrategy
SingleTypeStrategy
TaggedStrategy
StrategyFactory
StrategyLogger
LogParser
Logfil
e
jpg
svg
![Page 80: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/80.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
rstrategies: Usage
SingleValueStrategy
AllNilStrategy
SingleValueStrategy
value = nil
SmallIntegerStrategy
SingleTypeStrategy
type = SmallInteger
SingleTypeStrategy
StrategyFactory
RSqueakStrategyFact
orycreate_strategy()...
switch_strategy()...
![Page 81: How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain](https://reader034.vdocument.in/reader034/viewer/2022052514/586fe0cd1a28ab18428b7521/html5/thumbnails/81.jpg)
Software Architecture Group - Anton Gulenko - 23.02.2015
Example: RSqueak VM
@rstrat.strategy(generalize=[
SmallIntegerOrNilStrategy,
FloatOrNilStrategy,
ListStrategy])
class AllNilStrategy(AbstractStrategy):
repr_classname = "AllNilStrategy"
import_from_mixin(rstrat.SingleValueStrategy)
def value(self): return self.space.w_nil