Skip to content

Commit 2884f6d

Browse files
authored
Merge branch 'master' into fix/modbuf-global-gc-bug
2 parents e862642 + c0f9788 commit 2884f6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+759
-259
lines changed

.github/scripts/ci-common.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ cargo_toml=$project_root/Cargo.toml
99

1010
dummyvm_toml=$project_root/docs/dummyvm/Cargo.toml
1111

12+
# Pin certain deps for our MSRV
13+
cargo update -p home@0.5.11 --precise 0.5.5 # This can be removed once we move to Rust 1.81 or newer
14+
1215
# Repeat a command for all the features. Requires the command as one argument (with double quotes)
1316
for_all_features() {
1417
# without mutually exclusive features

.github/workflows/minimal-tests-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
target:
8888
- { os: ubuntu-22.04, triple: x86_64-unknown-linux-gnu }
8989
- { os: ubuntu-22.04, triple: i686-unknown-linux-gnu }
90-
- { os: macos-12, triple: x86_64-apple-darwin }
90+
- { os: macos-15, triple: x86_64-apple-darwin }
9191
rust: ${{ fromJson(needs.setup-test-matrix.outputs.rust )}}
9292

9393
name: style-check/${{ matrix.target.triple }}/${{ matrix.rust }}

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
0.30.0 (2024-12-20)
2+
===
3+
4+
## What's Changed
5+
6+
### policy
7+
* Allow setting object metadata for VM space objects. Expose VO bit under a feature. by @qinsoon in https://github.com/mmtk/mmtk-core/pull/1248
8+
9+
### Misc
10+
* Fix clippy warnings for Rust 1.83 by @wks in https://github.com/mmtk/mmtk-core/pull/1242
11+
* Annotate mmap ranges using PR_SET_VMA by @wks in https://github.com/mmtk/mmtk-core/pull/1236
12+
* Fix warnings for lifetime in MmapAnnotation impl by @qinsoon in https://github.com/mmtk/mmtk-core/pull/1244
13+
* Collect live bytes per space, and report by space by @qinsoon in https://github.com/mmtk/mmtk-core/pull/1238
14+
* Minor changes for debugging. by @wks in https://github.com/mmtk/mmtk-core/pull/1245
15+
* Use macos-15 for style check by @qinsoon in https://github.com/mmtk/mmtk-core/pull/1249
16+
* Check the option before aggregating live bytes data. Panic if the option is enabled on malloc space. by @qinsoon in https://github.com/mmtk/mmtk-core/pull/1250
17+
18+
19+
**Full Changelog**: https://github.com/mmtk/mmtk-core/compare/v0.29.0...v0.30.0
20+
121
0.29.0 (2024-11-08)
222
===
323

Cargo.toml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mmtk"
3-
version = "0.29.0"
3+
version = "0.30.0"
44
authors = ["The MMTk Developers <>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -38,7 +38,7 @@ log = { version = "0.4", features = ["max_level_trace", "release_max_level_off"]
3838
memoffset = "0.9"
3939
mimalloc-sys = { version = "0.1.6", optional = true }
4040
# MMTk macros - we have to specify a version here in order to publish the crate, even though we use the dependency from a local path.
41-
mmtk-macros = { version="0.29.0", path = "macros/" }
41+
mmtk-macros = { version="0.30.0", path = "macros/" }
4242
num_cpus = "1.8"
4343
num-traits = "0.2"
4444
pfm = { version = "0.1.1", optional = true }
@@ -172,13 +172,27 @@ work_packet_stats = []
172172
# Count the malloc'd memory into the heap size
173173
malloc_counted_size = []
174174

175-
# Count the size of all live objects in GC
176-
count_live_bytes_in_gc = []
177-
178175
# Workaround a problem where bpftrace scripts (see tools/tracing/timeline/capture.bt) cannot
179176
# capture the type names of work packets.
180177
bpftrace_workaround = []
181178

179+
# Disable mmap annotations.
180+
# All invocations of `mmap` in mmtk-core are accompanied by calls of `prctl` with
181+
# `PR_SET_VMA_ANON_NAME` to annotate the mmap ranges with human-readable names. It is enabled by
182+
# default and should work fine even with large heap sizes. However, if this is causing problems,
183+
# users can disable such annotations by enabling this Cargo feature.
184+
no_mmap_annotation = []
185+
186+
# Allow the binding to access Valid Object (VO) bit.
187+
# MMTk uses VO bit to identify a valid object. Thus VO bit is carefully managed by MMTk in cooperation with the binding.
188+
# So normally this feature is not needed, and its use should be discouraged.
189+
# However, in rare cases, a binding may want to directly access and manipulate VO bit. For example, a binding cannot cooperate
190+
# with MMTk to identify each object for setting the VO bit. This is usually due to the limitation of the VM.
191+
# In such cases, a binding may use this feature and manipulate the VO bit to their needs. The binding's manipulation on VO bit
192+
# may violate MMTk's semantics, and may result in undefined behaviors for VO bit related APIs. This feature should
193+
# only be used if you understand how VO bit works internally. Use at your own risk.
194+
vo_bit_access = []
195+
182196
# Do not modify the following line - ci-common.sh matches it
183197
# -- Mutally exclusive features --
184198
# Only one feature from each group can be provided. Otherwise build will fail.

docs/team/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MMTk releases include MMTk core and the officially supported bindings. They shar
1313
The current releases include the following bindings:
1414
* OpenJDK
1515
* JikesRVM
16+
* Julia
1617

1718
The current releases do not include the following bindings:
18-
* Julia: We have made good progress on the binding development, and we will include it soon.
1919
* Ruby: We have made good progress on the binding development, and we will include it soon.
2020
* V8: We currently lack of resources to work on the binding.
2121

docs/userguide/src/migration/prefix.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,44 @@ Notes for the mmtk-core developers:
3030

3131
<!-- Insert new versions here -->
3232

33+
## 0.30.0
34+
35+
### `live_bytes_in_last_gc` becomes a runtime option, and returns a map for live bytes in each space
36+
37+
```admonish tldr
38+
`count_live_bytes_in_gc` is now a runtime option instead of a features (build-time), and we collect
39+
live bytes statistics per space. Correspondingly, `memory_manager::live_bytes_in_last_gc` now returns a map for
40+
live bytes in each space.
41+
```
42+
43+
API changes:
44+
45+
- module `util::options`
46+
+ `Options` includes `count_live_bytes_in_gc`, which defaults to `false`. This can be turned on at run-time.
47+
+ The old `count_live_bytes_in_gc` feature is removed.
48+
- module `memory_manager`
49+
+ `live_bytes_in_last_gc` now returns a `HashMap<&'static str, LiveBytesStats>`. The keys are
50+
strings for space names, and the values are statistics for live bytes in the space.
51+
52+
See also:
53+
54+
- PR: <https://github.com/mmtk/mmtk-core/pull/1238>
55+
56+
57+
### mmap-related functions require annotation
58+
59+
```admonish tldr
60+
Memory-mapping functions in `mmtk::util::memory` now take an additional `MmapAnnotation` argument.
61+
```
62+
63+
API changes:
64+
65+
- module `util::memory`
66+
+ The following functions take an additional `MmapAnnotation` argument.
67+
* `dzmmap`
68+
* `dzmmap_noreplace`
69+
* `mmap_noreserve`
70+
3371
## 0.28.0
3472

3573
### `handle_user_collection_request` returns `bool`

macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mmtk-macros"
33
# the macro crate uses the same version as mmtk-core
4-
version = "0.29.0"
4+
version = "0.30.0"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
description = "MMTk macros provides procedural macros used by mmtk-core."

src/global_state.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use atomic_refcell::AtomicRefCell;
2+
use std::collections::HashMap;
13
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
24
use std::sync::Mutex;
35
use std::time::Instant;
46

5-
use atomic_refcell::AtomicRefCell;
6-
77
/// This stores some global states for an MMTK instance.
88
/// Some MMTK components like plans and allocators may keep an reference to the struct, and can access it.
99
// This used to be a part of the `BasePlan`. In that case, any component that accesses
@@ -45,9 +45,8 @@ pub struct GlobalState {
4545
/// A counteer that keeps tracks of the number of bytes allocated by malloc
4646
#[cfg(feature = "malloc_counted_size")]
4747
pub(crate) malloc_bytes: AtomicUsize,
48-
/// This stores the size in bytes for all the live objects in last GC. This counter is only updated in the GC release phase.
49-
#[cfg(feature = "count_live_bytes_in_gc")]
50-
pub(crate) live_bytes_in_last_gc: AtomicUsize,
48+
/// This stores the live bytes and the used bytes (by pages) for each space in last GC. This counter is only updated in the GC release phase.
49+
pub(crate) live_bytes_in_last_gc: AtomicRefCell<HashMap<&'static str, LiveBytesStats>>,
5150
}
5251

5352
impl GlobalState {
@@ -183,16 +182,6 @@ impl GlobalState {
183182
pub(crate) fn decrease_malloc_bytes_by(&self, size: usize) {
184183
self.malloc_bytes.fetch_sub(size, Ordering::SeqCst);
185184
}
186-
187-
#[cfg(feature = "count_live_bytes_in_gc")]
188-
pub fn get_live_bytes_in_last_gc(&self) -> usize {
189-
self.live_bytes_in_last_gc.load(Ordering::SeqCst)
190-
}
191-
192-
#[cfg(feature = "count_live_bytes_in_gc")]
193-
pub fn set_live_bytes_in_last_gc(&self, size: usize) {
194-
self.live_bytes_in_last_gc.store(size, Ordering::SeqCst);
195-
}
196185
}
197186

198187
impl Default for GlobalState {
@@ -213,8 +202,7 @@ impl Default for GlobalState {
213202
allocation_bytes: AtomicUsize::new(0),
214203
#[cfg(feature = "malloc_counted_size")]
215204
malloc_bytes: AtomicUsize::new(0),
216-
#[cfg(feature = "count_live_bytes_in_gc")]
217-
live_bytes_in_last_gc: AtomicUsize::new(0),
205+
live_bytes_in_last_gc: AtomicRefCell::new(HashMap::new()),
218206
}
219207
}
220208
}
@@ -225,3 +213,15 @@ pub enum GcStatus {
225213
GcPrepare,
226214
GcProper,
227215
}
216+
217+
/// Statistics for the live bytes in the last GC. The statistics is per space.
218+
#[derive(Copy, Clone, Debug)]
219+
pub struct LiveBytesStats {
220+
/// Total accumulated bytes of live objects in the space.
221+
pub live_bytes: usize,
222+
/// Total pages used by the space.
223+
pub used_pages: usize,
224+
/// Total bytes used by the space, computed from `used_pages`.
225+
/// The ratio of live_bytes and used_bytes reflects the utilization of the memory in the space.
226+
pub used_bytes: usize,
227+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub(crate) use mmtk::MMAPPER;
4646
pub use mmtk::MMTK;
4747

4848
mod global_state;
49+
pub use crate::global_state::LiveBytesStats;
4950

5051
mod policy;
5152

src/memory_manager.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use crate::vm::slot::MemorySlice;
2626
use crate::vm::ReferenceGlue;
2727
use crate::vm::VMBinding;
2828

29+
use std::collections::HashMap;
30+
2931
/// Initialize an MMTk instance. A VM should call this method after creating an [`crate::MMTK`]
3032
/// instance but before using any of the methods provided in MMTk (except `process()` and `process_bulk()`).
3133
///
@@ -531,16 +533,18 @@ pub fn free_bytes<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
531533
mmtk.get_plan().get_free_pages() << LOG_BYTES_IN_PAGE
532534
}
533535

534-
/// Return the size of all the live objects in bytes in the last GC. MMTk usually accounts for memory in pages.
536+
/// Return a hash map for live bytes statistics in the last GC for each space.
537+
///
538+
/// MMTk usually accounts for memory in pages by each space.
535539
/// This is a special method that we count the size of every live object in a GC, and sum up the total bytes.
536-
/// We provide this method so users can compare with `used_bytes` (which does page accounting), and know if
537-
/// the heap is fragmented.
540+
/// We provide this method so users can use [`crate::LiveBytesStats`] to know if
541+
/// the space is fragmented.
538542
/// The value returned by this method is only updated when we finish tracing in a GC. A recommended timing
539543
/// to call this method is at the end of a GC (e.g. when the runtime is about to resume threads).
540-
#[cfg(feature = "count_live_bytes_in_gc")]
541-
pub fn live_bytes_in_last_gc<VM: VMBinding>(mmtk: &MMTK<VM>) -> usize {
542-
use std::sync::atomic::Ordering;
543-
mmtk.state.live_bytes_in_last_gc.load(Ordering::SeqCst)
544+
pub fn live_bytes_in_last_gc<VM: VMBinding>(
545+
mmtk: &MMTK<VM>,
546+
) -> HashMap<&'static str, crate::LiveBytesStats> {
547+
mmtk.state.live_bytes_in_last_gc.borrow().clone()
544548
}
545549

546550
/// Return the starting address of the heap. *Note that currently MMTk uses

src/mmtk.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::util::address::ObjectReference;
1212
use crate::util::analysis::AnalysisManager;
1313
use crate::util::finalizable_processor::FinalizableProcessor;
1414
use crate::util::heap::gc_trigger::GCTrigger;
15+
use crate::util::heap::layout::heap_parameters::MAX_SPACES;
1516
use crate::util::heap::layout::vm_layout::VMLayout;
1617
use crate::util::heap::layout::{self, Mmapper, VMMap};
1718
use crate::util::heap::HeapMeta;
@@ -26,6 +27,7 @@ use crate::util::statistics::stats::Stats;
2627
use crate::vm::ReferenceGlue;
2728
use crate::vm::VMBinding;
2829
use std::cell::UnsafeCell;
30+
use std::collections::HashMap;
2931
use std::default::Default;
3032
use std::sync::atomic::{AtomicBool, Ordering};
3133
use std::sync::Arc;
@@ -526,4 +528,72 @@ impl<VM: VMBinding> MMTK<VM> {
526528
space.enumerate_objects(&mut enumerator);
527529
})
528530
}
531+
532+
/// Aggregate a hash map of live bytes per space with the space stats to produce
533+
/// a map of live bytes stats for the spaces.
534+
pub(crate) fn aggregate_live_bytes_in_last_gc(
535+
&self,
536+
live_bytes_per_space: [usize; MAX_SPACES],
537+
) -> HashMap<&'static str, crate::LiveBytesStats> {
538+
use crate::policy::space::Space;
539+
let mut ret = HashMap::new();
540+
self.get_plan().for_each_space(&mut |space: &dyn Space<VM>| {
541+
let space_name = space.get_name();
542+
let space_idx = space.get_descriptor().get_index();
543+
let used_pages = space.reserved_pages();
544+
if used_pages != 0 {
545+
let used_bytes = crate::util::conversions::pages_to_bytes(used_pages);
546+
let live_bytes = live_bytes_per_space[space_idx];
547+
debug_assert!(
548+
live_bytes <= used_bytes,
549+
"Live bytes of objects in {} ({} bytes) is larger than used pages ({} bytes), something is wrong.",
550+
space_name, live_bytes, used_bytes
551+
);
552+
ret.insert(space_name, crate::LiveBytesStats {
553+
live_bytes,
554+
used_pages,
555+
used_bytes,
556+
});
557+
}
558+
});
559+
ret
560+
}
561+
562+
/// Print VM maps. It will print the memory ranges used by spaces as well as some attributes of
563+
/// the spaces.
564+
///
565+
/// - "I": The space is immortal. Its objects will never die.
566+
/// - "N": The space is non-movable. Its objects will never move.
567+
///
568+
/// Arguments:
569+
/// * `out`: the place to print the VM maps.
570+
/// * `space_name`: If `None`, print all spaces;
571+
/// if `Some(n)`, only print the space whose name is `n`.
572+
pub fn debug_print_vm_maps(
573+
&self,
574+
out: &mut impl std::fmt::Write,
575+
space_name: Option<&str>,
576+
) -> Result<(), std::fmt::Error> {
577+
let mut result_so_far = Ok(());
578+
self.get_plan().for_each_space(&mut |space| {
579+
if result_so_far.is_ok()
580+
&& (space_name.is_none() || space_name == Some(space.get_name()))
581+
{
582+
result_so_far = crate::policy::space::print_vm_map(space, out);
583+
}
584+
});
585+
result_so_far
586+
}
587+
588+
/// Initialize object metadata for a VM space object.
589+
/// Objects in the VM space are allocated/managed by the binding. This function provides a way for
590+
/// the binding to set object metadata in MMTk for an object in the space.
591+
#[cfg(feature = "vm_space")]
592+
pub fn initialize_vm_space_object(&self, object: crate::util::ObjectReference) {
593+
use crate::policy::sft::SFT;
594+
self.get_plan()
595+
.base()
596+
.vm_space
597+
.initialize_object_metadata(object, false)
598+
}
529599
}

