1717
1818#include < vector>
1919
20- // FIXME We will probably end up not needing this table.
21- // If deemed useful, use some hashtable implementation instead.
22- std::vector<std::pair<CORINFO_METHOD_HANDLE,InterpMethod*>> g_interpCodeHash;
23-
24- static InterpMethod* InterpGetInterpMethod (CORINFO_METHOD_HANDLE methodHnd)
25- {
26- // FIXME lock for multiple thread access
27- for (size_t i = 0 ; i < g_interpCodeHash.size (); i++)
28- {
29- if (g_interpCodeHash[i].first == methodHnd)
30- {
31- return g_interpCodeHash[i].second ;
32- }
33- }
34-
35- InterpMethod* pMethod = new InterpMethod ();
36- pMethod->methodHnd = methodHnd;
37-
38- g_interpCodeHash.push_back ({methodHnd, pMethod});
39- return pMethod;
40- }
41-
4220/* ****************************************************************************/
4321ICorJitHost* g_interpHost = nullptr ;
4422bool g_interpInitialized = false ;
@@ -95,33 +73,36 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd,
9573 return CORJIT_SKIPPED;
9674 }
9775
98- InterpMethod *pMethod = InterpGetInterpMethod (methodInfo->ftn );
99- if (!pMethod->compiled )
100- {
101- InterpCompiler compiler (compHnd, methodInfo);
102- compiler.CompileMethod (pMethod);
103- }
76+ InterpCompiler compiler (compHnd, methodInfo);
77+ InterpMethod *pMethod = compiler.CompileMethod ();
78+
79+ int32_t IRCodeSize;
80+ int32_t *pIRCode = compiler.GetCode (&IRCodeSize);
10481
10582 // FIXME this shouldn't be here
10683 compHnd->setMethodAttribs (methodInfo->ftn , CORINFO_FLG_INTERPRETER);
10784
85+ uint32_t sizeOfCode = sizeof (void *) + IRCodeSize * sizeof (int32_t );
86+
10887 // TODO: get rid of the need to allocate fake unwind info.
10988 compHnd->reserveUnwindInfo (false /* isFunclet */ , false /* isColdCode */ , 8 /* unwindSize */ );
11089 AllocMemArgs args;
111- args.hotCodeSize = 16 ;
90+ args.hotCodeSize = sizeOfCode ;
11291 args.coldCodeSize = 0 ;
11392 args.roDataSize = 0 ;
11493 args.xcptnsCount = 0 ;
11594 args.flag = CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN;
11695 compHnd->allocMem (&args);
117- uint8_t *code = (uint8_t *)args.hotCodeBlockRW ;
118- *code++ = 1 ; // fake byte code
96+
97+ // We store first the InterpMethod pointer as the code header, followed by the actual code
98+ *(InterpMethod**)args.hotCodeBlockRW = pMethod;
99+ memcpy ((uint8_t *)args.hotCodeBlockRW + sizeof (InterpMethod*), pIRCode, IRCodeSize * sizeof (int32_t ));
119100
120101 // TODO: get rid of the need to allocate fake unwind info
121102 compHnd->allocUnwindInfo ((uint8_t *)args.hotCodeBlock , (uint8_t *)args.coldCodeBlock , 0 , 1 , 0 , nullptr , CORJIT_FUNC_ROOT);
122103
123104 *entryAddress = (uint8_t *)args.hotCodeBlock ;
124- *nativeSizeOfCode = 1 ;
105+ *nativeSizeOfCode = sizeOfCode ;
125106
126107 return CORJIT_OK;
127108}
@@ -140,8 +121,3 @@ void CILInterp::getVersionIdentifier(GUID* versionIdentifier)
140121void CILInterp::setTargetOS (CORINFO_OS os)
141122{
142123}
143-
144- void * InterpManager::GetInterpMethod (CORINFO_METHOD_HANDLE methodHnd)
145- {
146- return InterpGetInterpMethod (methodHnd);
147- }
0 commit comments