From 0883898514d482d9027c845e8d7f6976a49a39ac Mon Sep 17 00:00:00 2001 From: Yi Lin Date: Thu, 17 Oct 2024 20:00:03 +1300 Subject: [PATCH] Update CI macos image (#1216) macos-12 will no longer be supported: https://github.com/actions/runner-images/issues/10721 --- .github/workflows/minimal-tests-core.yml | 2 +- src/policy/space.rs | 2 +- src/util/memory.rs | 43 ++++++++++++++++--- .../mock_test_handle_mmap_conflict.rs | 2 + .../mock_tests/mock_test_handle_mmap_oom.rs | 2 + .../mock_test_vm_layout_compressed_pointer.rs | 2 +- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.github/workflows/minimal-tests-core.yml b/.github/workflows/minimal-tests-core.yml index 3a72c531e7..7334488d63 100644 --- a/.github/workflows/minimal-tests-core.yml +++ b/.github/workflows/minimal-tests-core.yml @@ -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 }} diff --git a/src/policy/space.rs b/src/policy/space.rs index 053b636963..8048009b20 100644 --- a/src/policy/space.rs +++ b/src/policy/space.rs @@ -151,7 +151,7 @@ pub trait Space: 'static + SFT + Sync + Downcast { .try_map_metadata_space(res.start, bytes), ) { - memory::handle_mmap_error::(mmap_error, tls); + memory::handle_mmap_error::(mmap_error, tls, res.start, bytes); } }; let grow_space = || { diff --git a/src/util/memory.rs b/src/util/memory.rs index bd550c599a..771068aaff 100644 --- a/src/util/memory.rs +++ b/src/util/memory.rs @@ -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(error: Error, tls: VMThread) -> ! { +pub fn handle_mmap_error( + 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); @@ -206,7 +213,6 @@ pub fn handle_mmap_error(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); @@ -215,12 +221,10 @@ pub fn handle_mmap_error(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) } @@ -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() } diff --git a/src/vm/tests/mock_tests/mock_test_handle_mmap_conflict.rs b/src/vm/tests/mock_tests/mock_test_handle_mmap_conflict.rs index b36ccaef7d..b4cc7be194 100644 --- a/src/vm/tests/mock_tests/mock_test_handle_mmap_conflict.rs +++ b/src/vm/tests/mock_tests/mock_test_handle_mmap_conflict.rs @@ -22,6 +22,8 @@ pub fn test_handle_mmap_conflict() { memory::handle_mmap_error::( mmap2_res.err().unwrap(), VMThread::UNINITIALIZED, + start, + one_megabyte, ); }); diff --git a/src/vm/tests/mock_tests/mock_test_handle_mmap_oom.rs b/src/vm/tests/mock_tests/mock_test_handle_mmap_oom.rs index 357169c78c..3e23db0fcb 100644 --- a/src/vm/tests/mock_tests/mock_test_handle_mmap_oom.rs +++ b/src/vm/tests/mock_tests/mock_test_handle_mmap_oom.rs @@ -24,6 +24,8 @@ pub fn test_handle_mmap_oom() { memory::handle_mmap_error::( mmap_res.err().unwrap(), VMThread::UNINITIALIZED, + start, + LARGE_SIZE, ); }); assert!(panic_res.is_err()); diff --git a/src/vm/tests/mock_tests/mock_test_vm_layout_compressed_pointer.rs b/src/vm/tests/mock_tests/mock_test_vm_layout_compressed_pointer.rs index 64146591db..658733f683 100644 --- a/src/vm/tests/mock_tests/mock_test_vm_layout_compressed_pointer.rs +++ b/src/vm/tests/mock_tests/mock_test_vm_layout_compressed_pointer.rs @@ -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 };