Skip to content

Commit c1ebb8f

Browse files
committed
Reduce codegen overhead for debugger to single check. Avoid retrieving sequence point until actually needed.
Brings use from ~20x slower to ~5x slower when debugger codegen is enabled vs no debugger codegen.
1 parent f0fcf2e commit c1ebb8f

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

mono/mini/debugger-agent.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,20 @@ void mono_debugger_install_runtime_callbacks(MonoDebuggerRuntimeCallbacks* cbs)
11601160
callbacks = *cbs;
11611161
}
11621162

1163+
uint32_t* g_unity_check;
1164+
void mono_debugger_install_sequence_point_check(uint32_t* check)
1165+
{
1166+
g_unity_check = check;
1167+
}
1168+
1169+
#define INC_PAUSE_COUNT() do { mono_atomic_inc_i32 (g_unity_check); } while (0)
1170+
#define DEC_PAUSE_COUNT() do { mono_atomic_dec_i32 (g_unity_check); } while (0)
1171+
1172+
#else
1173+
1174+
#define INC_PAUSE_COUNT()
1175+
#define DEC_PAUSE_COUNT()
1176+
11631177
#endif // RUNTIME_IL2CPP
11641178

11651179
/*
@@ -3430,7 +3444,7 @@ compute_frame_info (MonoInternalThread *thread, DebuggerTlsData *tls)
34303444
} else if (tls->il2cpp_context->frameCount > 0) {
34313445
for (int frame_index = tls->il2cpp_context->frameCount - 1; frame_index >= 0; --frame_index)
34323446
{
3433-
Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint;
3447+
Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point (tls->il2cpp_context->executionContexts[frame_index]->currentSequencePoint);
34343448
StackFrame* frame = g_new0(StackFrame, 1);
34353449
MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point);
34363450
frame->method = sp_method;
@@ -4836,6 +4850,7 @@ set_breakpoint (MonoMethod *method, long il_offset, EventRequest *req, MonoError
48364850
inst->seq_point = seqPoint;
48374851

48384852
seqPoint->isActive++;
4853+
INC_PAUSE_COUNT();
48394854

48404855
mono_loader_lock();
48414856
g_ptr_array_add(bp->children, inst);
@@ -4925,6 +4940,7 @@ static MonoBreakpoint* set_breakpoint_fast(Il2CppSequencePoint *sp, EventRequest
49254940
inst->seq_point = sp;
49264941

49274942
sp->isActive++;
4943+
INC_PAUSE_COUNT();
49284944

49294945
mono_loader_lock();
49304946
g_ptr_array_add(bp->children, inst);
@@ -4961,6 +4977,7 @@ clear_breakpoint (MonoBreakpoint *bp)
49614977
remove_breakpoint(inst);
49624978
#else
49634979
inst->seq_point->isActive--;
4980+
DEC_PAUSE_COUNT();
49644981
#endif
49654982

49664983
g_free (inst);
@@ -5038,6 +5055,7 @@ clear_breakpoints_for_domain (MonoDomain *domain)
50385055
remove_breakpoint (inst);
50395056
#else
50405057
inst->seq_point->isActive--;
5058+
DEC_PAUSE_COUNT();
50415059
#endif
50425060

50435061
g_free (inst);
@@ -5854,7 +5872,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal, int seque
58545872
#ifndef RUNTIME_IL2CPP
58555873
process_event (EVENT_KIND_STEP, jinfo_get_method (ji), il_offset, ctx, events, suspend_policy);
58565874
#else
5857-
Il2CppSequencePoint* sequence_pt = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint;
5875+
Il2CppSequencePoint* sequence_pt = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint);
58585876
MonoMethod *sp_method = il2cpp_get_seq_point_method(sequence_pt);
58595877

58605878
/*
@@ -5998,6 +6016,7 @@ start_single_stepping (void)
59986016
{
59996017
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
60006018
int val = mono_atomic_inc_i32 (&ss_count);
6019+
INC_PAUSE_COUNT();
60016020

60026021
if (val == 1) {
60036022
mono_arch_start_single_stepping ();
@@ -6015,6 +6034,7 @@ stop_single_stepping (void)
60156034
{
60166035
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
60176036
int val = mono_atomic_dec_i32 (&ss_count);
6037+
DEC_PAUSE_COUNT();
60186038

60196039
if (val == 0) {
60206040
mono_arch_stop_single_stepping ();
@@ -6443,7 +6463,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint
64436463
} else {
64446464
if (ss_req->depth == STEP_DEPTH_OVER)
64456465
{
6446-
MonoMethod* currentMethod = il2cpp_get_seq_point_method(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint);
6466+
MonoMethod* currentMethod = il2cpp_get_seq_point_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint));
64476467

64486468
void *seqPointIter = NULL;
64496469
Il2CppSequencePoint *seqPoint;
@@ -6459,7 +6479,7 @@ ss_start_il2cpp(SingleStepReq *ss_req, DebuggerTlsData *tls, Il2CppSequencePoint
64596479

64606480
if (tls->il2cpp_context->frameCount > 1)
64616481
{
6462-
Il2CppSequencePoint* sequencePointForStepOut = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint;
6482+
Il2CppSequencePoint* sequencePointForStepOut = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 2]->currentSequencePoint);
64636483
g_assert(sequencePointForStepOut->kind == kSequencePointKind_StepOut);
64646484
ss_bp_add_one_il2cpp(ss_req, &ss_req_bp_count, &ss_req_bp_cache, sequencePointForStepOut);
64656485
}
@@ -6528,6 +6548,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte
65286548
DEBUG_PRINTF (1, "[dbg] Starting single step of thread %p (depth=%s).\n", thread, ss_depth_to_string (depth));
65296549

65306550
ss_req = g_new0 (SingleStepReq, 1);
6551+
INC_PAUSE_COUNT();
65316552
ss_req->req = req;
65326553
ss_req->thread = thread;
65336554
ss_req->size = size;
@@ -6553,7 +6574,7 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte
65536574

65546575
if (tls->il2cpp_context->frameCount > 0)
65556576
{
6556-
Il2CppSequencePoint* seq_point = tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint;
6577+
Il2CppSequencePoint* seq_point = il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[tls->il2cpp_context->frameCount - 1]->currentSequencePoint);
65576578
MonoMethod *sp_method = il2cpp_get_seq_point_method(seq_point);
65586579
ss_req->start_method = sp_method;
65596580
ss_req->last_method = sp_method;
@@ -6669,6 +6690,7 @@ ss_destroy (SingleStepReq *req)
66696690
ss_stop (ss_req);
66706691

66716692
g_free (ss_req);
6693+
DEC_PAUSE_COUNT();
66726694
ss_req = NULL;
66736695
}
66746696

@@ -6788,7 +6810,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point(DebuggerTlsData *tl
67886810
int frameIndex = tls->il2cpp_context->frameCount - 1;
67896811
while (frameIndex >= 0)
67906812
{
6791-
Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, tls->exception);
6813+
Il2CppSequencePoint* sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), tls->exception);
67926814
if (sp)
67936815
return sp;
67946816

@@ -6812,7 +6834,7 @@ static Il2CppSequencePoint* il2cpp_find_catch_sequence_point_from_exeption(Debug
68126834
int frameIndex = tls->il2cpp_context->frameCount - 1;
68136835
while (frameIndex >= 0)
68146836
{
6815-
sp = il2cpp_find_catch_sequence_point_in_method(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint, exc);
6837+
sp = il2cpp_find_catch_sequence_point_in_method(il2cpp_get_sequence_point(tls->il2cpp_context->executionContexts[frameIndex]->currentSequencePoint), exc);
68166838
if (sp)
68176839
return sp;
68186840

0 commit comments

Comments
 (0)