From 94f50cd4248b6e33cc76546b5fdc102e620cda1f Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Sun, 16 Apr 2023 21:43:06 +0800 Subject: [PATCH 01/11] Rename alloc bit to valid object bit (VO bit) (#214) Rename "alloc bit" to "valid object bit" (VO bit) in code and scripts. --- ...t-global-alloc-bit.sh => ci-test-vo-bit.sh} | 2 +- .github/scripts/ci-test.sh | 2 +- .github/workflows/ci.yml | 4 ++-- README.md | 10 ++++++---- mmtk/Cargo.lock | 4 ++-- mmtk/Cargo.toml | 6 +++--- mmtk/src/lib.rs | 4 ++-- openjdk/CompileThirdPartyHeap.gmk | 10 +++++----- openjdk/mmtk.h | 2 +- openjdk/mmtkBarrierSet.hpp | 2 +- openjdk/mmtkBarrierSetAssembler_x86.cpp | 12 ++++++------ openjdk/mmtkBarrierSetC2.cpp | 18 +++++++++--------- 12 files changed, 39 insertions(+), 37 deletions(-) rename .github/scripts/{ci-test-global-alloc-bit.sh => ci-test-vo-bit.sh} (99%) diff --git a/.github/scripts/ci-test-global-alloc-bit.sh b/.github/scripts/ci-test-vo-bit.sh similarity index 99% rename from .github/scripts/ci-test-global-alloc-bit.sh rename to .github/scripts/ci-test-vo-bit.sh index d38c71bf..7c8d43fb 100755 --- a/.github/scripts/ci-test-global-alloc-bit.sh +++ b/.github/scripts/ci-test-vo-bit.sh @@ -5,7 +5,7 @@ set -xe unset JAVA_TOOL_OPTIONS export MMTK_EXTREME_ASSERTIONS=0 -export GLOBAL_ALLOC_BIT=1 +export VO_BIT=1 . $(dirname "$0")/ci-build.sh cd $OPENJDK_PATH diff --git a/.github/scripts/ci-test.sh b/.github/scripts/ci-test.sh index 1de23a83..6112d1b9 100755 --- a/.github/scripts/ci-test.sh +++ b/.github/scripts/ci-test.sh @@ -10,6 +10,6 @@ cd $cur cd $cur ./ci-test-assertions.sh cd $cur -./ci-test-global-alloc-bit.sh +./ci-test-vo-bit.sh cd $cur ./ci-test-malloc-mark-sweep.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b9252f..7c86df77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,8 +24,8 @@ jobs: run: | ./.github/scripts/ci-build.sh ./.github/scripts/ci-test-only-normal.sh - - name: DaCapo Tests with global allocation bit - run: ./.github/scripts/ci-test-global-alloc-bit.sh + - name: DaCapo Tests with valid object bit (VO bit) + run: ./.github/scripts/ci-test-vo-bit.sh - name: DaCapo Tests with malloc Mark-Sweep run: ./.github/scripts/ci-test-malloc-mark-sweep.sh diff --git a/README.md b/README.md index bb7c89bd..6e5c071e 100644 --- a/README.md +++ b/README.md @@ -197,12 +197,14 @@ building OpenJDK, we can change its location to be in the object's header: $ MARK_IN_HEADER=1 make CONF=linux-x86_64-normal-server-$DEBUG_LEVEL THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk ``` -### Alloc bit -To support the `global_alloc_bit` feature in mmtk-core, you can set the environment variable `GLOBAL_ALLOC_BIT=1` when -building OpenJDK. This will set the feature for mmtk-core, as well as compiling the fastpath for the alloc bit. +### Valid object bit + +To support the `vo_bit` (valid object bit) feature in mmtk-core, you can set the +environment variable `VO_BIT=1` when building OpenJDK. This will set the feature +for mmtk-core, as well as compiling the fastpath for the VO bit. ```console -$ GLOBAL_ALLOC_BIT=1 make CONF=linux-x86_64-normal-server-$DEBUG_LEVEL THIRD_PARTY_HEAP=$PWD/../mmtk-openjdk/openjdk +$ VO_BIT=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 0f560737..b95913e7 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -419,7 +419,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=f8469b0a019bea58cba26e9fb5c70fb7398ccd31#f8469b0a019bea58cba26e9fb5c70fb7398ccd31" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=df146b7af6cf41cc7d6996e1ca538fd2b32950f5#df146b7af6cf41cc7d6996e1ca538fd2b32950f5" dependencies = [ "atomic", "atomic-traits", @@ -448,7 +448,7 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=f8469b0a019bea58cba26e9fb5c70fb7398ccd31#f8469b0a019bea58cba26e9fb5c70fb7398ccd31" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=df146b7af6cf41cc7d6996e1ca538fd2b32950f5#df146b7af6cf41cc7d6996e1ca538fd2b32950f5" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index f99f27c0..cae04d45 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "f8469b0a019bea58cba26e9fb5c70fb7398ccd31" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "df146b7af6cf41cc7d6996e1ca538fd2b32950f5" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } @@ -42,9 +42,9 @@ default = [] mmtk_extreme_assertions = ["mmtk/extreme_assertions"] nogc_lock_free = ["mmtk/nogc_lock_free"] nogc_no_zeroing = ["mmtk/nogc_no_zeroing"] -# Use the env var GLOBAL_ALLOC_BIT=1 when building OpenJDK so the fastpath for setting the alloc bit will be compiled in. +# Use the env var VO_BIT=1 when building OpenJDK so the fastpath for setting the alloc bit will be compiled in. # See README. -global_alloc_bit = ["mmtk/global_alloc_bit"] +vo_bit = ["mmtk/vo_bit"] # 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 45820e47..7bca0753 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -108,8 +108,8 @@ pub static GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS: uintptr_t = mmtk::util::metadata::side_metadata::GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS.as_usize(); #[no_mangle] -pub static GLOBAL_ALLOC_BIT_ADDRESS: uintptr_t = - mmtk::util::metadata::side_metadata::ALLOC_SIDE_METADATA_ADDR.as_usize(); +pub static VO_BIT_ADDRESS: uintptr_t = + mmtk::util::metadata::side_metadata::VO_BIT_SIDE_METADATA_ADDR.as_usize(); #[no_mangle] pub static FREE_LIST_ALLOCATOR_SIZE: uintptr_t = diff --git a/openjdk/CompileThirdPartyHeap.gmk b/openjdk/CompileThirdPartyHeap.gmk index 7224526a..e946eb7e 100644 --- a/openjdk/CompileThirdPartyHeap.gmk +++ b/openjdk/CompileThirdPartyHeap.gmk @@ -19,11 +19,11 @@ ifdef MMTK_PLAN GC_FEATURES=--features $(MMTK_PLAN) endif -ifeq ($(GLOBAL_ALLOC_BIT), 1) +ifeq ($(VO_BIT), 1) ifndef GC_FEATURES - GC_FEATURES=--features global_alloc_bit + GC_FEATURES=--features vo_bit else - GC_FEATURES:=$(strip $(GC_FEATURES))",global_alloc_bit" + GC_FEATURES:=$(strip $(GC_FEATURES))",vo_bit" endif endif @@ -79,8 +79,8 @@ FORCE: TARGETS += $(LIB_MMTK) JVM_SRC_DIRS += $(MMTK_CPP_ROOT) $(MMTK_CPP_ROOT)/barriers JVM_CFLAGS += -std=c++11 -DINCLUDE_THIRD_PARTY_HEAP -DTHIRD_PARTY_HEAP_SRC=$(MMTK_CPP_ROOT) -ifeq ($(GLOBAL_ALLOC_BIT), 1) - JVM_CFLAGS += -DMMTK_ENABLE_GLOBAL_ALLOC_BIT +ifeq ($(VO_BIT), 1) + JVM_CFLAGS += -DMMTK_ENABLE_VO_BIT endif $(BUILD_LIBJVM): $(LIB_MMTK) diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index b1da9454..a2c3d9c9 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -20,7 +20,7 @@ typedef enum { extern const uintptr_t GLOBAL_SIDE_METADATA_BASE_ADDRESS; extern const uintptr_t GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS; -extern const uintptr_t GLOBAL_ALLOC_BIT_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; diff --git a/openjdk/mmtkBarrierSet.hpp b/openjdk/mmtkBarrierSet.hpp index efced87a..07990706 100644 --- a/openjdk/mmtkBarrierSet.hpp +++ b/openjdk/mmtkBarrierSet.hpp @@ -40,7 +40,7 @@ #define MMTK_ENABLE_ALLOCATION_FASTPATH true #define MMTK_ENABLE_BARRIER_FASTPATH true -const intptr_t ALLOC_BIT_BASE_ADDRESS = GLOBAL_ALLOC_BIT_ADDRESS; +const intptr_t VO_BIT_BASE_ADDRESS = VO_BIT_ADDRESS; struct MMTkAllocatorOffsets { int tlab_top_offset; diff --git a/openjdk/mmtkBarrierSetAssembler_x86.cpp b/openjdk/mmtkBarrierSetAssembler_x86.cpp index cb06763b..dc59274e 100644 --- a/openjdk/mmtkBarrierSetAssembler_x86.cpp +++ b/openjdk/mmtkBarrierSetAssembler_x86.cpp @@ -98,11 +98,11 @@ void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register threa __ jcc(Assembler::above, slow_case); // lab.cursor = end __ movptr(cursor, end); - bool enable_global_alloc_bit = false; - #ifdef MMTK_ENABLE_GLOBAL_ALLOC_BIT - enable_global_alloc_bit = true; + bool enable_vo_bit = false; + #ifdef MMTK_ENABLE_VO_BIT + enable_vo_bit = true; #endif - if (enable_global_alloc_bit || selector.tag == TAG_MARK_COMPACT) { + if (enable_vo_bit || selector.tag == TAG_MARK_COMPACT) { Register tmp3 = rdi; Register tmp2 = rscratch1; assert_different_registers(obj, tmp2, tmp3, rcx); @@ -110,7 +110,7 @@ void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register threa // tmp2 = load-byte (SIDE_METADATA_BASE_ADDRESS + (obj >> 6)); __ movptr(tmp3, obj); __ shrptr(tmp3, 6); - __ movptr(tmp2, ALLOC_BIT_BASE_ADDRESS); + __ movptr(tmp2, VO_BIT_BASE_ADDRESS); __ movb(tmp2, Address(tmp2, tmp3)); // tmp3 = 1 << ((obj >> 3) & 7) // 1. rcx = (obj >> 3) & 7 @@ -126,7 +126,7 @@ void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register threa // store-byte tmp2 (SIDE_METADATA_BASE_ADDRESS + (obj >> 6)) __ movptr(tmp3, obj); __ shrptr(tmp3, 6); - __ movptr(rcx, ALLOC_BIT_BASE_ADDRESS); + __ movptr(rcx, VO_BIT_BASE_ADDRESS); __ movb(Address(rcx, tmp3), tmp2); } diff --git a/openjdk/mmtkBarrierSetC2.cpp b/openjdk/mmtkBarrierSetC2.cpp index d885fe97..b58e433d 100644 --- a/openjdk/mmtkBarrierSetC2.cpp +++ b/openjdk/mmtkBarrierSetC2.cpp @@ -272,14 +272,14 @@ void MMTkBarrierSetC2::expand_allocate(PhaseMacroExpand* x, fast_oop_ctrl = needgc_false; // No contention, so this is the fast path fast_oop_rawmem = store_eden_top; - bool enable_global_alloc_bit = false; - #ifdef MMTK_ENABLE_GLOBAL_ALLOC_BIT - enable_global_alloc_bit = true; + bool enable_vo_bit = false; + #ifdef MMTK_ENABLE_VO_BIT + enable_vo_bit = true; #endif - if (enable_global_alloc_bit || selector.tag == TAG_MARK_COMPACT) { + if (enable_vo_bit || selector.tag == TAG_MARK_COMPACT) { // set the alloc bit: // intptr_t addr = (intptr_t) (void*) fast_oop; - // uint8_t* meta_addr = (uint8_t*) (ALLOC_BIT_BASE_ADDRESS + (addr >> 6)); + // uint8_t* meta_addr = (uint8_t*) (VO_BIT_BASE_ADDRESS + (addr >> 6)); // intptr_t shift = (addr >> 3) & 0b111; // uint8_t byte_val = *meta_addr; // uint8_t new_byte_val = byte_val | (1 << shift); @@ -293,7 +293,7 @@ void MMTkBarrierSetC2::expand_allocate(PhaseMacroExpand* x, Node *meta_offset = new URShiftLNode(obj_addr, addr_shift); x->transform_later(meta_offset); - Node *meta_base = ConLNode::make(ALLOC_BIT_BASE_ADDRESS); + Node *meta_base = ConLNode::make(VO_BIT_BASE_ADDRESS); x->transform_later(meta_base); Node *meta_addr = new AddLNode(meta_base, meta_offset); @@ -329,10 +329,10 @@ void MMTkBarrierSetC2::expand_allocate(PhaseMacroExpand* x, Node *new_meta_val = new OrINode(meta_val, set_bit); x->transform_later(new_meta_val); - Node *set_alloc_bit = new StoreBNode(fast_oop_ctrl, fast_oop_rawmem, meta_addr_p, TypeRawPtr::BOTTOM, new_meta_val, MemNode::unordered); - x->transform_later(set_alloc_bit); + Node *set_vo_bit = new StoreBNode(fast_oop_ctrl, fast_oop_rawmem, meta_addr_p, TypeRawPtr::BOTTOM, new_meta_val, MemNode::unordered); + x->transform_later(set_vo_bit); - fast_oop_rawmem = set_alloc_bit; + fast_oop_rawmem = set_vo_bit; } InitializeNode* init = alloc->initialization(); From 47a85ed66d719b2ca5681fb0b5fe77cd981df747 Mon Sep 17 00:00:00 2001 From: Wenyu Zhao Date: Wed, 19 Apr 2023 22:00:40 -0700 Subject: [PATCH 02/11] Fix invalid register values in `arraycopy_epilogue` barrier (#216) --- openjdk/barriers/mmtkObjectBarrier.cpp | 32 ++++++++++++++++++++++++++ openjdk/barriers/mmtkObjectBarrier.hpp | 1 + 2 files changed, 33 insertions(+) diff --git a/openjdk/barriers/mmtkObjectBarrier.cpp b/openjdk/barriers/mmtkObjectBarrier.cpp index 8aea1c00..d95944bc 100644 --- a/openjdk/barriers/mmtkObjectBarrier.cpp +++ b/openjdk/barriers/mmtkObjectBarrier.cpp @@ -82,9 +82,41 @@ void MMTkObjectBarrierSetAssembler::object_reference_write_post(MacroAssembler* #endif } +void MMTkObjectBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register src, Register dst, Register count) { + // `count` or `dst` register values may get overwritten after the array copy, and `arraycopy_epilogue` can receive invalid addresses. + // Save the register values here and restore them in `arraycopy_epilogue`. + // See https://github.com/openjdk/jdk/blob/jdk-11%2B19/src/hotspot/cpu/x86/gc/shared/modRefBarrierSetAssembler_x86.cpp#L37-L50 + bool checkcast = (decorators & ARRAYCOPY_CHECKCAST) != 0; + bool disjoint = (decorators & ARRAYCOPY_DISJOINT) != 0; + bool obj_int = type == T_OBJECT LP64_ONLY(&& UseCompressedOops); + if (type == T_OBJECT || type == T_ARRAY) { + if (!checkcast) { + if (!obj_int) { + // Save count for barrier + __ movptr(r11, count); + } else if (disjoint) { + // Save dst in r11 in the disjoint case + __ movq(r11, dst); + } + } + } +} + void MMTkObjectBarrierSetAssembler::arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register src, Register dst, Register count) { + bool checkcast = (decorators & ARRAYCOPY_CHECKCAST) != 0; + bool disjoint = (decorators & ARRAYCOPY_DISJOINT) != 0; + bool obj_int = type == T_OBJECT LP64_ONLY(&& UseCompressedOops); const bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0; if ((type == T_OBJECT || type == T_ARRAY) && !dest_uninitialized) { + if (!checkcast) { + if (!obj_int) { + // Save count for barrier + count = r11; + } else if (disjoint) { + // Use the saved dst in the disjoint case + dst = r11; + } + } __ pusha(); __ movptr(c_rarg0, src); __ movptr(c_rarg1, dst); diff --git a/openjdk/barriers/mmtkObjectBarrier.hpp b/openjdk/barriers/mmtkObjectBarrier.hpp index e8124785..c6087dad 100644 --- a/openjdk/barriers/mmtkObjectBarrier.hpp +++ b/openjdk/barriers/mmtkObjectBarrier.hpp @@ -32,6 +32,7 @@ class MMTkObjectBarrierSetAssembler: public MMTkBarrierSetAssembler { protected: virtual void object_reference_write_post(MacroAssembler* masm, DecoratorSet decorators, Address dst, Register val, Register tmp1, Register tmp2) const override; public: + virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register src, Register dst, Register count) override; virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register src, Register dst, Register count) override; }; From b80877cba8947f9d46550b99d4931ba556784540 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Fri, 28 Apr 2023 20:16:56 +0800 Subject: [PATCH 03/11] Remove deprecated const. (#217) The constant `COORDINATOR_ONLY_STW` is deprecated and has no effect. --- mmtk/src/collection.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mmtk/src/collection.rs b/mmtk/src/collection.rs index f02e3f56..af83d6b6 100644 --- a/mmtk/src/collection.rs +++ b/mmtk/src/collection.rs @@ -32,10 +32,6 @@ const GC_THREAD_KIND_CONTROLLER: libc::c_int = 0; const GC_THREAD_KIND_WORKER: libc::c_int = 1; impl Collection for VMCollection { - /// With the presence of the "VM companion thread", - /// the OpenJDK binding allows any MMTk GC thread to stop/start the world. - const COORDINATOR_ONLY_STW: bool = false; - fn stop_all_mutators(tls: VMWorkerThread, mut mutator_visitor: F) where F: FnMut(&'static mut Mutator), From 52680f92f9da008348e8da3a9721228a724832bf Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Fri, 26 May 2023 16:26:14 +0800 Subject: [PATCH 04/11] Update MMTk core PR #817 (alternative approach) (#220) This is an alternative approach for https://github.com/mmtk/mmtk-openjdk/pull/218 that addresses the upstream API change in https://github.com/mmtk/mmtk-core/pull/817. This PR simply saves the mutator pointers into a `VecDeque` and embeds it into the iterator. --- mmtk/Cargo.lock | 68 ++++++++++++++++++++++++++++++++++++----- mmtk/Cargo.toml | 2 +- mmtk/src/active_plan.rs | 54 +++++++++++++++++++------------- mmtk/src/collection.rs | 22 +------------ mmtk/src/lib.rs | 25 +++++++++++++-- openjdk/mmtk.h | 3 +- openjdk/mmtkUpcalls.cpp | 38 +++-------------------- 7 files changed, 125 insertions(+), 87 deletions(-) diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index b95913e7..dc47be06 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -95,6 +95,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "crossbeam" version = "0.8.2" @@ -162,6 +168,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "delegate" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d358e0ec5c59a5e1603b933def447096886121660fc680dc1e64a0753981fe3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "downcast-rs" version = "1.2.0" @@ -419,7 +436,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=df146b7af6cf41cc7d6996e1ca538fd2b32950f5#df146b7af6cf41cc7d6996e1ca538fd2b32950f5" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=de8bbfe623eee5e915f32870de8f81128df8ad41#de8bbfe623eee5e915f32870de8f81128df8ad41" dependencies = [ "atomic", "atomic-traits", @@ -427,6 +444,7 @@ dependencies = [ "built 0.6.0", "cfg-if", "crossbeam", + "delegate", "downcast-rs", "enum-map", "env_logger", @@ -442,13 +460,13 @@ dependencies = [ "static_assertions", "strum", "strum_macros", - "sys-info", + "sysinfo", ] [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=df146b7af6cf41cc7d6996e1ca538fd2b32950f5#df146b7af6cf41cc7d6996e1ca538fd2b32950f5" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=de8bbfe623eee5e915f32870de8f81128df8ad41#de8bbfe623eee5e915f32870de8f81128df8ad41" dependencies = [ "proc-macro-error", "proc-macro2", @@ -467,6 +485,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -556,6 +583,28 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "regex" version = "1.7.1" @@ -701,13 +750,18 @@ dependencies = [ ] [[package]] -name = "sys-info" -version = "0.9.1" +name = "sysinfo" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +checksum = "02f1dc6930a439cc5d154221b5387d153f8183529b07c19aca24ea31e0a167e1" dependencies = [ - "cc", + "cfg-if", + "core-foundation-sys", "libc", + "ntapi", + "once_cell", + "rayon", + "winapi", ] [[package]] diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index cae04d45..c1f5d040 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "df146b7af6cf41cc7d6996e1ca538fd2b32950f5" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "de8bbfe623eee5e915f32870de8f81128df8ad41" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } diff --git a/mmtk/src/active_plan.rs b/mmtk/src/active_plan.rs index 88d12958..5ecaa92d 100644 --- a/mmtk/src/active_plan.rs +++ b/mmtk/src/active_plan.rs @@ -1,3 +1,4 @@ +use crate::MutatorClosure; use crate::OpenJDK; use crate::SINGLETON; use crate::UPCALLS; @@ -5,7 +6,36 @@ use mmtk::util::opaque_pointer::*; use mmtk::vm::ActivePlan; use mmtk::Mutator; use mmtk::Plan; -use std::sync::Mutex; +use std::collections::VecDeque; +use std::marker::PhantomData; + +struct OpenJDKMutatorIterator<'a> { + mutators: VecDeque<&'a mut Mutator>, + phantom_data: PhantomData<&'a ()>, +} + +impl<'a> OpenJDKMutatorIterator<'a> { + fn new() -> Self { + let mut mutators = VecDeque::new(); + unsafe { + ((*UPCALLS).get_mutators)(MutatorClosure::from_rust_closure(&mut |mutator| { + mutators.push_back(mutator); + })); + } + Self { + mutators, + phantom_data: PhantomData, + } + } +} + +impl<'a> Iterator for OpenJDKMutatorIterator<'a> { + type Item = &'a mut Mutator; + + fn next(&mut self) -> Option { + self.mutators.pop_front() + } +} pub struct VMActivePlan {} @@ -25,29 +55,11 @@ impl ActivePlan for VMActivePlan { } } - fn reset_mutator_iterator() { - unsafe { - ((*UPCALLS).reset_mutator_iterator)(); - } - } - - fn get_next_mutator() -> Option<&'static mut Mutator> { - let _guard = MUTATOR_ITERATOR_LOCK.lock().unwrap(); - unsafe { - let m = ((*UPCALLS).get_next_mutator)(); - if m.is_null() { - None - } else { - Some(&mut *m) - } - } + fn mutators<'a>() -> Box> + 'a> { + Box::new(OpenJDKMutatorIterator::new()) } fn number_of_mutators() -> usize { unsafe { ((*UPCALLS).number_of_mutators)() } } } - -lazy_static! { - pub static ref MUTATOR_ITERATOR_LOCK: Mutex<()> = Mutex::new(()); -} diff --git a/mmtk/src/collection.rs b/mmtk/src/collection.rs index af83d6b6..f6b2cc33 100644 --- a/mmtk/src/collection.rs +++ b/mmtk/src/collection.rs @@ -8,26 +8,6 @@ use crate::{MutatorClosure, OpenJDK}; pub struct VMCollection {} -extern "C" fn report_mutator_stop( - mutator: *mut Mutator, - callback_ptr: *mut libc::c_void, -) where - F: FnMut(&'static mut Mutator), -{ - let callback: &mut F = unsafe { &mut *(callback_ptr as *mut F) }; - callback(unsafe { &mut *mutator }); -} - -fn to_mutator_closure(callback: &mut F) -> MutatorClosure -where - F: FnMut(&'static mut Mutator), -{ - MutatorClosure { - func: report_mutator_stop::, - data: callback as *mut F as *mut libc::c_void, - } -} - const GC_THREAD_KIND_CONTROLLER: libc::c_int = 0; const GC_THREAD_KIND_WORKER: libc::c_int = 1; @@ -43,7 +23,7 @@ impl Collection for VMCollection { ((*UPCALLS).stop_all_mutators)( tls, scan_mutators_in_safepoint, - to_mutator_closure(&mut mutator_visitor), + MutatorClosure::from_rust_closure(&mut mutator_visitor), ); } } diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index 7bca0753..d4847d5c 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -39,6 +39,28 @@ pub struct MutatorClosure { pub data: *mut libc::c_void, } +impl MutatorClosure { + fn from_rust_closure(callback: &mut F) -> Self + where + F: FnMut(&'static mut Mutator), + { + Self { + func: Self::call_rust_closure::, + data: callback as *mut F as *mut libc::c_void, + } + } + + extern "C" fn call_rust_closure( + mutator: *mut Mutator, + callback_ptr: *mut libc::c_void, + ) where + F: FnMut(&'static mut Mutator), + { + let callback: &mut F = unsafe { &mut *(callback_ptr as *mut F) }; + callback(unsafe { &mut *mutator }); + } +} + /// A closure for reporting root edges. The C++ code should pass `data` back as the last argument. #[repr(C)] pub struct EdgesClosure { @@ -62,8 +84,7 @@ pub struct OpenJDK_Upcalls { pub spawn_gc_thread: extern "C" fn(tls: VMThread, kind: libc::c_int, ctx: *mut libc::c_void), pub block_for_gc: extern "C" fn(), pub out_of_memory: extern "C" fn(tls: VMThread, err_kind: AllocationError), - pub get_next_mutator: extern "C" fn() -> *mut Mutator, - pub reset_mutator_iterator: extern "C" fn(), + pub get_mutators: extern "C" fn(closure: MutatorClosure), pub scan_object: extern "C" fn(trace: *mut c_void, object: ObjectReference, tls: OpaquePointer), pub dump_object: extern "C" fn(object: ObjectReference), pub get_object_size: extern "C" fn(object: ObjectReference) -> usize, diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index a2c3d9c9..35bf6e0b 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -149,8 +149,7 @@ typedef struct { void (*spawn_gc_thread) (void *tls, int kind, void *ctx); void (*block_for_gc) (); void (*out_of_memory) (void *tls, MMTkAllocationError err_kind); - void* (*get_next_mutator) (); - void (*reset_mutator_iterator) (); + void (*get_mutators) (MutatorClosure closure); void (*scan_object) (void* trace, void* object, void* tls); void (*dump_object) (void* object); size_t (*get_object_size) (void* object); diff --git a/openjdk/mmtkUpcalls.cpp b/openjdk/mmtkUpcalls.cpp index 3b983bcb..7059a0ca 100644 --- a/openjdk/mmtkUpcalls.cpp +++ b/openjdk/mmtkUpcalls.cpp @@ -177,40 +177,13 @@ static bool mmtk_is_mutator(void* tls) { return ((Thread*) tls)->third_party_heap_collector == NULL; } -template -struct MaybeUninit { - MaybeUninit() {} - T* operator->() { - return (T*) &_data; +static void mmtk_get_mutators(MutatorClosure closure) { + JavaThread *thr; + for (JavaThreadIteratorWithHandle jtiwh; thr = jtiwh.next();) { + closure.invoke(&thr->third_party_heap_mutator); } - T& operator*() { - return *((T*) &_data); - } -private: - char _data[sizeof(T)]; -}; - -static MaybeUninit jtiwh; -static bool mutator_iteration_start = true; - -static void* mmtk_get_next_mutator() { - if (mutator_iteration_start) { - *jtiwh = JavaThreadIteratorWithHandle(); - mutator_iteration_start = false; - } - JavaThread *thr = jtiwh->next(); - if (thr == NULL) { - mutator_iteration_start = true; - return NULL; - } - return (void*) &thr->third_party_heap_mutator; -} - -static void mmtk_reset_mutator_iterator() { - mutator_iteration_start = true; } - static void mmtk_scan_all_thread_roots(EdgesClosure closure) { MMTkRootsClosure2 cl(closure); MMTkHeap::heap()->scan_thread_roots(cl); @@ -347,8 +320,7 @@ OpenJDK_Upcalls mmtk_upcalls = { mmtk_spawn_gc_thread, mmtk_block_for_gc, mmtk_out_of_memory, - mmtk_get_next_mutator, - mmtk_reset_mutator_iterator, + mmtk_get_mutators, mmtk_scan_object, mmtk_dump_object, mmtk_get_object_size, From 21a3c45238268bc47831fdff8ebe9c63aa87d142 Mon Sep 17 00:00:00 2001 From: Yi Lin Date: Tue, 30 May 2023 00:22:05 +1200 Subject: [PATCH 05/11] Update to mmtk-core PR #838 (#221) This PR updates mmtk-core to https://github.com/mmtk/mmtk-core/pull/838. --- mmtk/Cargo.lock | 4 ++-- mmtk/Cargo.toml | 2 +- mmtk/src/api.rs | 2 +- mmtk/src/object_model.rs | 2 +- openjdk/mmtk.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index dc47be06..7cc1babe 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -436,7 +436,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=de8bbfe623eee5e915f32870de8f81128df8ad41#de8bbfe623eee5e915f32870de8f81128df8ad41" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" dependencies = [ "atomic", "atomic-traits", @@ -466,7 +466,7 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=de8bbfe623eee5e915f32870de8f81128df8ad41#de8bbfe623eee5e915f32870de8f81128df8ad41" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index c1f5d040..ba91f9d5 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "de8bbfe623eee5e915f32870de8f81128df8ad41" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 5bd6b820..402eea3a 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -129,7 +129,7 @@ pub extern "C" fn alloc( mutator: *mut Mutator, size: usize, align: usize, - offset: isize, + offset: usize, allocator: AllocationSemantics, ) -> Address { memory_manager::alloc::(unsafe { &mut *mutator }, size, align, offset, allocator) diff --git a/mmtk/src/object_model.rs b/mmtk/src/object_model.rs index 7ee39948..3cfe50fd 100644 --- a/mmtk/src/object_model.rs +++ b/mmtk/src/object_model.rs @@ -72,7 +72,7 @@ impl ObjectModel for VMObjectModel { ::std::mem::size_of::() } - fn get_align_offset_when_copied(_object: ObjectReference) -> isize { + fn get_align_offset_when_copied(_object: ObjectReference) -> usize { 0 } diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index 35bf6e0b..1f6076ce 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -44,7 +44,7 @@ extern void* alloc_slow_largeobject(MMTk_Mutator mutator, size_t size, size_t align, size_t offset); extern void post_alloc(MMTk_Mutator mutator, void* refer, - int bytes, int allocator); + size_t bytes, int allocator); /// Full pre-barrier extern void mmtk_object_reference_write_pre(MMTk_Mutator mutator, void* src, void* slot, void* target); From 54a249e877e1cbea147a71aafaafb8583f33843d Mon Sep 17 00:00:00 2001 From: Kunal Sareen Date: Thu, 8 Jun 2023 03:24:49 +1000 Subject: [PATCH 06/11] Rename ambiguous `scan_thread_root{,s}` functions (#222) --- mmtk/Cargo.toml | 2 +- mmtk/src/lib.rs | 4 ++-- mmtk/src/scanning.rs | 11 +++++++---- openjdk/mmtk.h | 4 ++-- openjdk/mmtkHeap.cpp | 2 +- openjdk/mmtkHeap.hpp | 2 +- openjdk/mmtkUpcalls.cpp | 10 +++++----- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index ba91f9d5..29e28a66 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "f1a0bb7fbec97dd84e35a40e8be01cf5018f2f9e" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index d4847d5c..e501c64f 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -98,8 +98,8 @@ pub struct OpenJDK_Upcalls { pub referent_offset: extern "C" fn() -> i32, pub discovered_offset: extern "C" fn() -> i32, pub dump_object_string: extern "C" fn(object: ObjectReference) -> *const c_char, - pub scan_all_thread_roots: extern "C" fn(closure: EdgesClosure), - pub scan_thread_roots: extern "C" fn(closure: EdgesClosure, tls: VMMutatorThread), + pub scan_roots_in_all_mutator_threads: extern "C" fn(closure: EdgesClosure), + pub scan_roots_in_mutator_thread: extern "C" fn(closure: EdgesClosure, tls: VMMutatorThread), pub scan_universe_roots: extern "C" fn(closure: EdgesClosure), pub scan_jni_handle_roots: extern "C" fn(closure: EdgesClosure), pub scan_object_synchronizer_roots: extern "C" fn(closure: EdgesClosure), diff --git a/mmtk/src/scanning.rs b/mmtk/src/scanning.rs index 17192e9c..aa1a5dba 100644 --- a/mmtk/src/scanning.rs +++ b/mmtk/src/scanning.rs @@ -58,20 +58,23 @@ impl Scanning for VMScanning { // TODO } - fn scan_thread_roots(_tls: VMWorkerThread, mut factory: impl RootsWorkFactory) { + fn scan_roots_in_all_mutator_threads( + _tls: VMWorkerThread, + mut factory: impl RootsWorkFactory, + ) { unsafe { - ((*UPCALLS).scan_all_thread_roots)(to_edges_closure(&mut factory)); + ((*UPCALLS).scan_roots_in_all_mutator_threads)(to_edges_closure(&mut factory)); } } - fn scan_thread_root( + fn scan_roots_in_mutator_thread( _tls: VMWorkerThread, mutator: &'static mut Mutator, mut factory: impl RootsWorkFactory, ) { let tls = mutator.get_tls(); unsafe { - ((*UPCALLS).scan_thread_roots)(to_edges_closure(&mut factory), tls); + ((*UPCALLS).scan_roots_in_mutator_thread)(to_edges_closure(&mut factory), tls); } } diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index 1f6076ce..88c96d49 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -163,8 +163,8 @@ typedef struct { int (*referent_offset) (); int (*discovered_offset) (); char* (*dump_object_string) (void* object); - void (*scan_all_thread_roots)(EdgesClosure closure); - void (*scan_thread_roots)(EdgesClosure closure, void* tls); + void (*scan_roots_in_all_mutator_threads)(EdgesClosure closure); + void (*scan_roots_in_mutator_thread)(EdgesClosure closure, void* tls); void (*scan_universe_roots) (EdgesClosure closure); void (*scan_jni_handle_roots) (EdgesClosure closure); void (*scan_object_synchronizer_roots) (EdgesClosure closure); diff --git a/openjdk/mmtkHeap.cpp b/openjdk/mmtkHeap.cpp index 6a573f74..4197f64d 100644 --- a/openjdk/mmtkHeap.cpp +++ b/openjdk/mmtkHeap.cpp @@ -415,7 +415,7 @@ void MMTkHeap::scan_vm_thread_roots(OopClosure& cl) { VMThread::vm_thread()->oops_do(&cl, NULL); } -void MMTkHeap::scan_thread_roots(OopClosure& cl) { +void MMTkHeap::scan_roots_in_all_mutator_threads(OopClosure& cl) { ResourceMark rm; Threads::possibly_parallel_oops_do(false, &cl, NULL); } diff --git a/openjdk/mmtkHeap.hpp b/openjdk/mmtkHeap.hpp index 55369244..e01dfaf9 100644 --- a/openjdk/mmtkHeap.hpp +++ b/openjdk/mmtkHeap.hpp @@ -195,7 +195,7 @@ class MMTkHeap : public CollectedHeap { void scan_roots(OopClosure& cl); - void scan_thread_roots(OopClosure& cl); + void scan_roots_in_all_mutator_threads(OopClosure& cl); void scan_universe_roots(OopClosure& cl); void scan_jni_handle_roots(OopClosure& cl); diff --git a/openjdk/mmtkUpcalls.cpp b/openjdk/mmtkUpcalls.cpp index 7059a0ca..5f1350d0 100644 --- a/openjdk/mmtkUpcalls.cpp +++ b/openjdk/mmtkUpcalls.cpp @@ -184,12 +184,12 @@ static void mmtk_get_mutators(MutatorClosure closure) { } } -static void mmtk_scan_all_thread_roots(EdgesClosure closure) { +static void mmtk_scan_roots_in_all_mutator_threads(EdgesClosure closure) { MMTkRootsClosure2 cl(closure); - MMTkHeap::heap()->scan_thread_roots(cl); + MMTkHeap::heap()->scan_roots_in_all_mutator_threads(cl); } -static void mmtk_scan_thread_roots(EdgesClosure closure, void* tls) { +static void mmtk_scan_roots_in_mutator_thread(EdgesClosure closure, void* tls) { ResourceMark rm; JavaThread* thread = (JavaThread*) tls; MMTkRootsClosure2 cl(closure); @@ -334,8 +334,8 @@ OpenJDK_Upcalls mmtk_upcalls = { referent_offset, discovered_offset, dump_object_string, - mmtk_scan_all_thread_roots, - mmtk_scan_thread_roots, + mmtk_scan_roots_in_all_mutator_threads, + mmtk_scan_roots_in_mutator_thread, mmtk_scan_universe_roots, mmtk_scan_jni_handle_roots, mmtk_scan_object_synchronizer_roots, From b86ed3f7629e8f33c48549a4998b76c28c1c9449 Mon Sep 17 00:00:00 2001 From: Yi Lin Date: Wed, 9 Aug 2023 21:23:05 +1200 Subject: [PATCH 07/11] Update to MMTk core PR #875 (#225) Updates to https://github.com/mmtk/mmtk-core/pull/875. --- mmtk/Cargo.lock | 126 +++++++++++++++++++++++++++++++--------- mmtk/Cargo.toml | 2 +- mmtk/src/collection.rs | 16 +---- mmtk/src/lib.rs | 6 +- mmtk/src/scanning.rs | 20 +------ openjdk/mmtk.h | 2 +- openjdk/mmtkUpcalls.cpp | 11 ++-- 7 files changed, 111 insertions(+), 72 deletions(-) diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 7cc1babe..6d3db38b 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,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=04a47feb4598b2120598453c2cceec83986c2122#04a47feb4598b2120598453c2cceec83986c2122" dependencies = [ "atomic", "atomic-traits", @@ -448,6 +448,7 @@ dependencies = [ "downcast-rs", "enum-map", "env_logger", + "is-terminal", "itertools", "lazy_static", "libc", @@ -455,6 +456,7 @@ dependencies = [ "mmtk-macros", "num-traits", "num_cpus", + "probe", "regex", "spin", "static_assertions", @@ -466,7 +468,7 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0#2ec37bde7955304f3e4bc5f7bed3fbfba3833cc0" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=04a47feb4598b2120598453c2cceec83986c2122#04a47feb4598b2120598453c2cceec83986c2122" dependencies = [ "proc-macro-error", "proc-macro2", @@ -541,6 +543,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 +641,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 +759,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 +912,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 +930,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 +960,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..196f5369 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "f1a0bb7fbec97dd84e35a40e8be01cf5018f2f9e" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "04a47feb4598b2120598453c2cceec83986c2122" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } diff --git a/mmtk/src/collection.rs b/mmtk/src/collection.rs index f6b2cc33..776c737a 100644 --- a/mmtk/src/collection.rs +++ b/mmtk/src/collection.rs @@ -1,7 +1,7 @@ use mmtk::util::alloc::AllocationError; use mmtk::util::opaque_pointer::*; -use mmtk::vm::{Collection, GCThreadContext, Scanning, VMBinding}; -use mmtk::{Mutator, MutatorContext}; +use mmtk::vm::{Collection, GCThreadContext}; +use mmtk::Mutator; use crate::UPCALLS; use crate::{MutatorClosure, OpenJDK}; @@ -16,13 +16,9 @@ impl Collection for VMCollection { where F: FnMut(&'static mut Mutator), { - let scan_mutators_in_safepoint = - ::VMScanning::SCAN_MUTATORS_IN_SAFEPOINT; - unsafe { ((*UPCALLS).stop_all_mutators)( tls, - scan_mutators_in_safepoint, MutatorClosure::from_rust_closure(&mut mutator_visitor), ); } @@ -55,14 +51,6 @@ impl Collection for VMCollection { } } - fn prepare_mutator>( - _tls_w: VMWorkerThread, - _tls_m: VMMutatorThread, - _m: &T, - ) { - // unimplemented!() - } - fn out_of_memory(tls: VMThread, err_kind: AllocationError) { unsafe { ((*UPCALLS).out_of_memory)(tls, err_kind); diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index e501c64f..8c7bd9d9 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -75,11 +75,7 @@ pub struct EdgesClosure { #[repr(C)] pub struct OpenJDK_Upcalls { - pub stop_all_mutators: extern "C" fn( - tls: VMWorkerThread, - scan_mutators_in_safepoint: bool, - closure: MutatorClosure, - ), + pub stop_all_mutators: extern "C" fn(tls: VMWorkerThread, closure: MutatorClosure), pub resume_mutators: extern "C" fn(tls: VMWorkerThread), pub spawn_gc_thread: extern "C" fn(tls: VMThread, kind: libc::c_int, ctx: *mut libc::c_void), pub block_for_gc: extern "C" fn(), diff --git a/mmtk/src/scanning.rs b/mmtk/src/scanning.rs index aa1a5dba..9d6955d1 100644 --- a/mmtk/src/scanning.rs +++ b/mmtk/src/scanning.rs @@ -42,9 +42,6 @@ pub(crate) fn to_edges_closure>(factory: &mut F } impl Scanning for VMScanning { - const SCAN_MUTATORS_IN_SAFEPOINT: bool = false; - const SINGLE_THREAD_MUTATOR_SCANNING: bool = false; - fn scan_object>( tls: VMWorkerThread, object: ObjectReference, @@ -58,15 +55,6 @@ impl Scanning for VMScanning { // TODO } - fn scan_roots_in_all_mutator_threads( - _tls: VMWorkerThread, - mut factory: impl RootsWorkFactory, - ) { - unsafe { - ((*UPCALLS).scan_roots_in_all_mutator_threads)(to_edges_closure(&mut factory)); - } - } - fn scan_roots_in_mutator_thread( _tls: VMWorkerThread, mutator: &'static mut Mutator, @@ -94,15 +82,9 @@ impl Scanning for VMScanning { Box::new(ScanStringTableRoots::new(factory.clone())) as _, Box::new(ScanClassLoaderDataGraphRoots::new(factory.clone())) as _, Box::new(ScanWeakProcessorRoots::new(factory.clone())) as _, + Box::new(ScanVMThreadRoots::new(factory)) as _, ], ); - if !(Self::SCAN_MUTATORS_IN_SAFEPOINT && Self::SINGLE_THREAD_MUTATOR_SCANNING) { - memory_manager::add_work_packet( - &SINGLETON, - WorkBucketStage::Prepare, - ScanVMThreadRoots::new(factory), - ); - } } fn supports_return_barrier() -> bool { diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index 88c96d49..ab47acca 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -144,7 +144,7 @@ struct EdgesClosure { * OpenJDK-specific */ typedef struct { - void (*stop_all_mutators) (void *tls, bool scan_mutators_in_safepoint, MutatorClosure closure); + void (*stop_all_mutators) (void *tls, MutatorClosure closure); void (*resume_mutators) (void *tls); void (*spawn_gc_thread) (void *tls, int kind, void *ctx); void (*block_for_gc) (); diff --git a/openjdk/mmtkUpcalls.cpp b/openjdk/mmtkUpcalls.cpp index 5f1350d0..68743261 100644 --- a/openjdk/mmtkUpcalls.cpp +++ b/openjdk/mmtkUpcalls.cpp @@ -45,7 +45,7 @@ // Note: This counter must be accessed using the Atomic class. static volatile size_t mmtk_start_the_world_count = 0; -static void mmtk_stop_all_mutators(void *tls, bool scan_mutators_in_safepoint, MutatorClosure closure) { +static void mmtk_stop_all_mutators(void *tls, MutatorClosure closure) { ClassLoaderDataGraph::clear_claimed_marks(); CodeCache::gc_prologue(); #if COMPILER2_OR_JVMCI @@ -56,12 +56,11 @@ static void mmtk_stop_all_mutators(void *tls, bool scan_mutators_in_safepoint, M MMTkHeap::heap()->companion_thread()->request(MMTkVMCompanionThread::_threads_suspended, true); log_debug(gc)("Mutators stopped. Now enumerate threads for scanning..."); - if (!scan_mutators_in_safepoint) { - JavaThreadIteratorWithHandle jtiwh; - while (JavaThread *cur = jtiwh.next()) { - closure.invoke((void*)&cur->third_party_heap_mutator); - } + JavaThreadIteratorWithHandle jtiwh; + while (JavaThread *cur = jtiwh.next()) { + closure.invoke((void*)&cur->third_party_heap_mutator); } + log_debug(gc)("Finished enumerating threads."); nmethod::oops_do_marking_prologue(); } From 48a827704a5535d8871d38d1b7544654a82aa5b3 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Fri, 11 Aug 2023 15:53:12 +0800 Subject: [PATCH 08/11] Show the version after cd (#227) That will show the actual used cargo version specified by `rust-toolchain`. --- openjdk/CompileThirdPartyHeap.gmk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openjdk/CompileThirdPartyHeap.gmk b/openjdk/CompileThirdPartyHeap.gmk index e946eb7e..2332fd0d 100644 --- a/openjdk/CompileThirdPartyHeap.gmk +++ b/openjdk/CompileThirdPartyHeap.gmk @@ -66,9 +66,8 @@ $(LIB_MMTK): FORCE echo -e $(YELLOW)Local OpenJDK version $(OPENJDK_LOCAL_VERSION)$(NC); \ echo -e $(YELLOW)mmtk/Cargo.toml OpenJDK version $(OPENJDK_VERSION)$(NC); \ fi - cargo --version - echo "cd $(MMTK_RUST_ROOT) && cargo build $(CARGO_PROFILE_FLAG) --target $(HOST_TRIPLE) $(GC_FEATURES)" - cd $(MMTK_RUST_ROOT) && cargo build $(CARGO_PROFILE_FLAG) --target $(HOST_TRIPLE) $(GC_FEATURES) + echo "cd $(MMTK_RUST_ROOT) && cargo --version && cargo build $(CARGO_PROFILE_FLAG) --target $(HOST_TRIPLE) $(GC_FEATURES)" + cd $(MMTK_RUST_ROOT) && cargo --version && cargo build $(CARGO_PROFILE_FLAG) --target $(HOST_TRIPLE) $(GC_FEATURES) cp $(MMTK_RUST_ROOT)/target/$(HOST_TRIPLE)/$(CARGO_PROFILE)/libmmtk_openjdk.so $(LIB_MMTK) JVM_LIBS += -L$(JVM_LIB_OUTPUTDIR) -lmmtk_openjdk From 511e72629023c12a23437dc666c4c21ba7a2a456 Mon Sep 17 00:00:00 2001 From: Yi Lin Date: Tue, 15 Aug 2023 16:26:32 +1200 Subject: [PATCH 09/11] Add features for genimmix and stickyimmix (#228) We currently allow build with a fixed plan to work with the current performance CI. https://github.com/mmtk/mmtk-core/pull/901 attempts to add more plans to our performance CI. This PR adds some missing features for genimmix and stickyimmix. We do not need those plans once we move to the new `running-ng` scripts. --- mmtk/Cargo.toml | 2 ++ mmtk/src/api.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 196f5369..99244cd3 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -62,3 +62,5 @@ gencopy = [] marksweep = [] pageprotect = [] immix = [] +genimmix = [] +stickyimmix = [] diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 402eea3a..25fb34af 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -72,6 +72,10 @@ pub extern "C" fn openjdk_gc_init(calls: *const OpenJDK_Upcalls) { Some(PlanSelector::PageProtect) } else if cfg!(feature = "immix") { Some(PlanSelector::Immix) + } else if cfg!(feature = "genimmix") { + Some(PlanSelector::GenImmix) + } else if cfg!(feature = "stickyimmix") { + Some(PlanSelector::StickyImmix) } else { None }; From 91e163a3e7961232189c5f2c8496c1b4a75a4f9b Mon Sep 17 00:00:00 2001 From: Wenyu Zhao Date: Fri, 18 Aug 2023 11:18:43 +1000 Subject: [PATCH 10/11] Pass hotspot command line flags to mmtk-core (#229) * Pass hotspot cmdline flags to mmtk * lower hotspot flag priority * Remove println * Use typed setter * Update mmtk-core --- mmtk/Cargo.lock | 4 ++-- mmtk/Cargo.toml | 2 +- mmtk/src/api.rs | 14 ++++++++++++++ openjdk/mmtk.h | 3 +++ openjdk/mmtkHeap.cpp | 2 ++ openjdk/thirdPartyHeapArguments.cpp | 6 ++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mmtk/Cargo.lock b/mmtk/Cargo.lock index 6d3db38b..e5c02fa6 100644 --- a/mmtk/Cargo.lock +++ b/mmtk/Cargo.lock @@ -436,7 +436,7 @@ dependencies = [ [[package]] name = "mmtk" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=04a47feb4598b2120598453c2cceec83986c2122#04a47feb4598b2120598453c2cceec83986c2122" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=4873b4ab4016a2a5ef413463443856efa373e90c#4873b4ab4016a2a5ef413463443856efa373e90c" dependencies = [ "atomic", "atomic-traits", @@ -468,7 +468,7 @@ dependencies = [ [[package]] name = "mmtk-macros" version = "0.18.0" -source = "git+https://github.com/mmtk/mmtk-core.git?rev=04a47feb4598b2120598453c2cceec83986c2122#04a47feb4598b2120598453c2cceec83986c2122" +source = "git+https://github.com/mmtk/mmtk-core.git?rev=4873b4ab4016a2a5ef413463443856efa373e90c#4873b4ab4016a2a5ef413463443856efa373e90c" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/mmtk/Cargo.toml b/mmtk/Cargo.toml index 99244cd3..04e25c33 100644 --- a/mmtk/Cargo.toml +++ b/mmtk/Cargo.toml @@ -30,7 +30,7 @@ once_cell = "1.10.0" # - change branch # - change repo name # But other changes including adding/removing whitespaces in commented lines may break the CI. -mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "04a47feb4598b2120598453c2cceec83986c2122" } +mmtk = { git = "https://github.com/mmtk/mmtk-core.git", rev = "4873b4ab4016a2a5ef413463443856efa373e90c" } # Uncomment the following to build locally # mmtk = { path = "../repos/mmtk-core" } diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index 25fb34af..c0e8317d 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -290,6 +290,20 @@ pub extern "C" fn process(name: *const c_char, value: *const c_char) -> bool { ) } +/// Pass hotspot `ParallelGCThreads` flag to mmtk +#[no_mangle] +pub extern "C" fn mmtk_builder_set_threads(value: usize) { + let mut builder = BUILDER.lock().unwrap(); + builder.options.threads.set(value); +} + +/// Pass hotspot `UseTransparentHugePages` flag to mmtk +#[no_mangle] +pub extern "C" fn mmtk_builder_set_transparent_hugepages(value: bool) { + let mut builder = BUILDER.lock().unwrap(); + builder.options.transparent_hugepages.set(value); +} + #[no_mangle] // We trust the name/value pointer is valid. #[allow(clippy::not_unsafe_ptr_arg_deref)] diff --git a/openjdk/mmtk.h b/openjdk/mmtk.h index ab47acca..3dacf6a9 100644 --- a/openjdk/mmtk.h +++ b/openjdk/mmtk.h @@ -211,6 +211,9 @@ extern void add_phantom_candidate(void* ref, void* referent); extern void mmtk_harness_begin_impl(); extern void mmtk_harness_end_impl(); +extern void mmtk_builder_set_threads(size_t value); +extern void mmtk_builder_set_transparent_hugepages(bool value); + #ifdef __cplusplus } #endif diff --git a/openjdk/mmtkHeap.cpp b/openjdk/mmtkHeap.cpp index 4197f64d..eb6f4e2e 100644 --- a/openjdk/mmtkHeap.cpp +++ b/openjdk/mmtkHeap.cpp @@ -84,6 +84,8 @@ jint MMTkHeap::initialize() { // printf("policy max heap size %zu, min heap size %zu\n", heap_size, collector_policy()->min_heap_byte_size()); // Set options + mmtk_builder_set_threads(ParallelGCThreads); + mmtk_builder_set_transparent_hugepages(UseTransparentHugePages); if (ThirdPartyHeapOptions != NULL) { bool set_options = process_bulk(strdup(ThirdPartyHeapOptions)); guarantee(set_options, "Failed to set MMTk options. Please check if the options are valid: %s\n", ThirdPartyHeapOptions); diff --git a/openjdk/thirdPartyHeapArguments.cpp b/openjdk/thirdPartyHeapArguments.cpp index 745250df..326b646f 100644 --- a/openjdk/thirdPartyHeapArguments.cpp +++ b/openjdk/thirdPartyHeapArguments.cpp @@ -45,6 +45,12 @@ void ThirdPartyHeapArguments::initialize() { FLAG_SET_DEFAULT(UseTLAB, false); FLAG_SET_DEFAULT(UseCompressedOops, false); FLAG_SET_DEFAULT(UseCompressedClassPointers, false); + FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); + if (ParallelGCThreads == 0) { + assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "ParallelGCThreads should not be 0."); + vm_exit_during_initialization("The flag -XX:+UseUseThirdPartyHeap can not be combined with -XX:ParallelGCThreads=0", NULL); + } + } CollectedHeap* ThirdPartyHeapArguments::create_heap() { From 129c88905c39fb4167dd25ed299cc2abd8c09572 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Tue, 22 Aug 2023 12:29:51 +0800 Subject: [PATCH 11/11] Fix unaligned edge access (#232) We load/store edges using ptr::{read,write}_unaligned on x86 and x86_64 to workaround unaligned edges in code roots. --- mmtk/src/api.rs | 10 ++-- mmtk/src/edges.rs | 103 ++++++++++++++++++++++++++++++++++++ mmtk/src/gc_work.rs | 2 +- mmtk/src/lib.rs | 12 ++--- mmtk/src/object_scanning.rs | 10 ++-- mmtk/src/scanning.rs | 4 +- 6 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 mmtk/src/edges.rs diff --git a/mmtk/src/api.rs b/mmtk/src/api.rs index c0e8317d..58949a56 100644 --- a/mmtk/src/api.rs +++ b/mmtk/src/api.rs @@ -343,7 +343,7 @@ pub extern "C" fn mmtk_object_reference_write_pre( ) { mutator .barrier() - .object_reference_write_pre(src, slot, target); + .object_reference_write_pre(src, slot.into(), target); } /// Full post barrier @@ -356,7 +356,7 @@ pub extern "C" fn mmtk_object_reference_write_post( ) { mutator .barrier() - .object_reference_write_post(src, slot, target); + .object_reference_write_post(src, slot.into(), target); } /// Barrier slow-path call @@ -369,7 +369,7 @@ pub extern "C" fn mmtk_object_reference_write_slow( ) { mutator .barrier() - .object_reference_write_slow(src, slot, target); + .object_reference_write_slow(src, slot.into(), target); } /// Array-copy pre-barrier @@ -383,7 +383,7 @@ pub extern "C" fn mmtk_array_copy_pre( let bytes = count << LOG_BYTES_IN_ADDRESS; mutator .barrier() - .memory_region_copy_pre(src..src + bytes, dst..dst + bytes); + .memory_region_copy_pre((src..src + bytes).into(), (dst..dst + bytes).into()); } /// Array-copy post-barrier @@ -397,7 +397,7 @@ pub extern "C" fn mmtk_array_copy_post( let bytes = count << LOG_BYTES_IN_ADDRESS; mutator .barrier() - .memory_region_copy_post(src..src + bytes, dst..dst + bytes); + .memory_region_copy_post((src..src + bytes).into(), (dst..dst + bytes).into()); } /// C2 Slowpath allocation barrier diff --git a/mmtk/src/edges.rs b/mmtk/src/edges.rs new file mode 100644 index 00000000..44f666d1 --- /dev/null +++ b/mmtk/src/edges.rs @@ -0,0 +1,103 @@ +use std::ops::Range; + +use mmtk::{ + util::{Address, ObjectReference}, + vm::edge_shape::{AddressRangeIterator, Edge, MemorySlice}, +}; + +/// The type of edges in OpenJDK. +/// Currently it has the same layout as `Address`, but we override its load and store methods. +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[repr(transparent)] +pub struct OpenJDKEdge { + pub addr: Address, +} + +impl From
for OpenJDKEdge { + fn from(value: Address) -> Self { + Self { addr: value } + } +} + +impl Edge for OpenJDKEdge { + fn load(&self) -> ObjectReference { + if cfg!(any(target_arch = "x86", target_arch = "x86_64")) { + // Workaround: On x86 (including x86_64), machine instructions may contain pointers as + // immediates, and they may be unaligned. It is an undefined behavior in Rust to + // dereference unaligned pointers. We have to explicitly use unaligned memory access + // methods. On x86, ordinary MOV instructions can load and store memory at unaligned + // addresses, so we expect `ptr.read_unaligned()` to have no performance penalty over + // `ptr.read()` if `ptr` is actually aligned. + unsafe { + let ptr = self.addr.to_ptr::(); + ptr.read_unaligned() + } + } else { + unsafe { self.addr.load() } + } + } + + fn store(&self, object: ObjectReference) { + if cfg!(any(target_arch = "x86", target_arch = "x86_64")) { + unsafe { + let ptr = self.addr.to_mut_ptr::(); + ptr.write_unaligned(object) + } + } else { + unsafe { self.addr.store(object) } + } + } +} + +/// A range of OpenJDKEdge, usually used for arrays. +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub struct OpenJDKEdgeRange { + range: Range
, +} + +impl From> for OpenJDKEdgeRange { + fn from(value: Range
) -> Self { + Self { range: value } + } +} + +pub struct OpenJDKEdgeRangeIterator { + inner: AddressRangeIterator, +} + +impl Iterator for OpenJDKEdgeRangeIterator { + type Item = OpenJDKEdge; + + fn next(&mut self) -> Option { + self.inner.next().map(|a| a.into()) + } +} + +// Note that we cannot implement MemorySlice for `Range` because neither +// `MemorySlice` nor `Range` are defined in the `mmtk-openjdk` crate. ("orphan rule") +impl MemorySlice for OpenJDKEdgeRange { + type Edge = OpenJDKEdge; + type EdgeIterator = OpenJDKEdgeRangeIterator; + + fn iter_edges(&self) -> Self::EdgeIterator { + OpenJDKEdgeRangeIterator { + inner: self.range.iter_edges(), + } + } + + fn object(&self) -> Option { + self.range.object() + } + + fn start(&self) -> Address { + self.range.start() + } + + fn bytes(&self) -> usize { + self.range.bytes() + } + + fn copy(src: &Self, tgt: &Self) { + MemorySlice::copy(&src.range, &tgt.range) + } +} diff --git a/mmtk/src/gc_work.rs b/mmtk/src/gc_work.rs index 4273f9f7..b9496410 100644 --- a/mmtk/src/gc_work.rs +++ b/mmtk/src/gc_work.rs @@ -59,7 +59,7 @@ impl> GCWork for ScanCodeCacheRoots let mut edges = Vec::with_capacity(crate::CODE_CACHE_ROOTS_SIZE.load(Ordering::Relaxed)); for roots in (*crate::CODE_CACHE_ROOTS.lock().unwrap()).values() { for r in roots { - edges.push(*r) + edges.push((*r).into()) } } // Create work packet diff --git a/mmtk/src/lib.rs b/mmtk/src/lib.rs index 8c7bd9d9..7a4d9e2c 100644 --- a/mmtk/src/lib.rs +++ b/mmtk/src/lib.rs @@ -2,11 +2,11 @@ extern crate lazy_static; use std::collections::HashMap; -use std::ops::Range; use std::ptr::null_mut; use std::sync::atomic::AtomicUsize; use std::sync::Mutex; +use edges::{OpenJDKEdge, OpenJDKEdgeRange}; use libc::{c_char, c_void, uintptr_t}; use mmtk::util::alloc::AllocationError; use mmtk::util::opaque_pointer::*; @@ -19,6 +19,7 @@ pub mod active_plan; pub mod api; mod build_info; pub mod collection; +mod edges; mod gc_work; pub mod object_model; mod object_scanning; @@ -135,13 +136,6 @@ pub static FREE_LIST_ALLOCATOR_SIZE: uintptr_t = #[derive(Default)] pub struct OpenJDK; -/// The type of edges in OpenJDK. -/// -/// TODO: We currently make it an alias to Address to make the change minimal. -/// If we support CompressedOOPs, we should define an enum type to support both -/// compressed and uncompressed OOPs. -pub type OpenJDKEdge = Address; - impl VMBinding for OpenJDK { type VMObjectModel = object_model::VMObjectModel; type VMScanning = scanning::VMScanning; @@ -150,7 +144,7 @@ impl VMBinding for OpenJDK { type VMReferenceGlue = reference_glue::VMReferenceGlue; type VMEdge = OpenJDKEdge; - type VMMemorySlice = Range
; + type VMMemorySlice = OpenJDKEdgeRange; const MIN_ALIGNMENT: usize = 8; const MAX_ALIGNMENT: usize = 8; diff --git a/mmtk/src/object_scanning.rs b/mmtk/src/object_scanning.rs index 6ca17e7f..a738a934 100644 --- a/mmtk/src/object_scanning.rs +++ b/mmtk/src/object_scanning.rs @@ -16,7 +16,7 @@ impl OopIterate for OopMapBlock { fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) { let start = oop.get_field_address(self.offset); for i in 0..self.count as usize { - let edge = start + (i << LOG_BYTES_IN_ADDRESS); + let edge = (start + (i << LOG_BYTES_IN_ADDRESS)).into(); closure.visit_edge(edge); } } @@ -66,7 +66,7 @@ impl OopIterate for InstanceMirrorKlass { let len = Self::static_oop_field_count(oop); let slice = unsafe { slice::from_raw_parts(start, len as _) }; for oop in slice { - closure.visit_edge(Address::from_ref(oop as &Oop)); + closure.visit_edge(Address::from_ref(oop as &Oop).into()); } } } @@ -88,7 +88,7 @@ impl OopIterate for ObjArrayKlass { fn oop_iterate(&self, oop: Oop, closure: &mut impl EdgeVisitor) { let array = unsafe { oop.as_array_oop() }; for oop in unsafe { array.data::(BasicType::T_OBJECT) } { - closure.visit_edge(Address::from_ref(oop as &Oop)); + closure.visit_edge(Address::from_ref(oop as &Oop).into()); } } } @@ -133,9 +133,9 @@ impl InstanceRefKlass { } fn process_ref_as_strong(oop: Oop, closure: &mut impl EdgeVisitor) { let referent_addr = Self::referent_address(oop); - closure.visit_edge(referent_addr); + closure.visit_edge(referent_addr.into()); let discovered_addr = Self::discovered_address(oop); - closure.visit_edge(discovered_addr); + closure.visit_edge(discovered_addr.into()); } } diff --git a/mmtk/src/scanning.rs b/mmtk/src/scanning.rs index 9d6955d1..d92d5dcd 100644 --- a/mmtk/src/scanning.rs +++ b/mmtk/src/scanning.rs @@ -20,7 +20,9 @@ extern "C" fn report_edges_and_renew_buffer>( factory_ptr: *mut libc::c_void, ) -> NewBuffer { if !ptr.is_null() { - let buf = unsafe { Vec::
::from_raw_parts(ptr, length, capacity) }; + // Note: Currently OpenJDKEdge has the same layout as Address. If the layout changes, we + // should fix the Rust-to-C interface. + let buf = unsafe { Vec::::from_raw_parts(ptr as _, length, capacity) }; let factory: &mut F = unsafe { &mut *(factory_ptr as *mut F) }; factory.create_process_edge_roots_work(buf); }