Skip to content

Commit

Permalink
Add DebuggerHidden to managed JitHelpers (#106167)
Browse files Browse the repository at this point in the history
* Consolidate throw helpers

* Move remaining simply helpers to the shared location.

* Move direct helpers in native AOT to shared location.

* Remove ThrowHelpers from suppression XML
  • Loading branch information
AaronRobinsonMSFT authored Aug 12, 2024
1 parent f18294b commit 58d6c58
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@

<!-- Sources -->
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\CompilerHelpers\ThrowHelpers.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\InteropServices\ComActivationContextInternal.cs" />
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\InteropServices\ComponentActivator.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\__Canon.cs" />
Expand Down Expand Up @@ -231,7 +232,6 @@
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\WaitHandle.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Type.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\ThrowHelper.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypedReference.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\TypeLoadException.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System
namespace Internal.Runtime.CompilerHelpers
{
internal static unsafe partial class ThrowHelper
internal static unsafe partial class ThrowHelpers
{
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")]
private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);

[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowAmbiguousResolutionException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
Expand All @@ -27,6 +29,7 @@ internal static void ThrowAmbiguousResolutionException(
private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);

[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowEntryPointNotFoundException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
Expand Down
24 changes: 12 additions & 12 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
DYNAMICJITHELPER(CORINFO_HELP_THROW, IL_Throw, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_RETHROW, IL_Rethrow, METHOD__NIL)
JITHELPER(CORINFO_HELP_USER_BREAKPOINT, JIT_UserBreakpoint, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_RNGCHKFAIL, NULL, METHOD__THROWHELPER__THROWINDEXOUTOFRANGEEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_OVERFLOW, NULL, METHOD__THROWHELPER__THROWOVERFLOWEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROWDIVZERO, NULL, METHOD__THROWHELPER__THROWDIVIDEBYZEROEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROWNULLREF, NULL, METHOD__THROWHELPER__THROWNULLREFEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_VERIFICATION, NULL, METHOD__THROWHELPER__THROWVERIFICATIONEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_RNGCHKFAIL, NULL, METHOD__THROWHELPERS__THROWINDEXOUTOFRANGEEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_OVERFLOW, NULL, METHOD__THROWHELPERS__THROWOVERFLOWEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROWDIVZERO, NULL, METHOD__THROWHELPERS__THROWDIVIDEBYZEROEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROWNULLREF, NULL, METHOD__THROWHELPERS__THROWNULLREFEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_VERIFICATION, NULL, METHOD__THROWHELPERS__THROWVERIFICATIONEXCEPTION)
JITHELPER(CORINFO_HELP_FAIL_FAST, JIT_FailFast, METHOD__NIL)
JITHELPER(CORINFO_HELP_METHOD_ACCESS_EXCEPTION,JIT_ThrowMethodAccessException, METHOD__NIL)
JITHELPER(CORINFO_HELP_FIELD_ACCESS_EXCEPTION,JIT_ThrowFieldAccessException, METHOD__NIL)
Expand Down Expand Up @@ -291,13 +291,13 @@
JITHELPER(CORINFO_HELP_LOOP_CLONE_CHOICE_ADDR, JIT_LoopCloneChoiceAddr, METHOD__NIL)
JITHELPER(CORINFO_HELP_DEBUG_LOG_LOOP_CLONING, JIT_DebugLogLoopCloning, METHOD__NIL)

DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTEXCEPTION, NULL, METHOD__THROWHELPER__THROWARGUMENTEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, NULL, METHOD__THROWHELPER__THROWARGUMENTOUTOFRANGEEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_NOT_IMPLEMENTED, NULL, METHOD__THROWHELPER__THROWNOTIMPLEMENTEDEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, NULL, METHOD__THROWHELPER__THROWPLATFORMNOTSUPPORTEDEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_TYPE_NOT_SUPPORTED, NULL, METHOD__THROWHELPER__THROWTYPENOTSUPPORTED)
DYNAMICJITHELPER(CORINFO_HELP_THROW_AMBIGUOUS_RESOLUTION_EXCEPTION, NULL, METHOD__THROWHELPER__THROWAMBIGUOUSRESOLUTIONEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_ENTRYPOINT_NOT_FOUND_EXCEPTION, NULL, METHOD__THROWHELPER__THROWENTRYPOINTNOTFOUNDEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTEXCEPTION, NULL, METHOD__THROWHELPERS__THROWARGUMENTEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION, NULL, METHOD__THROWHELPERS__THROWARGUMENTOUTOFRANGEEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_NOT_IMPLEMENTED, NULL, METHOD__THROWHELPERS__THROWNOTIMPLEMENTEDEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, NULL, METHOD__THROWHELPERS__THROWPLATFORMNOTSUPPORTEDEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_TYPE_NOT_SUPPORTED, NULL, METHOD__THROWHELPERS__THROWTYPENOTSUPPORTED)
DYNAMICJITHELPER(CORINFO_HELP_THROW_AMBIGUOUS_RESOLUTION_EXCEPTION, NULL, METHOD__THROWHELPERS__THROWAMBIGUOUSRESOLUTIONEXCEPTION)
DYNAMICJITHELPER(CORINFO_HELP_THROW_ENTRYPOINT_NOT_FOUND_EXCEPTION, NULL, METHOD__THROWHELPERS__THROWENTRYPOINTNOTFOUNDEXCEPTION)

JITHELPER(CORINFO_HELP_JIT_PINVOKE_BEGIN, JIT_PInvokeBegin, METHOD__NIL)
JITHELPER(CORINFO_HELP_JIT_PINVOKE_END, JIT_PInvokeEnd, METHOD__NIL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,6 @@
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CanonTypeKind</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerHelpers.ThrowHelpers</Target>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Internal.Runtime.CompilerServices.FunctionPointerOps</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Internal.Runtime.CompilerHelpers;
using Internal.Runtime.CompilerServices;

using ExceptionStringID = Internal.TypeSystem.ExceptionStringID;
using ReflectionPointer = System.Reflection.Pointer;

namespace Internal.Runtime.Augments
Expand Down Expand Up @@ -702,5 +703,45 @@ public static void RhHandleFree(IntPtr handle)
{
RuntimeImports.RhHandleFree(handle);
}

public static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg)
{
throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName, messageArg);
}

public static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName)
{
throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName);
}

