2
* Copyright (C) 2007, 2008 Campanoni Simone, Anelli Stefano
4
* iljit - This is a Just-in-time for the CIL language specified with the ECMA-335
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#ifndef IRSPECIALIZER_H
22
#define IRSPECIALIZER_H
29
#include <jitsystem.h>
30
#include <ir_method.h>
33
#include <irprofiler.h>
36
/* ----------------------------------------- Constant Common Values -----------------------------------------*/
37
#undef SPECIALIZE_EVERY_METHOD /* Define this if you want to specialize each method */
38
#define SPECIALIZE_EVERY_METHOD
40
#undef FULLMODE_PRINTDEBUG
41
//#define FULLMODE_PRINTDEBUG
43
#ifdef FULLMODE_PRINTDEBUG
44
# define FMODEPRINT(fmt, args...) fprintf(stderr, fmt, ## args)
46
# define FMODEPRINT(fmt, args...)
49
/* ----------------------------------------- Constant Common Values -----------------------------------------*/
50
#ifdef SPECIALIZE_EVERY_METHOD
51
#define SPECIALIZER_EVERY_METHOD_FACTOR specializer_fullspecialization_counter
52
#define SPECIALIZER_ZERO_PROFILER_MEMORY_SIZE (SPECIALIZER_EVERY_METHOD_FACTOR * sizeof(JITUINT32))
53
#define SEPCIALIZER_ZERO_PROFILER_THRESHOLD 0.3
54
#define SEPCIALIZER_ZERO_DISPATCHER_REMOVE_THRESHOLD SPECIALIZER_EVERY_METHOD_FACTOR
55
#define SPECIALIZER_FIRST_PROFILER_THRESHOLD 2
56
#define SPECIALIZER_SECOND_PROFILER_MEMORY_SIZE (SPECIALIZER_EVERY_METHOD_FACTOR*sizeof(JITFLOAT64))
57
#define SPECIALIZER_SECOND_PROFILER_STATIC_THRESHOLD 0.3
58
#define SPECIALIZER_DISPATCHER_REMOVE_THRESHOLD SPECIALIZER_EVERY_METHOD_FACTOR
60
#define SPECIALIZER_ZERO_PROFILER_MEMORY_SIZE (100 * sizeof(JITUINT32) - 1)
61
#define SEPCIALIZER_ZERO_PROFILER_THRESHOLD 0.3
62
#define SEPCIALIZER_ZERO_DISPATCHER_REMOVE_THRESHOLD 50
63
#define SPECIALIZER_FIRST_PROFILER_THRESHOLD 100
64
#define SPECIALIZER_SECOND_PROFILER_MEMORY_SIZE 1024
65
#define SPECIALIZER_SECOND_PROFILER_STATIC_THRESHOLD 0.3
66
#define SPECIALIZER_DISPATCHER_REMOVE_THRESHOLD 50
70
* Possible actions for a given expression
72
#define SPECIALIZER_ACTION_STATIC 0
73
#define SPECIALIZER_ACTION_STATIC_STR "STATIC"
74
#define SPECIALIZER_ACTION_STATIC_LENGTH 1
75
#define SPECIALIZER_ACTION_STATIC_LENGTH_STR "LENGTH"
76
#define SPECIALIZER_ACTION_STATIC_EQ 2
77
#define SPECIALIZER_ACTION_STATIC_EQ_STR "EQ"
78
#define SPECIALIZER_ACTION_STATIC_EQF 3
79
#define SPECIALIZER_ACTION_STATIC_EQF_STR "EQF"
80
#define SPECIALIZER_ACTION_STATIC_LESS 4
81
#define SPECIALIZER_ACTION_STATIC_LESS_STR "LESS"
82
#define SPECIALIZER_ACTION_STATIC_LESSF 5
83
#define SPECIALIZER_ACTION_STATIC_LESSF_STR "LESSF"
84
#define SPECIALIZER_ACTION_STATIC_GREAT 6
85
#define SPECIALIZER_ACTION_STATIC_GREAT_STR "GREAT"
86
#define SPECIALIZER_ACTION_STATIC_GREATF 7
87
#define SPECIALIZER_ACTION_STATIC_GREATF_STR "GREATF"
88
#define SPECIALIZER_ACTION_STATIC_LESSEQ 8
89
#define SPECIALIZER_ACTION_STATIC_LESSEQ_STR "LE"
90
#define SPECIALIZER_ACTION_STATIC_LESSEQF 9
91
#define SPECIALIZER_ACTION_STATIC_LESSEQF_STR "LEF"
92
#define SPECIALIZER_ACTION_STATIC_GREATEQ 10
93
#define SPECIALIZER_ACTION_STATIC_GREATEQ_STR "GE"
94
#define SPECIALIZER_ACTION_STATIC_GREATEQF 11
95
#define SPECIALIZER_ACTION_STATIC_GREATEQF_STR "GEF"
98
* These are all the possible states for a call site
100
#define SPECIALIZER_CALLSITE_STATUS_CLEAN 0 /*< Call site is clean and there a request for first profile injection */
101
#define SPECIALIZER_CALLSITE_STATUS_FIRST_PROFILER_INJECTED 1 /*< First Profiler Injected */
102
#define SPECIALIZER_CALLSITE_STATUS_SECOND_PROFILER_REQUEST 2 /*< Request for second profiler injection */
103
#define SPECIALIZER_CALLSITE_STATUS_SECOND_PROFILER_INJECTED 3 /*< Second Profiler Injected */
104
#define SPECIALIZER_CALLSITE_STATUS_DISPATCHER_REQUEST 4 /*< Request for dispatcher Injection */
105
#define SPECIALIZER_CALLSITE_STATUS_DISPATCHER_INJECTED 5 /*< Dispatcher Injected */
106
#define SPECIALIZER_CALLSITE_STATUS_DISPATCHER_REMOVE 6 /*< Request for dispatcher removal */
107
#define SPECIALIZER_CALLSITE_STATUS_DISPATCHER_UNSPECIALIZABLE 7 /*< The call site cannot be specialized at all */
108
#define SPECIALIZER_CALLSITE_STATUS_TYPE_DISPATCHER_REQUEST 8 /*< Perform a request for the type dispatcher */
109
#define SPECIALIZER_CALLSITE_STATUS_TYPE_DISPATCHER_INJECTED 9 /*< The type dispatcher for this IRVCALL has been injected */
110
#define SPECIALIZER_CALLSITE_STATUS_TYPE_DISPATCHER_REMOVE 10 /*< The type dispatcher must be removed */
112
/***************************************** VARIABLES */
113
#ifdef SPECIALIZE_EVERY_METHOD
114
static int specializer_fullspecialization_counter = -1;
117
/* ----------------------------------------- Structure for specialization hints -----------------------------------------*/
119
* @brief This structure describe a single expression hint
121
typedef struct specializer_expression_hint_t{
122
JITUINT32 position; /*< Position of the parameter */
123
JITUINT32 action; /*< One of the possible action */
125
JITINT64 ivalue; /*< Integer value for comparison for STATIC_EQ action */
126
JITFLOAT64 fvalue; /*< Float value for comparison for STATIC_EQF action */
127
} value; /*< Comparison value*/
128
JITUINT32 depth; /*< Depth of this expression */
129
struct specializer_expression_hint_t * next; /*< Next expression chained in AND or NULL if it's the last */
130
struct specializer_expression_hint_t * prev; /*< Previous expression chained in AND or NULL if it's the first */
132
void (*init) (struct specializer_expression_hint_t* expression, JITUINT32 position, JITUINT32 action, JITINT64 ivalue, JITFLOAT64 fvalue, struct specializer_expression_hint_t* prev, struct specializer_expression_hint_t* next);
133
void (*printSingle) (struct specializer_expression_hint_t* expression, FILE *out);
134
void (*printChain) (struct specializer_expression_hint_t* expression, FILE *out);
135
void (*clean) (struct specializer_expression_hint_t* expression, ir_specializer_t* specializer);
136
} specializer_expression_hint_t;
138
* Create a new expression hint
140
specializer_expression_hint_t* newSpecializerExpressionHint(ir_specializer_t* specializer);
143
* @brief This structure describe for a single method a list of possible specialization expression
145
typedef struct specializer_hintsForMethod_t{
146
char *methodCompleteName; /*< Full name of the method, for example System.Int32 */
147
char *methodSignature; /*< Signature of the method, for example Void or System.Int32 */
148
JITFLOAT32 zeroProfilerTypeThreshold; /*< Threshold of frequency to consider a layout (i.e.) a type sttaic */
149
JITUINT32 zeroProfilerMemorySize; /*< Number of bytes that can be used to store information for the type (a.k.a. zero) profiler */
150
JITUINT32 zeroDispatcherRemoveThreshold; /*< Threshold for type dispatcher removal */
151
JITUINT32 firstProfilerThreshold; /*< Threshold for the first profiler */
152
JITUINT32 secondProfilerMemorySize; /*< Number of bytes that can be used to store information for the second profiler */
153
JITFLOAT32 secondProfilerStaticThreshold; /*< Threshold that a value (or an expression) should cross to be considered static */
154
JITUINT32 dispatcherRemoveThreshold; /*< Threshold for dispatcher removal */
155
XanList *expressions; /*< List of expression for specialization (List of type specializer_expression_hint_t)*/
157
void (*init) (struct specializer_hintsForMethod_t *hints,
158
char* methodCompleteName, char* methodSignature,
159
JITFLOAT32 zeroProfilerTypeThreshold, JITUINT32 zeroProfilerMemorySize,
160
JITUINT32 zeroDispatcherRemoveThreshold, JITUINT32 firstProfilerThreshold,
161
JITUINT32 secondProfilerMemorySize, JITFLOAT32 secondProfilerStaticThreshold,
162
JITUINT32 dispatcherRemoveThreshold, ir_specializer_t* specializer);
163
void (*print) (struct specializer_hintsForMethod_t *hints, FILE* out);
164
void (*clean) (struct specializer_hintsForMethod_t *hints, ir_specializer_t* specializer);
166
JITBOOLEAN (*equals) (struct specializer_hintsForMethod_t *hints, char *methodCompleteName, char *methodSignature);
168
void (*addExpression) (struct specializer_hintsForMethod_t *hints, specializer_expression_hint_t* expression);
169
specializer_expression_hint_t* (*getExpression) (struct specializer_hintsForMethod_t *hints, JITUINT32 index);
170
JITUINT32 (*getExpressionsNumber) (struct specializer_hintsForMethod_t *hints);
171
} specializer_hintsForMethod_t;
173
* Create a new hints for method
175
specializer_hintsForMethod_t* newSpecializerHintsForMethod(ir_specializer_t* specializer);
177
/* ----------------------------------------- Wrapper for the IL Method -----------------------------------------*/
179
* @brief This structure is a wrapper for the ILMethod
181
typedef struct specializer_method_wrapper_t{
182
void *ilMethod; /*< The IL Method pointer*/
183
JITUINT32 recompileStateValue; /*< The value of the state for recompile */
185
/* Some functions for this IL Method */
186
ir_method_t*(*_getIRMethod)(void* ilMethod);
187
void (*_setState)(void* ilMethod, JITUINT32 state);
188
JITUINT32 (*_getState)(void* ilMethod);
189
void (*_setJITFunction) (void *ilMethod, void* jitFunction);
190
void* (*_getJITFunction) (void *ilMethod);
191
JITBOOLEAN (*_isCctor)(void* ilMethod);
193
/* Useful methods for this wrapper */
194
void (*init) (struct specializer_method_wrapper_t* methodWrapper,
195
void* ilMethod, JITUINT32 recompileStateValue,
196
ir_method_t* (*getIRMethod)(void* ilMethod),
197
void (*setState)(void* ilMethod, JITUINT32 state), JITUINT32 (*getState)(void* ilMethod),
198
void (*setJITFunction) (void *ilMethod, void* jitFunction), void* (*getJITFunction)(void *ilMethod),
199
JITBOOLEAN (*isCctor)(void* ilMethod));
200
void (*print) (ir_specializer_t *specializer, struct specializer_method_wrapper_t* methodWrapper, FILE* out);
201
void (*clean) (struct specializer_method_wrapper_t* methodWrapper, ir_specializer_t* specializer);
203
ir_method_t* (*getIRMethod)(struct specializer_method_wrapper_t* methodWrapper);
204
void (*setState)(struct specializer_method_wrapper_t* methodWrapper, JITUINT32 state);
205
JITUINT32 (*getState)(struct specializer_method_wrapper_t* methodWrapper);
206
void (*setToRecompileState) (struct specializer_method_wrapper_t* methodWrapper);
207
void (*setJITFunction) (struct specializer_method_wrapper_t* methodWrapper, void* jitFunction);
208
void* (*getJITFunction) (struct specializer_method_wrapper_t* methodWrapper);
209
JITBOOLEAN (*isCctor)(struct specializer_method_wrapper_t* methodWrapper);
210
}specializer_method_wrapper_t;
212
* Create a new specializer Method
214
specializer_method_wrapper_t* newSpecializerMethodWrapper(ir_specializer_t* specializer);
216
/* ----------------------------------------- Structure used by the second profiler -----------------------------------------*/
218
* This structure is used to wrap parameter information to use inside the second profiler,
219
* adding informations about the offset inside the paramAcquired vector and the position
222
typedef struct specializer_callSite_secondProfiler_param_t {
226
JITBOOLEAN _isVector;
228
void (*init) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam, ir_item_t* item, JITUINT32 offset, JITUINT32 position, JITBOOLEAN isVector);
229
void (*print) (struct specializer_callSite_secondProfiler_param_t* secspecializeram, FILE* out);
230
void (*clean) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam, ir_specializer_t* specializer);
232
JITUINT32 (*getParamType) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
233
JITUINT32 (*getParamInternalType) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
234
size_t (*getParameterSize) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
236
JITBOOLEAN (*isVariable) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
237
JITBOOLEAN (*isConstant) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
238
JITBOOLEAN (*isVector) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
240
IR_ITEM_VALUE (*getValue) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
241
IR_ITEM_FVALUE (*getFValue) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
243
JITUINT32 (*getType) (struct specializer_callSite_secondProfiler_param_t* secondProfilerParam);
244
} specializer_callSite_secondProfiler_param_t;
246
* Create a new second profiler parameter
248
specializer_callSite_secondProfiler_param_t* newSpecializerSecondProfileParameter(ir_specializer_t* specializer);
251
* @Structure useful to store different kind of values with their type
253
typedef struct specializer_multiValueContainer{
268
} value; /*< The value */
270
JITUINT32 type; /*< The type of the value */
271
}specializer_multiValueContainer;
274
* @brief Describe the frequency for a given parameter
276
typedef struct specializer_valueWithFrequency_t{
277
specializer_multiValueContainer valueContainer; /*< The value stored */
278
JITFLOAT32 frequency; /*< The frequency of the value */
280
void (*init) (struct specializer_valueWithFrequency_t* valueWithFrequency, specializer_multiValueContainer valueContainer, JITFLOAT32 frequency);
281
void (*print) (struct specializer_valueWithFrequency_t* valueWithFrequency, FILE* out);
282
void (*clean) (struct specializer_valueWithFrequency_t* valueWithFrequency, ir_specializer_t* specializer);
283
} specializer_valueWithFrequency_t;
286
* Create a new value with frequency
288
specializer_valueWithFrequency_t* newSpecializerValueWithFrequency(ir_specializer_t* specializer);
291
* @brief Describe all possible values a variable at a given position can assume
293
typedef struct specializer_callSite_secondProfiler_param_values_t{
294
JITUINT32 position; /*< The variable position */
295
XanList* values; /*< The values the variable can assume */
297
void (*init) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition, JITUINT32 position, ir_specializer_t* specializer);
298
void (*print) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition, FILE* out);
299
void (*clean) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition, ir_specializer_t* specializer);
301
void (*addValue) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition, specializer_valueWithFrequency_t* valueWithFrequency);
302
specializer_valueWithFrequency_t* (*getValue) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition, JITUINT32 index);
303
JITUINT32 (*getValuesNumber) (struct specializer_callSite_secondProfiler_param_values_t* valuesForPosition);
304
}specializer_callSite_secondProfiler_param_values_t;
307
* Create a new value with frequency
309
specializer_callSite_secondProfiler_param_values_t* newSpecializerValuesForParamPosition(ir_specializer_t* specializer);
312
* @brief This structure describe a static expression, i.e. and expression with associated actual values
314
typedef struct specializer_staticExpression_hint_t{
315
specializer_expression_hint_t *expression; /*< The static expression */
316
specializer_multiValueContainer *values; /*< The vector of values */
318
void (*init) (struct specializer_staticExpression_hint_t* staticExpression, specializer_expression_hint_t *expression, specializer_multiValueContainer *values);
319
void (*print) (struct specializer_staticExpression_hint_t* staticExpression, FILE* out);
320
void (*clean) (struct specializer_staticExpression_hint_t* staticExpression, ir_specializer_t* specializer);
322
JITBOOLEAN (*equals) (struct specializer_staticExpression_hint_t* staticExpression, struct specializer_staticExpression_hint_t* otherExpression);
323
}specializer_staticExpression_hint_t;
326
* Create a new static expression
328
specializer_staticExpression_hint_t* newSpecializerStaticExpression(ir_specializer_t* specializer);
330
/* ----------------------------------------- Specialized method -----------------------------------------*/
332
* @brief Describe a new specialized method wrapper
334
typedef struct specializer_specialized_method_wrapper_t{
335
specializer_staticExpression_hint_t *staticExpression; /*< The static expression associated to this method */
336
specializer_method_wrapper_t *originalMethodWrapper; /*< The original method wrapper */
337
specializer_method_wrapper_t *specializedMethodWrapper; /*< The specialized method wrapper */
339
void (*init) (struct specializer_specialized_method_wrapper_t* specializedMethod,
340
specializer_staticExpression_hint_t *staticExpression,
341
specializer_method_wrapper_t *originalMethodWrapper,
342
specializer_method_wrapper_t *specializedMethodWrapper);
343
void (*print) (struct specializer_specialized_method_wrapper_t* specializedMethod, FILE* out, ir_specializer_t *specializer);
344
void (*clean) (struct specializer_specialized_method_wrapper_t* specializedMethod, ir_specializer_t* specializer);
346
JITBOOLEAN (*equals) (struct specializer_specialized_method_wrapper_t* specializedMethod,
347
specializer_method_wrapper_t *originalMethodWrapper,
348
specializer_staticExpression_hint_t *staticExpression);
350
} specializer_specialized_method_wrapper_t;
353
* Create a new specialized method wrapper
355
specializer_specialized_method_wrapper_t* getSpecializerSpecializedMethodWrapper(ir_specializer_t* specializer);
357
/* ----------------------------------------- Profilers and Dispatcher -----------------------------------------*/
359
* @brief This structure describe the second profiler
361
typedef struct specializer_method_callSite_firstProfiler_t{
362
JITUINT32 counter; /*< Counter used to detect how many times this threshold has been reached */
363
JITUINT32 thresholdReached; /*< Keep track if the threshold has been reached */
364
JITUINT32* memory; /*< Memory where store informations about the type profiler */
365
void* callSiteContext; /*< Pointer to the current call site context that owns this profiler */
367
void (*init) (struct specializer_method_callSite_firstProfiler_t* profiler, void* callSiteContext, ir_specializer_t* specializer);
368
void (*print) (struct specializer_method_callSite_firstProfiler_t* profiler, FILE* out);
369
void (*clean) (struct specializer_method_callSite_firstProfiler_t* profiler, ir_specializer_t* specializer);
371
JITUINT32 * (*getCounterPointer) (struct specializer_method_callSite_firstProfiler_t* profiler);
372
JITUINT32 (*getCounterValue) (struct specializer_method_callSite_firstProfiler_t* profiler);
373
JITUINT32 * (*getThresholdReachedPointer) (struct specializer_method_callSite_firstProfiler_t* profiler);
374
JITUINT32 (*isThresholdReached) (struct specializer_method_callSite_firstProfiler_t* profiler);
376
void (*inject) (struct specializer_method_callSite_firstProfiler_t* profiler, specializer_method_wrapper_t* callerWrapper, ir_specializer_t* specializer);
377
void (*remove) (struct specializer_method_callSite_firstProfiler_t* profiler, specializer_method_wrapper_t* callerWrapper);
379
}specializer_method_callSite_firstProfiler_t;
382
* Create a new first profiler method
384
specializer_method_callSite_firstProfiler_t* newSpecializerFirstProfiler(ir_specializer_t* specializer);
387
* @brief This structure describe the second profiler
389
typedef struct specializer_method_callSite_secondProfiler_t{
390
void *callSiteContext; /*< Pointer to the the call site that owns this profiler */
392
void *memory; /*< Memory used by the profiler to store the value */
393
JITUINT32 threshold; /*< Threshold after which the memory has been full filled */
394
JITUINT32 thresholdReached; /*< Detect if the threshold has been reached */
395
JITUINT32 counter; /*< The counter for threshold */
397
JITUINT32 blockSize; /*< Size of a single block of parameters */
399
XanList *parameters; /*< List of parameters to check for specialization (Type : specializer_callSite_secondProfiler_param_t) */
401
void (*init) (struct specializer_method_callSite_secondProfiler_t* profiler, void *callSiteContext, ir_specializer_t* specializer);
402
void (*print) (struct specializer_method_callSite_secondProfiler_t* profiler, FILE* out);
403
void (*clean) (struct specializer_method_callSite_secondProfiler_t* profiler, ir_specializer_t* specializer);
405
void (*inject) (struct specializer_method_callSite_secondProfiler_t* profiler, specializer_method_wrapper_t* callerWrapper, ir_specializer_t* specializer);
406
void (*remove) (struct specializer_method_callSite_secondProfiler_t* profiler, specializer_method_wrapper_t* callerWrapper);
408
JITUINT32* (*getCounterPointer) (struct specializer_method_callSite_secondProfiler_t* profiler);
409
JITUINT32 (*getCounterValue) (struct specializer_method_callSite_secondProfiler_t* profiler);
410
JITUINT32* (*getThresholdReachedPointer) (struct specializer_method_callSite_secondProfiler_t* profiler);
411
JITUINT32 (*isThresholdReached) (struct specializer_method_callSite_secondProfiler_t* profiler);
412
JITUINT32 (*getThreshold) (struct specializer_method_callSite_secondProfiler_t* profiler);
413
JITUINT32 (*getBlockSize) (struct specializer_method_callSite_secondProfiler_t* profiler);
416
* Returns a list of parameters that are active because their frequency is over the required threshold frequency
418
XanList* (*getStaticExpressions) (struct specializer_method_callSite_secondProfiler_t* profiler, ir_specializer_t* specializer);
419
}specializer_method_callSite_secondProfiler_t;
422
* Create a new second profiler
424
specializer_method_callSite_secondProfiler_t* newSpecializerSecondProfiler(ir_specializer_t* specializer);
427
* @brief The dispatcher for a single call site
429
typedef struct specializer_method_callSite_dispatcher_t{
430
void *callSiteContext; /*< The call site that own this dispatcher */
431
JITINT32 counter; /*< Dispatcher counter */
432
JITUINT32 thresholdReached; /*< The threshold reached flag */
434
void (*init) (struct specializer_method_callSite_dispatcher_t* dispatcher, void *callSiteContext);
435
void (*print) (struct specializer_method_callSite_dispatcher_t* dispatcher, FILE* out);
436
void (*clean) (struct specializer_method_callSite_dispatcher_t* dispatcher, ir_specializer_t* specializer);
438
void (*inject) (struct specializer_method_callSite_dispatcher_t* dispatcher, specializer_method_wrapper_t* callerWrapper, XanList* staticExpressions, ir_specializer_t* specializer);
439
void (*remove) (struct specializer_method_callSite_dispatcher_t* dispatcher, specializer_method_wrapper_t* callerWrapper);
441
JITINT32* (*getCounterPointer) (struct specializer_method_callSite_dispatcher_t* dispatcher);
442
JITINT32 (*getCounterValue) (struct specializer_method_callSite_dispatcher_t* dispatcher);
444
}specializer_method_callSite_dispatcher_t;
447
* Create a new dispatcher
449
specializer_method_callSite_dispatcher_t* newSpecializerDispatcher(ir_specializer_t* specializer);
452
* @brief The dispatcher for a single IRVCALL call site
454
typedef struct specializer_method_callSite_type_dispatcher_t{
455
void *callSiteContext; /*< The call site that own this dispatcher */
456
JITINT32 counter; /*< Dispatcher counter */
457
JITUINT32 thresholdReached; /*< The threshold reached flag */
459
void (*init) (struct specializer_method_callSite_type_dispatcher_t* dispatcher, void *callSiteContext);
460
void (*print) (struct specializer_method_callSite_type_dispatcher_t* dispatcher, FILE* out);
461
void (*clean) (struct specializer_method_callSite_type_dispatcher_t* dispatcher, ir_specializer_t* specializer);
463
JITBOOLEAN (*inject) (struct specializer_method_callSite_type_dispatcher_t* dispatcher, specializer_method_wrapper_t* callerWrapper, JITUINT32* firstProfilerMemory, JITUINT32 firstProfilerCounter, ir_specializer_t* specializer);
464
void (*remove) (struct specializer_method_callSite_type_dispatcher_t* dispatcher, specializer_method_wrapper_t* callerWrapper);
466
JITINT32* (*getCounterPointer) (struct specializer_method_callSite_type_dispatcher_t* dispatcher);
467
JITINT32 (*getCounterValue) (struct specializer_method_callSite_type_dispatcher_t* dispatcher);
469
}specializer_method_callSite_type_dispatcher_t;
472
* Create a new dispatcher
474
specializer_method_callSite_type_dispatcher_t* newSpecializerTypeDispatcher(ir_specializer_t* specializer);
476
/* ----------------------------------------- Structure for call site informations -----------------------------------------*/
479
* @biref This structure describe a single call site that can be specialized/to specialize
482
typedef struct specializer_method_callSite_t{
483
specializer_method_wrapper_t *methodWrapper; /*< Callee wrapper */
484
t_ir_instruction *call; /*< Pointer to call instruction */
485
JITUINT32 status; /*< Status of this call site */
486
specializer_hintsForMethod_t *hints; /*< Hints for the method called at call site */
487
XanList *addedInstructions; /*< Instructions added to this call site */
489
specializer_method_callSite_firstProfiler_t *firstProfiler; /*< The first profiler */
490
specializer_method_callSite_secondProfiler_t *secondProfiler; /*< The second profiler */
491
specializer_method_callSite_dispatcher_t *dispatcher; /*< The dispatcher */
492
specializer_method_callSite_type_dispatcher_t *typeDispatcher; /*< The type dispatcher */
494
void (*init) (struct specializer_method_callSite_t* callSite, specializer_method_wrapper_t *methodWrapper, t_ir_instruction* call, specializer_hintsForMethod_t *hints, ir_specializer_t* specializer);
495
void (*print) (struct specializer_method_callSite_t* callSite, FILE* out, ir_specializer_t *specializer);
496
void (*clean) (struct specializer_method_callSite_t* callSite, ir_specializer_t* specializer);
497
void (*addInstruction) (struct specializer_method_callSite_t* callSite, t_ir_instruction* instruction);
498
void (*removeInstructionsFromMethod) (struct specializer_method_callSite_t* callSite, ir_method_t* irMethod);
499
void (*performAction) (struct specializer_method_callSite_t* callSite, specializer_method_wrapper_t* callerWrapper, ir_specializer_t* specializer);
500
JITINT32 (*hasVariableParameters) (struct specializer_method_callSite_t* callSite);
501
} specializer_method_callSite_t;
504
* Create a new method call site
506
specializer_method_callSite_t* newSpecializerCallSite(ir_specializer_t* specializer);
509
* @brief This structure describe a list of call sites that could be specialized (or are actually specialized) for a given method.
510
* The method is known by his pointer to his ilMethod structure.
512
typedef struct specializer_callSitesForMethod_t{
513
specializer_method_wrapper_t *methodWrapper; /* Method that have some specializable call sites */
514
XanList *callSites; /* List of call sites specialized/to specialize */
516
void (*init) (struct specializer_callSitesForMethod_t* callSitesForMethod, specializer_method_wrapper_t* wrapper, ir_specializer_t* specializer);
517
void (*print) (struct specializer_callSitesForMethod_t* callSitesForMethod, FILE* out, ir_specializer_t *specializer);
518
void (*clean) (struct specializer_callSitesForMethod_t* callSitesForMethod, ir_specializer_t* specializer);
521
* Return the call site at given instruction... if the call site do not exists create a new one
523
specializer_method_callSite_t* (*getCallSiteForInstruction) (struct specializer_callSitesForMethod_t* callSitesForMethod, specializer_method_wrapper_t *calleeWrapper, t_ir_instruction* call, specializer_hintsForMethod_t *hints, ir_specializer_t* specializer);
525
JITBOOLEAN (*isInjectedInstruction)(struct specializer_callSitesForMethod_t* callSitesForMethod, t_ir_instruction* instruction);
527
} specializer_callSitesForMethod_t;
530
* Create a new call sites for specializer method
532
specializer_callSitesForMethod_t* newSpecializerCallSitesForMethod(ir_specializer_t* specializer);
534
/* ----------------------------------------- Specializer common methods -----------------------------------------*/
535
specializer_callSitesForMethod_t* ir_specializer_getCallSitesFormMethod(ir_specializer_t* specializer,
536
specializer_method_wrapper_t* wrapper);
538
specializer_method_wrapper_t* ir_specializer_getSpecializedMethod(ir_specializer_t *specializer,
539
specializer_method_wrapper_t* originalMethodWrapper,
540
specializer_staticExpression_hint_t* staticExpression);
542
specializer_hintsForMethod_t* ir_specializer_getHintsForMethodForMethod(ir_specializer_t *specializer,
543
specializer_method_wrapper_t* wrapper);
545
specializer_method_wrapper_t* ir_specializer_getMethodWrapper(ir_specializer_t* specializer,
546
void* ilMethod, JITUINT32 recompileStateValue,
547
ir_method_t* (*getIRMethod)(void* ilMethod),
548
void (*setState)(void* ilMethod, JITUINT32 state), JITUINT32 (*getState)(void* ilMethod),
549
void (*setJITFunction) (void *ilMethod, void* jitFunction), void* (*getJITFunction)(void *ilMethod),
550
JITBOOLEAN (*isCctor)(void*ilMethod));