src/plan/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub struct CreateSpecificPlanArgs<'a, VM: VMBinding> {
390390
pub global_side_metadata_specs: Vec<SideMetadataSpec>,
391391
}
392392

393-
impl<'a, VM: VMBinding> CreateSpecificPlanArgs<'a, VM> {
393+
impl<VM: VMBinding> CreateSpecificPlanArgs<'_, VM> {
394394
/// Get a PlanCreateSpaceArgs that can be used to create a space
395395
pub fn get_space_args(
396396
&mut self,

src/plan/markcompact/gc_work.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl<VM: VMBinding> GCWork<VM> for UpdateReferences<VM> {
5151
mmtk.slot_logger.reset();
5252

5353
// We do two passes of transitive closures. We clear the live bytes from the first pass.
54-
#[cfg(feature = "count_live_bytes_in_gc")]
5554
mmtk.scheduler
5655
.worker_group
5756
.get_and_clear_worker_live_bytes();

src/plan/mutator_context.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl<VM: VMBinding> std::fmt::Debug for MutatorConfig<VM> {
8181
/// A mutator is a per-thread data structure that manages allocations and barriers. It is usually highly coupled with the language VM.
8282
/// It is recommended for MMTk users 1) to have a mutator struct of the same layout in the thread local storage that can be accessed efficiently,
8383
/// and 2) to implement fastpath allocation and barriers for the mutator in the VM side.
84-
8584
// We are trying to make this struct fixed-sized so that VM bindings can easily define a type to have the exact same layout as this struct.
8685
// Currently Mutator is fixed sized, and we should try keep this invariant:
8786
// - Allocators are fixed-length arrays of allocators.
@@ -256,7 +255,6 @@ impl<VM: VMBinding> Mutator<VM> {
256255

257256
/// Each GC plan should provide their implementation of a MutatorContext. *Note that this trait is no longer needed as we removed
258257
/// per-plan mutator implementation and we will remove this trait as well in the future.*
259-
260258
// TODO: We should be able to remove this trait, as we removed per-plan mutator implementation, and there is no other type that implements this trait.
261259
// The Mutator struct above is the only type that implements this trait. We should be able to merge them.
262260
pub trait MutatorContext<VM: VMBinding>: Send + 'static {

0 commit comments

Comments
 (0)