Skip to content

Commit

Permalink
address PR comments (dotnet#5011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed May 13, 2020
1 parent dc74830 commit a0a95a4
Showing 1 changed file with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,6 @@ private void InterpretLoadElement(int token)
private struct MethodCallInfo
{
public TypeDesc OwningType;
public bool IsStatic;
public IntPtr MethodAddress;
public IntPtr UnboxingStubAddress;
public TypeLoaderEnvironment.MethodAddressType MethodAddressType;
Expand All @@ -2467,13 +2466,13 @@ private void InterpretCallDelegate(ref MethodCallInfo callInfo, ref LocalVariabl
StackItem stackItem = PopWithValidation();
TypeDesc argumentType = default;

if (i == 1 && !callInfo.IsStatic)
if (i == 1 && !callInfo.Signature.IsStatic)
{
argumentType = callInfo.OwningType;
}
else
{
argumentType = callInfo.Signature[i - (callInfo.IsStatic ? 1 : 2)];
argumentType = callInfo.Signature[i - (callInfo.Signature.IsStatic ? 1 : 2)];
}

setvar:
Expand Down Expand Up @@ -2531,7 +2530,7 @@ private void InterpretCallDelegate(ref MethodCallInfo callInfo, ref LocalVariabl

if (callInfo.MethodAddress != IntPtr.Zero && callInfo.MethodAddressType == TypeLoaderEnvironment.MethodAddressType.Exact)
{
CallConverter.CallingConvention callingConvention = callInfo.IsStatic ? CallConverter.CallingConvention.ManagedStatic : CallConverter.CallingConvention.ManagedInstance;
CallConverter.CallingConvention callingConvention = callInfo.Signature.IsStatic ? CallConverter.CallingConvention.ManagedStatic : CallConverter.CallingConvention.ManagedInstance;
DynamicCallSignature dynamicCallSignature = new DynamicCallSignature(callingConvention, callInfo.LocalVariableTypes, callInfo.LocalVariableTypes.Length);
CallInterceptor.CallInterceptor.MakeDynamicCall(callInfo.MethodAddress, dynamicCallSignature, localVariableSet);
}
Expand Down Expand Up @@ -2606,7 +2605,9 @@ private void InterpretCallDelegate(ref MethodCallInfo callInfo, ref LocalVariabl
private void InterpretCall(int token)
{
MethodDesc method = (MethodDesc)_methodIL.GetObject(token);

MethodSignature signature = method.Signature;
int nSignature = signature.Length;

TypeDesc owningType = method.OwningType;
TypeDesc returnType = signature.ReturnType;
Expand All @@ -2616,7 +2617,7 @@ private void InterpretCall(int token)

int delta = (signature.IsStatic ? 1 : 2);

LocalVariableType[] localVariableTypes = new LocalVariableType[signature.Length + delta];
LocalVariableType[] localVariableTypes = new LocalVariableType[nSignature + delta];
if (returnType.IsByRef)
{
// TODO: Unwrap ref types
Expand All @@ -2626,9 +2627,17 @@ private void InterpretCall(int token)
localVariableTypes[0] = new LocalVariableType(returnType.GetRuntimeTypeHandle(), false, returnType.IsByRef);

if (!signature.IsStatic)
{
if (owningType.IsByRef)
{
// TODO: Unwrap ref types
throw new NotImplementedException();
}

localVariableTypes[1] = new LocalVariableType(owningType.GetRuntimeTypeHandle(), false, owningType.IsByRef);
}

for (int i = 0; i < signature.Length; i++)
for (int i = 0; i < nSignature; i++)
{
var argument = signature[i];
if (argument.IsByRef)
Expand All @@ -2644,7 +2653,6 @@ private void InterpretCall(int token)

var callInfo = new MethodCallInfo();
callInfo.OwningType = !signature.IsStatic ? owningType : null;
callInfo.IsStatic = signature.IsStatic;
callInfo.MethodAddress = methodAddress;
callInfo.MethodAddressType = foundAddressType;
callInfo.UnboxingStubAddress = unboxingStubAddress;
Expand All @@ -2660,36 +2668,39 @@ private void InterpretCall(int token)
private unsafe void InterpretNewObj(int token)
{
MethodDesc method = (MethodDesc)_methodIL.GetObject(token);
MethodSignature signature = method.Signature;
TypeDesc owningType = method.OwningType;

StackItem[] arguments = new StackItem[signature.Length];
MethodSignature signature = method.Signature;
int nSignature = signature.Length;

StackItem[] arguments = new StackItem[nSignature];

for (int i = 0; i < arguments.Length; i++)
{
arguments[i] = PopWithValidation();
}

if (owningType.IsArray)
{
int[] lArguments = new int[arguments.Length];
for (int i = arguments.Length - 1; i >= 0; i--)
int[] lArguments = new int[nSignature];

for (int i = nSignature - 1; i >= 0; i--)
{
lArguments[i] = arguments[i].AsInt32();
lArguments[(nSignature - 1) - i] = arguments[i].AsInt32();
}

Array.Reverse(lArguments);
Array array = RuntimeAugments.NewObjArray(owningType.GetRuntimeTypeHandle(), lArguments);
_stack.Push(StackItem.FromObjectRef(array));
return;
}

object @this = RuntimeAugments.RawNewObject(owningType.GetRuntimeTypeHandle());

LocalVariableType[] localVariableTypes = new LocalVariableType[signature.Length + 2];
LocalVariableType[] localVariableTypes = new LocalVariableType[nSignature + 2];
localVariableTypes[0] = new LocalVariableType(_context.GetWellKnownType(WellKnownType.Void).GetRuntimeTypeHandle(), false, false);
localVariableTypes[1] = new LocalVariableType(owningType.GetRuntimeTypeHandle(), false, false);

for (int i = 0; i < signature.Length; i++)
for (int i = 0; i < nSignature; i++)
{
TypeDesc argument = signature[i];
if (argument.IsByRef)
Expand All @@ -2703,7 +2714,7 @@ private unsafe void InterpretNewObj(int token)

_stack.Push(StackItem.FromObjectRef(@this));

for (int i = arguments.Length - 1; i >= 0; i--)
for (int i = nSignature - 1; i >= 0; i--)
{
_stack.Push(arguments[i]);
}
Expand All @@ -2712,7 +2723,6 @@ private unsafe void InterpretNewObj(int token)

var callInfo = new MethodCallInfo();
callInfo.OwningType = !signature.IsStatic ? owningType : null;
callInfo.IsStatic = signature.IsStatic;
callInfo.MethodAddress = methodAddress;
callInfo.MethodAddressType = foundAddressType;
callInfo.UnboxingStubAddress = unboxingStubAddress;
Expand Down

0 comments on commit a0a95a4

Please sign in to comment.