Implement Write Barrier and dsize for FFI::FunctionType#1001
Conversation
| // IMPORTANT: WB_PROTECTED objects must only use the RB_OBJ_WRITE() | ||
| // macro to update VALUE references, as to trigger write barriers. |
There was a problem hiding this comment.
I was asked to add this comment when I added write barriers in the protobuf gem, and I think it's a good idea as it might remind future contributors.
| } | ||
|
|
||
| static size_t | ||
| fntype_memsize(const void *data) |
There was a problem hiding this comment.
I think I accounted for all held data, but worst case these function don't have to be 100% accurate.
There was a problem hiding this comment.
A FunctionInfo can have a closurePool associated for all closures that are created in relation to this FunctionInfo. I'll add at least the management data of the ClosurePool to the size.
There was a problem hiding this comment.
Sounds good, I'll have a look at it.
We canalso report the size of the pool divided by the number of refs to it, I've done that in msgpack-ruby.
|
|
||
| function_type = FFI::FunctionType.new(:int, []) | ||
| size = ObjectSpace.memsize_of(function_type) | ||
| expect(size).to be > base_size |
There was a problem hiding this comment.
The size can vary on platforms etc, so I usually use this pattern to ensure the function report something, but not assert a precise size.
ddee7c8 to
617472b
Compare
|
|
||
| require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper")) | ||
|
|
||
| describe FFI::FunctionType, skip: RUBY_PLATFORM == "java" do |
There was a problem hiding this comment.
The java ext doesn't define this class, I suppose that's why it wasn't tested. But I think these specs are worth it for the MRI implementation.
There was a problem hiding this comment.
Yes, FunctionInfo is just an internal class not exposed through the API.
Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers.
617472b to
fae39d8
Compare
|
Ok, it's now 🟢 , moving on to the next one. |
Ref: #991
Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC.
The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected.
This commit also implement a
dsizefunction so that these instance report a more relevant size in various memory profilers.