Skip to content

Update CI macos image #1216

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

Merged
merged 8 commits into from
Oct 17, 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
2 changes: 1 addition & 1 deletion .github/workflows/minimal-tests-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
target:
- { os: ubuntu-22.04, triple: x86_64-unknown-linux-gnu }
- { os: ubuntu-22.04, triple: i686-unknown-linux-gnu }
- { os: macos-12, triple: x86_64-apple-darwin }
- { os: macos-15, triple: x86_64-apple-darwin }
rust: ${{ fromJson(needs.setup-test-matrix.outputs.rust )}}

name: minimal-tests-core/${{ matrix.target.triple }}/${{ matrix.rust }}
Expand Down
2 changes: 1 addition & 1 deletion src/policy/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
.try_map_metadata_space(res.start, bytes),
)
{
memory::handle_mmap_error::<VM>(mmap_error, tls);
memory::handle_mmap_error::<VM>(mmap_error, tls, res.start, bytes);
}
};
let grow_space = || {
Expand Down
43 changes: 37 additions & 6 deletions src/util/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,20 @@ pub fn munmap(start: Address, size: usize) -> Result<()> {

/// Properly handle errors from a mmap Result, including invoking the binding code in the case of
/// an OOM error.
pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
pub fn handle_mmap_error<VM: VMBinding>(
error: Error,
tls: VMThread,
addr: Address,
bytes: usize,
) -> ! {
use std::io::ErrorKind;

eprintln!("Failed to mmap {}, size {}", addr, bytes);
eprintln!("{}", get_process_memory_maps());

match error.kind() {
// From Rust nightly 2021-05-12, we started to see Rust added this ErrorKind.
ErrorKind::OutOfMemory => {
eprintln!("{}", get_process_memory_maps());
// Signal `MmapOutOfMemory`. Expect the VM to abort immediately.
trace!("Signal MmapOutOfMemory!");
VM::VMCollection::out_of_memory(tls, AllocationError::MmapOutOfMemory);
Expand All @@ -206,7 +213,6 @@ pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
if let Some(os_errno) = error.raw_os_error() {
// If it is OOM, we invoke out_of_memory() through the VM interface.
if os_errno == libc::ENOMEM {
eprintln!("{}", get_process_memory_maps());
// Signal `MmapOutOfMemory`. Expect the VM to abort immediately.
trace!("Signal MmapOutOfMemory!");
VM::VMCollection::out_of_memory(tls, AllocationError::MmapOutOfMemory);
Expand All @@ -215,12 +221,10 @@ pub fn handle_mmap_error<VM: VMBinding>(error: Error, tls: VMThread) -> ! {
}
}
ErrorKind::AlreadyExists => {
eprintln!("{}", get_process_memory_maps());
panic!("Failed to mmap, the address is already mapped. Should MMTk quarantine the address range first?");
}
_ => {}
}
eprintln!("{}", get_process_memory_maps());
panic!("Unexpected mmap failure: {:?}", error)
}

Expand Down Expand Up @@ -301,7 +305,34 @@ pub fn get_process_memory_maps() -> String {

/// Get the memory maps for the process. The returned string is a multi-line string.
/// This is only meant to be used for debugging. For example, log process memory maps after detecting a clash.
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(target_os = "macos")]
pub fn get_process_memory_maps() -> String {
// Get the current process ID (replace this with a specific PID if needed)
let pid = std::process::id();

// Execute the vmmap command
let output = std::process::Command::new("vmmap")
.arg(pid.to_string()) // Pass the PID as an argument
.output() // Capture the output
.expect("Failed to execute vmmap command");

// Check if the command was successful
if output.status.success() {
// Convert the command output to a string
let output_str =
std::str::from_utf8(&output.stdout).expect("Failed to convert output to string");
output_str.to_string()
} else {
// Handle the error case
let error_message =
std::str::from_utf8(&output.stderr).expect("Failed to convert error message to string");
panic!("Failed to get process memory map: {}", error_message)
}
}

/// Get the memory maps for the process. The returned string is a multi-line string.
/// This is only meant to be used for debugging. For example, log process memory maps after detecting a clash.
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))]
pub fn get_process_memory_maps() -> String {
"(process map unavailable)".to_string()
}
Expand Down
2 changes: 2 additions & 0 deletions src/vm/tests/mock_tests/mock_test_handle_mmap_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub fn test_handle_mmap_conflict() {
memory::handle_mmap_error::<MockVM>(
mmap2_res.err().unwrap(),
VMThread::UNINITIALIZED,
start,
one_megabyte,
);
});

Expand Down
2 changes: 2 additions & 0 deletions src/vm/tests/mock_tests/mock_test_handle_mmap_oom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub fn test_handle_mmap_oom() {
memory::handle_mmap_error::<MockVM>(
mmap_res.err().unwrap(),
VMThread::UNINITIALIZED,
start,
LARGE_SIZE,
);
});
assert!(panic_res.is_err());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_vm_layout_compressed_pointer() {
|| {
let start = if cfg!(target_os = "macos") {
// Impossible to map 0x4000_0000 on maocOS. SO choose a different address.
0x40_0000_0000
0x2_0000_0000
} else {
0x4000_0000
};
Expand Down
Loading