Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Simplify of OffsetToStringData as it's done on coreclr #93987

Merged
merged 7 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
}

[Obsolete("OffsetToStringData has been deprecated. Use string.GetPinnableReference() instead.")]
public static int OffsetToStringData
{
[Intrinsic]
get => OffsetToStringData;
}
public static int OffsetToStringData => string.OFFSET_TO_STRING;

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int InternalGetHashCode(object? o);
Expand Down
6 changes: 6 additions & 0 deletions src/mono/System.Private.CoreLib/src/System/String.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public static string IsInterned(string str)
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern string InternalIntern(string str);

#if TARGET_64BIT
internal const int OFFSET_TO_STRING = 20;
#else
internal const int OFFSET_TO_STRING = 12;
#endif

// TODO: Should be pointing to Buffer instead
#region Runtime method-to-ir dependencies

Expand Down
11 changes: 1 addition & 10 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2305,16 +2305,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
*op = MINT_INITBLK;
}
} else if (in_corlib && !strcmp (klass_name_space, "System.Runtime.CompilerServices") && !strcmp (klass_name, "RuntimeHelpers")) {
if (!strcmp (tm, "get_OffsetToStringData")) {
g_assert (csignature->param_count == 0);
int offset = MONO_STRUCT_OFFSET (MonoString, chars);
interp_add_ins (td, MINT_LDC_I4);
WRITE32_INS (td->last_ins, 0, &offset);
push_simple_type (td, STACK_TYPE_I4);
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
td->ip += 5;
return TRUE;
} else if (!strcmp (tm, "GetHashCode") || !strcmp (tm, "InternalGetHashCode")) {
if (!strcmp (tm, "GetHashCode") || !strcmp (tm, "InternalGetHashCode")) {
*op = MINT_INTRINS_GET_HASHCODE;
} else if (!strcmp (tm, "TryGetHashCode")) {
*op = MINT_INTRINS_TRY_GET_HASHCODE;
Expand Down
5 changes: 1 addition & 4 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
} else
return NULL;
} else if (cmethod->klass == runtime_helpers_class) {
if (strcmp (cmethod->name, "get_OffsetToStringData") == 0 && fsig->param_count == 0) {
EMIT_NEW_ICONST (cfg, ins, MONO_STRUCT_OFFSET (MonoString, chars));
return ins;
} else if (!strcmp (cmethod->name, "GetRawData")) {
if (!strcmp (cmethod->name, "GetRawData")) {
int dreg = alloc_preg (cfg);
EMIT_NEW_BIALU_IMM (cfg, ins, OP_PADD_IMM, dreg, args [0]->dreg, MONO_ABI_SIZEOF (MonoObject));
return ins;
Expand Down
Loading