15
15
#define INTERP_API __attribute__ ((visibility (" default" )))
16
16
#endif // _MSC_VER
17
17
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
-
42
18
/* ****************************************************************************/
43
19
ICorJitHost* g_interpHost = nullptr ;
44
20
bool g_interpInitialized = false ;
@@ -64,16 +40,6 @@ extern "C" INTERP_API ICorJitCompiler* getJit()
64
40
return &g_CILInterp;
65
41
}
66
42
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
-
77
43
// ****************************************************************************
78
44
CorJitResult CILInterp::compileMethod (ICorJitInfo* compHnd,
79
45
CORINFO_METHOD_INFO* methodInfo,
@@ -95,33 +61,36 @@ CorJitResult CILInterp::compileMethod(ICorJitInfo* compHnd,
95
61
return CORJIT_SKIPPED;
96
62
}
97
63
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);
104
69
105
70
// FIXME this shouldn't be here
106
71
compHnd->setMethodAttribs (methodInfo->ftn , CORINFO_FLG_INTERPRETER);
107
72
73
+ uint32_t sizeOfCode = sizeof (InterpMethod*) + IRCodeSize * sizeof (int32_t );
74
+
108
75
// TODO: get rid of the need to allocate fake unwind info.
109
76
compHnd->reserveUnwindInfo (false /* isFunclet */ , false /* isColdCode */ , 8 /* unwindSize */ );
110
77
AllocMemArgs args;
111
- args.hotCodeSize = 16 ;
78
+ args.hotCodeSize = sizeOfCode ;
112
79
args.coldCodeSize = 0 ;
113
80
args.roDataSize = 0 ;
114
81
args.xcptnsCount = 0 ;
115
82
args.flag = CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN;
116
83
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 ));
119
88
120
89
// TODO: get rid of the need to allocate fake unwind info
121
90
compHnd->allocUnwindInfo ((uint8_t *)args.hotCodeBlock , (uint8_t *)args.coldCodeBlock , 0 , 1 , 0 , nullptr , CORJIT_FUNC_ROOT);
122
91
123
92
*entryAddress = (uint8_t *)args.hotCodeBlock ;
124
- *nativeSizeOfCode = 1 ;
93
+ *nativeSizeOfCode = sizeOfCode ;
125
94
126
95
return CORJIT_OK;
127
96
}
@@ -140,8 +109,3 @@ void CILInterp::getVersionIdentifier(GUID* versionIdentifier)
140
109
void CILInterp::setTargetOS (CORINFO_OS os)
141
110
{
142
111
}
143
-
144
- void * InterpManager::GetInterpMethod (CORINFO_METHOD_HANDLE methodHnd)
145
- {
146
- return InterpGetInterpMethod (methodHnd);
147
- }
0 commit comments