Skip to content

Commit

Permalink
Inline runtime alloc (#79)
Browse files Browse the repository at this point in the history
This PR updates to mmtk/julia#23 and uses the runtime allocation fastpath.
  • Loading branch information
qinsoon authored Jul 27, 2023
1 parent c8fb2d9 commit 6ec08d5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .github/scripts/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ if [ "$build_type" == "release" ]; then
build_args=$build_args" --release"
fi

plan_feature=${plan,,}

cd $MMTK_JULIA_DIR/mmtk
cargo build --features $plan $build_args
cargo build --features $plan_feature $build_args

cd $JULIA_PATH

# Clean first
make cleanall
# Build
cp $BINDING_PATH/.github/scripts/Make.user $JULIA_PATH/
MMTK_BUILD=$build_type make
MMTK_PLAN=$plan MMTK_BUILD=$build_type make
# Run hello world
$JULIA_PATH/julia $HELLO_WORLD_JL
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
gc_plan: [immix, stickyimmix]
gc_plan: [Immix, StickyImmix]
uses: ./.github/workflows/binding-tests.yml
with:
gc_plan: ${{ matrix.gc_plan }}
9 changes: 4 additions & 5 deletions julia/mmtk_julia.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "mmtk_julia.h"
#include "mmtk.h"
#include "mmtkMutator.h"
#include <stdbool.h>
#include <stddef.h>
#include "gc.h"
Expand Down Expand Up @@ -46,16 +45,16 @@ JL_DLLEXPORT jl_value_t *jl_mmtk_gc_alloc_default(jl_ptls_t ptls, int pool_offse
jl_value_t *v;
if ((uintptr_t)ty != jl_buff_tag) {
// v needs to be 16 byte aligned, therefore v_tagged needs to be offset accordingly to consider the size of header
jl_taggedvalue_t *v_tagged = (jl_taggedvalue_t *)mmtk_alloc(&ptls->mmtk_mutator, osize, 16, sizeof(jl_taggedvalue_t), 0);
jl_taggedvalue_t *v_tagged = (jl_taggedvalue_t *)mmtk_immix_alloc_fast(&ptls->mmtk_mutator, osize, 16, sizeof(jl_taggedvalue_t));
v = jl_valueof(v_tagged);
mmtk_post_alloc(&ptls->mmtk_mutator, v, osize, 0);
mmtk_immix_post_alloc_fast(&ptls->mmtk_mutator, v, osize);
} else {
// allocating an extra word to store the size of buffer objects
jl_taggedvalue_t *v_tagged = (jl_taggedvalue_t *)mmtk_alloc(&ptls->mmtk_mutator, osize + sizeof(jl_taggedvalue_t), 16, 0, 0);
jl_taggedvalue_t *v_tagged = (jl_taggedvalue_t *)mmtk_immix_alloc_fast(&ptls->mmtk_mutator, osize + sizeof(jl_taggedvalue_t), 16, 0);
jl_value_t* v_tagged_aligned = ((jl_value_t*)((char*)(v_tagged) + sizeof(jl_taggedvalue_t)));
v = jl_valueof(v_tagged_aligned);
mmtk_store_obj_size_c(v, osize + sizeof(jl_taggedvalue_t));
mmtk_post_alloc(&ptls->mmtk_mutator, v, osize + sizeof(jl_taggedvalue_t), 0);
mmtk_immix_post_alloc_fast(&ptls->mmtk_mutator, v, osize + sizeof(jl_taggedvalue_t));
}

ptls->gc_num.allocd += osize;
Expand Down
6 changes: 0 additions & 6 deletions julia/mmtk_julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
extern Julia_Upcalls mmtk_upcalls;

int get_jl_last_err(void);

void set_jl_last_err(int e);

void set_gc_final_state(int8_t old_state);

int set_gc_running_state(jl_ptls_t ptls);

void set_gc_old_state(int8_t old_state);

void mmtk_jl_gc_run_all_finalizers(void);

void mmtk_jl_run_pending_finalizers(void* tls);
2 changes: 1 addition & 1 deletion mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2018"
[package.metadata.julia]
# Our CI matches the following line and extract mmtk/julia. If this line is updated, please check ci yaml files and make sure it works.
julia_repo = "https://github.com/mmtk/julia.git"
julia_version = "f690aa3a5621bfa1d6a07f911818f203d3f8d650"
julia_version = "73411572e118d7cfd0110da46663b34cb82eb520"

[lib]
crate-type = ["cdylib"]
Expand Down
3 changes: 0 additions & 3 deletions mmtk/api/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ extern void mmtk_immortal_region_post_alloc(void* addr, size_t size);
extern void mmtk_memory_region_copy(MMTk_Mutator mutator, void* src_obj, void* src_addr, void* dst_obj, void* dst_addr, size_t size);
extern void mmtk_object_reference_write_post(MMTk_Mutator mutator, const void* src, const void* target);
extern void mmtk_object_reference_write_slow(MMTk_Mutator mutator, const void* src, const void* target);
extern const uint8_t MMTK_NEEDS_WRITE_BARRIER;
extern const uint8_t MMTK_NO_BARRIER;
extern const uint8_t MMTK_OBJECT_BARRIER;
extern const void* MMTK_SIDE_LOG_BIT_BASE_ADDRESS;

extern uintptr_t JULIA_MALLOC_BYTES;
Expand Down
37 changes: 24 additions & 13 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ pub extern "C" fn mmtk_gc_init(
assert!(!crate::MMTK_INITIALIZED.load(Ordering::SeqCst));
// Make sure we initialize MMTk here
lazy_static::initialize(&SINGLETON);

// Assert to make sure our fastpath allocation is correct.
{
// If the assertion failed, check the allocation fastpath in Julia
// - runtime fastpath: mmtk_immix_alloc_fast and mmtk_immortal_alloc_fast in julia.h
// - compiler inserted fastpath: llvm-final-gc-lowering.cpp
use mmtk::util::alloc::AllocatorSelector;
let default_allocator = memory_manager::get_allocator_mapping::<JuliaVM>(
&SINGLETON,
AllocationSemantics::Default,
);
assert_eq!(default_allocator, AllocatorSelector::Immix(0));
let immortal_allocator = memory_manager::get_allocator_mapping::<JuliaVM>(
&SINGLETON,
AllocationSemantics::Immortal,
);
assert_eq!(immortal_allocator, AllocatorSelector::BumpPointer(0));
}

// Assert to make sure alignment used in C is correct
{
// If the assertion failed, check MMTK_MIN_ALIGNMENT in julia.h
assert_eq!(<JuliaVM as mmtk::vm::VMBinding>::MIN_ALIGNMENT, 4);
}
}

#[no_mangle]
Expand Down Expand Up @@ -447,19 +471,6 @@ pub extern "C" fn mmtk_object_reference_write_slow(
pub static MMTK_SIDE_LOG_BIT_BASE_ADDRESS: Address =
mmtk::util::metadata::side_metadata::GLOBAL_SIDE_METADATA_VM_BASE_ADDRESS;

#[no_mangle]
pub static MMTK_NO_BARRIER: u8 = 0;
#[no_mangle]
pub static MMTK_OBJECT_BARRIER: u8 = 1;

#[no_mangle]
#[cfg(feature = "immix")]
pub static MMTK_NEEDS_WRITE_BARRIER: u8 = 0;

#[no_mangle]
#[cfg(feature = "stickyimmix")]
pub static MMTK_NEEDS_WRITE_BARRIER: u8 = 1;

#[no_mangle]
pub extern "C" fn mmtk_object_is_managed_by_mmtk(addr: usize) -> bool {
crate::api::mmtk_is_mapped_address(unsafe { Address::from_usize(addr) })
Expand Down

0 comments on commit 6ec08d5

Please sign in to comment.