Skip to content

Commit

Permalink
[interp] do not bake object reference into code stream (mono#8021)
Browse files Browse the repository at this point in the history
it won't be scanned by the GC, defer string allocation to execution-time instead.


this fixes a GC crash when running mini regression suite on iOS/arm64.
  • Loading branch information
lewurm authored and akoeplinger committed Apr 5, 2018
1 parent 92b741f commit 8e0a121
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
17 changes: 17 additions & 0 deletions mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3477,6 +3477,23 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
++sp;
ip += 2;
MINT_IN_BREAK;
MINT_IN_CASE(MINT_LDSTR_TOKEN) {
MonoString *s = NULL;
guint32 strtoken = (guint32) rtm->data_items [* (guint16 *)(ip + 1)];

MonoMethod *method = frame->imethod->method;
if (method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD) {
s = mono_method_get_wrapper_data (method, strtoken);
} else if (method->wrapper_type != MONO_WRAPPER_NONE) {
s = mono_string_new_wrapper (mono_method_get_wrapper_data (method, strtoken));
} else {
g_assert_not_reached ();
}
sp->data.p = s;
++sp;
ip += 2;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_NEWOBJ) {
MonoClass *newobj_class;
MonoMethodSignature *csig;
Expand Down
1 change: 1 addition & 0 deletions mono/mini/interp/mintops.def
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ OPDEF(MINT_BLT_UN_R8_S, "blt.un.r8.s", 2, MintOpShortBranch)
OPDEF(MINT_SWITCH, "switch", 0, MintOpSwitch)

OPDEF(MINT_LDSTR, "ldstr", 2, MintOpMethodToken) /* not really */
OPDEF(MINT_LDSTR_TOKEN, "ldstr.token", 2, MintOpMethodToken) /* not really */

OPDEF(MINT_CALL, "call", 2, MintOpMethodToken)
OPDEF(MINT_VCALL, "vcall", 2, MintOpMethodToken)
Expand Down
19 changes: 10 additions & 9 deletions mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2855,19 +2855,20 @@ generate (MonoMethod *method, MonoMethodHeader *header, InterpMethod *rtm, unsig
break;
}
case CEE_LDSTR: {
MonoString *s;
token = mono_metadata_token_index (read32 (td->ip + 1));
td->ip += 5;
if (method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD) {
s = mono_method_get_wrapper_data (method, token);
} else if (method->wrapper_type != MONO_WRAPPER_NONE) {
s = mono_string_new_wrapper (mono_method_get_wrapper_data (method, token));
} else {
s = mono_ldstr_checked (domain, image, token, error);
if (method->wrapper_type == MONO_WRAPPER_NONE) {
MonoString *s = mono_ldstr_checked (domain, image, token, error);
goto_if_nok (error, exit);
/* GC won't scan code stream, but reference is held by metadata
* machinery so we are good here */
ADD_CODE (td, MINT_LDSTR);
ADD_CODE (td, get_data_item_index (td, s));
} else {
/* defer allocation to execution-time */
ADD_CODE (td, MINT_LDSTR_TOKEN);
ADD_CODE (td, get_data_item_index (td, (gpointer) token));
}
ADD_CODE(td, MINT_LDSTR);
ADD_CODE(td, get_data_item_index (td, s));
PUSH_TYPE(td, STACK_TYPE_O, mono_defaults.string_class);
break;
}
Expand Down

0 comments on commit 8e0a121

Please sign in to comment.