Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Compacting GC for MRI In Ruby 2.7

Slide 3

Slide 3 text

HELLO!!!

Slide 4

Slide 4 text

Aaron Patterson @tenderlove

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Rails Core Team

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Ruby Core Team

Slide 13

Slide 13 text

10 Years On Ruby Core! W ow !!!

Slide 14

Slide 14 text

Expectations

Slide 15

Slide 15 text

Ruby Cores [aaron@TC ~]$ ls /cores core.22948 core.32321 core.44049 core.73547 core.76951 core.31231 core.36549 core.73064 core.73848 core.77093 core.31784 core.36550 core.73479 core.76655 core.82911 core.31802 core.36605 core.73493 core.76710 core.86743

Slide 16

Slide 16 text

Compacting GC for MRI

Slide 17

Slide 17 text

Controversial Features in Ruby 2.7

Slide 18

Slide 18 text

Pipeline Operator

Slide 19

Slide 19 text

Pipeline Operator 1..100 |> map { |x| x.to_s } |> sort |> reverse |> take 5 |> display

Slide 20

Slide 20 text

"Ruby is designed for developer happiness" —matz

Slide 21

Slide 21 text

Smile Operator 1..100 map { |x| x.to_s } sort reverse take 5 display

Slide 22

Slide 22 text

https://github.com/ruby/ruby/pull/2273

Slide 23

Slide 23 text

Pipeline Operator ANCELLED

Slide 24

Slide 24 text

Typed Ruby?

Slide 25

Slide 25 text

Compacting GC for MRI

Slide 26

Slide 26 text

Manual Heap Compaction For MRI

Slide 27

Slide 27 text

~3 years to complete

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

"Novel Solution"

Slide 30

Slide 30 text

I am a genius

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

THANK YOU!

Slide 33

Slide 33 text

THANKS!!!!!

Slide 34

Slide 34 text

Today’s Topics!

Slide 35

Slide 35 text

Ruby’s Heap Compaction Algorithm Implementation Details Debugging Results

Slide 36

Slide 36 text

What is Compaction?

Slide 37

Slide 37 text

Compaction Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory

Slide 38

Slide 38 text

Compaction Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory

Slide 39

Slide 39 text

Compaction Allocated Memory Computer Memory Free Memory

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Why Compact?

Slide 42

Slide 42 text

Efficient Memory Usage

Slide 43

Slide 43 text

Efficient Memory Usage Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory Want To Allocate

Slide 44

Slide 44 text

Efficient Memory Usage Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory Want To Allocate

Slide 45

Slide 45 text

Efficient Memory Usage Allocated Memory Computer Memory Allocated Memory Allocated Memory Wanted To Allocate

Slide 46

Slide 46 text

CPU Caches

Slide 47

Slide 47 text

CPU Cache Hits Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory In CPU Cache

Slide 48

Slide 48 text

CPU Cache Hits Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory In CPU Cache

Slide 49

Slide 49 text

"Good Locality"

Slide 50

Slide 50 text

CoW Friendliness CoW is "Copy on Write"

Slide 51

Slide 51 text

CoW Friendliness Computer Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Parent Process Child Process

Slide 52

Slide 52 text

CoW Friendliness Computer Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Parent Process Child Process

Slide 53

Slide 53 text

CoW Friendliness Computer Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Parent Process Child Process

Slide 54

Slide 54 text

CoW Friendliness Computer Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Allocated Memory Allocated Memory Allocated Memory Free Memory Free Memory Parent Process Child Process

Slide 55

Slide 55 text

Eliminating Fragmentation

Slide 56

Slide 56 text

Fragmented Memory Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory

Slide 57

Slide 57 text

No Fragmentation Allocated Memory Computer Memory Allocated Memory Allocated Memory Free Memory Free Memory

Slide 58

Slide 58 text

Two Heaps

Slide 59

Slide 59 text

