Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
RSqueak/VM
Building a fast, malleable VM with students
Hasso-Plattner-Institut Potsdam
Software Architecture Group
Tim Fel...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Goals
2
• No C or assembler
– Useful for teaching
• ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
A VM WITHOUT LL CODE
3
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Background: the RPython Toolchain
4
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2008: Back to the Future in 1 Week
• Spy VM – a Smal...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
•
.
• Fast enough to run
many primitives
from Slang
...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 7
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2014: Software Transactional Memory
• 5 students, 3 ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2014: Software Transactional Memory
– Threads see di...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
• 3 students, 3 months
2014: Tagged vs Boxed Integer...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
• 3 students, 3 months
2015: Objects as Methods
11
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2015: Allocation Removal Strategies
• 1 student, 6 m...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
SmallInteger
valu...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
...
...
SmallInte...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Collection
storage
...
...
...
...
read
write
Storag...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Collection
storage
...
...
...
...
StorageStrategy
r...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Increment size of OrderedCollection
i215 = int_add_o...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Strategy
Transitions
(Big picture)
Scenario:
● Open ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Evaluation: Performance
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Architecture
AbstractStrategy
SingleVal...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Usage
SingleValueStrategy
AllNilStrateg...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
rstrategies: Usage
@rstrat.strategy(generalize=[
Sma...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
SIDETRACK
The tracing JIT optimizations from up high...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
BitBlt
24
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Algorithm Structure
25
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Type Specialization
26
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Type Specialization
27
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Inlining
28
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Folding
29
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Loops
30
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Loops
31
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Branch Pruning
32
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Branch Pruning
33
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2016: RSqueak + SQLite
• Joint-execution JIT and sha...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
2016: RSqueak + Topaz Ruby
• Joint-execution JIT and...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
THE (SMALL-ISH) CODEBASE
36
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Absolute Size of Codebases
37
0
100
200
300
400
500
...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
38
0
50
100
150...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
39
0%
10%
20%
3...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Code of VMs without Translation bits
40
0%
10%
20%
3...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Performance Tests
41
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Performance Tests
42
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
IMPRESSIONS FROM
STUDENTS
43
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
 Taking advantage of the (R)Python standard library...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Feedback
45
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Feedback
46
DETAILS ON THE PROJECT SETUP
From a non-...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 47
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 49
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 50
INT TAGGING ALLOCATION REMOVAL
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 51
FLOAT WORDS ALLOCATION REMOVAL
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 52
BITBLT PLUGIN AGGRESSIVE INLINING
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
BitBlt>>benchmark
Rule Depth VM copy 1x1warp 2x2warp...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rule Depth VM copy 1x1warp 2x2warp 3x3warp
Rule 25 8...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rule Depth VM copy 1x1warp 2x2warp 3x3warp
Rule 25 8...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Growing the method dictionary copies
56
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Removing methods creates copies
57
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Points to Consider
• No interrupts in VM-level primi...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Array filling
| index repOff |
repOff := repStart - ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Array filling
| index repOff |
repOff := repStart - ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Mandala
self isDefined: 'ENABLE_FAST_BLT'
inSmalltal...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Secure Hash Algorithm
self primHasSecureHashPrimitiv...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Secure Hash Algorithm
self primHasSecureHashPrimitiv...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 64
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rendering Fonts
65
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Rendering Fonts
66
Simulating C pointer arithmetic, ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 67
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present
Our Takeaway
• Useable Performance
reduces the need ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 69
(#('VMMaker-Translation to C' 'VMMaker-Building' ...
Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 70
find rpython/ -not -path "*test*" -not -path "*_c...
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
• A kind of Allocation Removal Optimization
– ...
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
SmallIntege...
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Slot 0
Slot 1
Slot 3
Slot 4
Slot 2
...
...
Sma...
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Collection
storage
...
...
...
...
read
write
Software Architecture Group - Anton Gulenko - 23.02.2015
Storage Strategies
Collection
storage
...
...
...
...
StorageStra...
Software Architecture Group - Anton Gulenko - 23.02.2015
Increment size of OrderedCollection
i215 = int_add_ovf(i213, 1)
p...
Software Architecture Group - Anton Gulenko - 23.02.2015
Strategy
Transitions
(Big picture)
Scenario:
● Open image
● Use b...
Software Architecture Group - Anton Gulenko - 23.02.2015
Evaluation: Performance
Software Architecture Group - Anton Gulenko - 23.02.2015
rstrategies: Architecture
AbstractStrategy
SingleValueStrategy
Em...
Software Architecture Group - Anton Gulenko - 23.02.2015
rstrategies: Usage
SingleValueStrategy
AllNilStrategy
SingleValue...
Software Architecture Group - Anton Gulenko - 23.02.2015
Example: RSqueak VM
@rstrat.strategy(generalize=[
SmallIntegerOrN...
How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Tool...
Upcoming SlideShare
Loading in …5
×

How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain

730 views

Published on

Presentation of IWST16, Prag

Published in: Software
  • Be the first to comment

  • Be the first to like this

How to Build a High-Performance VM for Squeak/Smalltalk in Your Spare Time: An Experience Report of Using the RPython Toolchain

  1. 1. 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/
  2. 2. 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
  3. 3. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present A VM WITHOUT LL CODE 3
  4. 4. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Background: the RPython Toolchain 4
  5. 5. 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
  6. 6. 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
  7. 7. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 7
  8. 8. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 2014: Software Transactional Memory • 5 students, 3 months 8
  9. 9. 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
  10. 10. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present • 3 students, 3 months 2014: Tagged vs Boxed Integers 10
  11. 11. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present • 3 students, 3 months 2015: Objects as Methods 11
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Collection storage ... ... ... ... read write Storage Strategies
  16. 16. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Collection storage ... ... ... ... StorageStrategy read write StorageStrategyA Storage Strategies
  17. 17. 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_SmallIntege r)) setfield_gc(p231, i207, W_SmallInteger.inst_value) setarrayitem_gc(p220, i222, p231) Without Strategie s With Strategie s
  18. 18. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Strategy Transitions (Big picture) Scenario: ● Open image ● Use browser ● Close image
  19. 19. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Evaluation: Performance
  20. 20. 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 pdf svg
  21. 21. 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 ory create_strategy()... switch_strategy()...
  22. 22. 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
  23. 23. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present SIDETRACK The tracing JIT optimizations from up high 23
  24. 24. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present BitBlt 24
  25. 25. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Algorithm Structure 25
  26. 26. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Type Specialization 26
  27. 27. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Type Specialization 27
  28. 28. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Inlining 28
  29. 29. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Folding 29
  30. 30. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Loops 30
  31. 31. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Loops 31
  32. 32. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Branch Pruning 32
  33. 33. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Branch Pruning 33
  34. 34. 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
  35. 35. 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
  36. 36. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present THE (SMALL-ISH) CODEBASE 36
  37. 37. 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 x1000 VMs including Translation Toolchains HLL-Code LL-Code Test-Code
  38. 38. 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 x1000 VMs without Toolchains HLL-Code LL-Code Test-Code
  39. 39. 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
  40. 40. 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 =>
  41. 41. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Performance Tests 41
  42. 42. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Performance Tests 42
  43. 43. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present IMPRESSIONS FROM STUDENTS 43
  44. 44. 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
  45. 45. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Feedback 45
  46. 46. 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.
  47. 47. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 47
  48. 48. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 49
  49. 49. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 50 INT TAGGING ALLOCATION REMOVAL
  50. 50. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 51 FLOAT WORDS ALLOCATION REMOVAL
  51. 51. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 52 BITBLT PLUGIN AGGRESSIVE INLINING
  52. 52. 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
  53. 53. 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
  54. 54. 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+
  55. 55. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Growing the method dictionary copies 56
  56. 56. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Removing methods creates copies 57
  57. 57. 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
  58. 58. 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
  59. 59. 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
  60. 60. 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
  61. 61. 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
  62. 62. 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
  63. 63. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 64
  64. 64. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Rendering Fonts 65
  65. 65. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present Rendering Fonts 66 Simulating C pointer arithmetic, casts, …
  66. 66. Software Architecture Group (www.hpi.uni-potsdam.de/swa) 2006-present 67
  67. 67. 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
  68. 68. 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
  69. 69. 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
  70. 70. 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
  71. 71. 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
  72. 72. 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
  73. 73. Software Architecture Group - Anton Gulenko - 23.02.2015 Storage Strategies Collection storage ... ... ... ... read write
  74. 74. Software Architecture Group - Anton Gulenko - 23.02.2015 Storage Strategies Collection storage ... ... ... ... StorageStrategy read write StorageStrategyA
  75. 75. 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_SmallIntege r)) setfield_gc(p231, i207, W_SmallInteger.inst_value) setarrayitem_gc(p220, i222, p231) Without Strategie s With Strategie s
  76. 76. Software Architecture Group - Anton Gulenko - 23.02.2015 Strategy Transitions (Big picture) Scenario: ● Open image ● Use browser ● Close image
  77. 77. Software Architecture Group - Anton Gulenko - 23.02.2015 Evaluation: Performance
  78. 78. Software Architecture Group - Anton Gulenko - 23.02.2015 rstrategies: Architecture AbstractStrategy SingleValueStrategy EmptyStrategy GenericStrategy SingleTypeStrategy TaggedStrategy StrategyFactory StrategyLogger LogParser Logfil e jpg pdf svg
  79. 79. Software Architecture Group - Anton Gulenko - 23.02.2015 rstrategies: Usage SingleValueStrategy AllNilStrategy SingleValueStrategy value = nil SmallIntegerStrategy SingleTypeStrategy type = SmallInteger SingleTypeStrategy StrategyFactory RSqueakStrategyFact ory create_strategy()... switch_strategy()...
  80. 80. 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

×