public static void ThrowMissingMethodException(ExceptionStringID id, string methodName)
{
throw TypeLoaderExceptionHelper.CreateMissingMethodException(id, methodName);
}

public static void ThrowMissingFieldException(ExceptionStringID id, string fieldName)
{
throw TypeLoaderExceptionHelper.CreateMissingFieldException(id, fieldName);
}

public static void ThrowFileNotFoundException(ExceptionStringID id, string fileName)
{
throw TypeLoaderExceptionHelper.CreateFileNotFoundException(id, fileName);
}

public static void ThrowInvalidProgramException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id);
}

public static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName)
{
throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id, methodName);
}

public static void ThrowBadImageFormatException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateBadImageFormatException(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,138 +2,116 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

using Internal.TypeSystem;

namespace Internal.Runtime.CompilerHelpers
{
/// <summary>
/// These methods are used to throw exceptions from generated code. The type and methods
/// need to be public as they constitute a public contract with the NativeAOT toolchain.
/// </summary>
public static class ThrowHelpers
internal static partial class ThrowHelpers
{
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowBodyRemoved()
{
throw new NotSupportedException(SR.NotSupported_BodyRemoved);
}

[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowFeatureBodyRemoved()
{
throw new NotSupportedException(SR.NotSupported_FeatureBodyRemoved);
}

[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowInstanceBodyRemoved()
{
throw new NotSupportedException(SR.NotSupported_InstanceBodyRemoved);
}

[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowUnavailableType()
{
throw new TypeLoadException(SR.Arg_UnavailableTypeLoadException);
}

public static void ThrowOverflowException()
{
throw new OverflowException();
}

public static void ThrowIndexOutOfRangeException()
{
throw new IndexOutOfRangeException();
}

public static void ThrowNullReferenceException()
{
throw new NullReferenceException();
}

public static void ThrowDivideByZeroException()
{
throw new DivideByZeroException();
}

public static void ThrowArrayTypeMismatchException()
{
throw new ArrayTypeMismatchException();
}

public static void ThrowPlatformNotSupportedException()
{
throw new PlatformNotSupportedException();
}

public static void ThrowNotImplementedException()
{
throw NotImplemented.ByDesign;
}

public static void ThrowNotSupportedException()
{
throw new NotSupportedException();
}

public static void ThrowBadImageFormatException(ExceptionStringID id)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowBadImageFormatException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateBadImageFormatException(id);
}

public static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowTypeLoadException(ExceptionStringID id, string className, string typeName)
{
throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName);
}

public static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowTypeLoadExceptionWithArgument(ExceptionStringID id, string className, string typeName, string messageArg)
{
throw TypeLoaderExceptionHelper.CreateTypeLoadException(id, className, typeName, messageArg);
}

public static void ThrowMissingMethodException(ExceptionStringID id, string methodName)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowMissingMethodException(ExceptionStringID id, string methodName)
{
throw TypeLoaderExceptionHelper.CreateMissingMethodException(id, methodName);
}

public static void ThrowMissingFieldException(ExceptionStringID id, string fieldName)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowMissingFieldException(ExceptionStringID id, string fieldName)
{
throw TypeLoaderExceptionHelper.CreateMissingFieldException(id, fieldName);
}

public static void ThrowFileNotFoundException(ExceptionStringID id, string fileName)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowFileNotFoundException(ExceptionStringID id, string fileName)
{
throw TypeLoaderExceptionHelper.CreateFileNotFoundException(id, fileName);
}

public static void ThrowInvalidProgramException(ExceptionStringID id)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowInvalidProgramException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id);
}

public static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowInvalidProgramExceptionWithArgument(ExceptionStringID id, string methodName)
{
throw TypeLoaderExceptionHelper.CreateInvalidProgramException(id, methodName);
}

public static void ThrowMarshalDirectiveException(ExceptionStringID id)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowMarshalDirectiveException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateMarshalDirectiveException(id);
}

public static void ThrowAmbiguousMatchException(ExceptionStringID id)
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowAmbiguousMatchException(ExceptionStringID id)
{
throw TypeLoaderExceptionHelper.CreateAmbiguousMatchException(id);
}

public static void ThrowArgumentException()
{
throw new ArgumentException();
}

public static void ThrowArgumentOutOfRangeException()
{
throw new ArgumentOutOfRangeException();
}

public static void ThrowNotSupportedInlineArrayEqualsGetHashCode()
[DoesNotReturn]
[DebuggerHidden]
internal static void ThrowNotSupportedInlineArrayEqualsGetHashCode()
{
throw new NotSupportedException(SR.NotSupported_InlineArrayEqualsGetHashCode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using CoreLibThrow = Internal.Runtime.CompilerHelpers.ThrowHelpers;
using CoreLibThrow = Internal.Runtime.Augments.RuntimeAugments;

namespace Internal.TypeSystem
{
Expand Down
26 changes: 13 additions & 13 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,19 +641,19 @@ DEFINE_METHOD(SPAN_HELPERS, MEMSET, Fill, SM_RefByte_Byt
DEFINE_METHOD(SPAN_HELPERS, MEMZERO, ClearWithoutReferences, SM_RefByte_UIntPtr_RetVoid)
DEFINE_METHOD(SPAN_HELPERS, MEMCOPY, Memmove, SM_RefByte_RefByte_UIntPtr_RetVoid)

DEFINE_CLASS(THROWHELPER, System, ThrowHelper)
DEFINE_METHOD(THROWHELPER, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid)
DEFINE_METHOD(THROWHELPER, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid)
DEFINE_CLASS(THROWHELPERS, InternalCompilerHelpers, ThrowHelpers)
DEFINE_METHOD(THROWHELPERS, THROWARGUMENTEXCEPTION, ThrowArgumentException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWARGUMENTOUTOFRANGEEXCEPTION, ThrowArgumentOutOfRangeException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWINDEXOUTOFRANGEEXCEPTION, ThrowIndexOutOfRangeException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWNOTIMPLEMENTEDEXCEPTION, ThrowNotImplementedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWPLATFORMNOTSUPPORTEDEXCEPTION, ThrowPlatformNotSupportedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWTYPENOTSUPPORTED, ThrowTypeNotSupportedException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWOVERFLOWEXCEPTION, ThrowOverflowException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWDIVIDEBYZEROEXCEPTION, ThrowDivideByZeroException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWNULLREFEXCEPTION, ThrowNullReferenceException, SM_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWVERIFICATIONEXCEPTION, ThrowVerificationException, SM_Int_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWAMBIGUOUSRESOLUTIONEXCEPTION, ThrowAmbiguousResolutionException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid)
DEFINE_METHOD(THROWHELPERS, THROWENTRYPOINTNOTFOUNDEXCEPTION, ThrowEntryPointNotFoundException, SM_PtrVoid_PtrVoid_PtrVoid_RetVoid)

DEFINE_CLASS(UNSAFE, CompilerServices, Unsafe)
DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define g_IntrinsicsNS g_RuntimeNS ".Intrinsics"
#define g_NumericsNS g_SystemNS ".Numerics"

#define g_InternalCompilerHelpersNS "Internal.Runtime.CompilerHelpers"
#define g_CompilerServicesNS g_RuntimeNS ".CompilerServices"

#define g_ConstrainedExecutionNS g_RuntimeNS ".ConstrainedExecution"
Expand Down
Loading

0 comments on commit 58d6c58

Please sign in to comment.