Ruby Heaps System Memory Malloc Heap Ruby’s Object Heap

Slide 60

Slide 60 text

Ruby Heaps System Memory Malloc Heap Ruby’s Object Heap Object.new

Slide 61

Slide 61 text

Ruby Heaps System Memory Malloc Heap Ruby’s Object Heap String.new "The Quick Brown Fox Jumps Over The Lazy Dog"

Slide 62

Slide 62 text

Fragmentation Can Occur in Both Heaps

Slide 63

Slide 63 text

For Malloc Heap: jemalloc

Slide 64

Slide 64 text

For Ruby Heap: GC.compact

Slide 65

Slide 65 text

Ruby’s Heap

Slide 66

Slide 66 text

Ruby Heaps System Memory Malloc Heap Ruby’s Object Heap

Slide 67

Slide 67 text

Ruby’s Heap Layout 40 bytes Each chunk is a "slot" Em pty Filled Empty Filled Moved

Slide 68

Slide 68 text

Ruby’s Heap Layout ~16 kb Contiguous slots make a "page"

Slide 69

Slide 69 text

Ruby’s Heap Layout

Slide 70

Slide 70 text

Ruby’s Heap Layout malloc( malloc( malloc( ) ) )

Slide 71

Slide 71 text

Ruby’s Heap Layout Each slot has a unique address 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Slide 72

Slide 72 text

Compaction Algorithm

Slide 73

Slide 73 text

Two Finger Compaction The Programming Language LISP: Its Operation and Applications (1964)

Slide 74

Slide 74 text

Move Objects Update References

Slide 75

Slide 75 text

Moving Objects A B C D E F Free Scan 1 2 3 4 5 6 7 8 9 10 Empty Filled Moved 4 5

Slide 76

Slide 76 text

Updating References A B C D E F 1 2 3 4 5 6 7 8 9 10 Empty Filled Moved Before Moving Objects

Slide 77

Slide 77 text

Updating References A B C D 5 4 1 2 3 4 5 6 7 8 9 10 Empty Filled F Moved E After Moving Objects

Slide 78

Slide 78 text

Updating References A B C D 5 4 1 2 3 4 5 6 7 8 9 10 Empty Filled F Moved E After Moving Objects

Slide 79

Slide 79 text

Object Movement def compact heap = [ ... ] # many slots left = 0 right = heap.length - 1 while left < right left_slot = heap[left] right_slot = heap[right] if is_empty?(left_slot) && !is_empty?(right_slot) && can_move?(right_slot) swap(left, right) heap[right] = T_MOVED.new(left) # leave forwarding address end while !is_empty?(heap[left]) left += 1 end while is_empty?(heap[right]) || !can_move?(heap[right]) right -= 1 end end end Pointers Met? Copy / Forward Advance "free" Retreat "scan"

Slide 80

Slide 80 text

Reference Updating def update_references heap.each do |slot| next if is_empty?(slot) || is_moved?(slot) slot.references.each_with_index do |child, i| if is_moved?(child) slot.set_reference(i, child.new_location) end end end end How are references stored?

Slide 81

Slide 81 text

Finding References • How do Hashes hold references? • How do Arrays hold references? • How do Objects hold references? • … • … • …

Slide 82

Slide 82 text

Reference Updating static void gc_ref_update_array(rb_objspace_t * objspace, VALUE v) { long i, len; if (FL_TEST(v, ELTS_SHARED)) return; len = RARRAY_LEN(v); if (len > 0) { VALUE *ptr = (VALUE *)RARRAY_CONST_PTR_TRANSIENT(v); for(i = 0; i < len; i++) { UPDATE_IF_MOVED(objspace, ptr[i]); } } } static void gc_ref_update_object(rb_objspace_t * objspace, VALUE v) { uint32_t i, len = ROBJECT_NUMIV(v); VALUE *ptr = ROBJECT_IVPTR(v); for (i = 0; i < len; i++) { UPDATE_IF_MOVED(objspace, ptr[i]); } } static int hash_replace_ref(st_data_t *key, st_data_t *value, st_data_t argp, int existing)

