Skip to content
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

Assert OBJECT_REF_OFFSET_LOWER_BOUND invariant #1194

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/util/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ impl ObjectReference {
use crate::vm::ObjectModel;
let object_start = VM::VMObjectModel::ref_to_object_start(self);
debug_assert!(!VM::VMObjectModel::UNIFIED_OBJECT_REFERENCE_ADDRESS || object_start == self.to_raw_address(), "The binding claims unified object reference address, but for object reference {}, ref_to_object_start() returns {}", self, object_start);
debug_assert!(
self.to_raw_address()
>= object_start + VM::VMObjectModel::OBJECT_REF_OFFSET_LOWER_BOUND,
"The invariant `object_ref >= object_start + OBJECT_REF_OFFSET_LOWER_BOUND` is violated. \
object_ref: {}, object_start: {}, OBJECT_REF_OFFSET_LOWER_BOUND: {}",
self.to_raw_address(),
object_start,
VM::VMObjectModel::OBJECT_REF_OFFSET_LOWER_BOUND,
);
object_start
}

Expand Down
3 changes: 3 additions & 0 deletions src/vm/object_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ pub trait ObjectModel<VM: VMBinding> {
/// Return the lowest address of the storage associated with an object. This should be
/// the address that a binding gets by an allocation call ([`crate::memory_manager::alloc`]).
///
/// Note that the return value needs to satisfy the invariant mentioned in the doc comment of
/// [`Self::OBJECT_REF_OFFSET_LOWER_BOUND`].
///
/// Arguments:
/// * `object`: The object to be queried.
fn ref_to_object_start(object: ObjectReference) -> Address;
Expand Down
Loading