From 26016a0cad02a1c21b16a4719490722140c67bf4 Mon Sep 17 00:00:00 2001 From: Tianle Qiu Date: Wed, 9 Aug 2023 02:23:16 +0000 Subject: [PATCH] implement a feature to allocate an extra word ahead of each individual object --- README.md | 9 ++ mmtk/Cargo.lock | 124 +++++++++++++++++++----- mmtk/Cargo.toml | 5 + mmtk/src/lib.rs | 4 + openjdk/CompileThirdPartyHeap.gmk | 12 +++ openjdk/mmtk.h | 3 + openjdk/mmtkBarrierSetAssembler_x86.cpp | 3 + openjdk/mmtkBarrierSetC2.cpp | 3 + openjdk/mmtkMutator.cpp | 6 +- 9 files changed, 142 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6e5c071e..bb8b6fc5 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,15 @@ for mmtk-core, as well as compiling the fastpath for the VO bit. ```console $ VO_BIT=1 make CONF=linux-x86_64-normal-server-$DEBUG_LEVEL THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk ``` +### Extra header + +To support the `extra_header` (allocate an extra word) feature in mmtk-core, you can set the +environment variable `EXTRA_HEADER=1` when building OpenJDK. This will set the feature +for mmtk-core, as well as compiling the fastpath for the extra header. + +```console +$ EXTRA_HEADER=1 make CONF=linux-x86_64-normal-server-$DEBUG_LEVEL THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk +``` ## Test diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 7cc1babe..f04fc916 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -226,13 +226,13 @@ dependencies = [ [[package]] name = "errno" -version = "0.2.8" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" dependencies = [ "errno-dragonfly", "libc", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -324,19 +324,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] name = "is-terminal" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -365,9 +365,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libgit2-sys" @@ -395,9 +395,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "lock_api" @@ -436,7 +436,6 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" dependencies = [ "atomic", "atomic-traits", @@ -448,6 +447,7 @@ dependencies = [ "downcast-rs", "enum-map", "env_logger", + "is-terminal", "itertools", "lazy_static", "libc", @@ -455,6 +455,7 @@ dependencies = [ "mmtk-macros", "num-traits", "num_cpus", + "probe", "regex", "spin", "static_assertions", @@ -466,7 +467,6 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" dependencies = [ "proc-macro-error", "proc-macro2", @@ -541,6 +541,12 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +[[package]] +name = "probe" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216e81fcf486280f0b8b18ca43ceafd32739eb0eb703eb024a8d00814eeba556" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -633,16 +639,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.8" +version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -751,9 +757,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.0" +version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f1dc6930a439cc5d154221b5387d153f8183529b07c19aca24ea31e0a167e1" +checksum = "6b949f01f9c23823744b71e0060472ecbde578ef68cc2a9e46d114efd77c3034" dependencies = [ "cfg-if", "core-foundation-sys", @@ -904,7 +910,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.1", ] [[package]] @@ -913,13 +928,28 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -928,38 +958,80 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 29e28a66..c9d37b00 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -46,6 +46,11 @@ nogc_no_zeroing = ["mmtk/nogc_no_zeroing"] # See README. vo_bit = ["mmtk/vo_bit"] +# Use the env var EXTRA_HEADER=1 when building OpenJDK so the fastpath for allocating extra header will be compiled in. +# See README. +extra_header = ["mmtk/extra_header"] + + # This compile time constant places the mark bit in the header of the object instead of on the side. mark_bit_in_header = [] diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index e501c64f..492f9023 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -188,3 +188,7 @@ lazy_static! { /// A counter tracking the total size of the `CODE_CACHE_ROOTS`. static CODE_CACHE_ROOTS_SIZE: AtomicUsize = AtomicUsize::new(0); + +#[cfg(feature = "extra_header")] +#[no_mangle] +pub static MMTK_EXTRA_HEADER_BYTES: usize = ::EXTRA_HEADER_BYTES; diff --git a/openjdk/CompileThirdPartyHeap.gmk b/openjdk/CompileThirdPartyHeap.gmk index e946eb7e..6b76bc0e 100644 --- a/openjdk/CompileThirdPartyHeap.gmk +++ b/openjdk/CompileThirdPartyHeap.gmk @@ -27,6 +27,14 @@ ifeq ($(VO_BIT), 1) endif endif +ifeq ($(EXTRA_HEADER), 1) + ifndef GC_FEATURES + GC_FEATURES=--features extra_header + else + GC_FEATURES:=$(strip $(GC_FEATURES))",extra_header" + endif +endif + ifeq ($(MARK_IN_HEADER), 1) ifndef GC_FEATURES GC_FEATURES=--features mark_bit_in_header @@ -83,4 +91,8 @@ ifeq ($(VO_BIT), 1) JVM_CFLAGS += -DMMTK_ENABLE_VO_BIT endif +ifeq ($(EXTRA_HEADER), 1) + JVM_CFLAGS += -DMMTK_ENABLE_EXTRA_HEADER +endif + $(BUILD_LIBJVM): $(LIB_MMTK) diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index 88c96d49..69736286 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -23,6 +23,9 @@ extern const uintptr_t GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS; extern const uintptr_t VO_BIT_ADDRESS; extern const size_t MMTK_MARK_COMPACT_HEADER_RESERVED_IN_BYTES; extern const uintptr_t FREE_LIST_ALLOCATOR_SIZE; +#ifdef MMTK_ENABLE_EXTRA_HEADER +extern const size_t MMTK_EXTRA_HEADER_BYTES; +#endif extern const char* get_mmtk_version(); diff --git a/openjdk/mmtkBarrierSetAssembler_x86.cpp b/openjdk/mmtkBarrierSetAssembler_x86.cpp index dc59274e..83797ad7 100644 --- a/openjdk/mmtkBarrierSetAssembler_x86.cpp +++ b/openjdk/mmtkBarrierSetAssembler_x86.cpp @@ -50,6 +50,9 @@ void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register threa assert(MMTkMutatorContext::max_non_los_default_alloc_bytes != 0, "max_non_los_default_alloc_bytes hasn't been initialized"); size_t max_non_los_bytes = MMTkMutatorContext::max_non_los_default_alloc_bytes; size_t extra_header = 0; +#ifdef MMTK_ENABLE_EXTRA_HEADER + extra_header = MMTK_EXTRA_HEADER_BYTES; +#endif // fastpath, we only use default allocator Allocator allocator = AllocatorDefault; // We need to figure out which allocator we are using by querying MMTk. diff --git a/openjdk/mmtkBarrierSetC2.cpp b/openjdk/mmtkBarrierSetC2.cpp index b58e433d..91f16847 100644 --- a/openjdk/mmtkBarrierSetC2.cpp +++ b/openjdk/mmtkBarrierSetC2.cpp @@ -82,6 +82,9 @@ void MMTkBarrierSetC2::expand_allocate(PhaseMacroExpand* x, assert(MMTkMutatorContext::max_non_los_default_alloc_bytes != 0, "max_non_los_default_alloc_bytes hasn't been initialized"); size_t max_non_los_bytes = MMTkMutatorContext::max_non_los_default_alloc_bytes; size_t extra_header = 0; +#ifdef MMTK_ENABLE_EXTRA_HEADER + extra_header = MMTK_EXTRA_HEADER_BYTES; +#endif // We always use the default allocator. // But we need to figure out which allocator we are using by querying MMTk. AllocatorSelector selector = get_allocator_mapping(AllocatorDefault); diff --git a/openjdk/mmtkMutator.cpp b/openjdk/mmtkMutator.cpp index acad0a92..f41b999d 100644 --- a/openjdk/mmtkMutator.cpp +++ b/openjdk/mmtkMutator.cpp @@ -21,7 +21,11 @@ HeapWord* MMTkMutatorContext::alloc(size_t bytes, Allocator allocator) { // All allocations with size larger than max non-los bytes will get to this slowpath here. // We will use LOS for those. assert(MMTkMutatorContext::max_non_los_default_alloc_bytes != 0, "max_non_los_default_alloc_bytes hasn't been initialized"); - if (bytes >= MMTkMutatorContext::max_non_los_default_alloc_bytes) { + size_t extra_header = 0; +#ifdef MMTK_ENABLE_EXTRA_HEADER + extra_header = MMTK_EXTRA_HEADER_BYTES; +#endif + if (bytes >= MMTkMutatorContext::max_non_los_default_alloc_bytes - extra_header) { allocator = AllocatorLos; }