Slide 83

Slide 83 text

Reference Updating

Slide 84

Slide 84 text

Supporting C Extensions

Slide 85

Slide 85 text

Where Are References Stored?

Slide 86

Slide 86 text

Array Array VALUE* Some Object Some Object Some Object

Slide 87

Slide 87 text

Hashes Hash VALUE* Some Object Some Object VALUE* Some Object Some Object Keys Values

Slide 88

Slide 88 text

Strings, Classes, Modules, Symbols, etc

Slide 89

Slide 89 text

GC Can Update All "Known Types"

Slide 90

Slide 90 text

"Known Types" Are Types Implemented by Ruby

Slide 91

Slide 91 text

What About "Unknown Types"?

Slide 92

Slide 92 text

Unknown Types are Types Implemented in C

Slide 93

Slide 93 text

Yajl typedef struct { VALUE builderStack; VALUE parse_complete_callback; int nestedArrayLevel; int nestedHashLevel; int objectsFound; int symbolizeKeys; yajl_handle parser; } yajl_parser_wrapper; C Code (yajl_ext.h) malloc(yajl_parser_wrapper) Ruby Object T_DATA Ruby Object Ruby Object builderStack parse_complete_callback Ruby Heap Malloc Heap

Slide 94

Slide 94 text

Yajl typedef struct { VALUE builderStack; VALUE parse_complete_callback; int nestedArrayLevel; int nestedHashLevel; int objectsFound; int symbolizeKeys; yajl_handle parser; } yajl_parser_wrapper; C Code (yajl_ext.h) malloc(yajl_parser_wrapper) Ruby Object T_DATA Ruby Object Ruby Object builderStack parse_complete_callback GC: "idk, " MOVED! Ruby Heap Malloc Heap

Slide 95

Slide 95 text

Yajl Mark Function void yajl_parser_wrapper_mark(void * wrapper) { yajl_parser_wrapper * w = wrapper; if (w) { rb_gc_mark(w->builderStack); rb_gc_mark(w->parse_complete_callback); } } malloc(yajl_parser_wrapper) Ruby Object T_DATA Ruby Object Ruby Object rb_gc_mark(builderStack) rb_gc_mark(parse_complete_callback) Ruby Heap Malloc Heap

Slide 96

Slide 96 text

Anything Marked With `rb_gc_mark` Cannot Move

Slide 97

Slide 97 text

Pinning Bits 1 2 3 4 5 6 7 8 9 10 Yajl [ ] ? "foo" "bar" ? Address Content Pinned x = [ "foo", "bar" ] y = Yajl.new Ruby Code rb_gc_m ark rb_gc_m ark gc_m ark_no_pin gc_m ark_no_pin

Slide 98

Slide 98 text

Pinning Bits 1 2 3 4 5 6 7 8 9 10 Yajl [ ] ? ? Address Content Pinned x = [ "foo", "bar" ] y = Yajl.new Ruby Code Free Scan "bar" "foo" 4 5 Move Step

Slide 99

Slide 99 text

Pinning Bits 1 2 3 4 5 6 7 8 9 10 Yajl [ ] ? ? Address Content Pinned x = [ "foo", "bar" ] y = Yajl.new Ruby Code 4 5 Reference Update Step "bar" "foo" Update

Slide 100

Slide 100 text

Known Types Use `gc_mark_no_pin`

Slide 101

Slide 101 text

Unknown Types Use `rb_gc_mark`

Slide 102

Slide 102 text

Allowing Movement in C Extensions

Slide 103

Slide 103 text

Compaction Callback Movable "No Pin" Marking New Location Function

Slide 104

Slide 104 text

GC Cannot Update a C Extension

Slide 105

Slide 105 text

