You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, only crate::util::heap::layout::vm_layout::VM_LAYOUT is affected.
(Note: There is another use case of static mut in mock_test_doc_avoid_resolving_allocator.rs, but it seems unnecessary.)
A simple workaround is possible. Change &VM_LAYOUT to unsafe { &*addr_of!(VM_LAYOUT) }, and the warning goes away.
But it reveals a problem. VM_LAYOUT is global. The function fn vm_layout() -> &'static VMLayout is used in 90+ different places in mmtk-core, and they all treat it as a global constant struct. But VM_LAYOUT is actually mutable (by set_custom_vm_layout). More precisely, it is immutable after initialization for each MMTK instance, as is explained in the doc comment:
/// .../// This function must be called before MMTk::new()pub(crate)fn set_custom_vm_layout(constants:VMLayout){
The proper fix is moving the VMLayout structure to a field of MMTK, and make all functions that depend on it a method of MMTK
For example, fn memory_manager::starting_heap_address() -> Address and fn memory_manager::last_heap_address() -> Address should be methods of MMTK because each MMTK instance should have its own heap range.
As another example, VMLayout is frequently used when creating spaces and page resources. Spaces and page resources belong to each MMTK instance. Understandably, if VMLayout is a per-MMTK constant, it should be a parameter to the constructor of MMTK, and therefore it can be passed to the constructors of spaces and page resources. We discussed refactoring the creation of spaces and page resources in another issue: #932
The text was updated successfully, but these errors were encountered:
wks
added a commit
to wks/mmtk-core
that referenced
this issue
Mar 25, 2024
As getting a ref `&` of `static mut` variables will become a compilation
error in the Rust 2024 Edition, we use `unsafe { &*addr_of!(VM_LAYOUT)
}` to work around it.
See: mmtk#1098
Changed the `static mut` in mock_test_doc_avoid_resolving_allocator.rs
to an ordinary local variable.
Initialize the thread-local variable `WORKER_ORDINAL` with a `const`
block. It avoids lazy initialization. We also bumped the
`rust-version` field in Cargo.toml to 1.71.1 because the semantics of
the `const` block in the `thread_local!` macro was undocumented in
1.70.0.
As getting a ref `&` of `static mut` variables will become a compilation
error in the Rust 2024 Edition, we use `unsafe { &*addr_of!(VM_LAYOUT)
}` to work around it. See: #1098
Changed the `static mut` in mock_test_doc_avoid_resolving_allocator.rs
to an ordinary local variable.
Initialize the thread-local variable `WORKER_ORDINAL` with a `const`
block. It avoids lazy initialization. We also bumped the `rust-version`
field in Cargo.toml to 1.71.1 because the semantics of the `const` block
in the `thread_local!` macro was undocumented in 1.70.0.
udesou
added
the
P-low
Priority: Low. A low-priority issue won't be scheduled and assigned. Any help is welcome.
label
May 15, 2024
In the Rust 2024 Edition it will be a compilation error to create
&
and&mut
ofstatic mut
variables. See https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-reference.htmlAlthough the 2024 edition not yet released, the current stable Rust (1.77.0) warns against this. See: https://doc.rust-lang.org/1.77.0/rustc/lints/listing/warn-by-default.html#static-mut-refs
This is causing some CI tests to fail. See https://github.com/mmtk/mmtk-core/actions/runs/8417778415/job/23046912436?pr=1067
Currently, only
crate::util::heap::layout::vm_layout::VM_LAYOUT
is affected.(Note: There is another use case of
static mut
in mock_test_doc_avoid_resolving_allocator.rs, but it seems unnecessary.)A simple workaround is possible. Change
&VM_LAYOUT
tounsafe { &*addr_of!(VM_LAYOUT) }
, and the warning goes away.But it reveals a problem.
VM_LAYOUT
is global. The functionfn vm_layout() -> &'static VMLayout
is used in 90+ different places in mmtk-core, and they all treat it as a global constant struct. ButVM_LAYOUT
is actually mutable (byset_custom_vm_layout
). More precisely, it is immutable after initialization for eachMMTK
instance, as is explained in the doc comment:The proper fix is moving the
VMLayout
structure to a field ofMMTK
, and make all functions that depend on it a method ofMMTK
For example,
fn memory_manager::starting_heap_address() -> Address
andfn memory_manager::last_heap_address() -> Address
should be methods ofMMTK
because eachMMTK
instance should have its own heap range.As another example,
VMLayout
is frequently used when creating spaces and page resources. Spaces and page resources belong to eachMMTK
instance. Understandably, ifVMLayout
is a per-MMTK constant, it should be a parameter to the constructor ofMMTK
, and therefore it can be passed to the constructors of spaces and page resources. We discussed refactoring the creation of spaces and page resources in another issue: #932The text was updated successfully, but these errors were encountered: