Add use-system-allocator to not use jemalloc (#31443)

* Add `use-system-allocator` feature

* Allow `servo_allocator/use-system-allocator` on servoshell
This commit is contained in:
Samson 2024-02-29 09:43:03 +01:00 committed by GitHub
parent cd92a17c5e
commit 9a9abe9152
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 3 deletions

1
Cargo.lock generated
View file

@ -5475,6 +5475,7 @@ dependencies = [
"log", "log",
"raw-window-handle", "raw-window-handle",
"servo-media", "servo-media",
"servo_allocator",
"shellwords", "shellwords",
"sig", "sig",
"surfman", "surfman",

View file

@ -9,9 +9,13 @@ publish = false
[lib] [lib]
path = "lib.rs" path = "lib.rs"
[features]
use-system-allocator = ["libc"]
[target.'cfg(not(any(windows, target_os = "android")))'.dependencies] [target.'cfg(not(any(windows, target_os = "android")))'.dependencies]
jemallocator = { workspace = true } jemallocator = { workspace = true }
jemalloc-sys = { workspace = true } jemalloc-sys = { workspace = true }
libc = { workspace = true, optional = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { workspace = true, features = ["heapapi"] } winapi = { workspace = true, features = ["heapapi"] }

View file

@ -9,7 +9,7 @@ static ALLOC: Allocator = Allocator;
pub use crate::platform::*; pub use crate::platform::*;
#[cfg(not(any(windows, target_os = "android")))] #[cfg(not(any(windows, target_os = "android", feature = "use-system-allocator")))]
mod platform { mod platform {
use std::os::raw::c_void; use std::os::raw::c_void;
@ -28,14 +28,21 @@ mod platform {
} }
} }
#[cfg(target_os = "android")] #[cfg(all(
not(windows),
any(target_os = "android", feature = "use-system-allocator")
))]
mod platform { mod platform {
pub use std::alloc::System as Allocator; pub use std::alloc::System as Allocator;
use std::os::raw::c_void; use std::os::raw::c_void;
/// Get the size of a heap block. /// Get the size of a heap block.
pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize { pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize {
libc::malloc_usable_size(ptr) #[cfg(target_os = "linux")]
return libc::malloc_usable_size(ptr as *mut _);
#[cfg(not(target_os = "linux"))]
return libc::malloc_usable_size(ptr);
} }
pub mod libc_compat { pub mod libc_compat {

View file

@ -48,6 +48,10 @@ webdriver = ["libservo/webdriver"]
webgl_backtrace = ["libservo/webgl_backtrace"] webgl_backtrace = ["libservo/webgl_backtrace"]
xr-profile = ["libservo/xr-profile"] xr-profile = ["libservo/xr-profile"]
[dependencies]
# For optional feature servo_allocator/use-system-allocator
servo_allocator = { path = "../../components/allocator" }
[target.'cfg(not(target_os = "android"))'.dependencies] [target.'cfg(not(target_os = "android"))'.dependencies]
arboard = "3" arboard = "3"
backtrace = { workspace = true } backtrace = { workspace = true }