Skip to content

Commit ec2eead

Browse files
authored
Merge branch 'master' into jb/fix32575
2 parents a63871d + 5366148 commit ec2eead

9 files changed

+94
-46
lines changed

base/reflection.jl

+6
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,8 @@ function method_instances(@nospecialize(f), @nospecialize(t), world::UInt = type
926926
return results
927927
end
928928

929+
default_debug_info_kind() = unsafe_load(cglobal(:jl_default_debug_info_kind, Cint))
930+
929931
# this type mirrors jl_cgparams_t (documented in julia.h)
930932
struct CodegenParams
931933
cached::Cint
@@ -934,6 +936,8 @@ struct CodegenParams
934936
code_coverage::Cint
935937
static_alloc::Cint
936938
prefer_specsig::Cint
939+
gnu_pubnames::Cint
940+
debug_info_kind::Cint
937941

938942
module_setup::Any
939943
module_activation::Any
@@ -944,11 +948,13 @@ struct CodegenParams
944948
CodegenParams(;cached::Bool=true,
945949
track_allocations::Bool=true, code_coverage::Bool=true,
946950
static_alloc::Bool=true, prefer_specsig::Bool=false,
951+
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
947952
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
948953
emit_function=nothing, emitted_function=nothing) =
949954
new(Cint(cached),
950955
Cint(track_allocations), Cint(code_coverage),
951956
Cint(static_alloc), Cint(prefer_specsig),
957+
Cint(gnu_pubnames), debug_info_kind,
952958
module_setup, module_activation, raise_exception,
953959
emit_function, emitted_function)
954960
end

src/codegen.cpp

+31-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ static std::map<jl_fptr_args_t, Function*> builtin_func_map;
340340
// --- code generation ---
341341
extern "C" {
342342
int globalUnique = 0;
343-
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 0, NULL, NULL, NULL, NULL, NULL};
343+
int jl_default_debug_info_kind = (int) DICompileUnit::DebugEmissionKind::FullDebug;
344+
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 0, 1, jl_default_debug_info_kind, NULL, NULL, NULL, NULL, NULL};
344345
}
345346

