未验证 提交 ba63deb2 编写于 作者: S Simon Nattress 提交者: GitHub

Pass opaque method signature handle between JIT/CG2 (#47779)

* Crossgen2 presently abuses the `CORINFO_SIG_INFO` pSig field to pass a handle representing a managed method signature object which the JIT passes back to us later in compilation. This field is for byte arrays and causes problems with SuperPMI which rightly doesn't know how to interpret a zero-length buffer whose pointer is set.
* Introduce a new field ,`methodSignature` where we pass the handle back to the JIT. This pattern saves us from allocating and pinning a byte buffer for signatures, something the native code VM and Crossgen1 don't have to worry about.
* Add strongly typed `ObjectToHandle` and `HandleToObject` methods for `CORINFO_MODULE_STRUCT_` <=> `MethodIL` and `MethodSignatureInfo` <=> `MethodSignature`.
* Add SuperPMI support for CORINFO_SIG_INFO.methodSignature
Co-authored-by: NBruce Forstall <brucefo@microsoft.com>
上级 17630561
...@@ -27,7 +27,7 @@ struct Agnostic_CORINFO_SIG_INFO ...@@ -27,7 +27,7 @@ struct Agnostic_CORINFO_SIG_INFO
DWORDLONG args; DWORDLONG args;
DWORD pSig_Index; DWORD pSig_Index;
DWORD cbSig; DWORD cbSig;
DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr) DWORDLONG methodSignature;
DWORDLONG scope; DWORDLONG scope;
DWORD token; DWORD token;
}; };
...@@ -136,7 +136,7 @@ struct Agnostic_GetArgType_Key ...@@ -136,7 +136,7 @@ struct Agnostic_GetArgType_Key
DWORD sigInst_classInst_Index; DWORD sigInst_classInst_Index;
DWORD sigInst_methInstCount; DWORD sigInst_methInstCount;
DWORD sigInst_methInst_Index; DWORD sigInst_methInst_Index;
DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr) DWORDLONG methodSignature;
DWORDLONG scope; DWORDLONG scope;
// Other getArgType() arguments // Other getArgType() arguments
...@@ -149,9 +149,9 @@ struct Agnostic_GetArgClass_Key ...@@ -149,9 +149,9 @@ struct Agnostic_GetArgClass_Key
DWORD sigInst_classInst_Index; DWORD sigInst_classInst_Index;
DWORD sigInst_methInstCount; DWORD sigInst_methInstCount;
DWORD sigInst_methInst_Index; DWORD sigInst_methInst_Index;
DWORDLONG methodSignature;
DWORDLONG scope; DWORDLONG scope;
DWORDLONG args; DWORDLONG args;
DWORDLONG sigHandle; // used instead of cbSig/pSig_Index on crossgen2 if (cbSig == 0) && (pSig != nullptr)
}; };
struct Agnostic_GetBoundaries struct Agnostic_GetBoundaries
......
...@@ -2524,21 +2524,15 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig, ...@@ -2524,21 +2524,15 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig,
// TODO: verify that the above comment is still true (that some of the fields of incoming argument `sig` contain garbage), or // TODO: verify that the above comment is still true (that some of the fields of incoming argument `sig` contain garbage), or
// can we store the whole thing and use StoreAgnostic_CORINFO_SIG_INFO()? // can we store the whole thing and use StoreAgnostic_CORINFO_SIG_INFO()?
key.flags = (DWORD)sig->flags; key.flags = (DWORD)sig->flags;
key.numArgs = (DWORD)sig->numArgs; key.numArgs = (DWORD)sig->numArgs;
if ((sig->cbSig == 0) && (sig->pSig != nullptr))
{
// In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer
// to an object), not a pointer to an array of signature bytes. Store the handle itself.
key.sigHandle = CastHandle((void*)sig->pSig);
}
SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index);
SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index);
key.scope = CastHandle(sig->scope); key.methodSignature = CastPointer(sig->methodSignature);
key.args = CastHandle(args); key.scope = CastHandle(sig->scope);
key.args = CastHandle(args);
Agnostic_GetArgType_Value value; Agnostic_GetArgType_Value value;
value.vcTypeRet = CastHandle(*vcTypeRet); value.vcTypeRet = CastHandle(*vcTypeRet);
...@@ -2550,12 +2544,11 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig, ...@@ -2550,12 +2544,11 @@ void MethodContext::recGetArgType(CORINFO_SIG_INFO* sig,
} }
void MethodContext::dmpGetArgType(const Agnostic_GetArgType_Key& key, const Agnostic_GetArgType_Value& value) void MethodContext::dmpGetArgType(const Agnostic_GetArgType_Key& key, const Agnostic_GetArgType_Value& value)
{ {
printf("GetArgType key flg-%08X na-%u sigHnd-%016llX %s %s scp-%016llX arg-%016llX", printf("GetArgType key flg-%08X na-%u %s %s msig-%016llX scp-%016llX arg-%016llX",
key.flags, key.numArgs, key.flags, key.numArgs,
key.sigHandle,
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(),
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(),
key.scope, key.args); key.methodSignature, key.scope, key.args);
printf(", value result(cit)-%u(%s) vcType-%016llX excp-%08X", value.result, toString((CorInfoTypeWithMod)value.result), value.vcTypeRet, value.exceptionCode); printf(", value result(cit)-%u(%s) vcType-%016llX excp-%08X", value.result, toString((CorInfoTypeWithMod)value.result), value.vcTypeRet, value.exceptionCode);
} }
CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig, CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig,
...@@ -2572,16 +2565,9 @@ CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig, ...@@ -2572,16 +2565,9 @@ CorInfoTypeWithMod MethodContext::repGetArgType(CORINFO_SIG_INFO* sig,
key.flags = (DWORD)sig->flags; key.flags = (DWORD)sig->flags;
key.numArgs = (DWORD)sig->numArgs; key.numArgs = (DWORD)sig->numArgs;
if ((sig->cbSig == 0) && (sig->pSig != nullptr))
{
// In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer
// to an object), not a pointer to an array of signature bytes. Store the handle itself.
key.sigHandle = CastHandle((void*)sig->pSig);
}
key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount; key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount;
key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount; key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount;
key.methodSignature = CastPointer(sig->methodSignature);
key.scope = CastHandle(sig->scope); key.scope = CastHandle(sig->scope);
key.args = CastHandle(args); key.args = CastHandle(args);
...@@ -2674,15 +2660,9 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig, ...@@ -2674,15 +2660,9 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig,
SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap, &key.sigInst_classInstCount, &key.sigInst_classInst_Index);
SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index); SpmiRecordsHelper::StoreAgnostic_CORINFO_SIG_INST_HandleArray(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap, &key.sigInst_methInstCount, &key.sigInst_methInst_Index);
key.scope = CastHandle(sig->scope); key.methodSignature = CastPointer(sig->methodSignature);
key.args = CastHandle(args); key.scope = CastHandle(sig->scope);
key.args = CastHandle(args);
if ((sig->cbSig == 0) && (sig->pSig != nullptr))
{
// In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer
// to an object), not a pointer to an array of signature bytes. Store the handle itself.
key.sigHandle = CastHandle((void*)sig->pSig);
}
Agnostic_GetArgClass_Value value; Agnostic_GetArgClass_Value value;
value.result = CastHandle(result); value.result = CastHandle(result);
...@@ -2693,10 +2673,10 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig, ...@@ -2693,10 +2673,10 @@ void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig,
} }
void MethodContext::dmpGetArgClass(const Agnostic_GetArgClass_Key& key, const Agnostic_GetArgClass_Value& value) void MethodContext::dmpGetArgClass(const Agnostic_GetArgClass_Key& key, const Agnostic_GetArgClass_Value& value)
{ {
printf("GetArgClass key %s %s scp-%016llX args-%016llX sigHnd-%016llX", printf("GetArgClass key %s %s msig-%016llX scp-%016llX args-%016llX",
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "cc", "ci", key.sigInst_classInstCount, key.sigInst_classInst_Index, SigInstHandleMap).c_str(),
SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INST_Element("", "mc", "mi", key.sigInst_methInstCount, key.sigInst_methInst_Index, SigInstHandleMap).c_str(),
key.scope, key.args, key.sigHandle); key.methodSignature, key.scope, key.args);
printf(", value %016llX excp-%08X", value.result, value.exceptionCode); printf(", value %016llX excp-%08X", value.result, value.exceptionCode);
} }
CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig, CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig,
...@@ -2712,16 +2692,10 @@ CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig, ...@@ -2712,16 +2692,10 @@ CORINFO_CLASS_HANDLE MethodContext::repGetArgClass(CORINFO_SIG_INFO* sig,
key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount; key.sigInst_classInstCount = (DWORD)sig->sigInst.classInstCount;
key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount; key.sigInst_methInstCount = (DWORD)sig->sigInst.methInstCount;
key.methodSignature = CastPointer(sig->methodSignature);
key.scope = CastHandle(sig->scope); key.scope = CastHandle(sig->scope);
key.args = CastHandle(args); key.args = CastHandle(args);
if ((sig->cbSig == 0) && (sig->pSig != nullptr))
{
// In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer
// to an object), not a pointer to an array of signature bytes. Store the handle itself.
key.sigHandle = CastHandle((void*)sig->pSig);
}
key.sigInst_classInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap); key.sigInst_classInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.classInstCount, sig->sigInst.classInst, SigInstHandleMap);
key.sigInst_methInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap); key.sigInst_methInst_Index = SpmiRecordsHelper::ContainsHandleMap(sig->sigInst.methInstCount, sig->sigInst.methInst, SigInstHandleMap);
......
...@@ -162,8 +162,8 @@ inline std::string SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO( ...@@ -162,8 +162,8 @@ inline std::string SpmiDumpHelper::DumpAgnostic_CORINFO_SIG_INFO(
FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "cc", "ci", sigInfo.sigInst_classInstCount, sigInfo.sigInst_classInst_Index, handleMap); FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "cc", "ci", sigInfo.sigInst_classInstCount, sigInfo.sigInst_classInst_Index, handleMap);
FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "mc", "mi", sigInfo.sigInst_methInstCount, sigInfo.sigInst_methInst_Index, handleMap); FormatAgnostic_CORINFO_SIG_INST_Element(pbuf, sizeOfBuffer, " ", "mc", "mi", sigInfo.sigInst_methInstCount, sigInfo.sigInst_methInst_Index, handleMap);
cch = sprintf_s(pbuf, sizeOfBuffer, " args-%016llX sig-%s sigHnd-%016llX scp-%016llX tok-%08X}", cch = sprintf_s(pbuf, sizeOfBuffer, " args-%016llX sig-%s msig-%016llX scp-%016llX tok-%08X}",
sigInfo.args, DumpPSig(sigInfo.pSig_Index, sigInfo.cbSig, buffers).c_str(), sigInfo.sigHandle, sigInfo.scope, sigInfo.token); sigInfo.args, DumpPSig(sigInfo.pSig_Index, sigInfo.cbSig, buffers).c_str(), sigInfo.methodSignature, sigInfo.scope, sigInfo.token);
pbuf += cch; pbuf += cch;
sizeOfBuffer -= cch; sizeOfBuffer -= cch;
......
...@@ -218,12 +218,7 @@ inline Agnostic_CORINFO_SIG_INFO SpmiRecordsHelper::CreateAgnostic_CORINFO_SIG_I ...@@ -218,12 +218,7 @@ inline Agnostic_CORINFO_SIG_INFO SpmiRecordsHelper::CreateAgnostic_CORINFO_SIG_I
sig.sigInst_methInstCount = (DWORD)sigInfo.sigInst.methInstCount; sig.sigInst_methInstCount = (DWORD)sigInfo.sigInst.methInstCount;
sig.args = CastHandle(sigInfo.args); sig.args = CastHandle(sigInfo.args);
sig.cbSig = (DWORD)sigInfo.cbSig; sig.cbSig = (DWORD)sigInfo.cbSig;
if ((sigInfo.cbSig == 0) && (sigInfo.pSig != nullptr)) sig.methodSignature = CastPointer(sigInfo.methodSignature);
{
// In this case, assume it is crossgen2 and pSig is actually a "handle" (some kind of pointer
// to an object), not a pointer to an array of signature bytes. Store the handle itself.
sig.sigHandle = CastHandle((void*)sigInfo.pSig);
}
sig.scope = CastHandle(sigInfo.scope); sig.scope = CastHandle(sigInfo.scope);
sig.token = (DWORD)sigInfo.token; sig.token = (DWORD)sigInfo.token;
return sig; return sig;
...@@ -391,16 +386,9 @@ inline CORINFO_SIG_INFO SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(const Agnost ...@@ -391,16 +386,9 @@ inline CORINFO_SIG_INFO SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(const Agnost
sig.flags = (unsigned)sigInfo.flags; sig.flags = (unsigned)sigInfo.flags;
sig.numArgs = (unsigned)sigInfo.numArgs; sig.numArgs = (unsigned)sigInfo.numArgs;
sig.args = (CORINFO_ARG_LIST_HANDLE)sigInfo.args; sig.args = (CORINFO_ARG_LIST_HANDLE)sigInfo.args;
if (sigInfo.sigHandle != 0) sig.cbSig = (unsigned int)sigInfo.cbSig;
{ sig.pSig = (PCCOR_SIGNATURE)buffers->GetBuffer(sigInfo.pSig_Index);
sig.cbSig = 0; sig.methodSignature = (MethodSignatureInfo*)sigInfo.methodSignature;
sig.pSig = (PCCOR_SIGNATURE)sigInfo.sigHandle;
}
else
{
sig.cbSig = (unsigned int)sigInfo.cbSig;
sig.pSig = (PCCOR_SIGNATURE)buffers->GetBuffer(sigInfo.pSig_Index);
}
sig.scope = (CORINFO_MODULE_HANDLE)sigInfo.scope; sig.scope = (CORINFO_MODULE_HANDLE)sigInfo.scope;
sig.token = (mdToken)sigInfo.token; sig.token = (mdToken)sigInfo.token;
......
...@@ -1048,6 +1048,9 @@ typedef struct CORINFO_VarArgInfo * CORINFO_VARARGS_HANDLE; ...@@ -1048,6 +1048,9 @@ typedef struct CORINFO_VarArgInfo * CORINFO_VARARGS_HANDLE;
// (or the open instantiation) is being referred to. // (or the open instantiation) is being referred to.
typedef struct CORINFO_CONTEXT_STRUCT_* CORINFO_CONTEXT_HANDLE; typedef struct CORINFO_CONTEXT_STRUCT_* CORINFO_CONTEXT_HANDLE;
// MethodSignatureInfo is an opaque handle for passing method signature information across the Jit/EE interface
struct MethodSignatureInfo;
typedef struct CORINFO_DEPENDENCY_STRUCT_ typedef struct CORINFO_DEPENDENCY_STRUCT_
{ {
CORINFO_MODULE_HANDLE moduleFrom; CORINFO_MODULE_HANDLE moduleFrom;
...@@ -1091,10 +1094,11 @@ struct CORINFO_SIG_INFO ...@@ -1091,10 +1094,11 @@ struct CORINFO_SIG_INFO
CorInfoType retType : 8; CorInfoType retType : 8;
unsigned flags : 8; // used by IL stubs code unsigned flags : 8; // used by IL stubs code
unsigned numArgs : 16; unsigned numArgs : 16;
struct CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code struct CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code
CORINFO_ARG_LIST_HANDLE args; CORINFO_ARG_LIST_HANDLE args;
PCCOR_SIGNATURE pSig; PCCOR_SIGNATURE pSig;
unsigned cbSig; unsigned cbSig;
MethodSignatureInfo* methodSignature;// used in place of pSig and cbSig to reference a method signature object handle
CORINFO_MODULE_HANDLE scope; // passed to getArgClass CORINFO_MODULE_HANDLE scope; // passed to getArgClass
mdToken token; mdToken token;
......
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
constexpr GUID JITEEVersionIdentifier = { /* a904114d-6fe1-4884-82ab-47849d22d882 */ constexpr GUID JITEEVersionIdentifier = { /* 20017875-6552-4375-80A8-F7E2CFC6AAB7 */
0xa904114d, 0x20017875,
0x6fe1, 0x6552,
0x4884, 0x4375,
{0x82, 0xab, 0x47, 0x84, 0x9d, 0x22, 0xd8, 0x82} { 0x80, 0xa8, 0xf7, 0xe2, 0xcf, 0xc6, 0xaa, 0xb7 }
}; };
////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -298,7 +298,7 @@ private void PublishCode() ...@@ -298,7 +298,7 @@ private void PublishCode()
_methodCodeNode.Fixups.Add(node); _methodCodeNode.Fixups.Add(node);
} }
#else #else
MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)_methodScope); MethodIL methodIL = HandleToObject(_methodScope);
CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(ref _additionalDependencies, _compilation.NodeFactory, MethodBeingCompiled, methodIL); CodeBasedDependencyAlgorithm.AddDependenciesDueToMethodCodePresence(ref _additionalDependencies, _compilation.NodeFactory, MethodBeingCompiled, methodIL);
_methodCodeNode.InitializeNonRelocationDependencies(_additionalDependencies); _methodCodeNode.InitializeNonRelocationDependencies(_additionalDependencies);
#endif #endif
...@@ -445,14 +445,16 @@ private Object HandleToObject(IntPtr handle) ...@@ -445,14 +445,16 @@ private Object HandleToObject(IntPtr handle)
return _handleToObject[index]; return _handleToObject[index];
} }
private MethodDesc HandleToObject(CORINFO_METHOD_STRUCT_* method) { return (MethodDesc)HandleToObject((IntPtr)method); } private MethodDesc HandleToObject(CORINFO_METHOD_STRUCT_* method) => (MethodDesc)HandleToObject((IntPtr)method);
private CORINFO_METHOD_STRUCT_* ObjectToHandle(MethodDesc method) { return (CORINFO_METHOD_STRUCT_*)ObjectToHandle((Object)method); } private CORINFO_METHOD_STRUCT_* ObjectToHandle(MethodDesc method) => (CORINFO_METHOD_STRUCT_*)ObjectToHandle((Object)method);
private TypeDesc HandleToObject(CORINFO_CLASS_STRUCT_* type) => (TypeDesc)HandleToObject((IntPtr)type);
private TypeDesc HandleToObject(CORINFO_CLASS_STRUCT_* type) { return (TypeDesc)HandleToObject((IntPtr)type); } private CORINFO_CLASS_STRUCT_* ObjectToHandle(TypeDesc type) => (CORINFO_CLASS_STRUCT_*)ObjectToHandle((Object)type);
private CORINFO_CLASS_STRUCT_* ObjectToHandle(TypeDesc type) { return (CORINFO_CLASS_STRUCT_*)ObjectToHandle((Object)type); } private FieldDesc HandleToObject(CORINFO_FIELD_STRUCT_* field) => (FieldDesc)HandleToObject((IntPtr)field);
private CORINFO_FIELD_STRUCT_* ObjectToHandle(FieldDesc field) => (CORINFO_FIELD_STRUCT_*)ObjectToHandle((object)field);
private FieldDesc HandleToObject(CORINFO_FIELD_STRUCT_* field) { return (FieldDesc)HandleToObject((IntPtr)field); } private MethodIL HandleToObject(CORINFO_MODULE_STRUCT_* module) => (MethodIL)HandleToObject((IntPtr)module);
private CORINFO_FIELD_STRUCT_* ObjectToHandle(FieldDesc field) { return (CORINFO_FIELD_STRUCT_*)ObjectToHandle((Object)field); } private CORINFO_MODULE_STRUCT_* ObjectToHandle(MethodIL methodIL) => (CORINFO_MODULE_STRUCT_*)ObjectToHandle((object)methodIL);
private MethodSignature HandleToObject(MethodSignatureInfo* method) => (MethodSignature)HandleToObject((IntPtr)method);
private MethodSignatureInfo* ObjectToHandle(MethodSignature method) => (MethodSignatureInfo*)ObjectToHandle((object)method);
private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORINFO_METHOD_INFO* methodInfo) private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORINFO_METHOD_INFO* methodInfo)
{ {
...@@ -463,7 +465,7 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN ...@@ -463,7 +465,7 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN
} }
methodInfo->ftn = ObjectToHandle(method); methodInfo->ftn = ObjectToHandle(method);
methodInfo->scope = (CORINFO_MODULE_STRUCT_*)ObjectToHandle(methodIL); methodInfo->scope = ObjectToHandle(methodIL);
var ilCode = methodIL.GetILBytes(); var ilCode = methodIL.GetILBytes();
methodInfo->ILCode = (byte*)GetPin(ilCode); methodInfo->ILCode = (byte*)GetPin(ilCode);
methodInfo->ILCodeSize = (uint)ilCode.Length; methodInfo->ILCodeSize = (uint)ilCode.Length;
...@@ -654,8 +656,9 @@ private void Get_CORINFO_SIG_INFO(MethodSignature signature, CORINFO_SIG_INFO* s ...@@ -654,8 +656,9 @@ private void Get_CORINFO_SIG_INFO(MethodSignature signature, CORINFO_SIG_INFO* s
sig->sigInst.methInst = null; // Not used by the JIT sig->sigInst.methInst = null; // Not used by the JIT
sig->sigInst.methInstCount = (uint)signature.GenericParameterCount; sig->sigInst.methInstCount = (uint)signature.GenericParameterCount;
sig->pSig = (byte*)ObjectToHandle(signature); sig->pSig = null;
sig->cbSig = 0; // Not used by the JIT sig->cbSig = 0; // Not used by the JIT
sig->methodSignature = ObjectToHandle(signature);
sig->scope = null; sig->scope = null;
sig->token = 0; // Not used by the JIT sig->token = 0; // Not used by the JIT
} }
...@@ -677,8 +680,10 @@ private void Get_CORINFO_SIG_INFO(LocalVariableDefinition[] locals, CORINFO_SIG_ ...@@ -677,8 +680,10 @@ private void Get_CORINFO_SIG_INFO(LocalVariableDefinition[] locals, CORINFO_SIG_
sig->args = (CORINFO_ARG_LIST_STRUCT_*)0; // CORINFO_ARG_LIST_STRUCT_ is argument index sig->args = (CORINFO_ARG_LIST_STRUCT_*)0; // CORINFO_ARG_LIST_STRUCT_ is argument index
sig->pSig = (byte*)ObjectToHandle(locals);
sig->pSig = null;
sig->cbSig = 0; // Not used by the JIT sig->cbSig = 0; // Not used by the JIT
sig->methodSignature = (MethodSignatureInfo*)ObjectToHandle(locals);
sig->scope = null; // Not used by the JIT sig->scope = null; // Not used by the JIT
sig->token = 0; // Not used by the JIT sig->token = 0; // Not used by the JIT
} }
...@@ -986,7 +991,7 @@ private void getEHinfo(CORINFO_METHOD_STRUCT_* ftn, uint EHnumber, ref CORINFO_E ...@@ -986,7 +991,7 @@ private void getEHinfo(CORINFO_METHOD_STRUCT_* ftn, uint EHnumber, ref CORINFO_E
{ {
return null; return null;
} }
return (CORINFO_MODULE_STRUCT_*)ObjectToHandle(methodIL); return ObjectToHandle(methodIL);
} }
private bool resolveVirtualMethod(CORINFO_DEVIRTUALIZATION_INFO* info) private bool resolveVirtualMethod(CORINFO_DEVIRTUALIZATION_INFO* info)
...@@ -1084,7 +1089,7 @@ private CorInfoCallConvExtension getUnmanagedCallConv(CORINFO_METHOD_STRUCT_* me ...@@ -1084,7 +1089,7 @@ private CorInfoCallConvExtension getUnmanagedCallConv(CORINFO_METHOD_STRUCT_* me
{ {
Debug.Assert(sig != null); Debug.Assert(sig != null);
CorInfoCallConvExtension callConv = GetUnmanagedCallConv((MethodSignature)HandleToObject((IntPtr)sig->pSig), out pSuppressGCTransition); CorInfoCallConvExtension callConv = GetUnmanagedCallConv(HandleToObject(sig->methodSignature), out pSuppressGCTransition);
return callConv; return callConv;
} }
} }
...@@ -1242,7 +1247,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe ...@@ -1242,7 +1247,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe
// dependency analysis operates on runtime determined ones, we convert the resolved token // dependency analysis operates on runtime determined ones, we convert the resolved token
// to the runtime determined form (e.g. Foo<__Canon> becomes Foo<T__Canon>). // to the runtime determined form (e.g. Foo<__Canon> becomes Foo<T__Canon>).
var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); var methodIL = HandleToObject(pResolvedToken.tokenScope);
var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ? var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ?
MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext); MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext);
...@@ -1290,7 +1295,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe ...@@ -1290,7 +1295,7 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe
private void resolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) private void resolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken)
{ {
var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); var methodIL = HandleToObject(pResolvedToken.tokenScope);
var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ? var typeOrMethodContext = (pResolvedToken.tokenContext == contextFromMethodBeingCompiled()) ?
MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext); MethodBeingCompiled : HandleToObject((IntPtr)pResolvedToken.tokenContext);
...@@ -1394,7 +1399,7 @@ private bool tryResolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) ...@@ -1394,7 +1399,7 @@ private bool tryResolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken)
private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig)
{ {
var methodIL = (MethodIL)HandleToObject((IntPtr)module); var methodIL = HandleToObject(module);
var methodSig = (MethodSignature)methodIL.GetObject((int)sigTOK); var methodSig = (MethodSignature)methodIL.GetObject((int)sigTOK);
Get_CORINFO_SIG_INFO(methodSig, sig); Get_CORINFO_SIG_INFO(methodSig, sig);
...@@ -1412,7 +1417,7 @@ private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEX ...@@ -1412,7 +1417,7 @@ private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEX
private void findCallSiteSig(CORINFO_MODULE_STRUCT_* module, uint methTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig) private void findCallSiteSig(CORINFO_MODULE_STRUCT_* module, uint methTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig)
{ {
var methodIL = (MethodIL)HandleToObject((IntPtr)module); var methodIL = HandleToObject(module);
Get_CORINFO_SIG_INFO(((MethodDesc)methodIL.GetObject((int)methTOK)), sig: sig); Get_CORINFO_SIG_INFO(((MethodDesc)methodIL.GetObject((int)methTOK)), sig: sig);
} }
...@@ -1445,7 +1450,7 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK) ...@@ -1445,7 +1450,7 @@ private bool isValidStringRef(CORINFO_MODULE_STRUCT_* module, uint metaTOK)
private char* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length) private char* getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, ref int length)
{ {
MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); MethodIL methodIL = HandleToObject(module);
string s = (string)methodIL.GetObject((int)metaTOK); string s = (string)methodIL.GetObject((int)metaTOK);
length = (int)s.Length; length = (int)s.Length;
return (char*)GetPin(s); return (char*)GetPin(s);
...@@ -2501,7 +2506,7 @@ private void freeArray(void* array) ...@@ -2501,7 +2506,7 @@ private void freeArray(void* array)
private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args, CORINFO_CLASS_STRUCT_** vcTypeRet) private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args, CORINFO_CLASS_STRUCT_** vcTypeRet)
{ {
int index = (int)args; int index = (int)args;
Object sigObj = HandleToObject((IntPtr)sig->pSig); Object sigObj = HandleToObject((IntPtr)sig->methodSignature);
MethodSignature methodSig = sigObj as MethodSignature; MethodSignature methodSig = sigObj as MethodSignature;
...@@ -2526,7 +2531,7 @@ private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_ST ...@@ -2526,7 +2531,7 @@ private CorInfoTypeWithMod getArgType(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_ST
private CORINFO_CLASS_STRUCT_* getArgClass(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args) private CORINFO_CLASS_STRUCT_* getArgClass(CORINFO_SIG_INFO* sig, CORINFO_ARG_LIST_STRUCT_* args)
{ {
int index = (int)args; int index = (int)args;
Object sigObj = HandleToObject((IntPtr)sig->pSig); Object sigObj = HandleToObject((IntPtr)sig->methodSignature);
MethodSignature methodSig = sigObj as MethodSignature; MethodSignature methodSig = sigObj as MethodSignature;
if (methodSig != null) if (methodSig != null)
......
...@@ -69,6 +69,10 @@ public struct PatchpointInfo ...@@ -69,6 +69,10 @@ public struct PatchpointInfo
{ {
} }
public struct MethodSignatureInfo
{
}
public enum _EXCEPTION_POINTERS public enum _EXCEPTION_POINTERS
{ } { }
...@@ -91,16 +95,17 @@ public enum HRESULT { ...@@ -91,16 +95,17 @@ public enum HRESULT {
public unsafe struct CORINFO_SIG_INFO public unsafe struct CORINFO_SIG_INFO
{ {
public CorInfoCallConv callConv; public CorInfoCallConv callConv;
public CORINFO_CLASS_STRUCT_* retTypeClass; // if the return type is a value class, this is its handle (enums are normalized) public CORINFO_CLASS_STRUCT_* retTypeClass; // if the return type is a value class, this is its handle (enums are normalized)
public CORINFO_CLASS_STRUCT_* retTypeSigClass;// returns the value class as it is in the sig (enums are not converted to primitives) public CORINFO_CLASS_STRUCT_* retTypeSigClass; // returns the value class as it is in the sig (enums are not converted to primitives)
public byte _retType; public byte _retType;
public CorInfoSigInfoFlags flags; // used by IL stubs code public CorInfoSigInfoFlags flags; // used by IL stubs code
public ushort numArgs; public ushort numArgs;
public CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code public CORINFO_SIG_INST sigInst; // information about how type variables are being instantiated in generic code
public CORINFO_ARG_LIST_STRUCT_* args; public CORINFO_ARG_LIST_STRUCT_* args;
public byte* pSig; public byte* pSig;
public uint cbSig; public uint cbSig;
public CORINFO_MODULE_STRUCT_* scope; // passed to getArgClass public MethodSignatureInfo* methodSignature; // used in place of pSig and cbSig to reference a method signature object handle
public CORINFO_MODULE_STRUCT_* scope; // passed to getArgClass
public mdToken token; public mdToken token;
public CorInfoType retType { get { return (CorInfoType)_retType; } set { _retType = (byte)value; } } public CorInfoType retType { get { return (CorInfoType)_retType; } set { _retType = (byte)value; } }
......
...@@ -487,7 +487,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref ...@@ -487,7 +487,7 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref
object helperArg = GetRuntimeDeterminedObjectForToken(ref pResolvedToken); object helperArg = GetRuntimeDeterminedObjectForToken(ref pResolvedToken);
if (helperArg is MethodDesc methodDesc) if (helperArg is MethodDesc methodDesc)
{ {
var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); var methodIL = HandleToObject(pResolvedToken.tokenScope);
MethodDesc sharedMethod = methodIL.OwningMethod.GetSharedRuntimeFormMethodTarget(); MethodDesc sharedMethod = methodIL.OwningMethod.GetSharedRuntimeFormMethodTarget();
helperArg = new MethodWithToken(methodDesc, HandleToModuleToken(ref pResolvedToken), constrainedType, unboxing: false, context: sharedMethod); helperArg = new MethodWithToken(methodDesc, HandleToModuleToken(ref pResolvedToken), constrainedType, unboxing: false, context: sharedMethod);
} }
...@@ -878,7 +878,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke ...@@ -878,7 +878,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke
private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken) private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken)
{ {
mdToken token = pResolvedToken.token; mdToken token = pResolvedToken.token;
var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); var methodIL = HandleToObject(pResolvedToken.tokenScope);
EcmaModule module; EcmaModule module;
// If the method body is synthetized by the compiler (the definition of the MethodIL is not // If the method body is synthetized by the compiler (the definition of the MethodIL is not
...@@ -952,7 +952,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke ...@@ -952,7 +952,7 @@ private ModuleToken HandleToModuleToken(ref CORINFO_RESOLVED_TOKEN pResolvedToke
private InfoAccessType constructStringLiteral(CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue) private InfoAccessType constructStringLiteral(CORINFO_MODULE_STRUCT_* module, mdToken metaTok, ref void* ppValue)
{ {
MethodIL methodIL = (MethodIL)HandleToObject((IntPtr)module); MethodIL methodIL = HandleToObject(module);
// If this is not a MethodIL backed by a physical method body, we need to remap the token. // If this is not a MethodIL backed by a physical method body, we need to remap the token.
Debug.Assert(methodIL.GetMethodILDefinition() is EcmaMethodIL); Debug.Assert(methodIL.GetMethodILDefinition() is EcmaMethodIL);
...@@ -1453,7 +1453,7 @@ private static bool IsTypeSpecForTypicalInstantiation(TypeDesc t) ...@@ -1453,7 +1453,7 @@ private static bool IsTypeSpecForTypicalInstantiation(TypeDesc t)
constrainedType == null && constrainedType == null &&
exactType == MethodBeingCompiled.OwningType) exactType == MethodBeingCompiled.OwningType)
{ {
var methodIL = (MethodIL)HandleToObject((IntPtr)pResolvedToken.tokenScope); var methodIL = HandleToObject(pResolvedToken.tokenScope);
var rawMethod = (MethodDesc)methodIL.GetMethodILDefinition().GetObject((int)pResolvedToken.token); var rawMethod = (MethodDesc)methodIL.GetMethodILDefinition().GetObject((int)pResolvedToken.token);
if (IsTypeSpecForTypicalInstantiation(rawMethod.OwningType)) if (IsTypeSpecForTypicalInstantiation(rawMethod.OwningType))
{ {
...@@ -2516,7 +2516,7 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S ...@@ -2516,7 +2516,7 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S
} }
else else
{ {
var sig = (MethodSignature)HandleToObject((IntPtr)callSiteSig->pSig); var sig = HandleToObject(callSiteSig->methodSignature);
return Marshaller.IsMarshallingRequired(sig, Array.Empty<ParameterMetadata>()); return Marshaller.IsMarshallingRequired(sig, Array.Empty<ParameterMetadata>());
} }
} }
......
...@@ -472,6 +472,7 @@ CEEInfo::ConvToJitSig( ...@@ -472,6 +472,7 @@ CEEInfo::ConvToJitSig(
sigRet->pSig = pSig; sigRet->pSig = pSig;
sigRet->cbSig = cbSig; sigRet->cbSig = cbSig;
sigRet->methodSignature = 0;
sigRet->retTypeClass = 0; sigRet->retTypeClass = 0;
sigRet->retTypeSigClass = 0; sigRet->retTypeSigClass = 0;
sigRet->scope = scopeHnd; sigRet->scope = scopeHnd;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册