C Extension Can Update Itself

Slide 106

Slide 106 text

Compaction Callback static const rb_data_type_t yajl_parser_type = { "Yajl/parser", {yajl_parser_wrapper_mark, yajl_parser_wrapper_free, NULL,}, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, }; Mark No Compaction Callback static const rb_data_type_t yajl_parser_type = { "Yajl/parser", {yajl_parser_wrapper_mark, yajl_parser_wrapper_free, NULL, yajl_parser_compact}, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, }; Compact With Compaction Callback Sweep

Slide 107

Slide 107 text

"No Pin" Marking void yajl_parser_wrapper_mark(void * wrapper) { yajl_parser_wrapper * w = wrapper; if (w) { rb_gc_mark(w->builderStack); rb_gc_mark(w->parse_complete_callback); } } No Compaction Support void yajl_parser_wrapper_mark(void * wrapper) { yajl_parser_wrapper * w = wrapper; if (w) { rb_gc_mark_movable(w->builderStack); rb_gc_mark_movable(w->parse_complete_callback); } } With Compaction Support

Slide 108

Slide 108 text

Compaction Callback void yajl_parser_compact(void *wrapper) { yajl_parser_wrapper * w = wrapper; if (w) { w->builderStack = rb_gc_new_location(w->builderStack); w->parse_complete_callback = rb_gc_location(w->parse_complete_callback); } } New Location

Slide 109

Slide 109 text

Known Issue

Slide 110

Slide 110 text

Problem Object Graph Object Implemented in Ruby Object Implemented in C Some Object Automatically Marked!! (gc_mark_no_pin) Not Marked

Slide 111

Slide 111 text

Compaction 1 2 3 4 5 6 7 8 9 10 Ruby Obj C Obj ? 4 5 3

Slide 112

Slide 112 text

Maybe Not Common

Slide 113

Slide 113 text

Compilation Process Text Abstract Syntax Tree Intermediate Representation Instruction Sequences

Slide 114

Slide 114 text

RubyVM Instruction Sequence ISeq Object (in C) def foo "bar" end Code Mark Array (Ruby) "bar" Marked Marked NOT Marked

Slide 115

Slide 115 text

"Direct Marking" in Ruby 2.6 ISeq Object (in C) def foo "bar" end Code "bar" Marked https://bugs.ruby-lang.org/issues/14370

Slide 116

Slide 116 text

Ruby AST AST Object (in C) def foo "bar" end Code Mark Array (Ruby) "bar" Marked Marked NOT Marked

Slide 117

Slide 117 text

Direct AST Marking AST Object (in C) def foo "bar" end Code "bar" Marked https://github.com/ruby/ruby/pull/2414

Slide 118

Slide 118 text

Ruby IR IR Object (in C) def foo "bar" end Code Mark Array (Ruby) "bar" Marked Marked NOT Marked

Slide 119

Slide 119 text

Compilation Process Text Abstract Syntax Tree Intermediate Representation Instruction Sequences

Slide 120

Slide 120 text

JSON Object Implemented in Ruby Object Implemented in C Some Object Automatically Marked!! (gc_mark) Not Marked

Slide 121

Slide 121 text