346347
template<typename T>
@@ -5631,9 +5632,36 @@ static std::unique_ptr<Module> emit_function(
56315632
DISubprogram *SP = NULL;
56325633
DebugLoc noDbg, topdebugloc;
56335634
if (ctx.debug_enabled) {
5634-
// TODO: Fix when moving to new LLVM version
5635+
DICompileUnit::DebugEmissionKind emissionKind = (DICompileUnit::DebugEmissionKind) ctx.params->debug_info_kind;
5636+
5637+
#if JL_LLVM_VERSION >= 80000
5638+
DICompileUnit::DebugNameTableKind tableKind;
5639+
5640+
if (JL_FEAT_TEST(ctx, gnu_pubnames)) {
5641+
tableKind = DICompileUnit::DebugNameTableKind::GNU;
5642+
}
5643+
else {
5644+
tableKind = DICompileUnit::DebugNameTableKind::None;
5645+
}
5646+
#endif
56355647
topfile = dbuilder.createFile(ctx.file, ".");
5636-
DICompileUnit *CU = dbuilder.createCompileUnit(0x01, topfile, "julia", true, "", 0);
5648+
DICompileUnit *CU =
5649+
dbuilder.createCompileUnit(llvm::dwarf::DW_LANG_Julia
5650+
,topfile // File
5651+
,"julia" // Producer
5652+
,true // isOptimized
5653+
,"" // Flags
5654+
,0 // RuntimeVersion
5655+
,"" // SplitName
5656+
,emissionKind // Kind
5657+
,0 // DWOId
5658+
,true // SplitDebugInlining
5659+
,false // DebugInfoForProfiling
5660+
#if JL_LLVM_VERSION >= 80000
5661+
,tableKind // NameTableKind
5662+
#endif
5663+
);
5664+
56375665
DISubroutineType *subrty;
56385666
if (jl_options.debug_level <= 1) {
56395667
subrty = jl_di_func_null_sig;

src/julia.h

+5
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,10 @@ typedef struct {
19841984
int static_alloc; // is the compiler allowed to allocate statically?
19851985
int prefer_specsig; // are specialized function signatures preferred?
19861986

1987+
// controls the emission of debug-info. mirrors the clang options
1988+
int gnu_pubnames; // can we emit the gnu pubnames debuginfo
1989+
int debug_info_kind; // Enum for line-table-only, line-directives-only,
1990+
// limited, standalone
19871991

19881992
// hooks
19891993

@@ -2013,6 +2017,7 @@ typedef struct {
20132017
jl_value_t *emitted_function;
20142018
} jl_cgparams_t;
20152019
extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;
2020+
extern JL_DLLEXPORT int jl_default_debug_info_kind;
20162021

20172022
#if defined(JULIA_ENABLE_THREADING) && !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
20182023
#define JULIA_DEFINE_FAST_TLS() \

src/julia_threads.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,12 @@ struct _jl_tls_states_t {
190190
// this is limited to the few places we do synchronous IO
191191
// we can make this more general (similar to defer_signal) if necessary
192192
volatile sig_atomic_t io_wait;
193-
#ifndef _OS_WINDOWS_
194-
// These are only used on unix now
195-
pthread_t system_id;
196-
void *signal_stack;
197-
#endif
198193
#ifdef _OS_WINDOWS_
199194
int needs_resetstkoflw;
195+
#else
196+
void *signal_stack;
200197
#endif
198+
unsigned long system_id;
201199
// execution of certain certain impure
202200
// statements is prohibited from certain
203201
// callbacks (such as generated functions)

src/partr.c

+28-27
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,14 @@ static int sleep_check_after_threshold(uint64_t *start_cycles)
311311
}
312312

313313

314-
static void wake_thread(int16_t self, int16_t tid)
314+
static void wake_thread(int16_t tid)
315315
{
316-
if (self != tid) {
317-
jl_ptls_t other = jl_all_tls_states[tid];
318-
int16_t state = jl_atomic_exchange(&other->sleep_check_state, not_sleeping);
319-
if (state == sleeping) {
320-
uv_mutex_lock(&other->sleep_lock);
321-
uv_cond_signal(&other->wake_signal);
322-
uv_mutex_unlock(&other->sleep_lock);
323-
}
316+
jl_ptls_t other = jl_all_tls_states[tid];
317+
int16_t state = jl_atomic_exchange(&other->sleep_check_state, not_sleeping);
318+
if (state == sleeping) {
319+
uv_mutex_lock(&other->sleep_lock);
320+
uv_cond_signal(&other->wake_signal);
321+
uv_mutex_unlock(&other->sleep_lock);
324322
}
325323
}
326324

@@ -345,34 +343,37 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
345343
{
346344
jl_ptls_t ptls = jl_get_ptls_states();
347345
int16_t self = ptls->tid;
346+
unsigned long system_self = jl_all_tls_states[self]->system_id;
348347
int16_t uvlock = jl_atomic_load_acquire(&jl_uv_mutex.owner);
349-
if (tid == self) {
348+
if (tid == self || tid == -1) {
350349
// we're already awake, but make sure we'll exit uv_run
351350
jl_atomic_store(&ptls->sleep_check_state, not_sleeping);
352-
if (uvlock == self)
351+
if (uvlock == system_self)
353352
uv_stop(jl_global_event_loop());
354353
}
355354
#ifdef JULIA_ENABLE_THREADING
356355
else {
356+
// something added to the sticky-queue: notify that thread
357+
wake_thread(tid);
358+
// check if we need to notify uv_run too
359+
if (uvlock != system_self)
360+
jl_wake_libuv();
361+
}
362+
if (tid == -1) {
357363
// check if the other threads might be sleeping
358364
if (jl_atomic_load_acquire(&sleep_check_state) != not_sleeping) {
359-
if (tid == -1) {
360-
// something added to the multi-queue: notify all threads
361-
// in the future, we might want to instead wake some fraction of threads,
362-
// and let each of those wake additional threads if they find work
363-
int16_t state = jl_atomic_exchange(&sleep_check_state, not_sleeping);
364-
if (state == sleeping) {
365-
for (tid = 0; tid < jl_n_threads; tid++)
366-
wake_thread(self, tid);
367-
}
368-
}
369-
else {
370-
// something added to the sticky-queue: notify that thread
371-
wake_thread(self, tid);
365+
// something added to the multi-queue: notify all threads
366+
// in the future, we might want to instead wake some fraction of threads,
367+
// and let each of those wake additional threads if they find work
368+
int16_t state = jl_atomic_exchange(&sleep_check_state, not_sleeping);
369+
if (state == sleeping) {
370+
for (tid = 0; tid < jl_n_threads; tid++)
371+
if (tid != self)
372+
wake_thread(tid);
373+
// check if we need to notify uv_run too
374+
if (uvlock != system_self)
375+
jl_wake_libuv();
372376
}
373-
// check if we need to notify uv_run too
374-
if (uvlock != self)
375-
jl_wake_libuv();
376377
}
377378
}
378379
#endif

src/signals-mach.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void jl_mach_gc_end(void)
3131
int8_t gc_state = (int8_t)(item >> 8);
3232
jl_ptls_t ptls2 = jl_all_tls_states[tid];
3333
jl_atomic_store_release(&ptls2->gc_state, gc_state);
34-
thread_resume(pthread_mach_thread_np(ptls2->system_id));
34+
thread_resume(pthread_mach_thread_np((pthread_t)ptls2->system_id));
3535
}
3636
suspended_threads.len = 0;
3737
}
@@ -101,7 +101,7 @@ static void allocate_segv_handler()
101101
}
102102
pthread_attr_destroy(&attr);
103103
for (int16_t tid = 0;tid < jl_n_threads;tid++) {
104-
attach_exception_port(pthread_mach_thread_np(jl_all_tls_states[tid]->system_id), 0);
104+
attach_exception_port(pthread_mach_thread_np((pthread_t)jl_all_tls_states[tid]->system_id), 0);
105105
}
106106
}
107107

@@ -178,7 +178,7 @@ kern_return_t catch_exception_raise(mach_port_t exception_port,
178178
jl_ptls_t ptls2 = NULL;
179179
for (tid = 0;tid < jl_n_threads;tid++) {
180180
jl_ptls_t _ptls2 = jl_all_tls_states[tid];
181-
if (pthread_mach_thread_np(_ptls2->system_id) == thread) {
181+
if (pthread_mach_thread_np((pthread_t)_ptls2->system_id) == thread) {
182182
ptls2 = _ptls2;
183183
break;
184184
}
@@ -269,7 +269,7 @@ static void attach_exception_port(thread_port_t thread, int segv_only)
269269
static void jl_thread_suspend_and_get_state(int tid, unw_context_t **ctx)
270270
{
271271
jl_ptls_t ptls2 = jl_all_tls_states[tid];
272-
mach_port_t tid_port = pthread_mach_thread_np(ptls2->system_id);
272+
mach_port_t tid_port = pthread_mach_thread_np((pthread_t)ptls2->system_id);
273273

274274
kern_return_t ret = thread_suspend(tid_port);
275275
HANDLE_MACH_ERROR("thread_suspend", ret);
@@ -289,7 +289,7 @@ static void jl_thread_suspend_and_get_state(int tid, unw_context_t **ctx)
289289
static void jl_thread_resume(int tid, int sig)
290290
{
291291
jl_ptls_t ptls2 = jl_all_tls_states[tid];
292-
mach_port_t thread = pthread_mach_thread_np(ptls2->system_id);
292+
mach_port_t thread = pthread_mach_thread_np((pthread_t)ptls2->system_id);
293293
kern_return_t ret = thread_resume(thread);
294294
HANDLE_MACH_ERROR("thread_resume", ret);
295295
}
@@ -299,7 +299,7 @@ static void jl_thread_resume(int tid, int sig)
299299
static void jl_try_deliver_sigint(void)
300300
{
301301
jl_ptls_t ptls2 = jl_all_tls_states[0];
302-
mach_port_t thread = pthread_mach_thread_np(ptls2->system_id);
302+
mach_port_t thread = pthread_mach_thread_np((pthread_t)ptls2->system_id);
303303

304304
kern_return_t ret = thread_suspend(thread);
305305
HANDLE_MACH_ERROR("thread_suspend", ret);
@@ -328,7 +328,7 @@ static void jl_try_deliver_sigint(void)
328328
static void jl_exit_thread0(int exitstate)
329329
{
330330
jl_ptls_t ptls2 = jl_all_tls_states[0];
331-
mach_port_t thread = pthread_mach_thread_np(ptls2->system_id);
331+
mach_port_t thread = pthread_mach_thread_np((pthread_t)ptls2->system_id);
332332
kern_return_t ret = thread_suspend(thread);
333333
HANDLE_MACH_ERROR("thread_suspend", ret);
334334

src/threading.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ JL_DLLEXPORT int16_t jl_threadid(void)
241241
void jl_init_threadtls(int16_t tid)
242242
{
243243
jl_ptls_t ptls = jl_get_ptls_states();
244+
ptls->system_id = jl_thread_self();
244245
seed_cong(&ptls->rngseed);
245246
#ifdef _OS_WINDOWS_
246247
if (tid == 0) {
@@ -251,8 +252,6 @@ void jl_init_threadtls(int16_t tid)
251252
hMainThread = INVALID_HANDLE_VALUE;
252253
}
253254
}
254-
#else
255-
ptls->system_id = pthread_self();
256255
#endif
257256
assert(ptls->world_age == 0);
258257
ptls->world_age = 1; // OK to run Julia code on this thread

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ end
5050
# Base.compilecache only works from node 1, so precompile test is handled specially
5151
move_to_node1("precompile")
5252
move_to_node1("SharedArrays")
53+
move_to_node1("threads")
5354
# Ensure things like consuming all kernel pipe memory doesn't interfere with other tests
5455
move_to_node1("stress")
5556

test/threads_exec.jl

+12-2
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,19 @@ function pfib(n::Int)
654654
end
655655
@test pfib(20) == 6765
656656

657+
# scheduling wake/sleep test (#32511)
658+
let timeout = 300 # this test should take about 1-10 seconds
659+
t = Timer(timeout) do t
660+
ccall(:uv_kill, Cint, (Cint, Cint), getpid(), Base.SIGTERM)
661+
end # set up a watchdog alarm
662+
for _ = 1:10^5
663+
@threads for idx in 1:1024; #=nothing=# end
664+
end
665+
close(t) # stop the watchdog
666+
end
667+
657668
# issue #32575
658-
begin
659-
ch = Channel{Char}(0)
669+
let ch = Channel{Char}(0), t
660670
t = Task(()->for v in "hello" put!(ch, v) end)
661671
t.sticky = false
662672
bind(ch, t)

0 commit comments

Comments
 (0)