Skip to content

Commit e57cf32

Browse files
committedMar 30, 2016
Standardized use of accessors.
There are two types of instance variables used in the C++ code: 1. Variables that reference managed objects and which the GC needs to know about to properly trace the object graph. We call these "slots". 2. Variables that reference native types (eg int, double, etc) that the GC *cannot* trace (the GC would misunderstand numbers for memory addresses, for example). Previously, we treated these to types quite differently. We used the '// slot' notation when declaring the first type so that we could automatically generate code to process the objects. The second type was usually somewhat consistent but also ad hoc in many places. Now we mostly use two macros (attr_accessor for the first type, and attr_field for the second type) that both define the variables and define setters and getters for them. There are still some places where this needs to be cleaned up. One reason that we need to be very careful about the setters for the first type of variable (the managed object references) is that when the concurrent GC is running, we need to know when an object reference is stored into an object that may have already been processed by the marker. If we don't see this, that object may be considered unreachable by the GC *even though it's being referenced*. This results in the equivalent to a use-after-free bug in a language with manually managed memory. Consistently using the managed object reference accessors means that we can layer other behavior on the access functions. For example, if we tag objects with an identifier for the thread that created them, we can log or prevent mutation access from a different thread.
1 parent 46bd531 commit e57cf32

File tree

127 files changed

+1600
-1771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1600
-1771
lines changed
 

‎core/constant_cache.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Rubinius
22
class ConstantCache
33
attr_reader :name
44
attr_reader :value
5-
attr_reader :under
6-
attr_reader :scope
5+
attr_reader :module
6+
attr_reader :constant_scope
77
attr_reader :executable
88

99
def ip
@@ -21,7 +21,7 @@ def location
2121
end
2222

2323
def inspect
24-
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name} constant=#{@value} under=#{@under}>"
24+
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name} constant=#{@value} module=#{@module} constant_scope=#{@constant_scope}>"
2525
end
2626
end
2727
end

‎machine/builtin/access_variable.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ namespace rubinius {
2020
static void initialize(STATE, AccessVariable* av) {
2121
Executable::initialize(state, av, AccessVariable::access_execute);
2222

23-
av->name_ = nil<Symbol>();
24-
av->write_ = nil<Object>();
23+
av->name(nil<Symbol>());
24+
av->write(nil<Object>());
2525
}
2626

2727
// Rubinius.primitive :accessvariable_allocate

0 commit comments

Comments
 (0)
Please sign in to comment.