Skip to content

Commit

Permalink
Merge branch 'master' into refactor-pre-mmtk
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou authored Aug 29, 2024
2 parents 975132d + a732dc3 commit 6b4d608
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 61 deletions.
2 changes: 2 additions & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ end
end
@inline checkindex(::Type{Bool}, inds::Tuple, I::CartesianIndex) =
checkbounds_indices(Bool, inds, I.I)
@inline checkindex(::Type{Bool}, inds::Tuple, i::AbstractRange{<:CartesianIndex}) =
isempty(i) | (checkindex(Bool, inds, first(i)) & checkindex(Bool, inds, last(i)))

# Indexing into Array with mixtures of Integers and CartesianIndices is
# extremely performance-sensitive. While the abstract fallbacks support this,
Expand Down
2 changes: 1 addition & 1 deletion cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
(*jl_codegen_exported_func_addrs[symbol_idx]) = addr;
}
// Next, if we're on Linux/FreeBSD, set up fast TLS.
#if !defined(_OS_WINDOWS_) && !defined(_OS_DARWIN_) && !defined(_OS_OPENBSD_)
#if !defined(_OS_WINDOWS_) && !defined(_OS_OPENBSD_)
void (*jl_pgcstack_setkey)(void*, void*(*)(void)) = lookup_symbol(libjulia_internal, "jl_pgcstack_setkey");
if (jl_pgcstack_setkey == NULL) {
jl_loader_print_stderr("ERROR: Cannot find jl_pgcstack_setkey() function within libjulia-internal!\n");
Expand Down
2 changes: 1 addition & 1 deletion doc/man/julia.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
julia - a high-level, high-performance dynamic programming language for technical computing

.SH SYNOPSIS
\fBjulia\fR [OPTIONS...] \fB--\fR [PROGRAMMFILE] [ARGS...]
\fBjulia\fR [OPTIONS...] \fB--\fR [PROGRAMFILE] [ARGS...]

If a Julia source file is given as a \fIPROGRAMFILE\fP (optionally followed by
arguments in \fIARGS\fP) Julia will execute the program and exit.
Expand Down
2 changes: 1 addition & 1 deletion src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ jl_code_instance_t *jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_
jl_value_t *ci = cgparams.lookup(mi, world, world);
JL_GC_PROMISE_ROOTED(ci);
jl_code_instance_t *codeinst = NULL;
if (ci != jl_nothing) {
if (ci != jl_nothing && jl_atomic_load_relaxed(&((jl_code_instance_t *)ci)->inferred) != jl_nothing) {
codeinst = (jl_code_instance_t*)ci;
}
else {
Expand Down
7 changes: 1 addition & 6 deletions src/julia_fasttls.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ extern "C" {

typedef struct _jl_gcframe_t jl_gcframe_t;

#if defined(_OS_DARWIN_)
#include <pthread.h>
typedef void *(jl_get_pgcstack_func)(pthread_key_t); // aka typeof(pthread_getspecific)
#else
typedef jl_gcframe_t **(jl_get_pgcstack_func)(void);
#endif

#if !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
#if !defined(_OS_WINDOWS_)
#define JULIA_DEFINE_FAST_TLS \
static __attribute__((tls_model("local-exec"))) __thread jl_gcframe_t **jl_pgcstack_localexec; \
JL_DLLEXPORT _Atomic(char) jl_pgcstack_static_semaphore; \
Expand Down
4 changes: 1 addition & 3 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,7 @@ int jl_safepoint_consume_sigint(void);
void jl_wake_libuv(void) JL_NOTSAFEPOINT;

void jl_set_pgcstack(jl_gcframe_t **) JL_NOTSAFEPOINT;
#if defined(_OS_DARWIN_)
typedef pthread_key_t jl_pgcstack_key_t;
#elif defined(_OS_WINDOWS_)
#if defined(_OS_WINDOWS_)
typedef DWORD jl_pgcstack_key_t;
#else
typedef jl_gcframe_t ***(*jl_pgcstack_key_t)(void) JL_NOTSAFEPOINT;
Expand Down
1 change: 1 addition & 0 deletions src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,7 @@ size_t jl_static_show_func_sig_(JL_STREAM *s, jl_value_t *type, jl_static_show_c
return n;
}
if ((jl_nparams(ftype) == 0 || ftype == ((jl_datatype_t*)ftype)->name->wrapper) &&
((jl_datatype_t*)ftype)->name->mt &&
((jl_datatype_t*)ftype)->name->mt != jl_type_type_mt &&
((jl_datatype_t*)ftype)->name->mt != jl_nonfunction_mt) {
n += jl_static_show_symbol(s, ((jl_datatype_t*)ftype)->name->mt->name);
Expand Down
15 changes: 9 additions & 6 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ static void wake_libuv(void) JL_NOTSAFEPOINT
JULIA_DEBUG_SLEEPWAKE( io_wakeup_leave = cycleclock() );
}

/* ensure thread tid is awake if necessary */
JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) JL_NOTSAFEPOINT
{
jl_task_t *ct = jl_current_task;
void wakeup_thread(jl_task_t *ct, int16_t tid) JL_NOTSAFEPOINT { // Pass in ptls when we have it already available to save a lookup
int16_t self = jl_atomic_load_relaxed(&ct->tid);
if (tid != self)
jl_fence(); // [^store_buffering_1]
Expand Down Expand Up @@ -307,6 +304,12 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) JL_NOTSAFEPOINT
JULIA_DEBUG_SLEEPWAKE( wakeup_leave = cycleclock() );
}

/* ensure thread tid is awake if necessary */
JL_DLLEXPORT void jl_wakeup_thread(int16_t tid) JL_NOTSAFEPOINT
{
jl_task_t *ct = jl_current_task;
wakeup_thread(ct, tid);
}

// get the next runnable task
static jl_task_t *get_next_task(jl_value_t *trypoptask, jl_value_t *q)
Expand Down Expand Up @@ -443,7 +446,7 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *trypoptask, jl_value_t *q,
// responsibility, so need to make sure thread 0 will take care
// of us.
if (jl_atomic_load_relaxed(&jl_uv_mutex.owner) == NULL) // aka trylock
jl_wakeup_thread(0);
wakeup_thread(ct, 0);
}
if (uvlock) {
int enter_eventloop = may_sleep(ptls);
Expand Down Expand Up @@ -571,7 +574,7 @@ void scheduler_delete_thread(jl_ptls_t ptls) JL_NOTSAFEPOINT
else {
jl_atomic_fetch_add_relaxed(&n_threads_running, 1);
}
jl_wakeup_thread(0); // force thread 0 to see that we do not have the IO lock (and am dead)
wakeup_thread(jl_atomic_load_relaxed(&ptls->current_task), 0); // force thread 0 to see that we do not have the IO lock (and am dead)
jl_atomic_fetch_add_relaxed(&n_threads_running, -1);
}

Expand Down
43 changes: 5 additions & 38 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,17 @@ JL_DLLEXPORT void jl_set_safe_restore(jl_jmp_buf *sr)
// The tls_states buffer:
//
// On platforms that do not use ELF (i.e. where `__thread` is emulated with
// lower level API) (Mac, Windows), we use the platform runtime API to create
// lower level API) (Windows), we use the platform runtime API to create
// TLS variable directly.
// This is functionally equivalent to using `__thread` but can be
// more efficient since we can have better control over the creation and
// initialization of the TLS buffer.
//
// On platforms that use ELF (Linux, FreeBSD), we use a `__thread` variable
// On platforms that support native TLS (ELF platforms + Macos) we use a `__thread` variable
// as the fallback in the shared object. For better efficiency, we also
// create a `__thread` variable in the main executable using a static TLS
// model.
#if defined(_OS_DARWIN_)
// Mac doesn't seem to have static TLS model so the runtime TLS getter
// registration will only add overhead to TLS access. The `__thread` variables
// are emulated with `pthread_key_t` so it is actually faster to use it directly.
static pthread_key_t jl_pgcstack_key;

__attribute__((constructor)) void jl_init_tls(void)
{
pthread_key_create(&jl_pgcstack_key, NULL);
}

JL_CONST_FUNC jl_gcframe_t **jl_get_pgcstack(void) JL_NOTSAFEPOINT
{
return (jl_gcframe_t**)pthread_getspecific(jl_pgcstack_key);
}

void jl_set_pgcstack(jl_gcframe_t **pgcstack) JL_NOTSAFEPOINT
{
pthread_setspecific(jl_pgcstack_key, (void*)pgcstack);
}

void jl_pgcstack_getkey(jl_get_pgcstack_func **f, pthread_key_t *k)
{
// for codegen
*f = pthread_getspecific;
*k = jl_pgcstack_key;
}


JL_DLLEXPORT void jl_pgcstack_setkey(jl_get_pgcstack_func *f, pthread_key_t k)
{
jl_safe_printf("ERROR: Attempt to change TLS address.\n");
}

#elif defined(_OS_WINDOWS_)
#if defined(_OS_WINDOWS_)
// Apparently windows doesn't have a static TLS model (or one that can be
// reliably used from a shared library) either..... Use `TLSAlloc` instead.

Expand Down Expand Up @@ -464,6 +430,7 @@ void jl_safepoint_resume_all_threads(jl_task_t *ct)

void jl_task_frame_noreturn(jl_task_t *ct) JL_NOTSAFEPOINT;
void scheduler_delete_thread(jl_ptls_t ptls) JL_NOTSAFEPOINT;
void _jl_free_stack(jl_ptls_t ptls, void *stkbuf, size_t bufsz) JL_NOTSAFEPOINT;

static void jl_delete_thread(void *value) JL_NOTSAFEPOINT_ENTER
{
Expand Down Expand Up @@ -492,7 +459,7 @@ static void jl_delete_thread(void *value) JL_NOTSAFEPOINT_ENTER
}
if (signal_stack != NULL) {
if (signal_stack_size)
jl_free_stack(signal_stack, signal_stack_size);
_jl_free_stack(ptls ,signal_stack, signal_stack_size);
else
free(signal_stack);
}
Expand Down
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1354,4 +1354,9 @@ end
end
end

@testset "bounds-check with CartesianIndex ranges" begin
D = Diagonal(1:typemax(Int))
@test checkbounds(Bool, D, diagind(D, IndexCartesian()))
end

end # module TestDiagonal
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ end
function test_one_oneunit_triangular(a)
b = Matrix(a)
@test (@inferred a^1) == b^1
@test (@inferred a^-1) == b^-1
@test (@inferred a^-1) b^-1
@test one(a) == one(b)
@test one(a)*a == a
@test a*one(a) == a
Expand Down
15 changes: 11 additions & 4 deletions test/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,15 @@ end
end

@testset "transcode" begin
str = "αβγ"
@test transcode(String, transcode(UInt16, str)) == str
@test transcode(String, transcode(UInt16, transcode(UInt8, str))) == str
@test transcode(String, transcode(UInt8, transcode(UInt16, str))) == str
# string starting with an ASCII character
str_1 = "zβγ"
# string starting with a 2 byte UTF-8 character
str_2 = "αβγ"
# string starting with a 3 byte UTF-8 character
str_3 = "आख"
@testset for str in (str_1, str_2, str_3)
@test transcode(String, transcode(UInt16, str)) == str
@test transcode(String, transcode(UInt16, transcode(UInt8, str))) == str
@test transcode(String, transcode(UInt8, transcode(UInt16, str))) == str
end
end

0 comments on commit 6b4d608

Please sign in to comment.