1515#define INTERP_API __attribute__ ((visibility (" default" )))
1616#endif // _MSC_VER
1717
18- #include < vector>
19-
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-
4218/* ****************************************************************************/
4319ICorJitHost* g_interpHost = nullptr ;
4420bool g_interpInitialized = false ;
@@ -64,16 +40,6 @@ extern "C" INTERP_API ICorJitCompiler* getJit()
6440 return &g_CILInterp;
6541}
6642
67- static InterpManager g_Manager;
68- extern " C" INTERP_API ICorInterpreter* getInterpreter ()
69- {
70- if (!g_interpInitialized)
71- {
72- return nullptr ;
73- }
74- return &g_Manager;
75- }
76-
7743// ****************************************************************************
7844CorJitResult CILInterp::compileMethod (ICorJitInfo* compHnd,
7945 CORINFO_METHOD_INFO* methodInfo,
@@ -95,33 +61,36 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd,
9561 return CORJIT_SKIPPED;
9662 }
9763
98- InterpMethod *pMethod = InterpGetInterpMethod (methodInfo->ftn );
99- if (!pMethod->compiled )
100- {
101- InterpCompiler compiler (compHnd, methodInfo);
102- compiler.CompileMethod (pMethod);
103- }
64+ InterpCompiler compiler (compHnd, methodInfo);
65+ InterpMethod *pMethod = compiler.CompileMethod ();
66+
67+ int32_t IRCodeSize;
68+ int32_t *pIRCode = compiler.GetCode (&IRCodeSize);
10469
10570 // FIXME this shouldn't be here
10671 compHnd->setMethodAttribs (methodInfo->ftn , CORINFO_FLG_INTERPRETER);
10772
73+ uint32_t sizeOfCode = sizeof (InterpMethod*) + IRCodeSize * sizeof (int32_t );
74+
10875 // TODO: get rid of the need to allocate fake unwind info.
10976 compHnd->reserveUnwindInfo (false /* isFunclet */ , false /* isColdCode */ , 8 /* unwindSize */ );
11077 AllocMemArgs args;
111- args.hotCodeSize = 16 ;
78+ args.hotCodeSize = sizeOfCode ;
11279 args.coldCodeSize = 0 ;
11380 args.roDataSize = 0 ;
11481 args.xcptnsCount = 0 ;
11582 args.flag = CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN;
11683 compHnd->allocMem (&args);
117- uint8_t *code = (uint8_t *)args.hotCodeBlockRW ;
118- *code++ = 1 ; // fake byte code
84+
85+ // We store first the InterpMethod pointer as the code header, followed by the actual code
86+ *(InterpMethod**)args.hotCodeBlockRW = pMethod;
87+ memcpy ((uint8_t *)args.hotCodeBlockRW + sizeof (InterpMethod*), pIRCode, IRCodeSize * sizeof (int32_t ));
11988
12089 // TODO: get rid of the need to allocate fake unwind info
12190 compHnd->allocUnwindInfo ((uint8_t *)args.hotCodeBlock , (uint8_t *)args.coldCodeBlock , 0 , 1 , 0 , nullptr , CORJIT_FUNC_ROOT);
12291
12392 *entryAddress = (uint8_t *)args.hotCodeBlock ;
124- *nativeSizeOfCode = 1 ;
93+ *nativeSizeOfCode = sizeOfCode ;
12594
12695 return CORJIT_OK;
12796}
@@ -140,8 +109,3 @@ void CILInterp::getVersionIdentifier(GUID* versionIdentifier)
140109void CILInterp::setTargetOS (CORINFO_OS os)
141110{
142111}
143-
144- void * InterpManager::GetInterpMethod (CORINFO_METHOD_HANDLE methodHnd)
145- {
146- return InterpGetInterpMethod (methodHnd);
147- }
0 commit comments