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

implement a feature to allocate an extra word ahead of each individua… #894

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tianleq
Copy link
Collaborator

@tianleq tianleq commented Aug 9, 2023

It does not support malloc marksweep

@tianleq tianleq marked this pull request as draft August 9, 2023 02:48
@tianleq tianleq requested a review from qinsoon August 9, 2023 04:50
Copy link
Member

@qinsoon qinsoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR generally looks okay, but one pity is that the code/mechanism is not reused for mark compact to add the policy-specific extra header word. I suggest ask @wks to review this PR once it is ready.

@@ -102,6 +102,9 @@ is_mmtk_object = ["vo_bit"]
# Enable object pinning, in particular, enable pinning/unpinning, and its metadata
object_pinning = []

# Enable allocate extra header of each individual object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to clarify that VM::EXTRA_HEADER_BYTES will control the exact size of extra header, and there is no control on the alignment of the extra header. We just guarantee there are EXTRA_HEADER_BYTES before the address we return. It could be unaligned access if the binding attempts to write pointers to the extra bytes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this feature only intended for debugging, or can be used in a performance setting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is only intended for debugging.

// The invariants we checked earlier ensures that we can use cell and object reference interchangably
// We may not really have an object in this cell, but if we do, this object reference is correct.
let potential_object = ObjectReference::from_raw_address(cell);
#[cfg(feature = "extra_header")]
let potential_object = ObjectReference::from_raw_address(cell + VM::EXTRA_HEADER_BYTES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The binding can config EXTRA_HEADER_BYTES, and there is no requirement on what value a binding can use. If a binding uses a value that is not a multiple of the fixed alignment, this code is wrong. You can either introduce some requirements for a 'valid EXTRA_HEADER_BYTES value', or simply change the condition in L264 so we use native_brute_force_sweep if extra_header is enabled.

@tianleq
Copy link
Collaborator Author

tianleq commented Aug 9, 2023

The PR generally looks okay, but one pity is that the code/mechanism is not reused for mark compact to add the policy-specific extra header word. I suggest ask @wks to review this PR once it is ready.
Steve has pointed out that markcompact only affects objects in markcompactspace but this one is a global setting, it affects all objects

@wks
Copy link
Collaborator

wks commented Aug 9, 2023

@tianleq Can you remind me what was the purpose of this feature? I see the size of the extra word is specified in VMBinding. This means it is controlled by the VM. But if the VM wants an additional word before every object, it can implement it in its own function that calculates the object size. For example, currently the Ruby binding puts an extra word before every object to record some extra information. I implemented this in the Ruby-side C function newobj_of0 which allocates Ruby objects, so that when calling mmtk_alloc, the passed object size is always one word larger than the original Ruby object size. So I wonder why this feature is necessary.

If the extra word is required by the MMTk for debug purposes, it shouldn't be set in VMBinding, but somewhere in the MMTk core. If it is plan-specific or space-specific, it should be specified in the respective plan or space.

@tianleq
Copy link
Collaborator Author

tianleq commented Aug 9, 2023

@wks
It allows storing info in the extra header, for various reasons(primarily debugging purpose). It is neither plan-specific nor policy-specific. It is more like a global setting. Once you enable the feature, all mmtk objects will have the extra header, regardless of the plan used.

@qinsoon
Copy link
Member

qinsoon commented Aug 9, 2023

The PR generally looks okay, but one pity is that the code/mechanism is not reused for mark compact to add the policy-specific extra header word. I suggest ask @wks to review this PR once it is ready.
Steve has pointed out that markcompact only affects objects in markcompactspace but this one is a global setting, it affects all objects

Right. But we could have some code that is used by both on how to compute a new result based on the extra bytes, and how to align the extra header size.

Computing result:

// Check if the result is valid and return the actual object start address
// Note that `rtn` can be null in the case of OOM
if !rtn.is_zero() {
rtn + Self::HEADER_RESERVED_IN_BYTES
} else {
rtn
}

// Check if the result is valid and return the actual object start address
// Note that `rtn` can be null in the case of OOM
if !rtn.is_zero() {
rtn + VM::EXTRA_HEADER_BYTES
} else {
rtn
}

Computing header size:

/// We need one extra header word for each object. Considering the alignment requirement, this is
/// the actual bytes we need to reserve for each allocation.
pub const HEADER_RESERVED_IN_BYTES: usize = if VM::MAX_ALIGNMENT > GC_EXTRA_HEADER_BYTES {
VM::MAX_ALIGNMENT
} else {
GC_EXTRA_HEADER_BYTES
}
.next_power_of_two();

mmtk-core/src/vm/mod.rs

Lines 75 to 82 in f1359c5

#[cfg(feature = "extra_header")]
const EXTRA_HEADER_BYTES: usize =
if Self::MAX_ALIGNMENT > crate::util::constants::BYTES_IN_WORD {
Self::MAX_ALIGNMENT
} else {
crate::util::constants::BYTES_IN_WORD
}
.next_power_of_two();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants