@@ -295,6 +295,8 @@ extern "C" JL_DLLEXPORT
295
295
int jl_compile_extern_c_impl (LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *sysimg, jl_value_t *declrt, jl_value_t *sigt)
296
296
{
297
297
JL_LOCK (&jl_codegen_lock);
298
+ auto ct = jl_current_task;
299
+ ct->reentrant_codegen ++;
298
300
uint64_t compiler_start_time = 0 ;
299
301
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
300
302
if (measure_compile_time_enabled)
@@ -329,11 +331,12 @@ int jl_compile_extern_c_impl(LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *
329
331
if (success && llvmmod == NULL )
330
332
jl_ExecutionEngine->addModule (std::move (*into));
331
333
}
332
- if (jl_codegen_lock. count == 1 && measure_compile_time_enabled)
334
+ if (ct-> reentrant_codegen == 1 && measure_compile_time_enabled)
333
335
jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, (jl_hrtime () - compiler_start_time));
334
336
if (ctx.getContext ()) {
335
337
jl_ExecutionEngine->releaseContext (std::move (ctx));
336
338
}
339
+ ct->reentrant_codegen --;
337
340
JL_UNLOCK (&jl_codegen_lock);
338
341
return success;
339
342
}
@@ -386,6 +389,8 @@ extern "C" JL_DLLEXPORT
386
389
jl_code_instance_t *jl_generate_fptr_impl (jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world)
387
390
{
388
391
JL_LOCK (&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
392
+ auto ct = jl_current_task;
393
+ ct->reentrant_codegen ++;
389
394
uint64_t compiler_start_time = 0 ;
390
395
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
391
396
bool is_recompile = false ;
@@ -436,12 +441,13 @@ jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES
436
441
else {
437
442
codeinst = NULL ;
438
443
}
439
- if (jl_codegen_lock. count == 1 && measure_compile_time_enabled) {
444
+ if (ct-> reentrant_codegen == 1 && measure_compile_time_enabled) {
440
445
uint64_t t_comp = jl_hrtime () - compiler_start_time;
441
446
if (is_recompile)
442
447
jl_atomic_fetch_add_relaxed (&jl_cumulative_recompile_time, t_comp);
443
448
jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, t_comp);
444
449
}
450
+ ct->reentrant_codegen --;
445
451
JL_UNLOCK (&jl_codegen_lock);
446
452
JL_GC_POP ();
447
453
return codeinst;
@@ -454,6 +460,8 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
454
460
return ;
455
461
}
456
462
JL_LOCK (&jl_codegen_lock);
463
+ auto ct = jl_current_task;
464
+ ct->reentrant_codegen ++;
457
465
uint64_t compiler_start_time = 0 ;
458
466
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
459
467
if (measure_compile_time_enabled)
@@ -485,8 +493,9 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
485
493
}
486
494
JL_GC_POP ();
487
495
}
488
- if (jl_codegen_lock. count == 1 && measure_compile_time_enabled)
496
+ if (ct-> reentrant_codegen == 1 && measure_compile_time_enabled)
489
497
jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, (jl_hrtime () - compiler_start_time));
498
+ ct->reentrant_codegen --;
490
499
JL_UNLOCK (&jl_codegen_lock); // Might GC
491
500
}
492
501
@@ -508,6 +517,8 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
508
517
// (using sentinel value `1` instead)
509
518
// so create an exception here so we can print pretty our lies
510
519
JL_LOCK (&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion
520
+ auto ct = jl_current_task;
521
+ ct->reentrant_codegen --;
511
522
uint64_t compiler_start_time = 0 ;
512
523
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
513
524
if (measure_compile_time_enabled)
@@ -535,8 +546,9 @@ jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world,
535
546
}
536
547
JL_GC_POP ();
537
548
}
538
- if (measure_compile_time_enabled)
549
+ if (ct-> reentrant_codegen == 1 && measure_compile_time_enabled)
539
550
jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, (jl_hrtime () - compiler_start_time));
551
+ ct->reentrant_codegen --;
540
552
JL_UNLOCK (&jl_codegen_lock);
541
553
}
542
554
if (specfptr != 0 )
0 commit comments