Problem Code static VALUE CNaN, CInfinity, CMinusInfinity; void Init_parser(void) { #undef rb_intern CNaN = rb_const_get(mJSON, rb_intern("NaN")); CInfinity = rb_const_get(mJSON, rb_intern("Infinity")); CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity")); }

Slide 122

Slide 122 text

Potential Crasher require 'json' JSON.send :remove_const, :NaN GC.start json = '{ "foo": NaN }' JSON.load(json, nil, :allow_nan => true)['foo'].nan? Cut the reference

Slide 123

Slide 123 text

Fix diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index 0bd328ca42..6f0d31c2eb 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -2099,8 +2099,13 @@ void Init_parser(void) rb_define_method(cParser, "source", cParser_source, 0); CNaN = rb_const_get(mJSON, rb_intern("NaN")); + rb_gc_register_mark_object(CNaN); + CInfinity = rb_const_get(mJSON, rb_intern("Infinity")); + rb_gc_register_mark_object(CInfinity); + CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity")); + rb_gc_register_mark_object(CMinusInfinity); i_json_creatable_p = rb_intern("json_creatable?"); i_json_create = rb_intern("json_create");

Slide 124

Slide 124 text

MsgPack Object Implemented in Ruby Object Implemented in C Some Object Automatically Marked!! (gc_mark) Not Marked

Slide 125

Slide 125 text

Pure Ruby Shouldn’t Crash https://github.com/msgpack/msgpack-ruby/issues/133

Slide 126

Slide 126 text

If you hold a reference, you must mark the reference

Slide 127

Slide 127 text

More Challenges Object#object_id

Slide 128

Slide 128 text

Direct Memory Access Prevents Movement

Slide 129

Slide 129 text

object_id is based on location 1 2 3 4 5 6 7 8 9 10 Ruby Obj Ruby Obj Ruby Obj 5 object#object_id => 1 object#object_id => 2 object#object_id => 9 object#object_id => ?

Slide 130

Slide 130 text

Object ID After Move x = Object.new GC.compact x.object_id 1 2 3 4 X x.object_id => 1 Heap

Slide 131

Slide 131 text

Object ID After Move x = Object.new x.object_id GC.compact x.object_id 1 2 3 4 X x.object_id => 4 Heap

Slide 132

Slide 132 text

"Seen" Object IDs $seen_object_id = {} class Object def object_id $seen_object_id[memory_location] ||= memory_location end end

Slide 133

Slide 133 text

Object ID After Move x = Object.new x.object_id GC.compact x.object_id 1 2 3 4 X Heap Object ID Table Memory Location Object ID 4 4 Updated Object ID Table Memory Location Object ID 1 4

Slide 134

Slide 134 text

Object ID Collisions x = Object.new x.object_id GC.compact x.object_id y = Object.new y.object_id 1 2 3 4 X Heap Object ID Table Memory Location Object ID 4 4 Updated Object ID Table Memory Location Object ID 1 4 y.object_id => ??? x.object_id => 4 Y

Slide 135

Slide 135 text

Collision Resolution $seen_object_id = {} $location_to_object_id = {} class Object def object_id id = memory_location while $seen_object_id[id] id += 1 end $seen_object_id[id] = id $location_to_object_id[memory_location] = id end end

Slide 136

Slide 136 text

Object ID Collisions x = Object.new x.object_id GC.compact x.object_id y = Object.new y.object_id 1 2 3 4 X Heap Object ID Table Memory Location Object ID 4 4 Updated Object ID Table Memory Location Object ID 1 4 y.object_id => 5 x.object_id => 4 Y Updated Object ID Table- Memory Location Object ID 1 4 4 5

Slide 137

Slide 137 text

GC Cleanup $seen_object_id = {} $location_to_object_id = {} def free_obj(obj) if $location_to_object_id[obj.memory_location] id = $location_to_object_id.delete(obj.memory_location) $seen_object_id.delete(id) end end

Slide 138

Slide 138 text

"Mostly Location Based" ANCELLED 20% CANCELLED Refactored o be better

Slide 139

Slide 139 text

Monotonic Object ID Thanks @jhawthorn!!!

Slide 140

Slide 140 text

Monotonic IDs irb(main):001:0> Object.new.object_id => 480 irb(main):002:0> Object.new.object_id => 500 irb(main):003:0> Object.new.object_id => 520 irb(main):004:0> Object.new => # irb(main):005:0> Object.new.object_id => 540

Slide 141

Slide 141 text

Object IDs are Truly Unique

Slide 142

Slide 142 text

Count object_id Calls

Slide 143

Slide 143 text

Inspect vs Object ID $ ruby -v -e'x = Object.new; p x; p x.object_id' ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18] # 70161462322340 $ ruby -v -e'x = Object.new; p x; p x.object_id' ruby 2.7.0dev (2019-11-15T09:07:34Z master 11ae47c266) [x86_64-darwin19] # 40 Related! No Relationship! Ruby 2.6 Ruby 2.7

