Skip to content

Commit

Permalink
Cleaning up full_sweep_reasons function and making it stock-specific;…
Browse files Browse the repository at this point in the history
… Adding _Atomic() to mmtk's tls malloc counter
  • Loading branch information
udesou committed Dec 9, 2024
1 parent 4ea1782 commit 4c940c1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
15 changes: 11 additions & 4 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ function gc_page_utilization_data()
return Base.unsafe_wrap(Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own=false)
end

# Full sweep reasons are currently only available for the stock GC
@static if occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
# must be kept in sync with `src/gc-stock.h``
const FULL_SWEEP_REASONS = [:FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL, :FULL_SWEEP_REASON_FORCED_FULL_SWEEP,
:FULL_SWEEP_REASON_USER_MAX_EXCEEDED, :FULL_SWEEP_REASON_LARGE_PROMOTION_RATE]
end

"""
Base.full_sweep_reasons()
Expand All @@ -124,11 +127,15 @@ The reasons are:
Note that the set of reasons is not guaranteed to be stable across minor versions of Julia.
"""
function full_sweep_reasons()
reason = cglobal(:jl_full_sweep_reasons, UInt64)
reasons_as_array = Base.unsafe_wrap(Vector{UInt64}, reason, length(FULL_SWEEP_REASONS), own=false)
d = Dict{Symbol, Int64}()
for (i, r) in enumerate(FULL_SWEEP_REASONS)
d[r] = reasons_as_array[i]
# populate the dictionary according to the reasons above for the stock GC
# otherwise return an empty dictionary for now
@static if occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
reason = cglobal(:jl_full_sweep_reasons, UInt64)
reasons_as_array = Base.unsafe_wrap(Vector{UInt64}, reason, length(FULL_SWEEP_REASONS), own=false)
for (i, r) in enumerate(FULL_SWEEP_REASONS)
d[r] = reasons_as_array[i]
end
end
return d
end
Expand Down
6 changes: 2 additions & 4 deletions src/gc-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ JL_DLLEXPORT int gc_is_collector_thread(int tid) JL_NOTSAFEPOINT;
// Returns which GC implementation is being used and possibly its version according to the list of supported GCs
// NB: it should clearly identify the GC by including e.g. ‘stock’ or ‘mmtk’ as a substring.
JL_DLLEXPORT const char* jl_gc_active_impl(void);
// Sweep Julia's stack pools and mtarray buffers. Note that this function has been added to the interface since
// each GC should implement this but this function will most likely not be used by other code in the runtime.
// Sweep Julia's stack pools and mtarray buffers. Note that this function has been added to the interface as
// each GC should implement it but it will most likely not be used by other code in the runtime.
// It still needs to be annotated with JL_DLLEXPORT since it is called from Rust by MMTk.
JL_DLLEXPORT void jl_gc_sweep_stack_pools_and_mtarraylist_buffers(jl_ptls_t ptls) JL_NOTSAFEPOINT;

Expand Down Expand Up @@ -145,7 +145,6 @@ JL_DLLEXPORT uint64_t jl_gc_total_hrtime(void);
// **must** also set the type of the returning object to be `ty`. The type `ty` may also be used to record
// an allocation of that type in the allocation profiler.
struct _jl_value_t *jl_gc_alloc_(struct _jl_tls_states_t * ptls, size_t sz, void *ty);

// Allocates small objects and increments Julia allocation counterst. Size of the object
// header must be included in the object size. The (possibly unused in some implementations)
// offset to the arena in which we're allocating is passed in the second parameter, and the
Expand Down Expand Up @@ -205,7 +204,6 @@ JL_DLLEXPORT void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align,
// the allocated object. All objects stored in fields of this object
// must be either permanently allocated or have other roots.
struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT;

// This function notifies the GC about memory addresses that are set when loading the boot image.
// The GC may use that information to, for instance, determine that such objects should
// be treated as marked and belonged to the old generation in nursery collections.
Expand Down
14 changes: 1 addition & 13 deletions src/gc-mmtk.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "gc-common.h"
#include "gc-tls-mmtk.h"
#include "mmtkMutator.h"
#include "threading.h"

Expand All @@ -17,19 +18,6 @@ extern jl_value_t *cmpswap_names JL_GLOBALLY_ROOTED;
extern const unsigned pool_sizes[];
extern jl_mutex_t finalizers_lock;

// FIXME: Does it make sense for MMTk to implement something similar
// for now, just ignoring this.

// Must be kept in sync with `base/timing.jl`
#define FULL_SWEEP_REASON_SWEEP_ALWAYS_FULL (0)
#define FULL_SWEEP_REASON_FORCED_FULL_SWEEP (1)
#define FULL_SWEEP_REASON_USER_MAX_EXCEEDED (2)
#define FULL_SWEEP_REASON_LARGE_PROMOTION_RATE (3)
#define FULL_SWEEP_NUM_REASONS (4)

// Table recording number of full GCs due to each reason
JL_DLLEXPORT uint64_t jl_full_sweep_reasons[FULL_SWEEP_NUM_REASONS];

// FIXME: Should the values below be shared between both GC's?
// Note that MMTk uses a hard max heap limit, which is set by default
// as 70% of the free available memory. The min heap is set as the
Expand Down
8 changes: 7 additions & 1 deletion src/gc-tls-mmtk.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#ifndef JL_GC_TLS_H
#define JL_GC_TLS_H

#include <assert.h>
#include "mmtkMutator.h"
#include "julia_atomics.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
MMTkMutatorContext mmtk_mutator;
size_t malloc_sz_since_last_poll;
_Atomic(size_t) malloc_sz_since_last_poll;
} jl_gc_tls_states_t;

#ifdef __cplusplus
}
#endif

#endif // JL_GC_TLS_H

0 comments on commit 4c940c1

Please sign in to comment.