-
Notifications
You must be signed in to change notification settings - Fork 341
Implement Write Barrier and dsize for FFI::FunctionType #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
spec/ffi/function_type_spec.rb
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.