Slide 144

Slide 144 text

Don’t Use Object ID! (Unless you need to, it’s really fine)

Slide 145

Slide 145 text

Compaction Impact Patch Results

Slide 146

Slide 146 text

Basic Rails Application Before Compaction

Slide 147

Slide 147 text

Basic Rails Application After Compaction

Slide 148

Slide 148 text

GitHub Before Compaction After Compaction

Slide 149

Slide 149 text

~3% Pinned

Slide 150

Slide 150 text

GitHub Before Compaction After Compaction

Slide 151

Slide 151 text

~1% pinned

Slide 152

Slide 152 text

GitHub Before Compaction After Compaction

Slide 153

Slide 153 text

0.3% pinned

Slide 154

Slide 154 text

~10% smaller heap

Slide 155

Slide 155 text

Future Plans

Slide 156

Slide 156 text

Performance Improvements

Slide 157

Slide 157 text

Full GC Move Objects Update References Full GC

Slide 158

Slide 158 text

Automatic Compaction Ruby 3.0

Slide 159

Slide 159 text

Sliding Compaction

Slide 160

Slide 160 text

Sliding Compaction 1 2 3 4 5 6 7 8 9 10 Yajl [ ] ? "foo" "bar" ? Address Content

Slide 161

Slide 161 text

Better Locality

Slide 162

Slide 162 text

Supports Variable Widths

Slide 163

Slide 163 text

Variable Width Allocation

Slide 164

Slide 164 text

Fixed Width Layout

Slide 165

Slide 165 text

Variable Width Layout

Slide 166

Slide 166 text

We’re constantly improving

Slide 167

Slide 167 text

Ruby’s Future is Exciting!

Slide 168

Slide 168 text

THANK YOU! http://bugs.ruby-lang.org/issues/15626

Slide 169

Slide 169 text

Debugging GC

Slide 170

Slide 170 text

Problem Code /* static value pointing at Foo constant */ static VALUE foo = rb_const_get("Foo");

Slide 171

Slide 171 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo");

Slide 172

Slide 172 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo"); Bar

Slide 173

Slide 173 text

3 Major Techniques

Slide 174

Slide 174 text

1. Maximum Chaos

Slide 175

Slide 175 text

Heap Doubling 1 2 3 4 5 6 7 8 9 10 4 5 11 12 13 14 15 16 17 18 19 20 18 19 20

Slide 176

Slide 176 text

2 Space Collector

Slide 177

Slide 177 text

2. Zombie Objects

Slide 178

Slide 178 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo");

Slide 179

Slide 179 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo"); Bar

Slide 180

Slide 180 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo"); Bar

Slide 181

Slide 181 text

3. Address Sanitizer

Slide 182

Slide 182 text

2 Features Custom Allocator Compiler Extension

Slide 183

Slide 183 text

Read / Write Checks if (isPoisoned(foo)) abort(); *foo = 1;

Slide 184

Slide 184 text

Read / Write Checks if (isPoisoned(foo)) abort(); *foo = 1;

Slide 185

Slide 185 text

Compaction Bug 1 2 3 4 5 6 7 8 9 10 Foo 4 5 3 static VALUE foo = rb_const_get("Foo"); Bar

Slide 186

Slide 186 text

Using Address Sanitizer $ clang -fsanitize=address … __asan_poison_memory_region(ptr, size); Compiler Flags Runtime Function

Slide 187

Slide 187 text

Stuff to Google 2 Space Collector Zombie Objects Address Sanitizer