From: Rama Krishnan Raghupathy Date: Fri, 22 Apr 2016 02:51:49 +0000 (-0700) Subject: Arm64:Implemeting ThisPtrRetBufPrecode: X-Git-Tag: submit/tizen/20210909.063632~11030^2~10652^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a4a1c478059fa9e0e9e377015d521b0bcb67603;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Arm64:Implemeting ThisPtrRetBufPrecode: Precode to shuffle this and retbuf for closed delegates over static methods with return buffer Commit migrated from https://github.com/dotnet/coreclr/commit/ea83434a4f3a92f3d476291031300b9de9c3528b --- diff --git a/src/coreclr/src/vm/arm/cgencpu.h b/src/coreclr/src/vm/arm/cgencpu.h index 301118b..30573eb 100644 --- a/src/coreclr/src/vm/arm/cgencpu.h +++ b/src/coreclr/src/vm/arm/cgencpu.h @@ -1196,7 +1196,7 @@ struct FixupPrecode { typedef DPTR(FixupPrecode) PTR_FixupPrecode; -// Precode to stuffle this and retbuf for closed delegates over static methods with return buffer +// Precode to shuffle this and retbuf for closed delegates over static methods with return buffer struct ThisPtrRetBufPrecode { static const int Type = 0x84; diff --git a/src/coreclr/src/vm/arm64/cgencpu.h b/src/coreclr/src/vm/arm64/cgencpu.h index 9ac7d49..cd54ea0 100644 --- a/src/coreclr/src/vm/arm64/cgencpu.h +++ b/src/coreclr/src/vm/arm64/cgencpu.h @@ -614,18 +614,12 @@ struct FixupPrecode { typedef DPTR(FixupPrecode) PTR_FixupPrecode; -// Precode to stuffle this and retbuf for closed delegates over static methods with return buffer +// Precode to shuffle this and retbuf for closed delegates over static methods with return buffer struct ThisPtrRetBufPrecode { - static const int Type = 0x84; + static const int Type = 0x10; - // mov r12, r0 - // mov r0, r1 - // mov r1, r12 - // ldr pc, [pc, #0] ; =m_pTarget - // dcd pTarget - // dcd pMethodDesc - WORD m_rgCode[6]; + UINT32 m_rgCode[6]; TADDR m_pTarget; TADDR m_pMethodDesc; @@ -633,20 +627,29 @@ struct ThisPtrRetBufPrecode { TADDR GetMethodDesc() { - _ASSERTE(!"ARM64:NYI"); - return NULL; + LIMITED_METHOD_DAC_CONTRACT; + + return m_pMethodDesc; } PCODE GetTarget() { - _ASSERTE(!"ARM64:NYI"); - return NULL; + LIMITED_METHOD_DAC_CONTRACT; + return m_pTarget; } BOOL SetTargetInterlocked(TADDR target, TADDR expected) { - _ASSERTE(!"ARM64:NYI"); - return NULL; + CONTRACTL + { + THROWS; + GC_TRIGGERS; + } + CONTRACTL_END; + + EnsureWritableExecutablePages(&m_pTarget); + return (TADDR)InterlockedCompareExchange64( + (LONGLONG*)&m_pTarget, (TADDR)target, (TADDR)expected) == expected; } }; typedef DPTR(ThisPtrRetBufPrecode) PTR_ThisPtrRetBufPrecode; diff --git a/src/coreclr/src/vm/arm64/stubs.cpp b/src/coreclr/src/vm/arm64/stubs.cpp index 38ce1d9..2a3cddb 100644 --- a/src/coreclr/src/vm/arm64/stubs.cpp +++ b/src/coreclr/src/vm/arm64/stubs.cpp @@ -572,9 +572,27 @@ void FixupPrecode::Fixup(DataImage *image, MethodDesc * pMD) } #endif // FEATURE_NATIVE_IMAGE_GENERATION + void ThisPtrRetBufPrecode::Init(MethodDesc* pMD, LoaderAllocator *pLoaderAllocator) { - _ASSERTE(!"ARM64:NYI"); + WRAPPER_NO_CONTRACT; + + int n = 0; + //Initially + //x0 -This ptr + //x1 -ReturnBuffer + m_rgCode[n++] = 0x91000010; // mov x16, x0 + m_rgCode[n++] = 0x91000020; // mov x0, x1 + m_rgCode[n++] = 0x91000201; // mov x1, x16 + m_rgCode[n++] = 0x58000070; // ldr x16, [pc, #12] + _ASSERTE((UINT32*)&m_pTarget == &m_rgCode[n + 2]); + m_rgCode[n++] = 0xd61f0200; // br x16 + n++; // empty 4 bytes for data alignment below + _ASSERTE(n == _countof(m_rgCode)); + + + m_pTarget = GetPreStubEntryPoint(); + m_pMethodDesc = (TADDR)pMD; } diff --git a/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs b/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs new file mode 100644 index 0000000..6b35433 --- /dev/null +++ b/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using System; +using System.Reflection; + +class Program +{ + public int scale; + + public Program(int scale) + { + this.scale = scale; + } + public static decimal getfunc(Program prog,int constituent) + { + return new decimal(constituent/prog.scale); + } + static int Main(string[] args) + { + int result = -1; + + int constituent = 3; + Program prog = new Program(1); + 2.Equals(3); + + MethodInfo info = typeof(Program).GetMethod("getfunc", BindingFlags.Static | BindingFlags.Public); + + //Tests closed delegates over static methods with return buffer + Func deepThought = (Func)info.CreateDelegate(typeof(Func), prog); + + var res1 = deepThought(constituent); + var res2 = deepThought(constituent); + + if (decimal.Compare(res1, res2) == 0) + return 100; + + return result; + + } +} diff --git a/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj b/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj new file mode 100644 index 0000000..59b1c83 --- /dev/null +++ b/src/coreclr/tests/src/CoreMangLib/system/delegate/miscellaneous/ClosedStatic.csproj @@ -0,0 +1,47 @@ + + + + + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + 7a9bfb7d + true + false + BuildAndRun + + + + + + + + + False + + + + + + + + + + + + + + + + + + + +