Skip to content

Commit

Permalink
[mono] Simplify of OffsetToStringData as it's done on coreclr (dotnet…
Browse files Browse the repository at this point in the history
…#93987)

* Change implementation of OffsetToStringData as it's done on coreclr

* Fix comment

* Remove more comments

* completely remove the comments

* Update RuntimeHelpers.Mono.cs

* Addressing comments

* Addressing @lambdageek comment.
  • Loading branch information
thaystg authored and liveans committed Nov 9, 2023
1 parent a6ff336 commit 21306e8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
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

0 comments on commit 21306e8

Please sign in to comment.