Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Move p/invoke pregeneration out of single-exe branch #27585

Closed
Closed
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 @@ -139,7 +139,7 @@ static IntrinsicHashtable InitializeIntrinsicHashtable()
table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_TypeEQ, "op_Equality", "System", "Type");
table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_TypeNEQ, "op_Inequality", "System", "Type");
table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_Object_GetType, "GetType", "System", "Object");
// table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_StubHelpers_GetStubContext, "GetStubContext", "System.StubHelpers", "StubHelpers"); // interop-specific
table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_StubHelpers_GetStubContext, "GetStubContext", "System.StubHelpers", "StubHelpers"); // interop-specific
// table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_StubHelpers_GetStubContextAddr, "GetStubContextAddr", "System.StubHelpers", "StubHelpers"); // interop-specific
// table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_StubHelpers_GetNDirectTarget, "GetNDirectTarget", "System.StubHelpers", "StubHelpers"); // interop-specific
// table.Add(CorInfoIntrinsics.CORINFO_INTRINSIC_InterlockedAdd32, "Add", System.Threading", "Interlocked"); // unused
Expand Down
15 changes: 15 additions & 0 deletions src/tools/crossgen2/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,15 @@ private CorInfoInline canInline(CORINFO_METHOD_STRUCT_* callerHnd, CORINFO_METHO
{
MethodDesc callerMethod = HandleToObject(callerHnd);
MethodDesc calleeMethod = HandleToObject(calleeHnd);

#if READYTORUN
// IL stubs don't inline well
if (calleeMethod.IsPInvoke)
{
return CorInfoInline.INLINE_NEVER;
}
#endif

if (_compilation.CanInline(callerMethod, calleeMethod))
{
// No restrictions on inlining
Expand Down Expand Up @@ -3046,8 +3055,14 @@ private uint getJitFlags(ref CORJIT_FLAGS flags, uint sizeInBytes)
flags.Set(CorJitFlag.CORJIT_FLAG_REVERSE_PINVOKE);

if (this.MethodBeingCompiled.IsPInvoke)
{
flags.Set(CorJitFlag.CORJIT_FLAG_IL_STUB);

#if READYTORUN
flags.Set(CorJitFlag.CORJIT_FLAG_PUBLISH_SECRET_PARAM);
#endif
}

if (this.MethodBeingCompiled.IsNoOptimization)
flags.Set(CorJitFlag.CORJIT_FLAG_MIN_OPT);

Expand Down
18 changes: 18 additions & 0 deletions src/tools/crossgen2/Common/TypeSystem/Ecma/EcmaSignatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ public MarshalAsDescriptor ParseMarshalAsDescriptor()
}
}
break;
case NativeTypeKind.SafeArray:
{
// There's nobody to consume SafeArrays, so let's just parse the data
// to avoid asserting later.

// Get optional VARTYPE for the element
if (_reader.RemainingBytes != 0)
{
_reader.ReadCompressedInteger();
}

// VARTYPE can be followed by optional type name
if (_reader.RemainingBytes != 0)
{
_reader.ReadSerializedString();
}
}
break;
default:
break;
}
Expand Down
8 changes: 8 additions & 0 deletions src/tools/crossgen2/Common/TypeSystem/IL/EcmaMethodIL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ private EcmaMethodIL(EcmaMethod method, int rva, bool clearInitLocals)
_clearInitLocals = clearInitLocals;
}

public EcmaModule Module
{
get
{
return _module;
}
}

public override MethodDesc OwningMethod
{
get
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

namespace Internal.IL.Stubs
{
internal sealed class PInvokeILCodeStreams
{
public ILEmitter Emitter { get; }
public ILCodeStream FunctionPointerLoadStream { get; }
public ILCodeStream MarshallingCodeStream { get; }
public ILCodeStream CallsiteSetupCodeStream { get; }
public ILCodeStream ReturnValueMarshallingCodeStream { get; }
public ILCodeStream UnmarshallingCodestream { get; }
public PInvokeILCodeStreams()
{
Emitter = new ILEmitter();

// We have 4 code streams:
// - _marshallingCodeStream is used to convert each argument into a native type and
// store that into the local
// - callsiteSetupCodeStream is used to used to load each previously generated local
// and call the actual target native method.
// - _returnValueMarshallingCodeStream is used to convert the native return value
// to managed one.
// - _unmarshallingCodestream is used to propagate [out] native arguments values to
// managed ones.
FunctionPointerLoadStream = Emitter.NewCodeStream();
MarshallingCodeStream = Emitter.NewCodeStream();
CallsiteSetupCodeStream = Emitter.NewCodeStream();
ReturnValueMarshallingCodeStream = Emitter.NewCodeStream();
UnmarshallingCodestream = Emitter.NewCodeStream();
}

public PInvokeILCodeStreams(ILEmitter emitter, ILCodeStream codeStream)
{
Emitter = emitter;
MarshallingCodeStream = codeStream;
}
}
}
Loading