Skip to content

Fixing the binding to apply the changes from Julia's PR #57625 #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/Make.user
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FORCE_ASSERTIONS=1
LLVM_ASSERTIONS=1
USE_BINARYBUILDER_MMTK_JULIA=0
WITH_THIRD_PARTY_GC=mmtk
5 changes: 5 additions & 0 deletions .github/scripts/ci-test-LinearAlgebra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ set -e

. $(dirname "$0")/common.sh

# plan to use
plan=$1

export MMTK_PLAN=$plan

export MMTK_MAX_HSIZE_G=8
total_mem=$(free -m | awk '/^Mem:/ {print $2}')
mem_threshold=512 # use 0.5Gb as a threshold for the max rss based on the total free memory
Expand Down
11 changes: 11 additions & 0 deletions .github/scripts/ci-test-other.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ set -xe

. $(dirname "$0")/common.sh

# plan to use
plan=$1

export MMTK_PLAN=$plan

# Get all the tests
CHOOSE_TESTS_JL_PATH=$JULIA_PATH/test/choosetests.jl
CHOOSE_TESTS_JL_CONTENT=`cat $CHOOSE_TESTS_JL_PATH`
Expand All @@ -28,6 +33,12 @@ if [[ $CHOOSE_TESTS_JL_CONTENT =~ $REGEX_PATTERN ]]; then
continue
fi

if [[ $test =~ "compiler_extras" ]]; then
# Skipping compiler_extras for now
echo "-> Skip compiler_extras"
continue
fi

