-
Notifications
You must be signed in to change notification settings - Fork 69
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
Remove NULL ObjectReference #1064
Conversation
0d1c7d3
to
a5035a2
Compare
Here are some preliminary benchmark results. Two builds:
I ran it with From the data, the impact on total time is between -0.5% to +0.5%, and the error bar is large. Interestingly, it always shows slowdown on shrew, and always speed-up on vole. For STW time, "shrew 2.5x" has a slow-down of 1%, and "vole 3x" has a speed-up of 1.5%, but their error bars are too large. I think the result of forcing |
binding-refs |
This PR is now ready for review. Associated PRs for the bindings: |
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.
Looks good to me. There are some minor points.
Also a quick check: is there any change that may affect performance for OpenJDK and MMTk since the evaluation in #1064 (comment)?
@@ -479,28 +480,40 @@ use crate::vm::VMBinding; | |||
/// the opaque `ObjectReference` type, and we haven't seen a use case for now. | |||
#[repr(transparent)] | |||
#[derive(Copy, Clone, Eq, Hash, PartialOrd, Ord, PartialEq, NoUninit)] | |||
pub struct ObjectReference(usize); | |||
pub struct ObjectReference(NonZeroUsize); |
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 comments for the type should note that ObjectReference
cannot be null, and for places where we may have an invalid object reference, we use Option<ObjectReference>
. NonZeroUsize
makes sure that Option<ObjectReference>
has the same length as ObjectReference
.
src/util/mod.rs
Outdated
@@ -11,6 +11,8 @@ pub mod address; | |||
/// Allocators | |||
// This module is made public so the binding could implement allocator slowpaths if they would like to. | |||
pub mod alloc; | |||
/// Helpers for making native APIs. | |||
pub mod apiutils; |
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.
Could use the name api_util
to be consistent with other existing modules such as rust_util
/test_util
.
I don't think so, but I'll re-run the benchmarks just to be safe. |
I re-ran the benchmarks with the same setting as in #1064 (comment) Total time: (geomens of build2 are between 99.5% to 100.2% of build1, varying among Other time: (99.6% to 100.1%) STW time: (99.2% to 100.8%) The differences are within 1%. This result is consistent with the last evaluation. |
There were a few comments that still mentioned null ObjectReference. They have been removed.
Parent PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
Parent PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
Upstream PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
Upstream PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
Parent PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
Parent PR: mmtk/mmtk-core#1064 --------- Co-authored-by: mmtkgc-bot <[email protected]>
We changed
ObjectReference
so that it is backed byNonZeroUsize
, and can no longer represent a NULL reference. For cases where anObjectReferences
may or may not exist,Option<ObjectReference>
should be used instead.This is an API-breaking change.
ObjectReference::NULL
andObjectReference::is_null()
are removed.ObjectReference::from_raw_address()
now returnsOption<ObjectReference>
. The unsafe methodObjectReference::from_raw_address_unchecked()
assumes the address is not zero, and returnsObjectReference
.ObjectReference
now returnOption<ObjectReference>
. Examples includeEdge::load()
andReferenceGlue::get_referent()
.If a VM binding needs to expose
Option<ObjectReference>
to native (C/C++) programs, a convenient typecrate::util::api_util::NullableObjectReference
is provided.Fixes: #1043