[interp] Remove varargs from InterpFrame and recompute it instead (#16598)
[mono-project.git] / mono / mini / interp / interp-internals.h
blobf359f1c1ecaaf78af49e8295cd97d309f85d56d2
1 #ifndef __MONO_MINI_INTERPRETER_INTERNALS_H__
2 #define __MONO_MINI_INTERPRETER_INTERNALS_H__
4 #include <setjmp.h>
5 #include <glib.h>
6 #include <mono/metadata/loader.h>
7 #include <mono/metadata/object.h>
8 #include <mono/metadata/domain-internals.h>
9 #include <mono/metadata/class-internals.h>
10 #include <mono/metadata/debug-internals.h>
11 #include "interp.h"
13 #define MINT_TYPE_I1 0
14 #define MINT_TYPE_U1 1
15 #define MINT_TYPE_I2 2
16 #define MINT_TYPE_U2 3
17 #define MINT_TYPE_I4 4
18 #define MINT_TYPE_I8 5
19 #define MINT_TYPE_R4 6
20 #define MINT_TYPE_R8 7
21 #define MINT_TYPE_O 8
22 #define MINT_TYPE_P 9
23 #define MINT_TYPE_VT 10
25 #define BOX_NOT_CLEAR_VT_SP 0x4000
27 #define MINT_VT_ALIGNMENT 8
29 enum {
30 VAL_I32 = 0,
31 VAL_DOUBLE = 1,
32 VAL_I64 = 2,
33 VAL_VALUET = 3,
34 VAL_POINTER = 4,
35 VAL_NATI = 0 + VAL_POINTER,
36 VAL_MP = 1 + VAL_POINTER,
37 VAL_TP = 2 + VAL_POINTER,
38 VAL_OBJ = 3 + VAL_POINTER
41 enum {
42 INTERP_OPT_INLINE = 1
45 #if SIZEOF_VOID_P == 4
46 typedef guint32 mono_u;
47 typedef gint32 mono_i;
48 #elif SIZEOF_VOID_P == 8
49 typedef guint64 mono_u;
50 typedef gint64 mono_i;
51 #endif
54 * Value types are represented on the eval stack as pointers to the
55 * actual storage. The size field tells how much storage is allocated.
56 * A value type can't be larger than 16 MB.
58 typedef struct {
59 union {
60 gint32 i;
61 gint64 l;
62 struct {
63 gint32 lo;
64 gint32 hi;
65 } pair;
66 float f_r4;
67 double f;
68 #ifdef TARGET_WASM
69 MonoObject * volatile o;
70 #else
71 MonoObject *o;
72 #endif
73 /* native size integer and pointer types */
74 gpointer p;
75 mono_u nati;
76 gpointer vt;
77 } data;
78 #if defined(__ppc__) || defined(__powerpc__)
79 int pad;
80 #endif
81 } stackval;
83 typedef struct _InterpFrame InterpFrame;
85 typedef void (*MonoFuncV) (void);
86 typedef void (*MonoPIFunc) (void *callme, void *margs);
88 /*
89 * Structure representing a method transformed for the interpreter
90 * This is domain specific
92 typedef struct _InterpMethod
94 /* NOTE: These first two elements (method and
95 next_jit_code_hash) must be in the same order and at the
96 same offset as in MonoJitInfo, because of the jit_code_hash
97 internal hash table in MonoDomain. */
98 MonoMethod *method;
99 struct _InterpMethod *next_jit_code_hash;
100 guint32 locals_size;
101 guint32 total_locals_size;
102 guint32 stack_size;
103 guint32 vt_stack_size;
104 guint32 alloca_size;
105 unsigned int init_locals : 1;
106 unsigned int vararg : 1;
107 unsigned int needs_thread_attach : 1;
108 unsigned short *code;
109 MonoPIFunc func;
110 int num_clauses;
111 MonoExceptionClause *clauses;
112 void **data_items;
113 int transformed;
114 guint32 *local_offsets;
115 guint32 *exvar_offsets;
116 unsigned int param_count;
117 unsigned int hasthis;
118 gpointer jit_wrapper;
119 gpointer jit_addr;
120 MonoMethodSignature *jit_sig;
121 gpointer jit_entry;
122 gpointer llvmonly_unbox_entry;
123 MonoType *rtype;
124 MonoType **param_types;
125 MonoJitInfo *jinfo;
126 MonoDomain *domain;
127 MonoProfilerCallInstrumentationFlags prof_flags;
128 } InterpMethod;
130 struct _InterpFrame {
131 InterpFrame *parent; /* parent */
132 InterpMethod *imethod; /* parent */
133 stackval *retval; /* parent */
134 stackval *stack_args; /* parent */
135 stackval *stack;
137 * For GC tracking of local objrefs in exec_method ().
138 * Storing into this field will keep the object pinned
139 * until the objref can be stored into stackval->data.o.
141 #ifdef TARGET_WASM
142 MonoObject* volatile o;
143 #endif
144 /* exception info */
145 const unsigned short *ip;
146 MonoException *ex;
149 #define frame_locals(frame) (((guchar*)((frame)->stack)) + (frame)->imethod->stack_size + (frame)->imethod->vt_stack_size)
151 typedef struct {
152 /* Resume state for resuming execution in mixed mode */
153 gboolean has_resume_state;
154 /* Frame to resume execution at */
155 InterpFrame *handler_frame;
156 /* IP to resume execution at */
157 const guint16 *handler_ip;
158 /* Clause that we are resuming to */
159 MonoJitExceptionInfo *handler_ei;
160 } ThreadContext;
162 typedef struct {
163 gint64 transform_time;
164 gint32 inlined_methods;
165 gint32 inline_failures;
166 } MonoInterpStats;
168 extern MonoInterpStats mono_interp_stats;
170 extern int mono_interp_traceopt;
171 extern int mono_interp_opt;
172 extern GSList *mono_interp_jit_classes;
174 void
175 mono_interp_transform_method (InterpMethod *imethod, ThreadContext *context, MonoError *error);
177 void
178 mono_interp_transform_init (void);
180 InterpMethod *
181 mono_interp_get_imethod (MonoDomain *domain, MonoMethod *method, MonoError *error);
183 void
184 mono_interp_print_code (InterpMethod *imethod);
186 static inline int
187 mint_type(MonoType *type_)
189 MonoType *type = mini_native_type_replace_type (type_);
190 if (type->byref)
191 return MINT_TYPE_P;
192 enum_type:
193 switch (type->type) {
194 case MONO_TYPE_I1:
195 return MINT_TYPE_I1;
196 case MONO_TYPE_U1:
197 case MONO_TYPE_BOOLEAN:
198 return MINT_TYPE_U1;
199 case MONO_TYPE_I2:
200 return MINT_TYPE_I2;
201 case MONO_TYPE_U2:
202 case MONO_TYPE_CHAR:
203 return MINT_TYPE_U2;
204 case MONO_TYPE_I4:
205 case MONO_TYPE_U4:
206 return MINT_TYPE_I4;
207 case MONO_TYPE_I:
208 case MONO_TYPE_U:
209 #if SIZEOF_VOID_P == 4
210 return MINT_TYPE_I4;
211 #else
212 return MINT_TYPE_I8;
213 #endif
214 case MONO_TYPE_PTR:
215 return MINT_TYPE_P;
216 case MONO_TYPE_R4:
217 return MINT_TYPE_R4;
218 case MONO_TYPE_I8:
219 case MONO_TYPE_U8:
220 return MINT_TYPE_I8;
221 case MONO_TYPE_R8:
222 return MINT_TYPE_R8;
223 case MONO_TYPE_STRING:
224 case MONO_TYPE_SZARRAY:
225 case MONO_TYPE_CLASS:
226 case MONO_TYPE_OBJECT:
227 case MONO_TYPE_ARRAY:
228 return MINT_TYPE_O;
229 case MONO_TYPE_VALUETYPE:
230 if (m_class_is_enumtype (type->data.klass)) {
231 type = mono_class_enum_basetype_internal (type->data.klass);
232 goto enum_type;
233 } else
234 return MINT_TYPE_VT;
235 case MONO_TYPE_TYPEDBYREF:
236 return MINT_TYPE_VT;
237 case MONO_TYPE_GENERICINST:
238 type = m_class_get_byval_arg (type->data.generic_class->container_class);
239 goto enum_type;
240 default:
241 g_warning ("got type 0x%02x", type->type);
242 g_assert_not_reached ();
244 return -1;
247 #endif /* __MONO_MINI_INTERPRETER_INTERNALS_H__ */