echo "-> Run"
ci_run_jl_test $test
fi
Expand Down
4 changes: 3 additions & 1 deletion .github/scripts/ci-test-patching.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ declare -a tests_to_skip=(
'@test contains(sshot, "redact_this")' "$JULIA_PATH/stdlib/Profile/test/runtests.jl"

# This test checks GC logging
'@test occursin("GC: pause", read(tmppath, String))' "$JULIA_PATH/test/misc.jl"
'@test !isempty(test_complete("?("))' "$JULIA_PATH/stdlib/REPL/test/replcompletions.jl"

# This test seems to be failing in the new version of Julia
'@test occursin("int.jl", code)' "$JULIA_PATH/test/cmdlineargs.jl"
# These tests check for the number of stock GC threads (which we set to 0 with mmtk)
'@test (cpu_threads == 1 ? "1" : string(div(cpu_threads, 2))) ==' "$JULIA_PATH/test/cmdlineargs.jl"
'@test read(`$exename --gcthreads=2 -e $code`, String) == "2"' "$JULIA_PATH/test/cmdlineargs.jl"
Expand Down
5 changes: 5 additions & 0 deletions .github/scripts/ci-test-stdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ set -e

. $(dirname "$0")/common.sh

# plan to use
plan=$1

export MMTK_PLAN=$plan

# These tests seem to fail. We skip them.
declare -a tests_to_skip=(
# Test Failed at /home/runner/work/mmtk-julia/mmtk-julia/vm/julia/usr/share/julia/stdlib/v1.8/Dates/test/io.jl:45
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cur=$(realpath $(dirname "$0"))
cd $cur
./ci-build.sh release Immix

export MMTK_PLAN=Immix

# Use release build to run tests
cd $cur
./ci-test-gc-core.sh
6 changes: 3 additions & 3 deletions .github/workflows/binding-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
$JULIA_PATH/julia --project=. -e "using InteractiveUtils; versioninfo()"
- name: Test Julia
run: |
./.github/scripts/ci-test-other.sh
./.github/scripts/ci-test-other.sh ${{ inputs.gc_plan }}

build-test-stdlib:
runs-on: ubuntu-22.04
Expand All @@ -135,7 +135,7 @@ jobs:
$JULIA_PATH/julia --project=. -e "using InteractiveUtils; versioninfo()"
- name: Test Julia
run: |
./.github/scripts/ci-test-stdlib.sh
./.github/scripts/ci-test-stdlib.sh ${{ inputs.gc_plan }}

build-test-LinearAlgebra:
runs-on: ubuntu-22.04
Expand All @@ -158,4 +158,4 @@ jobs:
$JULIA_PATH/julia --project=. -e "using InteractiveUtils; versioninfo()"
- name: Test Julia
run: |
./.github/scripts/ci-test-LinearAlgebra.sh
./.github/scripts/ci-test-LinearAlgebra.sh ${{ inputs.gc_plan }}
4 changes: 3 additions & 1 deletion mmtk/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ fn main() {
.clang_arg("c++")
.clang_arg("-std=c++14")
// using MMTK types
.clang_arg("-DMMTK_GC")
.clang_arg("-DWITH_THIRD_PARTY_HEAP=1")
// using sticky, but it should not matter for the FFI bindings
.clang_arg("-DMMTK_PLAN_STICKYIMMIX")
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
Expand Down
36 changes: 6 additions & 30 deletions mmtk/src/julia_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
}
process_slot(closure, Address::from_ptr(usings_backeges_slot));

let scanned_methods_slot = ::std::ptr::addr_of!((*m).scanned_methods);
if PRINT_OBJ_TYPE {
println!(" - scan parent: {:?}\n", scanned_methods_slot);
}
process_slot(closure, Address::from_ptr(scanned_methods_slot));

// m.usings.items may be inlined in the module when the array list size <= AL_N_INLINE (cf. arraylist_new)
// In that case it may be an mmtk object and not a malloced address.
// If it is an mmtk object, (*m).usings.items will then be an internal pointer to the module
Expand Down Expand Up @@ -317,15 +323,6 @@ pub unsafe fn scan_julia_object<SV: SlotVisitor<JuliaVMSlot>>(obj: Address, clos
let layout = (*vt).layout;
let npointers = (*layout).npointers;
if npointers != 0 {
if vt == jl_binding_partition_type {
let bpart_ptr = obj.to_mut_ptr::<jl_binding_partition_t>();
let restriction = (*bpart_ptr).restriction._M_i;
let offset = mmtk_decode_restriction_value(restriction);
let slot = Address::from_ptr(::std::ptr::addr_of!((*bpart_ptr).restriction));
if restriction - offset != 0 {
process_offset_slot(closure, slot, offset);
}
}
debug_assert!(
(*layout).nfields > 0 && (*layout).fielddesc_type_custom() != 3,
"opaque types should have been handled specially"
Expand Down Expand Up @@ -526,27 +523,6 @@ pub fn process_slot<EV: SlotVisitor<JuliaVMSlot>>(closure: &mut EV, slot: Addres
closure.visit_slot(JuliaVMSlot::Simple(simple_slot));
}

// This is based on the function decode_restriction_value from julia_internal.h.
// However, since MMTk uses the slot to load the object, we get the offset from pku using
// that offset to pass to process_offset_edge and get the right address.
#[inline(always)]
pub fn mmtk_decode_restriction_value(pku: usize) -> usize {
#[cfg(target_pointer_width = "64")]
{
// need to apply (pku & ~0x7) to get the object to be traced
// so we use (pku & 0x7) to get the offset from the object
// and pass it to process_offset_slot
pku & 0x7
}

#[cfg(not(target_pointer_width = "64"))]
{
// when not #ifdef _P64 we simply return pku.val
// i.e., the offset is 0, since val is the first field
0
}
}

#[inline(always)]
pub fn process_offset_slot<EV: SlotVisitor<JuliaVMSlot>>(
closure: &mut EV,
Expand Down
72 changes: 39 additions & 33 deletions mmtk/src/julia_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ const _: () = {
pub type sigjmp_buf = [__jmp_buf_tag; 1usize];
pub type jl_taggedvalue_t = _jl_taggedvalue_t;
pub type jl_ptls_t = *mut _jl_tls_states_t;
pub type jl_genericmemory_t = _jl_genericmemory_t;
pub type sig_atomic_t = __sig_atomic_t;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _jl_value_t {
_unused: [u8; 0],
}
pub type sig_atomic_t = __sig_atomic_t;
pub type jl_value_t = _jl_value_t;
#[repr(C)]
#[repr(align(8))]
Expand Down Expand Up @@ -930,18 +931,18 @@ const _: () = {
};
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct jl_genericmemory_t {
pub struct _jl_genericmemory_t {
pub length: usize,
pub ptr: *mut ::std::os::raw::c_void,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of jl_genericmemory_t"][::std::mem::size_of::<jl_genericmemory_t>() - 16usize];
["Alignment of jl_genericmemory_t"][::std::mem::align_of::<jl_genericmemory_t>() - 8usize];
["Offset of field: jl_genericmemory_t::length"]
[::std::mem::offset_of!(jl_genericmemory_t, length) - 0usize];
["Offset of field: jl_genericmemory_t::ptr"]
[::std::mem::offset_of!(jl_genericmemory_t, ptr) - 8usize];
["Size of _jl_genericmemory_t"][::std::mem::size_of::<_jl_genericmemory_t>() - 16usize];
["Alignment of _jl_genericmemory_t"][::std::mem::align_of::<_jl_genericmemory_t>() - 8usize];
["Offset of field: _jl_genericmemory_t::length"]
[::std::mem::offset_of!(_jl_genericmemory_t, length) - 0usize];
["Offset of field: _jl_genericmemory_t::ptr"]
[::std::mem::offset_of!(_jl_genericmemory_t, ptr) - 8usize];
};
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -1936,15 +1937,14 @@ const _: () = {
[::std::mem::offset_of!(_jl_weakref_t, value) - 0usize];
};
pub type jl_weakref_t = _jl_weakref_t;
pub type jl_ptr_kind_union_t = usize;
#[repr(C)]
#[derive(Debug)]
pub struct _jl_binding_partition_t {
pub restriction: std_atomic<jl_ptr_kind_union_t>,
pub restriction: *mut jl_value_t,
pub min_world: usize,
pub max_world: std_atomic<usize>,
pub next: u64,
pub reserved: usize,
pub kind: usize,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
Expand All @@ -1959,8 +1959,8 @@ const _: () = {
[::std::mem::offset_of!(_jl_binding_partition_t, max_world) - 16usize];
["Offset of field: _jl_binding_partition_t::next"]
[::std::mem::offset_of!(_jl_binding_partition_t, next) - 24usize];
["Offset of field: _jl_binding_partition_t::reserved"]
[::std::mem::offset_of!(_jl_binding_partition_t, reserved) - 32usize];
["Offset of field: _jl_binding_partition_t::kind"]
[::std::mem::offset_of!(_jl_binding_partition_t, kind) - 32usize];
};
pub type jl_binding_partition_t = _jl_binding_partition_t;
#[repr(C)]
Expand All @@ -1986,6 +1986,7 @@ pub struct _jl_module_t {
pub file: *mut jl_sym_t,
pub line: i32,
pub usings_backedges: *mut jl_value_t,
pub scanned_methods: *mut jl_value_t,
pub usings: arraylist_t,
pub build_id: jl_uuid_t,
pub uuid: jl_uuid_t,
Expand All @@ -1996,12 +1997,13 @@ pub struct _jl_module_t {
pub infer: i8,
pub istopmod: u8,
pub max_methods: i8,
pub export_set_changed_since_require_world: std_atomic<i8>,
pub lock: jl_mutex_t,
pub hash: isize,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of _jl_module_t"][::std::mem::size_of::<_jl_module_t>() - 384usize];
["Size of _jl_module_t"][::std::mem::size_of::<_jl_module_t>() - 392usize];
["Alignment of _jl_module_t"][::std::mem::align_of::<_jl_module_t>() - 8usize];
["Offset of field: _jl_module_t::name"][::std::mem::offset_of!(_jl_module_t, name) - 0usize];
["Offset of field: _jl_module_t::parent"]
Expand All @@ -2014,27 +2016,31 @@ const _: () = {
["Offset of field: _jl_module_t::line"][::std::mem::offset_of!(_jl_module_t, line) - 40usize];
["Offset of field: _jl_module_t::usings_backedges"]
[::std::mem::offset_of!(_jl_module_t, usings_backedges) - 48usize];
["Offset of field: _jl_module_t::scanned_methods"]
[::std::mem::offset_of!(_jl_module_t, scanned_methods) - 56usize];
["Offset of field: _jl_module_t::usings"]
[::std::mem::offset_of!(_jl_module_t, usings) - 56usize];
[::std::mem::offset_of!(_jl_module_t, usings) - 64usize];
["Offset of field: _jl_module_t::build_id"]
[::std::mem::offset_of!(_jl_module_t, build_id) - 312usize];
["Offset of field: _jl_module_t::uuid"][::std::mem::offset_of!(_jl_module_t, uuid) - 328usize];
[::std::mem::offset_of!(_jl_module_t, build_id) - 320usize];
["Offset of field: _jl_module_t::uuid"][::std::mem::offset_of!(_jl_module_t, uuid) - 336usize];
["Offset of field: _jl_module_t::counter"]
[::std::mem::offset_of!(_jl_module_t, counter) - 344usize];
[::std::mem::offset_of!(_jl_module_t, counter) - 352usize];
["Offset of field: _jl_module_t::nospecialize"]
[::std::mem::offset_of!(_jl_module_t, nospecialize) - 348usize];
[::std::mem::offset_of!(_jl_module_t, nospecialize) - 356usize];
["Offset of field: _jl_module_t::optlevel"]
[::std::mem::offset_of!(_jl_module_t, optlevel) - 352usize];
[::std::mem::offset_of!(_jl_module_t, optlevel) - 360usize];
["Offset of field: _jl_module_t::compile"]
[::std::mem::offset_of!(_jl_module_t, compile) - 353usize];
[::std::mem::offset_of!(_jl_module_t, compile) - 361usize];
["Offset of field: _jl_module_t::infer"]
[::std::mem::offset_of!(_jl_module_t, infer) - 354usize];
[::std::mem::offset_of!(_jl_module_t, infer) - 362usize];
["Offset of field: _jl_module_t::istopmod"]
[::std::mem::offset_of!(_jl_module_t, istopmod) - 355usize];
[::std::mem::offset_of!(_jl_module_t, istopmod) - 363usize];
["Offset of field: _jl_module_t::max_methods"]
[::std::mem::offset_of!(_jl_module_t, max_methods) - 356usize];
["Offset of field: _jl_module_t::lock"][::std::mem::offset_of!(_jl_module_t, lock) - 360usize];
["Offset of field: _jl_module_t::hash"][::std::mem::offset_of!(_jl_module_t, hash) - 376usize];
[::std::mem::offset_of!(_jl_module_t, max_methods) - 364usize];
["Offset of field: _jl_module_t::export_set_changed_since_require_world"]
[::std::mem::offset_of!(_jl_module_t, export_set_changed_since_require_world) - 365usize];
["Offset of field: _jl_module_t::lock"][::std::mem::offset_of!(_jl_module_t, lock) - 368usize];
["Offset of field: _jl_module_t::hash"][::std::mem::offset_of!(_jl_module_t, hash) - 384usize];
};
pub type jl_module_t = _jl_module_t;
#[repr(C)]
Expand Down Expand Up @@ -2340,13 +2346,6 @@ const _: () = {
[::std::mem::align_of::<std_atomic<i16>>() - 2usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of template specialization: std_atomic_open0_jl_ptr_kind_union_t_close0"]
[::std::mem::size_of::<std_atomic<jl_ptr_kind_union_t>>() - 8usize];
["Align of template specialization: std_atomic_open0_jl_ptr_kind_union_t_close0"]
[::std::mem::align_of::<std_atomic<jl_ptr_kind_union_t>>() - 8usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of template specialization: std_atomic_open0_size_t_close0"]
[::std::mem::size_of::<std_atomic<usize>>() - 8usize];
Expand All @@ -2361,6 +2360,13 @@ const _: () = {
[::std::mem::align_of::<std_atomic<u32>>() - 4usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of template specialization: std_atomic_open0_int8_t_close0"]
[::std::mem::size_of::<std_atomic<i8>>() - 1usize];
["Align of template specialization: std_atomic_open0_int8_t_close0"]
[::std::mem::align_of::<std_atomic<i8>>() - 1usize];
};
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of template specialization: std_atomic_open0_intptr_t_close0"]
[::std::mem::size_of::<std_atomic<isize>>() - 8usize];
Expand Down