From 038ad34ff59b4297123dbb9438ab244c650b4ea1 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 1 Nov 2019 10:46:06 -0700 Subject: [PATCH 1/3] Disable JIT/Directed/pinvoke/pinvoke-examples test. --- tests/issues.targets | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/issues.targets b/tests/issues.targets index 95800c3fe2c8..4db5c1dc16c3 100644 --- a/tests/issues.targets +++ b/tests/issues.targets @@ -84,6 +84,9 @@ Unix does not support tailcall helper + + 27602 + From 37857878f8607d1c88283864140cd99f5969d17f Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 1 Nov 2019 15:04:14 -0700 Subject: [PATCH 2/3] Revert "Disable JIT/Directed/pinvoke/pinvoke-examples test." This reverts commit 038ad34ff59b4297123dbb9438ab244c650b4ea1. --- tests/issues.targets | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/issues.targets b/tests/issues.targets index 4db5c1dc16c3..95800c3fe2c8 100644 --- a/tests/issues.targets +++ b/tests/issues.targets @@ -84,9 +84,6 @@ Unix does not support tailcall helper - - 27602 - From 83486b9d34402bbaea7954b24a7c431a9ab70f4c Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Fri, 1 Nov 2019 15:07:53 -0700 Subject: [PATCH 3/3] Revert suppress test and fix pinvoke-examples test --- tests/src/JIT/Directed/pinvoke/CMakeLists.txt | 10 +-- .../JIT/Directed/pinvoke/pinvoke-examples.cs | 70 +++++++++++-------- .../Directed/pinvoke/pinvoke-examples.csproj | 3 + ...ser32menu.cpp => pinvokeexamplenative.cpp} | 5 ++ tests/src/JIT/Directed/pinvoke/tail.il | 8 +-- 5 files changed, 58 insertions(+), 38 deletions(-) rename tests/src/JIT/Directed/pinvoke/{user32menu.cpp => pinvokeexamplenative.cpp} (97%) diff --git a/tests/src/JIT/Directed/pinvoke/CMakeLists.txt b/tests/src/JIT/Directed/pinvoke/CMakeLists.txt index 7fc8f06887fd..9ed78ec3d431 100644 --- a/tests/src/JIT/Directed/pinvoke/CMakeLists.txt +++ b/tests/src/JIT/Directed/pinvoke/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 2.6) -project(pinvoke_user32menu) +project(PInvokeExampleNative) set(CMAKE_SHARED_LIBRARY_PREFIX "") -add_library(user32menu SHARED user32menu.cpp) -SET_TARGET_PROPERTIES(user32menu PROPERTIES COMPILE_FLAGS "-c") +add_library(PInvokeExampleNative SHARED pinvokeexamplenative.cpp) +SET_TARGET_PROPERTIES(PInvokeExampleNative PROPERTIES COMPILE_FLAGS "-c") # add the install targets (this "installs" the native file on Windows systems) -install(TARGETS user32menu DESTINATION bin) +install(TARGETS PInvokeExampleNative DESTINATION bin) # This "installs" the native file on System V systems -set_target_properties(user32menu PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/user32menu) +set_target_properties(PInvokeExampleNative PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/PInvokeExampleNative) diff --git a/tests/src/JIT/Directed/pinvoke/pinvoke-examples.cs b/tests/src/JIT/Directed/pinvoke/pinvoke-examples.cs index d25a24ea2706..d043260b696e 100644 --- a/tests/src/JIT/Directed/pinvoke/pinvoke-examples.cs +++ b/tests/src/JIT/Directed/pinvoke/pinvoke-examples.cs @@ -8,27 +8,39 @@ using System; using System.Threading; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace PInvokeTest { + static class PInvokeExampleNative + { + public static int GetConstant() + { + return GetConstantInternal(); + } + + [DllImport(nameof(PInvokeExampleNative))] + private extern static int GetConstantInternal(); + } + internal class Test { [MethodImpl(MethodImplOptions.AggressiveInlining)] - static bool AsForceInline() + static int AsForceInline() { - return Thread.Yield(); + return PInvokeExampleNative.GetConstant(); } - static bool AsNormalInline() + static int AsNormalInline() { - return Thread.Yield(); + return PInvokeExampleNative.GetConstant(); } [MethodImpl(MethodImplOptions.NoInlining)] - static bool AsNoInline() + static int AsNoInline() { - return Thread.Yield(); + return PInvokeExampleNative.GetConstant(); } static bool FromTryCatch() @@ -37,7 +49,7 @@ static bool FromTryCatch() try { // All pinvokes should be inline, except on x64 - result = (Thread.Yield() == AsNormalInline()); + result = (PInvokeExampleNative.GetConstant() == AsNormalInline()); } catch (Exception) { @@ -54,8 +66,8 @@ static bool FromTryFinally() try { // All pinvokes should be inline, except on x64 - result1 = (Thread.Yield() == AsNormalInline()); - result2 = (Thread.Yield() == AsNormalInline()); + result1 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); + result2 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); } finally { @@ -73,12 +85,12 @@ static bool FromTryFinally2() try { // These two pinvokes should be inline, except on x64 - result1 = (Thread.Yield() == AsNormalInline()); + result1 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); } finally { // These two pinvokes should *not* be inline (finally) - result2 = (Thread.Yield() == AsNormalInline()); + result2 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); result = result1 && result2; } @@ -94,14 +106,14 @@ static bool FromTryFinally3() try { // These two pinvokes should be inline, except on x64 - result1 = (Thread.Yield() == AsNormalInline()); + result1 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); } finally { try { // These two pinvokes should *not* be inline (finally) - result2 = (Thread.Yield() == AsNormalInline()); + result2 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); } catch (Exception) { @@ -118,7 +130,7 @@ static bool FromTryFinally3() static bool FromInline() { // These two pinvokes should be inline - bool result = (Thread.Yield() == AsForceInline()); + bool result = (PInvokeExampleNative.GetConstant() == AsForceInline()); return result; } @@ -126,8 +138,8 @@ static bool FromInline() static bool FromInline2() { // These four pinvokes should be inline - bool result1 = (Thread.Yield() == AsNormalInline()); - bool result2 = (Thread.Yield() == AsForceInline()); + bool result1 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); + bool result2 = (PInvokeExampleNative.GetConstant() == AsForceInline()); return result1 && result2; } @@ -135,7 +147,7 @@ static bool FromInline2() static bool FromNoInline() { // The only pinvoke should be inline - bool result = (Thread.Yield() == AsNoInline()); + bool result = (PInvokeExampleNative.GetConstant() == AsNoInline()); return result; } @@ -143,8 +155,8 @@ static bool FromNoInline() static bool FromNoInline2() { // Three pinvokes should be inline - bool result1 = (Thread.Yield() == AsNormalInline()); - bool result2 = (Thread.Yield() == AsNoInline()); + bool result1 = (PInvokeExampleNative.GetConstant() == AsNormalInline()); + bool result2 = (PInvokeExampleNative.GetConstant() == AsNoInline()); return result1 && result2; } @@ -159,13 +171,13 @@ static bool FromFilter() // These two pinvokes should *not* be inline (filter) // // For the first call the jit won't inline the wrapper, so - // it just calls get_ProcessorCount. + // it just calls GetConstant(). // // For the second call, the force inline works, and the - // subsequent inline of Thread.Yield exposes a call - // to the pinvoke YieldInternal. This pinvoke will + // subsequent inline of GetConstant() exposes a call + // to the pinvoke GetConstantInternal(). This pinvoke will // not be inline. - catch (Exception) when (Thread.Yield() == AsForceInline()) + catch (Exception) when (PInvokeExampleNative.GetConstant() == AsForceInline()) { result = true; } @@ -175,14 +187,14 @@ static bool FromFilter() static bool FromColdCode() { - bool yield = false; + int yield = -1; bool result1 = false; bool result2 = false; try { // This pinvoke should not be inline (cold) - yield = Thread.Yield(); + yield = PInvokeExampleNative.GetConstant(); throw new Exception("expected"); } catch (Exception) @@ -190,13 +202,13 @@ static bool FromColdCode() // These two pinvokes should not be inline (catch) // // For the first call the jit won't inline the - // wrapper, so it just calls Thread.Yield. + // wrapper, so it just calls GetConstant(). // // For the second call, the force inline works, and - // the subsequent inline of Thread.Yield exposes - // a call to the pinvoke YieldInternal. This + // the subsequent inline of GetConstant() exposes + // a call to the pinvoke GetConstantInternal(). This // pinvoke will not be inline. - result1 = (yield == Thread.Yield()); + result1 = (yield == PInvokeExampleNative.GetConstant()); result2 = (yield == AsForceInline()); } diff --git a/tests/src/JIT/Directed/pinvoke/pinvoke-examples.csproj b/tests/src/JIT/Directed/pinvoke/pinvoke-examples.csproj index fa0aa1d64b91..382d1ca1c9db 100644 --- a/tests/src/JIT/Directed/pinvoke/pinvoke-examples.csproj +++ b/tests/src/JIT/Directed/pinvoke/pinvoke-examples.csproj @@ -12,4 +12,7 @@ + + + diff --git a/tests/src/JIT/Directed/pinvoke/user32menu.cpp b/tests/src/JIT/Directed/pinvoke/pinvokeexamplenative.cpp similarity index 97% rename from tests/src/JIT/Directed/pinvoke/user32menu.cpp rename to tests/src/JIT/Directed/pinvoke/pinvokeexamplenative.cpp index f3a2c545267d..a434a33ab786 100644 --- a/tests/src/JIT/Directed/pinvoke/user32menu.cpp +++ b/tests/src/JIT/Directed/pinvoke/pinvokeexamplenative.cpp @@ -112,3 +112,8 @@ GetMenuStringA( return cch; } +EXPORT_API +int GetConstantInternal() +{ + return 27; +} diff --git a/tests/src/JIT/Directed/pinvoke/tail.il b/tests/src/JIT/Directed/pinvoke/tail.il index 542bc340f5ac..6237a6aba58e 100644 --- a/tests/src/JIT/Directed/pinvoke/tail.il +++ b/tests/src/JIT/Directed/pinvoke/tail.il @@ -15,22 +15,22 @@ .class private auto ansi beforefieldinit Test extends [mscorlib]System.Object { - .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) + .method private hidebysig static pinvokeimpl("PInvokeExampleNative" ansi winapi) native uint CreatePopupMenu() cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) + .method private hidebysig static pinvokeimpl("PInvokeExampleNative" ansi winapi) bool DestroyMenu(native uint hMenu) cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) + .method private hidebysig static pinvokeimpl("PInvokeExampleNative" ansi winapi) bool AppendMenu(native uint hMenu, unsigned int32 uFlags, unsigned int32 uID, string item) cil managed preservesig { } - .method private hidebysig static pinvokeimpl("user32menu" ansi winapi) + .method private hidebysig static pinvokeimpl("PInvokeExampleNative" ansi winapi) int32 GetMenuString(native uint hMenu, unsigned int32 uIDItem, class [mscorlib]System.Text.StringBuilder data,