3 * PLEASE NOTE: This is a research prototype.
6 * interp.c: Interpreter for CIL byte codes
9 * Paolo Molaro (lupus@ximian.com)
10 * Miguel de Icaza (miguel@ximian.com)
11 * Dietmar Maurer (dietmar@ximian.com)
13 * (C) 2001, 2002 Ximian, Inc.
28 #include <mono/utils/gc_wrapper.h>
34 # define alloca __builtin_alloca
38 /* trim excessive headers */
39 #include <mono/metadata/image.h>
40 #include <mono/metadata/assembly-internals.h>
41 #include <mono/metadata/cil-coff.h>
42 #include <mono/metadata/mono-endian.h>
43 #include <mono/metadata/tabledefs.h>
44 #include <mono/metadata/tokentype.h>
45 #include <mono/metadata/loader.h>
46 #include <mono/metadata/threads.h>
47 #include <mono/metadata/threadpool.h>
48 #include <mono/metadata/profiler-private.h>
49 #include <mono/metadata/appdomain.h>
50 #include <mono/metadata/reflection.h>
51 #include <mono/metadata/reflection-internals.h>
52 #include <mono/metadata/exception.h>
53 #include <mono/metadata/verify.h>
54 #include <mono/metadata/opcodes.h>
55 #include <mono/metadata/debug-helpers.h>
56 #include <mono/metadata/mono-config.h>
57 #include <mono/metadata/marshal.h>
58 #include <mono/metadata/environment.h>
59 #include <mono/metadata/mono-debug.h>
60 #include <mono/utils/atomic.h>
63 #include "interp-internals.h"
67 #include <mono/mini/mini.h>
68 #include <mono/mini/jit-icalls.h>
71 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
74 #define finite _finite
78 #define finite isfinite
83 init_frame (MonoInvocation *frame, MonoInvocation *parent_frame, RuntimeMethod *rmethod, stackval *method_args, stackval *method_retval)
85 frame->parent = parent_frame;
86 frame->stack_args = method_args;
87 frame->retval = method_retval;
88 frame->runtime_method = rmethod;
91 frame->invoke_trap = 0;
94 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) do { \
95 RuntimeMethod *_rmethod = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
96 init_frame ((frame), (parent_frame), _rmethod, (method_args), (method_retval)); \
100 * List of classes whose methods will be executed by transitioning to JITted code.
105 void ves_exec_method (MonoInvocation *frame);
107 static char* dump_frame (MonoInvocation *inv);
108 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
109 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception, int exit_at_finally);
111 typedef void (*ICallMethod) (MonoInvocation *frame);
113 static guint32 die_on_exception = 0;
114 static MonoNativeTlsKey thread_context_id;
116 static char* dump_args (MonoInvocation *inv);
118 #define DEBUG_INTERP 0
121 int mono_interp_traceopt = 2;
122 /* If true, then we output the opcodes as we interpret them */
123 static int global_tracing = 2;
125 static int debug_indent_level = 0;
127 static int break_on_method = 0;
128 static int nested_trace = 0;
129 static GList *db_methods = NULL;
136 for (h = 0; h < debug_indent_level; h++)
141 db_match_method (gpointer data, gpointer user_data)
143 MonoMethod *m = (MonoMethod*)user_data;
144 MonoMethodDesc *desc = data;
146 if (mono_method_desc_full_match (desc, m))
151 debug_enter (MonoInvocation *frame, int *tracing)
154 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
156 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
160 MonoMethod *method = frame->runtime_method->method;
161 char *mn, *args = dump_args (frame);
162 debug_indent_level++;
164 mn = mono_method_full_name (method, FALSE);
165 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
167 g_print ("%s)\n", args);
170 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
171 mono_profiler_method_enter (frame->runtime_method->method);
175 #define DEBUG_LEAVE() \
178 args = dump_retval (frame); \
180 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
181 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
183 g_print (" => %s\n", args); \
185 debug_indent_level--; \
186 if (tracing == 3) global_tracing = 0; \
188 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
189 mono_profiler_method_leave (frame->runtime_method->method);
193 int mono_interp_traceopt = 0;
194 static void debug_enter (MonoInvocation *frame, int *tracing)
197 #define DEBUG_LEAVE()
201 /* Set the current execution state to the resume state in context */
202 #define SET_RESUME_STATE(context) do { \
203 ip = (context)->handler_ip; \
204 sp->data.p = frame->ex; \
207 (context)->has_resume_state = 0; \
208 (context)->handler_frame = NULL; \
213 ves_real_abort (int line, MonoMethod *mh,
214 const unsigned short *ip, stackval *stack, stackval *sp)
217 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
218 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
219 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
220 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
221 g_print ("0x%04x %02x\n",
222 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
223 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
225 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
228 #define ves_abort() \
230 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
231 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
235 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
238 MonoJitDomainInfo *info;
239 MonoMethodSignature *sig;
244 info = domain_jit_info (domain);
245 mono_domain_jit_code_hash_lock (domain);
246 rtm = mono_internal_hash_table_lookup (&info->interp_code_hash, method);
247 mono_domain_jit_code_hash_unlock (domain);
251 sig = mono_method_signature (method);
253 rtm = mono_domain_alloc0 (domain, sizeof (RuntimeMethod));
254 rtm->method = method;
255 rtm->param_count = sig->param_count;
256 rtm->hasthis = sig->hasthis;
257 rtm->rtype = mini_get_underlying_type (sig->ret);
258 rtm->param_types = mono_domain_alloc0 (domain, sizeof (MonoType*) * sig->param_count);
259 for (i = 0; i < sig->param_count; ++i)
260 rtm->param_types [i] = mini_get_underlying_type (sig->params [i]);
262 mono_domain_jit_code_hash_lock (domain);
263 if (!mono_internal_hash_table_lookup (&info->interp_code_hash, method))
264 mono_internal_hash_table_insert (&info->interp_code_hash, method, rtm);
265 mono_domain_jit_code_hash_unlock (domain);
271 mono_interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
273 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
274 method = mono_marshal_get_synchronized_wrapper (method);
275 return mono_interp_get_runtime_method (domain, method, error);
278 static inline RuntimeMethod*
279 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
281 MonoMethod *m = runtime_method->method;
284 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
285 RuntimeMethod *ret = NULL;
286 if (mono_object_is_transparent_proxy (obj)) {
287 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
288 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
289 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
290 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
291 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
293 ret = runtime_method;
298 mono_class_setup_vtable (obj->vtable->klass);
300 int slot = mono_method_get_vtable_slot (m);
301 if (mono_class_is_interface (m->klass)) {
302 g_assert (obj->vtable->klass != m->klass);
303 /* TODO: interface offset lookup is slow, go through IMT instead */
304 gboolean non_exact_match;
305 slot += mono_class_interface_offset_with_variance (obj->vtable->klass, m->klass, &non_exact_match);
308 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
309 if (m->is_inflated && mono_method_get_context (m)->method_inst) {
310 MonoGenericContext context = { NULL, NULL };
312 if (mono_class_is_ginst (virtual_method->klass))
313 context.class_inst = mono_class_get_generic_class (virtual_method->klass)->context.class_inst;
314 else if (mono_class_is_gtd (virtual_method->klass))
315 context.class_inst = mono_class_get_generic_container (virtual_method->klass)->context.class_inst;
316 context.method_inst = mono_method_get_context (m)->method_inst;
318 virtual_method = mono_class_inflate_generic_method_checked (virtual_method, &context, &error);
319 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
322 if (virtual_method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
323 virtual_method = mono_marshal_get_synchronized_wrapper (virtual_method);
326 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
327 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
328 return virtual_runtime_method;
332 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
335 switch (type->type) {
336 case MONO_TYPE_OBJECT:
337 case MONO_TYPE_CLASS:
338 case MONO_TYPE_STRING:
339 case MONO_TYPE_ARRAY:
340 case MONO_TYPE_SZARRAY:
345 result->data.p = *(gpointer*)data;
348 switch (type->type) {
352 result->data.i = *(gint8*)data;
355 case MONO_TYPE_BOOLEAN:
356 result->data.i = *(guint8*)data;
359 result->data.i = *(gint16*)data;
363 result->data.i = *(guint16*)data;
366 result->data.i = *(gint32*)data;
370 result->data.nati = *(mono_i*)data;
373 result->data.p = *(gpointer*)data;
376 result->data.i = *(guint32*)data;
379 result->data.f = *(float*)data;
383 result->data.l = *(gint64*)data;
386 result->data.f = *(double*)data;
388 case MONO_TYPE_STRING:
389 case MONO_TYPE_SZARRAY:
390 case MONO_TYPE_CLASS:
391 case MONO_TYPE_OBJECT:
392 case MONO_TYPE_ARRAY:
393 result->data.p = *(gpointer*)data;
395 case MONO_TYPE_VALUETYPE:
396 if (type->data.klass->enumtype) {
397 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
400 mono_value_copy (result->data.vt, data, type->data.klass);
402 case MONO_TYPE_GENERICINST: {
403 MonoClass *container_class = type->data.generic_class->container_class;
405 if (container_class->valuetype && !container_class->enumtype) {
406 mono_value_copy (result->data.vt, data, mono_class_from_mono_type (type));
409 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
413 g_warning ("got type 0x%02x", type->type);
414 g_assert_not_reached ();
419 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
422 gpointer *p = (gpointer*)data;
426 /* printf ("TODAT0 %p\n", data); */
427 switch (type->type) {
430 guint8 *p = (guint8*)data;
434 case MONO_TYPE_BOOLEAN: {
435 guint8 *p = (guint8*)data;
436 *p = (val->data.i != 0);
441 case MONO_TYPE_CHAR: {
442 guint16 *p = (guint16*)data;
447 mono_i *p = (mono_i*)data;
448 /* In theory the value used by stloc should match the local var type
449 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
450 a native int - both by csc and mcs). Not sure what to do about sign extension
451 as it is outside the spec... doing the obvious */
452 *p = (mono_i)val->data.nati;
456 mono_u *p = (mono_u*)data;
458 *p = (mono_u)val->data.nati;
463 gint32 *p = (gint32*)data;
469 gint64 *p = (gint64*)data;
474 float *p = (float*)data;
479 double *p = (double*)data;
483 case MONO_TYPE_STRING:
484 case MONO_TYPE_SZARRAY:
485 case MONO_TYPE_CLASS:
486 case MONO_TYPE_OBJECT:
487 case MONO_TYPE_ARRAY: {
488 gpointer *p = (gpointer *) data;
489 mono_gc_wbarrier_generic_store (p, val->data.p);
492 case MONO_TYPE_PTR: {
493 gpointer *p = (gpointer *) data;
497 case MONO_TYPE_VALUETYPE:
498 if (type->data.klass->enumtype) {
499 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
502 mono_value_copy (data, val->data.vt, type->data.klass);
504 case MONO_TYPE_GENERICINST: {
505 MonoClass *container_class = type->data.generic_class->container_class;
507 if (container_class->valuetype && !container_class->enumtype) {
508 mono_value_copy (data, val->data.vt, mono_class_from_mono_type (type));
511 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
515 g_warning ("got type %x", type->type);
516 g_assert_not_reached ();
521 fill_in_trace (MonoException *exception, MonoInvocation *frame)
524 char *stack_trace = dump_frame (frame);
525 MonoDomain *domain = mono_domain_get();
526 (exception)->stack_trace = mono_string_new_checked (domain, stack_trace, &error);
527 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
528 (exception)->trace_ips = get_trace_ips (domain, frame);
529 g_free (stack_trace);
532 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
534 #define THROW_EX(exception,ex_ip) \
536 frame->ip = (ex_ip); \
537 frame->ex = (MonoException*)(exception); \
538 FILL_IN_TRACE(frame->ex, frame); \
539 goto handle_exception; \
543 ves_array_create (MonoInvocation *frame, MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
546 intptr_t *lower_bounds;
551 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
552 for (i = 0; i < sig->param_count; ++i) {
553 lengths [i] = values->data.i;
556 if (klass->rank == sig->param_count) {
557 /* Only lengths provided. */
560 /* lower bounds are first. */
561 lower_bounds = (intptr_t *) lengths;
562 lengths += klass->rank;
564 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
565 if (!mono_error_ok (&error)) {
566 frame->ex = mono_error_convert_to_exception (&error);
567 FILL_IN_TRACE (frame->ex, frame);
569 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
574 ves_array_calculate_index (MonoArray *ao, stackval *sp, MonoInvocation *frame, gboolean safe)
576 g_assert (!frame->ex);
577 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
581 for (gint32 i = 0; i < ac->rank; i++) {
582 guint32 idx = sp [i].data.i;
583 guint32 lower = ao->bounds [i].lower_bound;
584 guint32 len = ao->bounds [i].length;
585 if (safe && (idx < lower || (idx - lower) >= len)) {
586 frame->ex = mono_get_exception_index_out_of_range ();
587 FILL_IN_TRACE (frame->ex, frame);
590 pos = (pos * len) + idx - lower;
594 if (safe && pos >= ao->max_length) {
595 frame->ex = mono_get_exception_index_out_of_range ();
596 FILL_IN_TRACE (frame->ex, frame);
604 ves_array_set (MonoInvocation *frame)
606 stackval *sp = frame->stack_args + 1;
608 MonoObject *o = frame->stack_args->data.p;
609 MonoArray *ao = (MonoArray *) o;
610 MonoClass *ac = o->vtable->klass;
612 g_assert (ac->rank >= 1);
614 gint32 pos = ves_array_calculate_index (ao, sp, frame, TRUE);
618 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
620 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
621 mono_error_cleanup (&error);
623 frame->ex = mono_get_exception_array_type_mismatch ();
624 FILL_IN_TRACE (frame->ex, frame);
629 gint32 esize = mono_array_element_size (ac);
630 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
632 MonoType *mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
633 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
637 ves_array_get (MonoInvocation *frame, gboolean safe)
639 stackval *sp = frame->stack_args + 1;
641 MonoObject *o = frame->stack_args->data.p;
642 MonoArray *ao = (MonoArray *) o;
643 MonoClass *ac = o->vtable->klass;
645 g_assert (ac->rank >= 1);
647 gint32 pos = ves_array_calculate_index (ao, sp, frame, safe);
651 gint32 esize = mono_array_element_size (ac);
652 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
654 MonoType *mt = mono_method_signature (frame->runtime_method->method)->ret;
655 stackval_from_data (mt, frame->retval, ea, FALSE);
659 ves_array_element_address (MonoInvocation *frame, MonoClass *required_type, MonoArray *ao, stackval *sp, gboolean needs_typecheck)
661 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
663 g_assert (ac->rank >= 1);
665 gint32 pos = ves_array_calculate_index (ao, sp, frame, TRUE);
669 if (needs_typecheck && !mono_class_is_assignable_from (mono_object_class ((MonoObject *) ao)->element_class, required_type->element_class)) {
670 frame->ex = mono_get_exception_array_type_mismatch ();
671 FILL_IN_TRACE (frame->ex, frame);
674 gint32 esize = mono_array_element_size (ac);
675 return mono_array_addr_with_size (ao, esize, pos);
679 interp_walk_stack_with_ctx (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data)
682 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
687 MonoInvocation *frame = context->current_frame;
690 MonoStackFrameInfo fi;
691 memset (&fi, 0, sizeof (MonoStackFrameInfo));
693 /* TODO: hack to make some asserts happy. */
694 fi.ji = (MonoJitInfo *) frame->runtime_method;
696 if (frame->runtime_method)
697 fi.method = fi.actual_method = frame->runtime_method->method;
699 if (!fi.method || (fi.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (fi.method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
701 fi.type = FRAME_TYPE_MANAGED_TO_NATIVE;
703 MonoMethodHeader *hd = mono_method_get_header_checked (fi.method, &error);
704 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
705 fi.type = FRAME_TYPE_MANAGED;
706 fi.il_offset = frame->ip - (const unsigned short *) hd->code;
707 if (!fi.method->wrapper_type)
711 if (func (&fi, ctx, user_data))
713 frame = frame->parent;
717 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
719 static InterpMethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
721 InterpMethodArguments *margs = g_malloc0 (sizeof (InterpMethodArguments));
726 for (int i = 0; i < sig->param_count; i++) {
727 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
729 case MONO_TYPE_BOOLEAN:
740 case MONO_TYPE_SZARRAY:
741 case MONO_TYPE_CLASS:
742 case MONO_TYPE_OBJECT:
743 case MONO_TYPE_STRING:
744 case MONO_TYPE_VALUETYPE:
745 case MONO_TYPE_GENERICINST:
746 #if SIZEOF_VOID_P == 8
751 #if SIZEOF_VOID_P == 4
754 /* pairs begin at even registers */
762 #if SIZEOF_VOID_P == 8
767 #if SIZEOF_VOID_P == 4
773 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
778 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
781 margs->fargs = g_malloc0 (sizeof (double) * margs->flen);
783 if (margs->ilen > INTERP_ICALL_TRAMP_IARGS)
784 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs->ilen);
786 if (margs->flen > INTERP_ICALL_TRAMP_FARGS)
787 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs->flen);
794 margs->iargs [0] = frame->stack_args->data.p;
798 for (int i = 0; i < sig->param_count; i++) {
799 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
801 case MONO_TYPE_BOOLEAN:
812 case MONO_TYPE_SZARRAY:
813 case MONO_TYPE_CLASS:
814 case MONO_TYPE_OBJECT:
815 case MONO_TYPE_STRING:
816 case MONO_TYPE_VALUETYPE:
817 case MONO_TYPE_GENERICINST:
818 #if SIZEOF_VOID_P == 8
821 margs->iargs [int_i] = frame->stack_args [i].data.p;
823 g_print ("build_args_from_sig: margs->iargs [%d]: %p (frame @ %d)\n", int_i, margs->iargs [int_i], i);
827 #if SIZEOF_VOID_P == 4
829 stackval *sarg = &frame->stack_args [i];
831 /* pairs begin at even registers */
835 margs->iargs [int_i] = (gpointer) sarg->data.pair.lo;
837 margs->iargs [int_i] = (gpointer) sarg->data.pair.hi;
839 g_print ("build_args_from_sig: margs->iargs [%d/%d]: 0x%016llx, hi=0x%08x lo=0x%08x (frame @ %d)\n", int_i - 1, int_i, *((guint64 *) &margs->iargs [int_i - 1]), sarg->data.pair.hi, sarg->data.pair.lo, i);
847 if (ptype == MONO_TYPE_R4)
848 * (float *) &(margs->fargs [int_f]) = (float) frame->stack_args [i].data.f;
850 margs->fargs [int_f] = frame->stack_args [i].data.f;
852 g_print ("build_args_from_sig: margs->fargs [%d]: %p (%f) (frame @ %d)\n", int_f, margs->fargs [int_f], margs->fargs [int_f], i);
854 #if SIZEOF_VOID_P == 4
861 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
865 switch (sig->ret->type) {
866 case MONO_TYPE_BOOLEAN:
877 case MONO_TYPE_SZARRAY:
878 case MONO_TYPE_CLASS:
879 case MONO_TYPE_OBJECT:
880 case MONO_TYPE_STRING:
882 case MONO_TYPE_VALUETYPE:
883 case MONO_TYPE_GENERICINST:
884 margs->retval = &(frame->retval->data.p);
885 margs->is_float_ret = 0;
889 margs->retval = &(frame->retval->data.p);
890 margs->is_float_ret = 1;
893 margs->retval = NULL;
896 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig->ret->type);
903 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
906 MonoInvocation *old_frame = context->current_frame;
907 MonoInvocation *old_env_frame = context->env_frame;
908 jmp_buf *old_env = context->current_env;
912 context->current_frame = old_frame;
913 context->env_frame = old_env_frame;
914 context->current_env = old_env;
915 context->managed_code = 1;
920 context->env_frame = frame;
921 context->current_env = &env;
923 g_assert (!frame->runtime_method);
924 if (!mono_interp_enter_icall_trampoline) {
926 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
928 // mono_tramp_info_register (info, NULL);
931 InterpMethodArguments *margs = build_args_from_sig (sig, frame);
933 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
934 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
937 context->current_frame = frame;
938 context->managed_code = 0;
941 * Push an LMF frame on the LMF stack
942 * to mark the transition to native code.
944 memset (&ext, 0, sizeof (ext));
945 ext.interp_exit = TRUE;
946 ext.interp_exit_data = frame;
948 mono_push_lmf (&ext);
950 mono_interp_enter_icall_trampoline (addr, margs);
952 mono_pop_lmf (&ext.lmf);
954 context->managed_code = 1;
955 /* domain can only be changed by native code */
956 context->domain = mono_domain_get ();
958 if (*mono_thread_interruption_request_flag ()) {
959 MonoException *exc = mono_thread_interruption_checkpoint ();
962 context->search_for_handler = 1;
966 if (!frame->ex && !MONO_TYPE_ISSTRUCT (sig->ret))
967 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
969 context->current_frame = old_frame;
970 context->env_frame = old_env_frame;
971 context->current_env = old_env;
973 g_free (margs->iargs);
974 g_free (margs->fargs);
979 mono_interp_init_delegate (MonoDelegate *del)
983 /* shouldn't need a write barrier because we don't write a MonoObject into the field */
984 del->method = ((RuntimeMethod *) del->method_ptr)->method;
989 * runtime specifies that the implementation of the method is automatically
990 * provided by the runtime and is primarily used for the methods of delegates.
993 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
995 MonoMethod *method = frame->runtime_method->method;
996 const char *name = method->name;
997 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
998 MonoObject *isinst_obj;
1001 mono_class_init (method->klass);
1003 if (method->klass == mono_defaults.array_class) {
1004 if (!strcmp (method->name, "UnsafeMov")) {
1005 /* TODO: layout checks */
1006 MonoType *mt = mono_method_signature (method)->ret;
1007 stackval_from_data (mt, frame->retval, (char *) frame->stack_args, FALSE);
1010 if (!strcmp (method->name, "UnsafeLoad")) {
1011 ves_array_get (frame, FALSE);
1016 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
1017 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1018 if (obj && isinst_obj) {
1019 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
1020 ves_array_set (frame);
1023 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
1024 ves_array_get (frame, TRUE);
1029 g_error ("Don't know how to exec runtime method %s.%s::%s",
1030 method->klass->name_space, method->klass->name,
1036 dump_stack (stackval *stack, stackval *sp)
1038 stackval *s = stack;
1039 GString *str = g_string_new ("");
1042 return g_string_free (str, FALSE);
1045 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
1048 return g_string_free (str, FALSE);
1053 dump_stackval (GString *str, stackval *s, MonoType *type)
1055 switch (type->type) {
1062 case MONO_TYPE_CHAR:
1063 case MONO_TYPE_BOOLEAN:
1064 g_string_append_printf (str, "[%d] ", s->data.i);
1066 case MONO_TYPE_STRING:
1067 case MONO_TYPE_SZARRAY:
1068 case MONO_TYPE_CLASS:
1069 case MONO_TYPE_OBJECT:
1070 case MONO_TYPE_ARRAY:
1074 g_string_append_printf (str, "[%p] ", s->data.p);
1076 case MONO_TYPE_VALUETYPE:
1077 if (type->data.klass->enumtype)
1078 g_string_append_printf (str, "[%d] ", s->data.i);
1080 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1084 g_string_append_printf (str, "[%g] ", s->data.f);
1089 GString *res = g_string_new ("");
1090 mono_type_get_desc (res, type, TRUE);
1091 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1092 g_string_free (res, TRUE);
1100 dump_retval (MonoInvocation *inv)
1102 GString *str = g_string_new ("");
1103 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1105 if (ret->type != MONO_TYPE_VOID)
1106 dump_stackval (str, inv->retval, ret);
1108 return g_string_free (str, FALSE);
1113 dump_args (MonoInvocation *inv)
1115 GString *str = g_string_new ("");
1117 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1119 if (signature->param_count == 0 && !signature->hasthis)
1120 return g_string_free (str, FALSE);
1122 if (signature->hasthis) {
1123 MonoMethod *method = inv->runtime_method->method;
1124 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1127 for (i = 0; i < signature->param_count; ++i)
1128 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1130 return g_string_free (str, FALSE);
1134 dump_frame (MonoInvocation *inv)
1136 GString *str = g_string_new ("");
1141 for (i = 0; inv; inv = inv->parent) {
1142 if (inv->runtime_method != NULL) {
1143 MonoMethod *method = inv->runtime_method->method;
1147 const char * opname = "";
1149 gchar *source = NULL;
1153 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1154 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1155 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1156 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1160 opname = mono_interp_opname [*inv->ip];
1161 codep = inv->ip - inv->runtime_method->code;
1162 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1167 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1168 source = mono_debug_method_lookup_location (minfo, codep);
1172 args = dump_args (inv);
1173 name = mono_method_full_name (method, TRUE);
1175 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1177 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1184 return g_string_free (str, FALSE);
1188 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1192 MonoInvocation *inv;
1195 for (i = 0, inv = top; inv; inv = inv->parent)
1196 if (inv->runtime_method != NULL)
1199 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1200 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1202 for (i = 0, inv = top; inv; inv = inv->parent)
1203 if (inv->runtime_method != NULL) {
1204 mono_array_set (res, gpointer, i, inv->runtime_method);
1206 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1214 #define MYGUINT64_MAX 18446744073709551615ULL
1215 #define MYGINT64_MAX 9223372036854775807LL
1216 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1218 #define MYGUINT32_MAX 4294967295U
1219 #define MYGINT32_MAX 2147483647
1220 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1222 #define CHECK_ADD_OVERFLOW(a,b) \
1223 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1224 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1226 #define CHECK_SUB_OVERFLOW(a,b) \
1227 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1228 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1230 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1231 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1233 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1234 (guint32)(a) < (guint32)(b) ? -1 : 0
1236 #define CHECK_ADD_OVERFLOW64(a,b) \
1237 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1238 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1240 #define CHECK_SUB_OVERFLOW64(a,b) \
1241 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1242 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1244 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1245 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1247 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1248 (guint64)(a) < (guint64)(b) ? -1 : 0
1250 #if SIZEOF_VOID_P == 4
1251 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1252 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1254 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1255 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1258 /* Resolves to TRUE if the operands would overflow */
1259 #define CHECK_MUL_OVERFLOW(a,b) \
1260 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1261 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1262 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1263 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1264 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1265 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1266 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1268 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1269 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1270 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1272 #define CHECK_MUL_OVERFLOW64(a,b) \
1273 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1274 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1275 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1276 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1277 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1278 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1279 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1281 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1282 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1283 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1285 #if SIZEOF_VOID_P == 4
1286 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1287 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1289 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1290 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1294 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1296 MonoInvocation frame;
1297 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1298 MonoObject *retval = NULL;
1299 MonoMethodSignature *sig = mono_method_signature (method);
1300 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1301 int i, type, isobject = 0;
1304 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1305 ThreadContext context_struct;
1306 MonoInvocation *old_frame = NULL;
1316 if (context != &context_struct) {
1317 context->domain = mono_domain_get ();
1318 context->current_frame = old_frame;
1319 context->managed_code = 0;
1321 mono_native_tls_set_value (thread_context_id, NULL);
1323 *exc = (MonoObject *)frame.ex;
1327 if (context == NULL) {
1328 context = &context_struct;
1329 memset (context, 0, sizeof (ThreadContext));
1330 context_struct.base_frame = &frame;
1331 context_struct.env_frame = &frame;
1332 context_struct.current_env = &env;
1333 mono_native_tls_set_value (thread_context_id, context);
1336 old_frame = context->current_frame;
1338 context->domain = mono_domain_get ();
1340 switch (sig->ret->type) {
1341 case MONO_TYPE_VOID:
1343 case MONO_TYPE_STRING:
1344 case MONO_TYPE_OBJECT:
1345 case MONO_TYPE_CLASS:
1346 case MONO_TYPE_ARRAY:
1347 case MONO_TYPE_SZARRAY:
1350 case MONO_TYPE_VALUETYPE:
1351 retval = mono_object_new_checked (context->domain, klass, error);
1352 ret = mono_object_unbox (retval);
1353 if (!sig->ret->data.klass->enumtype)
1354 result.data.vt = ret;
1356 result.data.vt = alloca (mono_class_instance_size (klass));
1358 case MONO_TYPE_GENERICINST:
1359 if (!MONO_TYPE_IS_REFERENCE (sig->ret)) {
1360 retval = mono_object_new_checked (context->domain, klass, error);
1361 ret = mono_object_unbox (retval);
1362 if (!sig->ret->data.klass->enumtype)
1363 result.data.vt = ret;
1365 result.data.vt = alloca (mono_class_instance_size (klass));
1372 retval = mono_object_new_checked (context->domain, mono_defaults.int_class, error);
1373 ret = mono_object_unbox (retval);
1376 retval = mono_object_new_checked (context->domain, klass, error);
1377 ret = mono_object_unbox (retval);
1382 args [0].data.p = obj;
1384 for (i = 0; i < sig->param_count; ++i) {
1385 int a_index = i + !!sig->hasthis;
1386 if (sig->params [i]->byref) {
1387 args [a_index].data.p = params [i];
1390 type = sig->params [i]->type;
1395 case MONO_TYPE_BOOLEAN:
1396 args [a_index].data.i = *(MonoBoolean*)params [i];
1400 case MONO_TYPE_CHAR:
1401 args [a_index].data.i = *(gint16*)params [i];
1403 #if SIZEOF_VOID_P == 4
1404 case MONO_TYPE_U: /* use VAL_POINTER? */
1409 args [a_index].data.i = *(gint32*)params [i];
1411 #if SIZEOF_VOID_P == 8
1417 args [a_index].data.l = *(gint64*)params [i];
1420 args [a_index].data.f = *(gfloat *) params [i];
1423 args [a_index].data.f = *(gdouble *) params [i];
1425 case MONO_TYPE_VALUETYPE:
1426 if (sig->params [i]->data.klass->enumtype) {
1427 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1430 args [a_index].data.p = params [i];
1433 case MONO_TYPE_STRING:
1435 case MONO_TYPE_CLASS:
1436 case MONO_TYPE_ARRAY:
1437 case MONO_TYPE_SZARRAY:
1438 case MONO_TYPE_OBJECT:
1439 case MONO_TYPE_GENERICINST:
1440 args [a_index].data.p = params [i];
1443 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1447 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1448 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1449 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1451 frame.invoke_trap = 1;
1452 context->managed_code = 1;
1453 ves_exec_method_with_context (&frame, context, NULL, NULL, -1);
1454 context->managed_code = 0;
1455 if (context == &context_struct)
1456 mono_native_tls_set_value (thread_context_id, NULL);
1458 context->current_frame = old_frame;
1459 if (frame.ex != NULL) {
1461 *exc = (MonoObject*) frame.ex;
1464 if (context->current_env != NULL) {
1465 context->env_frame->ex = frame.ex;
1466 longjmp(*context->current_env, 1);
1469 printf("dropped exception...\n");
1471 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1473 if (isobject || method->string_ctor)
1474 return result.data.p;
1475 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1480 RuntimeMethod *rmethod;
1484 gpointer *many_args;
1487 /* Main function for entering the interpreter from compiled code */
1489 interp_entry (InterpEntryData *data)
1491 MonoInvocation frame;
1492 RuntimeMethod *rmethod = data->rmethod;
1493 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
1494 ThreadContext context_struct;
1495 MonoInvocation *old_frame;
1499 MonoMethodSignature *sig;
1503 method = rmethod->method;
1504 sig = mono_method_signature (method);
1506 // FIXME: Optimize this
1508 //printf ("%s\n", mono_method_full_name (method, 1));
1511 if (context == NULL) {
1512 context = &context_struct;
1513 memset (context, 0, sizeof (ThreadContext));
1514 context_struct.base_frame = &frame;
1515 context_struct.env_frame = &frame;
1516 mono_native_tls_set_value (thread_context_id, context);
1519 old_frame = context->current_frame;
1520 context->domain = mono_domain_get ();
1522 args = alloca (sizeof (stackval) * (sig->param_count + (sig->hasthis ? 1 : 0)));
1524 args [0].data.p = data->this_arg;
1527 if (data->many_args)
1528 params = data->many_args;
1530 params = data->args;
1531 for (i = 0; i < sig->param_count; ++i) {
1532 int a_index = i + (sig->hasthis ? 1 : 0);
1533 if (sig->params [i]->byref) {
1534 args [a_index].data.p = params [i];
1537 type = rmethod->param_types [i];
1538 switch (type->type) {
1541 args [a_index].data.i = *(MonoBoolean*)params [i];
1545 args [a_index].data.i = *(gint16*)params [i];
1548 #if SIZEOF_VOID_P == 4
1549 args [a_index].data.p = GINT_TO_POINTER (*(guint32*)params [i]);
1551 args [a_index].data.p = GINT_TO_POINTER (*(guint64*)params [i]);
1555 #if SIZEOF_VOID_P == 4
1556 args [a_index].data.p = GINT_TO_POINTER (*(gint32*)params [i]);
1558 args [a_index].data.p = GINT_TO_POINTER (*(gint64*)params [i]);
1562 args [a_index].data.i = *(guint32*)params [i];
1565 args [a_index].data.i = *(gint32*)params [i];
1568 args [a_index].data.l = *(guint64*)params [i];
1571 args [a_index].data.l = *(gint64*)params [i];
1574 case MONO_TYPE_OBJECT:
1575 args [a_index].data.p = *(MonoObject**)params [i];
1577 case MONO_TYPE_VALUETYPE:
1578 args [a_index].data.p = params [i];
1580 case MONO_TYPE_GENERICINST:
1581 if (MONO_TYPE_IS_REFERENCE (type))
1582 args [a_index].data.p = params [i];
1584 args [a_index].data.vt = params [i];
1587 printf ("%s\n", mono_type_full_name (sig->params [i]));
1593 init_frame (&frame, NULL, data->rmethod, args, &result);
1594 context->managed_code = 1;
1596 type = rmethod->rtype;
1597 switch (type->type) {
1598 case MONO_TYPE_GENERICINST:
1599 if (!MONO_TYPE_IS_REFERENCE (type))
1600 frame.retval->data.vt = data->res;
1602 case MONO_TYPE_VALUETYPE:
1603 frame.retval->data.vt = data->res;
1609 ves_exec_method_with_context (&frame, context, NULL, NULL, -1);
1610 context->managed_code = 0;
1611 if (context == &context_struct)
1612 mono_native_tls_set_value (thread_context_id, NULL);
1614 context->current_frame = old_frame;
1617 g_assert (frame.ex == NULL);
1619 type = rmethod->rtype;
1620 switch (type->type) {
1621 case MONO_TYPE_VOID:
1624 *(gint8*)data->res = frame.retval->data.i;
1627 *(guint8*)data->res = frame.retval->data.i;
1630 *(gint16*)data->res = frame.retval->data.i;
1633 *(guint16*)data->res = frame.retval->data.i;
1636 *(gint32*)data->res = frame.retval->data.i;
1639 *(guint64*)data->res = frame.retval->data.i;
1642 *(gint64*)data->res = frame.retval->data.i;
1645 *(guint64*)data->res = frame.retval->data.i;
1648 #if SIZEOF_VOID_P == 8
1649 *(gint64*)data->res = (gint64)frame.retval->data.p;
1651 *(gint32*)data->res = (gint32)frame.retval->data.p;
1655 #if SIZEOF_VOID_P == 8
1656 *(guint64*)data->res = (guint64)frame.retval->data.p;
1658 *(guint32*)data->res = (guint32)frame.retval->data.p;
1661 case MONO_TYPE_OBJECT:
1662 /* No need for a write barrier */
1663 *(MonoObject**)data->res = (MonoObject*)frame.retval->data.p;
1665 case MONO_TYPE_GENERICINST:
1666 if (MONO_TYPE_IS_REFERENCE (type)) {
1667 *(MonoObject**)data->res = *(MonoObject**)frame.retval->data.p;
1669 /* Already set before the call */
1672 case MONO_TYPE_VALUETYPE:
1673 /* Already set before the call */
1676 printf ("%s\n", mono_type_full_name (sig->ret));
1683 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1685 MonoInvocation *old_frame = context->current_frame;
1686 MonoInvocation *old_env_frame = context->env_frame;
1687 jmp_buf *old_env = context->current_env;
1691 context->current_frame = old_frame;
1692 context->env_frame = old_env_frame;
1693 context->current_env = old_env;
1694 context->managed_code = 1;
1698 context->env_frame = context->current_frame;
1699 context->current_env = &env;
1700 context->managed_code = 0;
1703 case MINT_ICALL_V_V: {
1704 void (*func)(void) = ptr;
1708 case MINT_ICALL_V_P: {
1709 gpointer (*func)(void) = ptr;
1711 sp [-1].data.p = func ();
1714 case MINT_ICALL_P_V: {
1715 void (*func)(gpointer) = ptr;
1716 func (sp [-1].data.p);
1720 case MINT_ICALL_P_P: {
1721 gpointer (*func)(gpointer) = ptr;
1722 sp [-1].data.p = func (sp [-1].data.p);
1725 case MINT_ICALL_PP_V: {
1726 void (*func)(gpointer,gpointer) = ptr;
1728 func (sp [0].data.p, sp [1].data.p);
1731 case MINT_ICALL_PI_V: {
1732 void (*func)(gpointer,int) = ptr;
1734 func (sp [0].data.p, sp [1].data.i);
1737 case MINT_ICALL_PP_P: {
1738 gpointer (*func)(gpointer,gpointer) = ptr;
1740 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1743 case MINT_ICALL_PI_P: {
1744 gpointer (*func)(gpointer,int) = ptr;
1746 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1749 case MINT_ICALL_PPP_V: {
1750 void (*func)(gpointer,gpointer,gpointer) = ptr;
1752 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1755 case MINT_ICALL_PPI_V: {
1756 void (*func)(gpointer,gpointer,int) = ptr;
1758 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1762 g_assert_not_reached ();
1765 context->env_frame = old_env_frame;
1766 context->current_env = old_env;
1772 * These functions are the entry points into the interpreter from compiled code.
1773 * They are called by the interp_in wrappers. They have the following signature:
1774 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
1775 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
1776 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
1777 * more wrappers then these functions.
1778 * this/static * ret/void * 16 arguments -> 64 functions.
1781 #define MAX_INTERP_ENTRY_ARGS 8
1783 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
1784 InterpEntryData data; \
1785 (data).rmethod = (_method); \
1786 (data).res = (_res); \
1787 (data).this_arg = (_this_arg); \
1788 (data).many_args = NULL;
1790 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
1791 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1792 interp_entry (&data); \
1794 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
1795 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1796 (data).args [0] = arg1; \
1797 interp_entry (&data); \
1799 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
1800 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1801 (data).args [0] = arg1; \
1802 (data).args [1] = arg2; \
1803 interp_entry (&data); \
1805 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
1806 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1807 (data).args [0] = arg1; \
1808 (data).args [1] = arg2; \
1809 (data).args [2] = arg3; \
1810 interp_entry (&data); \
1812 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
1813 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1814 (data).args [0] = arg1; \
1815 (data).args [1] = arg2; \
1816 (data).args [2] = arg3; \
1817 (data).args [3] = arg4; \
1818 interp_entry (&data); \
1820 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
1821 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1822 (data).args [0] = arg1; \
1823 (data).args [1] = arg2; \
1824 (data).args [2] = arg3; \
1825 (data).args [3] = arg4; \
1826 (data).args [4] = arg5; \
1827 interp_entry (&data); \
1829 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
1830 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1831 (data).args [0] = arg1; \
1832 (data).args [1] = arg2; \
1833 (data).args [2] = arg3; \
1834 (data).args [3] = arg4; \
1835 (data).args [4] = arg5; \
1836 (data).args [5] = arg6; \
1837 interp_entry (&data); \
1839 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
1840 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1841 (data).args [0] = arg1; \
1842 (data).args [1] = arg2; \
1843 (data).args [2] = arg3; \
1844 (data).args [3] = arg4; \
1845 (data).args [4] = arg5; \
1846 (data).args [5] = arg6; \
1847 (data).args [6] = arg7; \
1848 interp_entry (&data); \
1850 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
1851 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1852 (data).args [0] = arg1; \
1853 (data).args [1] = arg2; \
1854 (data).args [2] = arg3; \
1855 (data).args [3] = arg4; \
1856 (data).args [4] = arg5; \
1857 (data).args [5] = arg6; \
1858 (data).args [6] = arg7; \
1859 (data).args [7] = arg8; \
1860 interp_entry (&data); \
1863 #define ARGLIST0 RuntimeMethod *rmethod
1864 #define ARGLIST1 gpointer arg1, RuntimeMethod *rmethod
1865 #define ARGLIST2 gpointer arg1, gpointer arg2, RuntimeMethod *rmethod
1866 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, RuntimeMethod *rmethod
1867 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, RuntimeMethod *rmethod
1868 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, RuntimeMethod *rmethod
1869 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, RuntimeMethod *rmethod
1870 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, RuntimeMethod *rmethod
1871 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, RuntimeMethod *rmethod
1873 static void interp_entry_static_0 (ARGLIST0) INTERP_ENTRY0 (NULL, NULL, rmethod)
1874 static void interp_entry_static_1 (ARGLIST1) INTERP_ENTRY1 (NULL, NULL, rmethod)
1875 static void interp_entry_static_2 (ARGLIST2) INTERP_ENTRY2 (NULL, NULL, rmethod)
1876 static void interp_entry_static_3 (ARGLIST3) INTERP_ENTRY3 (NULL, NULL, rmethod)
1877 static void interp_entry_static_4 (ARGLIST4) INTERP_ENTRY4 (NULL, NULL, rmethod)
1878 static void interp_entry_static_5 (ARGLIST5) INTERP_ENTRY5 (NULL, NULL, rmethod)
1879 static void interp_entry_static_6 (ARGLIST6) INTERP_ENTRY6 (NULL, NULL, rmethod)
1880 static void interp_entry_static_7 (ARGLIST7) INTERP_ENTRY7 (NULL, NULL, rmethod)
1881 static void interp_entry_static_8 (ARGLIST8) INTERP_ENTRY8 (NULL, NULL, rmethod)
1882 static void interp_entry_static_ret_0 (gpointer res, ARGLIST0) INTERP_ENTRY0 (NULL, res, rmethod)
1883 static void interp_entry_static_ret_1 (gpointer res, ARGLIST1) INTERP_ENTRY1 (NULL, res, rmethod)
1884 static void interp_entry_static_ret_2 (gpointer res, ARGLIST2) INTERP_ENTRY2 (NULL, res, rmethod)
1885 static void interp_entry_static_ret_3 (gpointer res, ARGLIST3) INTERP_ENTRY3 (NULL, res, rmethod)
1886 static void interp_entry_static_ret_4 (gpointer res, ARGLIST4) INTERP_ENTRY4 (NULL, res, rmethod)
1887 static void interp_entry_static_ret_5 (gpointer res, ARGLIST5) INTERP_ENTRY5 (NULL, res, rmethod)
1888 static void interp_entry_static_ret_6 (gpointer res, ARGLIST6) INTERP_ENTRY6 (NULL, res, rmethod)
1889 static void interp_entry_static_ret_7 (gpointer res, ARGLIST7) INTERP_ENTRY7 (NULL, res, rmethod)
1890 static void interp_entry_static_ret_8 (gpointer res, ARGLIST8) INTERP_ENTRY8 (NULL, res, rmethod)
1891 static void interp_entry_instance_0 (gpointer this_arg, ARGLIST0) INTERP_ENTRY0 (this_arg, NULL, rmethod)
1892 static void interp_entry_instance_1 (gpointer this_arg, ARGLIST1) INTERP_ENTRY1 (this_arg, NULL, rmethod)
1893 static void interp_entry_instance_2 (gpointer this_arg, ARGLIST2) INTERP_ENTRY2 (this_arg, NULL, rmethod)
1894 static void interp_entry_instance_3 (gpointer this_arg, ARGLIST3) INTERP_ENTRY3 (this_arg, NULL, rmethod)
1895 static void interp_entry_instance_4 (gpointer this_arg, ARGLIST4) INTERP_ENTRY4 (this_arg, NULL, rmethod)
1896 static void interp_entry_instance_5 (gpointer this_arg, ARGLIST5) INTERP_ENTRY5 (this_arg, NULL, rmethod)
1897 static void interp_entry_instance_6 (gpointer this_arg, ARGLIST6) INTERP_ENTRY6 (this_arg, NULL, rmethod)
1898 static void interp_entry_instance_7 (gpointer this_arg, ARGLIST7) INTERP_ENTRY7 (this_arg, NULL, rmethod)
1899 static void interp_entry_instance_8 (gpointer this_arg, ARGLIST8) INTERP_ENTRY8 (this_arg, NULL, rmethod)
1900 static void interp_entry_instance_ret_0 (gpointer this_arg, gpointer res, ARGLIST0) INTERP_ENTRY0 (this_arg, res, rmethod)
1901 static void interp_entry_instance_ret_1 (gpointer this_arg, gpointer res, ARGLIST1) INTERP_ENTRY1 (this_arg, res, rmethod)
1902 static void interp_entry_instance_ret_2 (gpointer this_arg, gpointer res, ARGLIST2) INTERP_ENTRY2 (this_arg, res, rmethod)
1903 static void interp_entry_instance_ret_3 (gpointer this_arg, gpointer res, ARGLIST3) INTERP_ENTRY3 (this_arg, res, rmethod)
1904 static void interp_entry_instance_ret_4 (gpointer this_arg, gpointer res, ARGLIST4) INTERP_ENTRY4 (this_arg, res, rmethod)
1905 static void interp_entry_instance_ret_5 (gpointer this_arg, gpointer res, ARGLIST5) INTERP_ENTRY5 (this_arg, res, rmethod)
1906 static void interp_entry_instance_ret_6 (gpointer this_arg, gpointer res, ARGLIST6) INTERP_ENTRY6 (this_arg, res, rmethod)
1907 static void interp_entry_instance_ret_7 (gpointer this_arg, gpointer res, ARGLIST7) INTERP_ENTRY6 (this_arg, res, rmethod)
1908 static void interp_entry_instance_ret_8 (gpointer this_arg, gpointer res, ARGLIST8) INTERP_ENTRY6 (this_arg, res, rmethod)
1910 #define INTERP_ENTRY_FUNCLIST(type) interp_entry_ ## type ## _0, interp_entry_ ## type ## _1, interp_entry_ ## type ## _2, interp_entry_ ## type ## _3, interp_entry_ ## type ## _4, interp_entry_ ## type ## _5, interp_entry_ ## type ## _6, interp_entry_ ## type ## _7, interp_entry_ ## type ## _8
1912 gpointer entry_funcs_static [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static) };
1913 gpointer entry_funcs_static_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static_ret) };
1914 gpointer entry_funcs_instance [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance) };
1915 gpointer entry_funcs_instance_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance_ret) };
1917 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
1919 interp_entry_general (gpointer this_arg, gpointer res, gpointer *args, gpointer rmethod)
1921 INTERP_ENTRY_BASE (rmethod, this_arg, res);
1922 data.many_args = args;
1923 interp_entry (&data);
1927 * mono_interp_create_method_pointer:
1929 * Return a function pointer which can be used to call METHOD using the
1930 * interpreter. Return NULL for methods which are not supported.
1933 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1936 MonoMethodSignature *sig = mono_method_signature (method);
1937 MonoMethod *wrapper;
1938 RuntimeMethod *rmethod;
1940 /* HACK: method_ptr of delegate should point to a runtime method*/
1941 if (method->wrapper_type && method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD)
1942 return mono_interp_get_runtime_method (mono_domain_get (), method, error);
1944 rmethod = mono_interp_get_runtime_method (mono_domain_get (), method, error);
1945 if (rmethod->jit_entry)
1946 return rmethod->jit_entry;
1947 wrapper = mini_get_interp_in_wrapper (sig);
1949 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, error);
1950 mono_error_assert_ok (error);
1952 //printf ("%s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
1953 gpointer entry_func;
1954 if (sig->param_count > MAX_INTERP_ENTRY_ARGS) {
1955 entry_func = interp_entry_general;
1956 } else if (sig->hasthis) {
1957 if (sig->ret->type == MONO_TYPE_VOID)
1958 entry_func = entry_funcs_instance [sig->param_count];
1960 entry_func = entry_funcs_instance_ret [sig->param_count];
1962 if (sig->ret->type == MONO_TYPE_VOID)
1963 entry_func = entry_funcs_static [sig->param_count];
1965 entry_func = entry_funcs_static_ret [sig->param_count];
1967 g_assert (entry_func);
1969 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
1970 MonoFtnDesc *ftndesc = g_new0 (MonoFtnDesc, 1);
1971 ftndesc->addr = entry_func;
1972 ftndesc->arg = rmethod;
1973 mono_error_assert_ok (error);
1976 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
1977 * rgctx register using a trampoline.
1981 g_assert (!mono_aot_only);
1982 addr = mono_arch_get_static_rgctx_trampoline (ftndesc, jit_wrapper);
1984 mono_memory_barrier ();
1985 rmethod->jit_entry = addr;
1991 static int opcode_counts[512];
1993 #define COUNT_OP(op) opcode_counts[op]++
1995 #define COUNT_OP(op)
1999 #define DUMP_INSTR() \
2000 if (tracing > 1) { \
2002 if (sp > frame->stack) { \
2003 ins = dump_stack (frame->stack, sp); \
2005 ins = g_strdup (""); \
2009 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
2010 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
2012 mono_interp_dis_mintop(rtm->code, ip); \
2013 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
2017 #define DUMP_INSTR()
2021 #define USE_COMPUTED_GOTO 1
2023 #if USE_COMPUTED_GOTO
2024 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
2025 #define MINT_IN_CASE(x) LAB_ ## x:
2027 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
2029 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
2031 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
2033 #define MINT_IN_SWITCH(op) switch (op)
2034 #define MINT_IN_CASE(x) case x:
2035 #define MINT_IN_BREAK break
2036 #define MINT_IN_DEFAULT default:
2040 * If EXIT_AT_FINALLY is not -1, exit after exiting the finally clause with that index.
2043 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception, int exit_at_finally)
2045 MonoInvocation child_frame;
2046 GSList *finally_ips = NULL;
2047 const unsigned short *endfinally_ip = NULL;
2048 const unsigned short *ip = NULL;
2049 register stackval *sp;
2052 gint tracing = global_tracing;
2053 unsigned char *vtalloc;
2058 unsigned char *vt_sp;
2059 unsigned char *locals;
2061 MonoObject *o = NULL;
2063 #if USE_COMPUTED_GOTO
2064 static void *in_labels[] = {
2065 #define OPDEF(a,b,c,d) \
2067 #include "mintops.def"
2072 frame->ex_handler = NULL;
2074 context->current_frame = frame;
2076 debug_enter (frame, &tracing);
2078 if (!frame->runtime_method->transformed) {
2079 context->managed_code = 0;
2081 char *mn = mono_method_full_name (frame->runtime_method->method, TRUE);
2082 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
2085 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
2086 context->managed_code = 1;
2094 rtm = frame->runtime_method;
2095 if (!start_with_ip ) {
2096 frame->args = alloca (rtm->alloca_size);
2097 memset (frame->args, 0, rtm->alloca_size);
2103 sp = frame->stack = (stackval *) ((char *) frame->args + rtm->args_size);
2104 vt_sp = (unsigned char *) sp + rtm->stack_size;
2108 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
2109 child_frame.parent = frame;
2111 if (filter_exception) {
2112 sp->data.p = filter_exception;
2117 * using while (ip < end) may result in a 15% performance drop,
2118 * but it may be useful for debug
2122 /* g_assert (sp >= frame->stack); */
2123 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
2125 MINT_IN_SWITCH (*ip) {
2126 MINT_IN_CASE(MINT_INITLOCALS)
2127 memset (locals, 0, rtm->locals_size);
2130 MINT_IN_CASE(MINT_NOP)
2133 MINT_IN_CASE(MINT_BREAK)
2135 G_BREAKPOINT (); /* this is not portable... */
2137 MINT_IN_CASE(MINT_LDNULL)
2142 MINT_IN_CASE(MINT_VTRESULT) {
2143 int ret_size = * (guint16 *)(ip + 1);
2144 unsigned char *ret_vt_sp = vt_sp;
2145 vt_sp -= READ32(ip + 2);
2147 memmove (vt_sp, ret_vt_sp, ret_size);
2148 sp [-1].data.p = vt_sp;
2149 vt_sp += (ret_size + 7) & ~7;
2154 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
2155 MINT_IN_CASE(MINT_LDC_I4_M1)
2158 MINT_IN_CASE(MINT_LDC_I4_0)
2161 MINT_IN_CASE(MINT_LDC_I4_1)
2164 MINT_IN_CASE(MINT_LDC_I4_2)
2167 MINT_IN_CASE(MINT_LDC_I4_3)
2170 MINT_IN_CASE(MINT_LDC_I4_4)
2173 MINT_IN_CASE(MINT_LDC_I4_5)
2176 MINT_IN_CASE(MINT_LDC_I4_6)
2179 MINT_IN_CASE(MINT_LDC_I4_7)
2182 MINT_IN_CASE(MINT_LDC_I4_8)
2185 MINT_IN_CASE(MINT_LDC_I4_S)
2186 sp->data.i = *(const short *)(ip + 1);
2190 MINT_IN_CASE(MINT_LDC_I4)
2192 sp->data.i = READ32 (ip);
2196 MINT_IN_CASE(MINT_LDC_I8)
2198 sp->data.l = READ64 (ip);
2202 MINT_IN_CASE(MINT_LDC_R4) {
2206 sp->data.f = * (float *)&val;
2211 MINT_IN_CASE(MINT_LDC_R8)
2212 sp->data.l = READ64 (ip + 1); /* note union usage */
2216 MINT_IN_CASE(MINT_DUP)
2221 MINT_IN_CASE(MINT_DUP_VT)
2222 i32 = READ32 (ip + 1);
2224 memcpy(sp->data.p, sp [-1].data.p, i32);
2225 vt_sp += (i32 + 7) & ~7;
2229 MINT_IN_CASE(MINT_POP) {
2230 guint16 u16 = (* (guint16 *)(ip + 1)) + 1;
2232 memmove (sp - u16, sp - 1, (u16 - 1) * sizeof (stackval));
2237 MINT_IN_CASE(MINT_JMP) {
2238 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
2239 if (!new_method->transformed) {
2241 frame->ex = mono_interp_transform_method (new_method, context);
2246 if (new_method->alloca_size > rtm->alloca_size)
2247 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
2248 rtm = frame->runtime_method = new_method;
2249 vt_sp = (unsigned char *) sp + rtm->stack_size;
2253 locals = vt_sp + rtm->vt_stack_size;
2254 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
2257 MINT_IN_CASE(MINT_CALLI) {
2258 MonoMethodSignature *csignature;
2259 stackval *endsp = sp;
2263 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2267 child_frame.runtime_method = sp->data.p;
2270 child_frame.retval = sp;
2271 /* decrement by the actual number of args */
2272 sp -= csignature->param_count;
2273 if (csignature->hasthis)
2275 child_frame.stack_args = sp;
2277 /* `this' can be NULL for string:.ctor */
2278 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2279 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2280 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2281 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
2282 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
2283 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2286 if (csignature->hasthis) {
2287 MonoObject *this_arg = sp->data.p;
2289 if (this_arg->vtable->klass->valuetype) {
2290 gpointer *unboxed = mono_object_unbox (this_arg);
2291 sp [0].data.p = unboxed;
2295 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2297 context->current_frame = frame;
2299 if (context->has_resume_state) {
2300 if (frame == context->handler_frame)
2301 SET_RESUME_STATE (context);
2306 if (child_frame.ex) {
2308 * An exception occurred, need to run finally, fault and catch handlers..
2310 frame->ex = child_frame.ex;
2311 goto handle_finally;
2314 /* need to handle typedbyref ... */
2315 if (csignature->ret->type != MONO_TYPE_VOID) {
2321 MINT_IN_CASE(MINT_CALLI_NAT) {
2322 MonoMethodSignature *csignature;
2323 stackval *endsp = sp;
2324 unsigned char *code = NULL;
2328 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2333 child_frame.runtime_method = NULL;
2336 child_frame.retval = sp;
2337 /* decrement by the actual number of args */
2338 sp -= csignature->param_count;
2339 if (csignature->hasthis)
2341 child_frame.stack_args = sp;
2342 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
2344 context->current_frame = frame;
2346 if (context->has_resume_state) {
2347 if (frame == context->handler_frame)
2348 SET_RESUME_STATE (context);
2353 if (child_frame.ex) {
2355 * An exception occurred, need to run finally, fault and catch handlers..
2357 frame->ex = child_frame.ex;
2358 if (context->search_for_handler) {
2359 context->search_for_handler = 0;
2360 goto handle_exception;
2362 goto handle_finally;
2365 /* need to handle typedbyref ... */
2366 if (csignature->ret->type != MONO_TYPE_VOID) {
2372 MINT_IN_CASE(MINT_CALL) {
2373 stackval *endsp = sp;
2377 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2380 child_frame.retval = sp;
2381 /* decrement by the actual number of args */
2382 sp -= child_frame.runtime_method->param_count;
2383 if (child_frame.runtime_method->hasthis)
2385 child_frame.stack_args = sp;
2387 /* `this' can be NULL for string:.ctor */
2388 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2389 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2390 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2393 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2395 context->current_frame = frame;
2397 if (context->has_resume_state) {
2398 if (frame == context->handler_frame)
2399 SET_RESUME_STATE (context);
2404 if (child_frame.ex) {
2406 * An exception occurred, need to run finally, fault and catch handlers..
2408 frame->ex = child_frame.ex;
2409 goto handle_exception;;
2412 /* need to handle typedbyref ... */
2417 MINT_IN_CASE(MINT_VCALL) {
2420 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2424 child_frame.retval = sp;
2425 /* decrement by the actual number of args */
2426 sp -= child_frame.runtime_method->param_count;
2427 if (child_frame.runtime_method->hasthis) {
2429 MonoObject *this_arg = sp->data.p;
2431 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2433 child_frame.stack_args = sp;
2435 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
2436 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2437 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2440 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2442 context->current_frame = frame;
2444 if (context->has_resume_state) {
2445 if (frame == context->handler_frame)
2446 SET_RESUME_STATE (context);
2451 if (child_frame.ex) {
2453 * An exception occurred, need to run finally, fault and catch handlers..
2455 frame->ex = child_frame.ex;
2456 goto handle_finally;
2461 MINT_IN_CASE(MINT_JIT_CALL) {
2462 MonoMethodSignature *sig;
2463 RuntimeMethod *rmethod = rtm->data_items [* (guint16 *)(ip + 1)];
2464 MonoFtnDesc ftndesc;
2465 guint8 res_buf [256];
2469 //printf ("%s\n", mono_method_full_name (rmethod->method, 1));
2472 * Call JITted code through a gsharedvt_out wrapper. These wrappers receive every argument
2473 * by ref and return a return value using an explicit return value argument.
2475 if (!rmethod->jit_wrapper) {
2476 MonoMethod *method = rmethod->method;
2479 sig = mono_method_signature (method);
2482 MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
2483 //printf ("J: %s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
2485 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, &error);
2486 mono_error_assert_ok (&error);
2488 gpointer addr = mono_jit_compile_method_jit_only (method, &error);
2490 mono_error_assert_ok (&error);
2492 rmethod->jit_addr = addr;
2493 rmethod->jit_sig = sig;
2494 mono_memory_barrier ();
2495 rmethod->jit_wrapper = jit_wrapper;
2498 sig = rmethod->jit_sig;
2503 sp -= sig->param_count;
2507 ftndesc.addr = rmethod->jit_addr;
2510 // FIXME: Optimize this
2514 int stack_index = 0;
2515 if (rmethod->hasthis) {
2516 args [pindex ++] = sp [0].data.p;
2519 type = rmethod->rtype;
2520 if (type->type != MONO_TYPE_VOID) {
2521 if (MONO_TYPE_ISSTRUCT (type))
2522 args [pindex ++] = vt_sp;
2524 args [pindex ++] = res_buf;
2526 for (int i = 0; i < rmethod->param_count; ++i) {
2527 MonoType *t = rmethod->param_types [i];
2528 stackval *sval = &sp [stack_index + i];
2529 if (sig->params [i]->byref) {
2530 args [pindex ++] = sval->data.p;
2531 } else if (MONO_TYPE_ISSTRUCT (t)) {
2532 args [pindex ++] = sval->data.p;
2533 } else if (MONO_TYPE_IS_REFERENCE (t)) {
2534 args [pindex ++] = &sval->data.p;
2543 case MONO_TYPE_VALUETYPE:
2544 args [pindex ++] = &sval->data.i;
2547 case MONO_TYPE_FNPTR:
2550 case MONO_TYPE_OBJECT:
2551 args [pindex ++] = &sval->data.p;
2555 args [pindex ++] = &sval->data.l;
2558 printf ("%s\n", mono_type_full_name (t));
2559 g_assert_not_reached ();
2565 * Push an LMF frame on the LMF stack
2566 * to mark the transition to compiled code.
2568 memset (&ext, 0, sizeof (ext));
2569 ext.interp_exit = TRUE;
2570 ext.interp_exit_data = frame;
2572 mono_push_lmf (&ext);
2576 void (*func)(gpointer) = rmethod->jit_wrapper;
2582 void (*func)(gpointer, gpointer) = rmethod->jit_wrapper;
2584 func (args [0], &ftndesc);
2588 void (*func)(gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2590 func (args [0], args [1], &ftndesc);
2594 void (*func)(gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2596 func (args [0], args [1], args [2], &ftndesc);
2600 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2602 func (args [0], args [1], args [2], args [3], &ftndesc);
2606 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2608 func (args [0], args [1], args [2], args [3], args [4], &ftndesc);
2612 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2614 func (args [0], args [1], args [2], args [3], args [4], args [5], &ftndesc);
2618 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2620 func (args [0], args [1], args [2], args [3], args [4], args [5], args [6], &ftndesc);
2624 g_assert_not_reached ();
2628 mono_pop_lmf (&ext.lmf);
2630 if (context->has_resume_state) {
2632 * If this bit is set, it means the call has thrown the exception, and we
2633 * reached this point because the EH code in mono_handle_exception ()
2634 * unwound all the JITted frames below us. mono_interp_set_resume_state ()
2635 * has set the fields in context to indicate where we have to resume execution.
2637 if (frame == context->handler_frame)
2638 SET_RESUME_STATE (context);
2643 MonoType *rtype = rmethod->rtype;
2644 switch (rtype->type) {
2645 case MONO_TYPE_VOID:
2646 case MONO_TYPE_OBJECT:
2647 case MONO_TYPE_STRING:
2648 case MONO_TYPE_CLASS:
2649 case MONO_TYPE_ARRAY:
2650 case MONO_TYPE_SZARRAY:
2653 sp->data.p = *(gpointer*)res_buf;
2656 sp->data.i = *(gint8*)res_buf;
2659 sp->data.i = *(guint8*)res_buf;
2662 sp->data.i = *(gint16*)res_buf;
2665 sp->data.i = *(guint16*)res_buf;
2668 sp->data.i = *(gint32*)res_buf;
2671 sp->data.i = *(guint32*)res_buf;
2673 case MONO_TYPE_VALUETYPE:
2674 /* The result was written to vt_sp */
2677 case MONO_TYPE_GENERICINST:
2678 if (MONO_TYPE_IS_REFERENCE (rtype)) {
2679 sp->data.p = *(gpointer*)res_buf;
2681 /* The result was written to vt_sp */
2686 printf ("%s\n", mono_type_full_name (rtype));
2687 g_assert_not_reached ();
2690 if (rtype->type != MONO_TYPE_VOID)
2695 MINT_IN_CASE(MINT_CALLVIRT) {
2696 stackval *endsp = sp;
2697 MonoObject *this_arg;
2702 token = * (unsigned short *)(ip + 1);
2704 child_frame.runtime_method = rtm->data_items [token];
2706 child_frame.retval = sp;
2708 /* decrement by the actual number of args */
2709 sp -= child_frame.runtime_method->param_count + 1;
2710 child_frame.stack_args = sp;
2711 this_arg = sp->data.p;
2713 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2714 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2716 MonoClass *this_class = this_arg->vtable->klass;
2717 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2719 gpointer *unboxed = mono_object_unbox (this_arg);
2720 sp [0].data.p = unboxed;
2723 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2725 context->current_frame = frame;
2727 if (context->has_resume_state) {
2728 if (frame == context->handler_frame)
2729 SET_RESUME_STATE (context);
2734 if (child_frame.ex) {
2736 * An exception occurred, need to run finally, fault and catch handlers..
2738 frame->ex = child_frame.ex;
2739 if (context->search_for_handler) {
2740 context->search_for_handler = 0;
2741 goto handle_exception;
2743 goto handle_finally;
2746 /* need to handle typedbyref ... */
2751 MINT_IN_CASE(MINT_VCALLVIRT) {
2752 MonoObject *this_arg;
2757 token = * (unsigned short *)(ip + 1);
2759 child_frame.runtime_method = rtm->data_items [token];
2761 child_frame.retval = sp;
2763 /* decrement by the actual number of args */
2764 sp -= child_frame.runtime_method->param_count + 1;
2765 child_frame.stack_args = sp;
2766 this_arg = sp->data.p;
2768 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2769 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2771 MonoClass *this_class = this_arg->vtable->klass;
2772 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2773 gpointer *unboxed = mono_object_unbox (this_arg);
2774 sp [0].data.p = unboxed;
2777 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2779 context->current_frame = frame;
2781 if (context->has_resume_state) {
2782 if (frame == context->handler_frame)
2783 SET_RESUME_STATE (context);
2788 if (child_frame.ex) {
2790 * An exception occurred, need to run finally, fault and catch handlers..
2792 frame->ex = child_frame.ex;
2793 if (context->search_for_handler) {
2794 context->search_for_handler = 0;
2795 goto handle_exception;
2797 goto handle_finally;
2801 MINT_IN_CASE(MINT_CALLRUN)
2802 ves_runtime_method (frame, context);
2805 goto handle_exception;
2808 MINT_IN_CASE(MINT_RET)
2810 *frame->retval = *sp;
2811 if (sp > frame->stack)
2812 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2814 MINT_IN_CASE(MINT_RET_VOID)
2815 if (sp > frame->stack)
2816 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2818 MINT_IN_CASE(MINT_RET_VT)
2819 i32 = READ32(ip + 1);
2821 memcpy(frame->retval->data.p, sp->data.p, i32);
2822 if (sp > frame->stack)
2823 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2825 MINT_IN_CASE(MINT_BR_S)
2826 ip += (short) *(ip + 1);
2828 MINT_IN_CASE(MINT_BR)
2829 ip += (gint32) READ32(ip + 1);
2831 #define ZEROP_S(datamem, op) \
2833 if (sp->data.datamem op 0) \
2834 ip += * (gint16 *)(ip + 1); \
2838 #define ZEROP(datamem, op) \
2840 if (sp->data.datamem op 0) \
2841 ip += READ32(ip + 1); \
2845 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2848 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2851 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2854 MINT_IN_CASE(MINT_BRFALSE_I4)
2857 MINT_IN_CASE(MINT_BRFALSE_I8)
2860 MINT_IN_CASE(MINT_BRFALSE_R8)
2863 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2866 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2869 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2872 MINT_IN_CASE(MINT_BRTRUE_I4)
2875 MINT_IN_CASE(MINT_BRTRUE_I8)
2878 MINT_IN_CASE(MINT_BRTRUE_R8)
2881 #define CONDBR_S(cond) \
2884 ip += * (gint16 *)(ip + 1); \
2887 #define BRELOP_S(datamem, op) \
2888 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2890 #define CONDBR(cond) \
2893 ip += READ32(ip + 1); \
2897 #define BRELOP(datamem, op) \
2898 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2900 MINT_IN_CASE(MINT_BEQ_I4_S)
2903 MINT_IN_CASE(MINT_BEQ_I8_S)
2906 MINT_IN_CASE(MINT_BEQ_R8_S)
2907 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2909 MINT_IN_CASE(MINT_BEQ_I4)
2912 MINT_IN_CASE(MINT_BEQ_I8)
2915 MINT_IN_CASE(MINT_BEQ_R8)
2916 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2918 MINT_IN_CASE(MINT_BGE_I4_S)
2921 MINT_IN_CASE(MINT_BGE_I8_S)
2924 MINT_IN_CASE(MINT_BGE_R8_S)
2925 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2927 MINT_IN_CASE(MINT_BGE_I4)
2930 MINT_IN_CASE(MINT_BGE_I8)
2933 MINT_IN_CASE(MINT_BGE_R8)
2934 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2936 MINT_IN_CASE(MINT_BGT_I4_S)
2939 MINT_IN_CASE(MINT_BGT_I8_S)
2942 MINT_IN_CASE(MINT_BGT_R8_S)
2943 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2945 MINT_IN_CASE(MINT_BGT_I4)
2948 MINT_IN_CASE(MINT_BGT_I8)
2951 MINT_IN_CASE(MINT_BGT_R8)
2952 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2954 MINT_IN_CASE(MINT_BLT_I4_S)
2957 MINT_IN_CASE(MINT_BLT_I8_S)
2960 MINT_IN_CASE(MINT_BLT_R8_S)
2961 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2963 MINT_IN_CASE(MINT_BLT_I4)
2966 MINT_IN_CASE(MINT_BLT_I8)
2969 MINT_IN_CASE(MINT_BLT_R8)
2970 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2972 MINT_IN_CASE(MINT_BLE_I4_S)
2975 MINT_IN_CASE(MINT_BLE_I8_S)
2978 MINT_IN_CASE(MINT_BLE_R8_S)
2979 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2981 MINT_IN_CASE(MINT_BLE_I4)
2984 MINT_IN_CASE(MINT_BLE_I8)
2987 MINT_IN_CASE(MINT_BLE_R8)
2988 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2990 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2993 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2996 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2997 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2999 MINT_IN_CASE(MINT_BNE_UN_I4)
3002 MINT_IN_CASE(MINT_BNE_UN_I8)
3005 MINT_IN_CASE(MINT_BNE_UN_R8)
3006 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
3009 #define BRELOP_S_CAST(datamem, op, type) \
3011 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3012 ip += * (gint16 *)(ip + 1); \
3016 #define BRELOP_CAST(datamem, op, type) \
3018 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3019 ip += READ32(ip + 1); \
3023 MINT_IN_CASE(MINT_BGE_UN_I4_S)
3024 BRELOP_S_CAST(i, >=, guint32);
3026 MINT_IN_CASE(MINT_BGE_UN_I8_S)
3027 BRELOP_S_CAST(l, >=, guint64);
3029 MINT_IN_CASE(MINT_BGE_UN_R8_S)
3030 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
3032 MINT_IN_CASE(MINT_BGE_UN_I4)
3033 BRELOP_CAST(i, >=, guint32);
3035 MINT_IN_CASE(MINT_BGE_UN_I8)
3036 BRELOP_CAST(l, >=, guint64);
3038 MINT_IN_CASE(MINT_BGE_UN_R8)
3039 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
3041 MINT_IN_CASE(MINT_BGT_UN_I4_S)
3042 BRELOP_S_CAST(i, >, guint32);
3044 MINT_IN_CASE(MINT_BGT_UN_I8_S)
3045 BRELOP_S_CAST(l, >, guint64);
3047 MINT_IN_CASE(MINT_BGT_UN_R8_S)
3048 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
3050 MINT_IN_CASE(MINT_BGT_UN_I4)
3051 BRELOP_CAST(i, >, guint32);
3053 MINT_IN_CASE(MINT_BGT_UN_I8)
3054 BRELOP_CAST(l, >, guint64);
3056 MINT_IN_CASE(MINT_BGT_UN_R8)
3057 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
3059 MINT_IN_CASE(MINT_BLE_UN_I4_S)
3060 BRELOP_S_CAST(i, <=, guint32);
3062 MINT_IN_CASE(MINT_BLE_UN_I8_S)
3063 BRELOP_S_CAST(l, <=, guint64);
3065 MINT_IN_CASE(MINT_BLE_UN_R8_S)
3066 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
3068 MINT_IN_CASE(MINT_BLE_UN_I4)
3069 BRELOP_CAST(i, <=, guint32);
3071 MINT_IN_CASE(MINT_BLE_UN_I8)
3072 BRELOP_CAST(l, <=, guint64);
3074 MINT_IN_CASE(MINT_BLE_UN_R8)
3075 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
3077 MINT_IN_CASE(MINT_BLT_UN_I4_S)
3078 BRELOP_S_CAST(i, <, guint32);
3080 MINT_IN_CASE(MINT_BLT_UN_I8_S)
3081 BRELOP_S_CAST(l, <, guint64);
3083 MINT_IN_CASE(MINT_BLT_UN_R8_S)
3084 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
3086 MINT_IN_CASE(MINT_BLT_UN_I4)
3087 BRELOP_CAST(i, <, guint32);
3089 MINT_IN_CASE(MINT_BLT_UN_I8)
3090 BRELOP_CAST(l, <, guint64);
3092 MINT_IN_CASE(MINT_BLT_UN_R8)
3093 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
3095 MINT_IN_CASE(MINT_SWITCH) {
3097 const unsigned short *st;
3103 if ((guint32)sp->data.i < n) {
3105 ip += 2 * (guint32)sp->data.i;
3106 offset = READ32 (ip);
3113 MINT_IN_CASE(MINT_LDIND_I1)
3115 sp[-1].data.i = *(gint8*)sp[-1].data.p;
3117 MINT_IN_CASE(MINT_LDIND_U1)
3119 sp[-1].data.i = *(guint8*)sp[-1].data.p;
3121 MINT_IN_CASE(MINT_LDIND_I2)
3123 sp[-1].data.i = *(gint16*)sp[-1].data.p;
3125 MINT_IN_CASE(MINT_LDIND_U2)
3127 sp[-1].data.i = *(guint16*)sp[-1].data.p;
3129 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
3130 MINT_IN_CASE(MINT_LDIND_U4)
3132 sp[-1].data.i = *(gint32*)sp[-1].data.p;
3134 MINT_IN_CASE(MINT_LDIND_I8)
3136 sp[-1].data.l = *(gint64*)sp[-1].data.p;
3138 MINT_IN_CASE(MINT_LDIND_I) {
3139 guint16 offset = * (guint16 *)(ip + 1);
3140 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
3144 MINT_IN_CASE(MINT_LDIND_R4)
3146 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
3148 MINT_IN_CASE(MINT_LDIND_R8)
3150 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
3152 MINT_IN_CASE(MINT_LDIND_REF)
3154 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
3156 MINT_IN_CASE(MINT_STIND_REF)
3159 mono_gc_wbarrier_generic_store (sp->data.p, sp [1].data.p);
3161 MINT_IN_CASE(MINT_STIND_I1)
3164 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
3166 MINT_IN_CASE(MINT_STIND_I2)
3169 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
3171 MINT_IN_CASE(MINT_STIND_I4)
3174 * (gint32 *) sp->data.p = sp[1].data.i;
3176 MINT_IN_CASE(MINT_STIND_I)
3179 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
3181 MINT_IN_CASE(MINT_STIND_I8)
3184 * (gint64 *) sp->data.p = sp[1].data.l;
3186 MINT_IN_CASE(MINT_STIND_R4)
3189 * (float *) sp->data.p = (gfloat)sp[1].data.f;
3191 MINT_IN_CASE(MINT_STIND_R8)
3194 * (double *) sp->data.p = sp[1].data.f;
3196 MINT_IN_CASE(MINT_MONO_ATOMIC_STORE_I4)
3199 InterlockedWrite ((gint32 *) sp->data.p, sp [1].data.i);
3201 #define BINOP(datamem, op) \
3203 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3205 MINT_IN_CASE(MINT_ADD_I4)
3208 MINT_IN_CASE(MINT_ADD_I8)
3211 MINT_IN_CASE(MINT_ADD_R8)
3214 MINT_IN_CASE(MINT_ADD1_I4)
3218 MINT_IN_CASE(MINT_SUB_I4)
3221 MINT_IN_CASE(MINT_SUB_I8)
3224 MINT_IN_CASE(MINT_SUB_R8)
3227 MINT_IN_CASE(MINT_SUB1_I4)
3231 MINT_IN_CASE(MINT_MUL_I4)
3234 MINT_IN_CASE(MINT_MUL_I8)
3237 MINT_IN_CASE(MINT_MUL_R8)
3240 MINT_IN_CASE(MINT_DIV_I4)
3241 if (sp [-1].data.i == 0)
3242 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3243 if (sp [-1].data.i == (-1))
3244 THROW_EX (mono_get_exception_overflow (), ip);
3247 MINT_IN_CASE(MINT_DIV_I8)
3248 if (sp [-1].data.l == 0)
3249 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3250 if (sp [-1].data.l == (-1))
3251 THROW_EX (mono_get_exception_overflow (), ip);
3254 MINT_IN_CASE(MINT_DIV_R8)
3258 #define BINOP_CAST(datamem, op, type) \
3260 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3262 MINT_IN_CASE(MINT_DIV_UN_I4)
3263 if (sp [-1].data.i == 0)
3264 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3265 BINOP_CAST(i, /, guint32);
3267 MINT_IN_CASE(MINT_DIV_UN_I8)
3268 if (sp [-1].data.l == 0)
3269 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3270 BINOP_CAST(l, /, guint64);
3272 MINT_IN_CASE(MINT_REM_I4)
3273 if (sp [-1].data.i == 0)
3274 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3275 if (sp [-1].data.i == (-1))
3276 THROW_EX (mono_get_exception_overflow (), ip);
3279 MINT_IN_CASE(MINT_REM_I8)
3280 if (sp [-1].data.l == 0)
3281 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3282 if (sp [-1].data.l == (-1))
3283 THROW_EX (mono_get_exception_overflow (), ip);
3286 MINT_IN_CASE(MINT_REM_R8)
3287 /* FIXME: what do we actually do here? */
3289 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
3292 MINT_IN_CASE(MINT_REM_UN_I4)
3293 if (sp [-1].data.i == 0)
3294 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3295 BINOP_CAST(i, %, guint32);
3297 MINT_IN_CASE(MINT_REM_UN_I8)
3298 if (sp [-1].data.l == 0)
3299 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3300 BINOP_CAST(l, %, guint64);
3302 MINT_IN_CASE(MINT_AND_I4)
3305 MINT_IN_CASE(MINT_AND_I8)
3308 MINT_IN_CASE(MINT_OR_I4)
3311 MINT_IN_CASE(MINT_OR_I8)
3314 MINT_IN_CASE(MINT_XOR_I4)
3317 MINT_IN_CASE(MINT_XOR_I8)
3321 #define SHIFTOP(datamem, op) \
3323 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
3326 MINT_IN_CASE(MINT_SHL_I4)
3329 MINT_IN_CASE(MINT_SHL_I8)
3332 MINT_IN_CASE(MINT_SHR_I4)
3335 MINT_IN_CASE(MINT_SHR_I8)
3338 MINT_IN_CASE(MINT_SHR_UN_I4)
3340 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
3343 MINT_IN_CASE(MINT_SHR_UN_I8)
3345 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
3348 MINT_IN_CASE(MINT_NEG_I4)
3349 sp [-1].data.i = - sp [-1].data.i;
3352 MINT_IN_CASE(MINT_NEG_I8)
3353 sp [-1].data.l = - sp [-1].data.l;
3356 MINT_IN_CASE(MINT_NEG_R8)
3357 sp [-1].data.f = - sp [-1].data.f;
3360 MINT_IN_CASE(MINT_NOT_I4)
3361 sp [-1].data.i = ~ sp [-1].data.i;
3364 MINT_IN_CASE(MINT_NOT_I8)
3365 sp [-1].data.l = ~ sp [-1].data.l;
3368 MINT_IN_CASE(MINT_CONV_I1_I4)
3369 sp [-1].data.i = (gint8)sp [-1].data.i;
3372 MINT_IN_CASE(MINT_CONV_I1_I8)
3373 sp [-1].data.i = (gint8)sp [-1].data.l;
3376 MINT_IN_CASE(MINT_CONV_I1_R8)
3377 sp [-1].data.i = (gint8)sp [-1].data.f;
3380 MINT_IN_CASE(MINT_CONV_U1_I4)
3381 sp [-1].data.i = (guint8)sp [-1].data.i;
3384 MINT_IN_CASE(MINT_CONV_U1_I8)
3385 sp [-1].data.i = (guint8)sp [-1].data.l;
3388 MINT_IN_CASE(MINT_CONV_U1_R8)
3389 sp [-1].data.i = (guint8)sp [-1].data.f;
3392 MINT_IN_CASE(MINT_CONV_I2_I4)
3393 sp [-1].data.i = (gint16)sp [-1].data.i;
3396 MINT_IN_CASE(MINT_CONV_I2_I8)
3397 sp [-1].data.i = (gint16)sp [-1].data.l;
3400 MINT_IN_CASE(MINT_CONV_I2_R8)
3401 sp [-1].data.i = (gint16)sp [-1].data.f;
3404 MINT_IN_CASE(MINT_CONV_U2_I4)
3405 sp [-1].data.i = (guint16)sp [-1].data.i;
3408 MINT_IN_CASE(MINT_CONV_U2_I8)
3409 sp [-1].data.i = (guint16)sp [-1].data.l;
3412 MINT_IN_CASE(MINT_CONV_U2_R8)
3413 sp [-1].data.i = (guint16)sp [-1].data.f;
3416 MINT_IN_CASE(MINT_CONV_I4_R8)
3417 sp [-1].data.i = (gint32)sp [-1].data.f;
3420 MINT_IN_CASE(MINT_CONV_U4_I8)
3421 MINT_IN_CASE(MINT_CONV_I4_I8)
3422 sp [-1].data.i = (gint32)sp [-1].data.l;
3425 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
3426 sp [-2].data.i = (gint32)sp [-2].data.l;
3429 MINT_IN_CASE(MINT_CONV_U4_R8)
3430 /* needed on arm64 */
3431 if (isinf (sp [-1].data.f))
3434 sp [-1].data.i = (guint32)sp [-1].data.f;
3437 MINT_IN_CASE(MINT_CONV_I8_I4)
3438 sp [-1].data.l = sp [-1].data.i;
3441 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
3442 sp [-2].data.l = sp [-2].data.i;
3445 MINT_IN_CASE(MINT_CONV_I8_U4)
3446 sp [-1].data.l = (guint32)sp [-1].data.i;
3449 MINT_IN_CASE(MINT_CONV_I8_R8)
3450 sp [-1].data.l = (gint64)sp [-1].data.f;
3453 MINT_IN_CASE(MINT_CONV_R4_I4)
3454 sp [-1].data.f = (float)sp [-1].data.i;
3457 MINT_IN_CASE(MINT_CONV_R4_I8)
3458 sp [-1].data.f = (float)sp [-1].data.l;
3461 MINT_IN_CASE(MINT_CONV_R4_R8)
3462 sp [-1].data.f = (float)sp [-1].data.f;
3465 MINT_IN_CASE(MINT_CONV_R8_I4)
3466 sp [-1].data.f = (double)sp [-1].data.i;
3469 MINT_IN_CASE(MINT_CONV_R8_I8)
3470 sp [-1].data.f = (double)sp [-1].data.l;
3473 MINT_IN_CASE(MINT_CONV_U8_I4)
3474 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
3477 MINT_IN_CASE(MINT_CONV_U8_R8)
3478 sp [-1].data.l = (guint64)sp [-1].data.f;
3481 MINT_IN_CASE(MINT_CPOBJ) {
3482 c = rtm->data_items[* (guint16 *)(ip + 1)];
3483 g_assert (c->byval_arg.type == MONO_TYPE_VALUETYPE);
3484 /* if this assertion fails, we need to add a write barrier */
3485 g_assert (!MONO_TYPE_IS_REFERENCE (&c->byval_arg));
3486 stackval_from_data (&c->byval_arg, &sp [-2], sp [-1].data.p, FALSE);
3491 MINT_IN_CASE(MINT_LDOBJ) {
3493 c = rtm->data_items[* (guint16 *)(ip + 1)];
3496 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3497 int size = mono_class_value_size (c, NULL);
3498 sp [-1].data.p = vt_sp;
3499 vt_sp += (size + 7) & ~7;
3501 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
3504 MINT_IN_CASE(MINT_LDSTR)
3505 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3509 MINT_IN_CASE(MINT_NEWOBJ) {
3510 MonoClass *newobj_class;
3511 MonoMethodSignature *csig;
3512 stackval valuetype_this;
3518 token = * (guint16 *)(ip + 1);
3521 child_frame.ip = NULL;
3522 child_frame.ex = NULL;
3524 child_frame.runtime_method = rtm->data_items [token];
3525 csig = mono_method_signature (child_frame.runtime_method->method);
3526 newobj_class = child_frame.runtime_method->method->klass;
3527 /*if (profiling_classes) {
3528 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
3530 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
3533 if (newobj_class->parent == mono_defaults.array_class) {
3534 sp -= csig->param_count;
3535 child_frame.stack_args = sp;
3536 o = ves_array_create (&child_frame, context->domain, newobj_class, csig, sp);
3538 THROW_EX (child_frame.ex, ip);
3539 goto array_constructed;
3542 g_assert (csig->hasthis);
3543 if (csig->param_count) {
3544 sp -= csig->param_count;
3545 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
3547 child_frame.stack_args = sp;
3550 * First arg is the object.
3552 if (newobj_class->valuetype) {
3553 MonoType *t = &newobj_class->byval_arg;
3554 memset (&valuetype_this, 0, sizeof (stackval));
3555 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
3557 valuetype_this.data.p = vt_sp;
3559 sp->data.p = &valuetype_this;
3562 if (newobj_class != mono_defaults.string_class) {
3563 context->managed_code = 0;
3564 o = mono_object_new_checked (context->domain, newobj_class, &error);
3565 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3566 context->managed_code = 1;
3567 if (*mono_thread_interruption_request_flag ())
3568 mono_thread_interruption_checkpoint ();
3572 child_frame.retval = &retval;
3576 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
3578 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
3580 context->current_frame = frame;
3582 if (context->has_resume_state) {
3583 if (frame == context->handler_frame)
3584 SET_RESUME_STATE (context);
3589 if (child_frame.ex) {
3591 * An exception occurred, need to run finally, fault and catch handlers..
3593 frame->ex = child_frame.ex;
3594 goto handle_finally;
3597 * a constructor returns void, but we need to return the object we created
3600 if (newobj_class->valuetype && !newobj_class->enumtype) {
3601 *sp = valuetype_this;
3602 } else if (newobj_class == mono_defaults.string_class) {
3610 MINT_IN_CASE(MINT_CASTCLASS)
3611 c = rtm->data_items [*(guint16 *)(ip + 1)];
3612 if ((o = sp [-1].data.p)) {
3613 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3614 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3616 THROW_EX (mono_get_exception_invalid_cast (), ip);
3620 MINT_IN_CASE(MINT_ISINST)
3621 c = rtm->data_items [*(guint16 *)(ip + 1)];
3622 if ((o = sp [-1].data.p)) {
3623 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3624 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3626 sp [-1].data.p = NULL;
3630 MINT_IN_CASE(MINT_CONV_R_UN_I4)
3631 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
3634 MINT_IN_CASE(MINT_CONV_R_UN_I8)
3635 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
3638 MINT_IN_CASE(MINT_UNBOX)
3639 c = rtm->data_items[*(guint16 *)(ip + 1)];
3643 THROW_EX (mono_get_exception_null_reference (), ip);
3645 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3646 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3647 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
3648 THROW_EX (mono_get_exception_invalid_cast (), ip);
3650 sp [-1].data.p = mono_object_unbox (o);
3653 MINT_IN_CASE(MINT_THROW)
3655 frame->ex_handler = NULL;
3657 sp->data.p = mono_get_exception_null_reference ();
3658 THROW_EX ((MonoException *)sp->data.p, ip);
3660 MINT_IN_CASE(MINT_LDFLDA_UNSAFE)
3662 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3665 MINT_IN_CASE(MINT_LDFLDA)
3668 THROW_EX (mono_get_exception_null_reference (), ip);
3669 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3672 MINT_IN_CASE(MINT_CKNULL)
3675 THROW_EX (mono_get_exception_null_reference (), ip);
3679 #define LDFLD(datamem, fieldtype) \
3680 o = sp [-1].data.p; \
3682 THROW_EX (mono_get_exception_null_reference (), ip); \
3683 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
3686 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
3687 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
3688 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
3689 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
3690 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
3691 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
3692 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
3693 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
3694 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
3695 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
3697 MINT_IN_CASE(MINT_LDFLD_VT)
3700 THROW_EX (mono_get_exception_null_reference (), ip);
3701 i32 = READ32(ip + 2);
3702 sp [-1].data.p = vt_sp;
3703 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3704 vt_sp += (i32 + 7) & ~7;
3708 MINT_IN_CASE(MINT_LDRMFLD) {
3710 MonoClassField *field;
3715 THROW_EX (mono_get_exception_null_reference (), ip);
3716 field = rtm->data_items[* (guint16 *)(ip + 1)];
3718 if (mono_object_is_transparent_proxy (o)) {
3719 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3721 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3722 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3724 addr = (char*)o + field->offset;
3727 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3731 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3732 MonoClassField *field;
3738 THROW_EX (mono_get_exception_null_reference (), ip);
3739 field = rtm->data_items[* (guint16 *)(ip + 1)];
3740 i32 = READ32(ip + 2);
3742 if (mono_object_is_transparent_proxy (o)) {
3743 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3744 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3745 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3747 addr = (char*)o + field->offset;
3750 sp [-1].data.p = vt_sp;
3751 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3752 vt_sp += (i32 + 7) & ~7;
3753 memcpy(sp [-1].data.p, addr, i32);
3757 #define STFLD(datamem, fieldtype) \
3758 o = sp [-2].data.p; \
3760 THROW_EX (mono_get_exception_null_reference (), ip); \
3762 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3765 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3766 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3767 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3768 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3769 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3770 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3771 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3772 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3773 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3774 MINT_IN_CASE(MINT_STFLD_O)
3777 THROW_EX (mono_get_exception_null_reference (), ip);
3779 mono_gc_wbarrier_set_field (o, (char *) o + * (guint16 *)(ip + 1), sp [1].data.p);
3783 MINT_IN_CASE(MINT_STFLD_VT)
3786 THROW_EX (mono_get_exception_null_reference (), ip);
3787 i32 = READ32(ip + 2);
3789 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3790 vt_sp -= (i32 + 7) & ~7;
3794 MINT_IN_CASE(MINT_STRMFLD) {
3795 MonoClassField *field;
3799 THROW_EX (mono_get_exception_null_reference (), ip);
3801 field = rtm->data_items[* (guint16 *)(ip + 1)];
3804 if (mono_object_is_transparent_proxy (o)) {
3805 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3806 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3807 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3809 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3814 MINT_IN_CASE(MINT_STRMFLD_VT) {
3815 MonoClassField *field;
3819 THROW_EX (mono_get_exception_null_reference (), ip);
3820 field = rtm->data_items[* (guint16 *)(ip + 1)];
3821 i32 = READ32(ip + 2);
3824 if (mono_object_is_transparent_proxy (o)) {
3825 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3826 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3827 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3829 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3832 vt_sp -= (i32 + 7) & ~7;
3835 MINT_IN_CASE(MINT_LDSFLDA) {
3836 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3837 sp->data.p = mono_class_static_field_address (context->domain, field);
3842 MINT_IN_CASE(MINT_LDSFLD) {
3843 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3844 gpointer addr = mono_class_static_field_address (context->domain, field);
3845 stackval_from_data (field->type, sp, addr, FALSE);
3850 MINT_IN_CASE(MINT_LDSFLD_VT) {
3851 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3852 gpointer addr = mono_class_static_field_address (context->domain, field);
3853 int size = READ32 (ip + 2);
3857 vt_sp += (size + 7) & ~7;
3858 stackval_from_data (field->type, sp, addr, FALSE);
3862 MINT_IN_CASE(MINT_STSFLD) {
3863 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3864 gpointer addr = mono_class_static_field_address (context->domain, field);
3867 stackval_to_data (field->type, sp, addr, FALSE);
3870 MINT_IN_CASE(MINT_STSFLD_VT) {
3871 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3872 gpointer addr = mono_class_static_field_address (context->domain, field);
3873 int size = READ32 (ip + 2);
3877 stackval_to_data (field->type, sp, addr, FALSE);
3878 vt_sp -= (size + 7) & ~7;
3881 MINT_IN_CASE(MINT_STOBJ_VT) {
3883 c = rtm->data_items[* (guint16 *)(ip + 1)];
3885 size = mono_class_value_size (c, NULL);
3886 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3887 vt_sp -= (size + 7) & ~7;
3891 MINT_IN_CASE(MINT_STOBJ) {
3892 c = rtm->data_items[* (guint16 *)(ip + 1)];
3895 g_assert (!c->byval_arg.byref);
3896 if (MONO_TYPE_IS_REFERENCE (&c->byval_arg))
3897 mono_gc_wbarrier_generic_store (sp [-2].data.p, sp [-1].data.p);
3899 stackval_from_data (&c->byval_arg, sp [-2].data.p, (char *) &sp [-1].data.p, FALSE);
3903 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3904 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3905 THROW_EX (mono_get_exception_overflow (), ip);
3906 sp [-1].data.i = (guint32)sp [-1].data.f;
3909 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3910 if (sp [-1].data.i < 0)
3911 THROW_EX (mono_get_exception_overflow (), ip);
3912 sp [-1].data.l = sp [-1].data.i;
3915 MINT_IN_CASE(MINT_CONV_OVF_U8_I8)
3916 if (sp [-1].data.l < 0)
3917 THROW_EX (mono_get_exception_overflow (), ip);
3920 MINT_IN_CASE(MINT_CONV_OVF_I8_U8)
3921 if ((guint64) sp [-1].data.l > MYGINT64_MAX)
3922 THROW_EX (mono_get_exception_overflow (), ip);
3925 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3926 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3927 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGINT64_MAX)
3928 THROW_EX (mono_get_exception_overflow (), ip);
3929 sp [-1].data.l = (guint64)sp [-1].data.f;
3932 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3933 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3934 THROW_EX (mono_get_exception_overflow (), ip);
3935 sp [-1].data.l = (gint64)sp [-1].data.f;
3938 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3939 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3940 THROW_EX (mono_get_exception_overflow (), ip);
3941 sp [-1].data.i = (mono_u)sp [-1].data.l;
3944 MINT_IN_CASE(MINT_BOX) {
3945 c = rtm->data_items [* (guint16 *)(ip + 1)];
3946 guint16 offset = * (guint16 *)(ip + 2);
3948 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3949 int size = mono_class_value_size (c, NULL);
3950 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3951 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3952 size = (size + 7) & ~7;
3955 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3956 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3957 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3962 MINT_IN_CASE(MINT_NEWARR)
3963 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3964 if (!mono_error_ok (&error)) {
3965 THROW_EX (mono_error_convert_to_exception (&error), ip);
3967 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3969 /*if (profiling_classes) {
3970 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3972 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3976 MINT_IN_CASE(MINT_LDLEN)
3979 THROW_EX (mono_get_exception_null_reference (), ip);
3980 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3983 MINT_IN_CASE(MINT_GETCHR) {
3987 THROW_EX (mono_get_exception_null_reference (), ip);
3988 i32 = sp [-1].data.i;
3989 if (i32 < 0 || i32 >= mono_string_length (s))
3990 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3992 sp [-1].data.i = mono_string_chars(s)[i32];
3996 MINT_IN_CASE(MINT_STRLEN)
4000 THROW_EX (mono_get_exception_null_reference (), ip);
4001 sp [-1].data.i = mono_string_length ((MonoString*) o);
4003 MINT_IN_CASE(MINT_ARRAY_RANK)
4006 THROW_EX (mono_get_exception_null_reference (), ip);
4007 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
4010 MINT_IN_CASE(MINT_LDELEMA)
4011 MINT_IN_CASE(MINT_LDELEMA_TC) {
4012 gboolean needs_typecheck = *ip == MINT_LDELEMA_TC;
4014 MonoClass *klass = rtm->data_items [*(guint16 *) (ip + 1)];
4015 guint16 numargs = *(guint16 *) (ip + 2);
4020 sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck);
4022 THROW_EX (frame->ex, ip);
4027 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
4028 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
4029 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
4030 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
4031 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
4032 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
4033 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
4034 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
4035 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
4036 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
4037 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
4038 MINT_IN_CASE(MINT_LDELEM_VT) {
4046 THROW_EX (mono_get_exception_null_reference (), ip);
4048 aindex = sp [1].data.i;
4049 if (aindex >= mono_array_length (o))
4050 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4053 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
4056 case MINT_LDELEM_I1:
4057 sp [0].data.i = mono_array_get (o, gint8, aindex);
4059 case MINT_LDELEM_U1:
4060 sp [0].data.i = mono_array_get (o, guint8, aindex);
4062 case MINT_LDELEM_I2:
4063 sp [0].data.i = mono_array_get (o, gint16, aindex);
4065 case MINT_LDELEM_U2:
4066 sp [0].data.i = mono_array_get (o, guint16, aindex);
4069 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
4071 case MINT_LDELEM_I4:
4072 sp [0].data.i = mono_array_get (o, gint32, aindex);
4074 case MINT_LDELEM_U4:
4075 sp [0].data.i = mono_array_get (o, guint32, aindex);
4077 case MINT_LDELEM_I8:
4078 sp [0].data.l = mono_array_get (o, guint64, aindex);
4080 case MINT_LDELEM_R4:
4081 sp [0].data.f = mono_array_get (o, float, aindex);
4083 case MINT_LDELEM_R8:
4084 sp [0].data.f = mono_array_get (o, double, aindex);
4086 case MINT_LDELEM_REF:
4087 sp [0].data.p = mono_array_get (o, gpointer, aindex);
4089 case MINT_LDELEM_VT: {
4090 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4091 i32 = READ32 (ip + 2);
4092 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4093 sp [0].data.vt = vt_sp;
4094 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
4095 vt_sp += (i32 + 7) & ~7;
4107 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
4108 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
4109 MINT_IN_CASE(MINT_STELEM_U1) /* fall through */
4110 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
4111 MINT_IN_CASE(MINT_STELEM_U2) /* fall through */
4112 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
4113 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
4114 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
4115 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
4116 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
4117 MINT_IN_CASE(MINT_STELEM_VT) {
4124 THROW_EX (mono_get_exception_null_reference (), ip);
4126 aindex = sp [1].data.i;
4127 if (aindex >= mono_array_length ((MonoArray *)o))
4128 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4132 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
4134 case MINT_STELEM_I1:
4135 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
4137 case MINT_STELEM_U1:
4138 mono_array_set ((MonoArray *) o, guint8, aindex, sp [2].data.i);
4140 case MINT_STELEM_I2:
4141 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
4143 case MINT_STELEM_U2:
4144 mono_array_set ((MonoArray *)o, guint16, aindex, sp [2].data.i);
4146 case MINT_STELEM_I4:
4147 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
4149 case MINT_STELEM_I8:
4150 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
4152 case MINT_STELEM_R4:
4153 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
4155 case MINT_STELEM_R8:
4156 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
4158 case MINT_STELEM_REF: {
4159 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
4160 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4161 if (sp [2].data.p && !isinst_obj)
4162 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
4163 mono_array_setref ((MonoArray *) o, aindex, sp [2].data.p);
4166 case MINT_STELEM_VT: {
4167 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4168 i32 = READ32 (ip + 2);
4169 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4171 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
4172 vt_sp -= (i32 + 7) & ~7;
4183 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
4184 if (sp [-1].data.i < 0)
4185 THROW_EX (mono_get_exception_overflow (), ip);
4188 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
4189 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
4190 THROW_EX (mono_get_exception_overflow (), ip);
4191 sp [-1].data.i = (gint32) sp [-1].data.l;
4194 MINT_IN_CASE(MINT_CONV_OVF_I4_U8)
4195 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGINT32_MAX)
4196 THROW_EX (mono_get_exception_overflow (), ip);
4197 sp [-1].data.i = (gint32) sp [-1].data.l;
4200 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
4201 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
4202 THROW_EX (mono_get_exception_overflow (), ip);
4203 sp [-1].data.i = (gint32) sp [-1].data.f;
4206 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
4207 if (sp [-1].data.i < 0)
4208 THROW_EX (mono_get_exception_overflow (), ip);
4211 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
4212 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
4213 THROW_EX (mono_get_exception_overflow (), ip);
4214 sp [-1].data.i = (guint32) sp [-1].data.l;
4217 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
4218 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
4219 THROW_EX (mono_get_exception_overflow (), ip);
4220 sp [-1].data.i = (guint32) sp [-1].data.f;
4223 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
4224 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
4225 THROW_EX (mono_get_exception_overflow (), ip);
4228 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
4229 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
4230 THROW_EX (mono_get_exception_overflow (), ip);
4231 sp [-1].data.i = (gint16) sp [-1].data.l;
4234 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
4235 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
4236 THROW_EX (mono_get_exception_overflow (), ip);
4237 sp [-1].data.i = (gint16) sp [-1].data.f;
4240 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
4241 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
4242 THROW_EX (mono_get_exception_overflow (), ip);
4245 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
4246 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
4247 THROW_EX (mono_get_exception_overflow (), ip);
4248 sp [-1].data.i = (guint16) sp [-1].data.l;
4251 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
4252 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
4253 THROW_EX (mono_get_exception_overflow (), ip);
4254 sp [-1].data.i = (guint16) sp [-1].data.f;
4257 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
4258 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
4259 THROW_EX (mono_get_exception_overflow (), ip);
4262 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
4263 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
4264 THROW_EX (mono_get_exception_overflow (), ip);
4265 sp [-1].data.i = (gint8) sp [-1].data.l;
4268 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
4269 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
4270 THROW_EX (mono_get_exception_overflow (), ip);
4271 sp [-1].data.i = (gint8) sp [-1].data.f;
4274 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
4275 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
4276 THROW_EX (mono_get_exception_overflow (), ip);
4279 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
4280 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
4281 THROW_EX (mono_get_exception_overflow (), ip);
4282 sp [-1].data.i = (guint8) sp [-1].data.l;
4285 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
4286 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
4287 THROW_EX (mono_get_exception_overflow (), ip);
4288 sp [-1].data.i = (guint8) sp [-1].data.f;
4292 MINT_IN_CASE(MINT_LDELEM)
4293 MINT_IN_CASE(MINT_STELEM)
4294 MINT_IN_CASE(MINT_UNBOX_ANY)
4296 MINT_IN_CASE(MINT_CKFINITE)
4297 if (!isfinite(sp [-1].data.f))
4298 THROW_EX (mono_get_exception_arithmetic (), ip);
4301 MINT_IN_CASE(MINT_MKREFANY) {
4302 c = rtm->data_items [*(guint16 *)(ip + 1)];
4304 /* The value address is on the stack */
4305 gpointer addr = sp [-1].data.p;
4306 /* Push the typedref value on the stack */
4307 sp [-1].data.p = vt_sp;
4308 vt_sp += sizeof (MonoTypedRef);
4310 MonoTypedRef *tref = sp [-1].data.p;
4312 tref->type = &c->byval_arg;
4318 MINT_IN_CASE(MINT_REFANYTYPE) {
4319 MonoTypedRef *tref = sp [-1].data.p;
4320 MonoType *type = tref->type;
4322 vt_sp -= sizeof (MonoTypedRef);
4323 sp [-1].data.p = vt_sp;
4325 *(gpointer*)sp [-1].data.p = type;
4329 MINT_IN_CASE(MINT_REFANYVAL) {
4330 MonoTypedRef *tref = sp [-1].data.p;
4331 gpointer addr = tref->value;
4333 vt_sp -= sizeof (MonoTypedRef);
4335 sp [-1].data.p = addr;
4339 MINT_IN_CASE(MINT_LDTOKEN)
4342 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
4346 MINT_IN_CASE(MINT_ADD_OVF_I4)
4347 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4348 THROW_EX (mono_get_exception_overflow (), ip);
4351 MINT_IN_CASE(MINT_ADD_OVF_I8)
4352 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4353 THROW_EX (mono_get_exception_overflow (), ip);
4356 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
4357 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4358 THROW_EX (mono_get_exception_overflow (), ip);
4359 BINOP_CAST(i, +, guint32);
4361 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
4362 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4363 THROW_EX (mono_get_exception_overflow (), ip);
4364 BINOP_CAST(l, +, guint64);
4366 MINT_IN_CASE(MINT_MUL_OVF_I4)
4367 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4368 THROW_EX (mono_get_exception_overflow (), ip);
4371 MINT_IN_CASE(MINT_MUL_OVF_I8)
4372 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4373 THROW_EX (mono_get_exception_overflow (), ip);
4376 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
4377 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4378 THROW_EX (mono_get_exception_overflow (), ip);
4379 BINOP_CAST(i, *, guint32);
4381 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
4382 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4383 THROW_EX (mono_get_exception_overflow (), ip);
4384 BINOP_CAST(l, *, guint64);
4386 MINT_IN_CASE(MINT_SUB_OVF_I4)
4387 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4388 THROW_EX (mono_get_exception_overflow (), ip);
4391 MINT_IN_CASE(MINT_SUB_OVF_I8)
4392 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4393 THROW_EX (mono_get_exception_overflow (), ip);
4396 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
4397 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4398 THROW_EX (mono_get_exception_overflow (), ip);
4399 BINOP_CAST(i, -, guint32);
4401 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
4402 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4403 THROW_EX (mono_get_exception_overflow (), ip);
4404 BINOP_CAST(l, -, guint64);
4406 MINT_IN_CASE(MINT_ENDFINALLY)
4408 int clause_index = *ip;
4409 if (clause_index == exit_at_finally)
4411 while (sp > frame->stack) {
4415 ip = finally_ips->data;
4416 finally_ips = g_slist_remove (finally_ips, ip);
4423 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
4424 MINT_IN_CASE(MINT_LEAVE_S)
4425 while (sp > frame->stack) {
4429 if (*ip == MINT_LEAVE_S) {
4430 ip += (short) *(ip + 1);
4432 ip += (gint32) READ32 (ip + 1);
4435 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
4436 frame->ex_handler = NULL;
4439 goto handle_finally;
4441 MINT_IN_CASE(MINT_ICALL_V_V)
4442 MINT_IN_CASE(MINT_ICALL_V_P)
4443 MINT_IN_CASE(MINT_ICALL_P_V)
4444 MINT_IN_CASE(MINT_ICALL_P_P)
4445 MINT_IN_CASE(MINT_ICALL_PP_V)
4446 MINT_IN_CASE(MINT_ICALL_PI_V)
4447 MINT_IN_CASE(MINT_ICALL_PP_P)
4448 MINT_IN_CASE(MINT_ICALL_PI_P)
4449 MINT_IN_CASE(MINT_ICALL_PPP_V)
4450 MINT_IN_CASE(MINT_ICALL_PPI_V)
4451 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
4452 if (*mono_thread_interruption_request_flag ()) {
4453 MonoException *exc = mono_thread_interruption_checkpoint ();
4456 context->search_for_handler = 1;
4459 if (frame->ex != NULL)
4460 goto handle_exception;
4463 MINT_IN_CASE(MINT_MONO_LDPTR)
4464 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
4468 MINT_IN_CASE(MINT_MONO_NEWOBJ)
4469 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
4470 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4474 MINT_IN_CASE(MINT_MONO_FREE)
4477 g_error ("that doesn't seem right");
4478 g_free (sp->data.p);
4480 MINT_IN_CASE(MINT_MONO_RETOBJ)
4483 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
4484 mono_method_signature (frame->runtime_method->method)->pinvoke);
4485 if (sp > frame->stack)
4486 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
4488 MINT_IN_CASE(MINT_MONO_TLS) {
4489 MonoTlsKey key = *(gint32 *)(ip + 1);
4490 sp->data.p = ((gpointer (*)()) mono_tls_get_tls_getter (key, FALSE)) ();
4495 MINT_IN_CASE(MINT_MONO_JIT_ATTACH) {
4498 context->original_domain = NULL;
4499 MonoDomain *tls_domain = (MonoDomain *) ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4500 gpointer tls_jit = ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4502 if (tls_domain != context->domain || !tls_jit)
4503 context->original_domain = mono_jit_thread_attach (context->domain);
4506 MINT_IN_CASE(MINT_MONO_JIT_DETACH)
4508 mono_jit_set_domain (context->original_domain);
4511 #define RELOP(datamem, op) \
4513 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
4515 MINT_IN_CASE(MINT_CEQ_I4)
4518 MINT_IN_CASE(MINT_CEQ0_I4)
4519 sp [-1].data.i = (sp [-1].data.i == 0);
4522 MINT_IN_CASE(MINT_CEQ_I8)
4525 MINT_IN_CASE(MINT_CEQ_R8)
4527 if (isunordered (sp [-1].data.f, sp [0].data.f))
4530 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
4533 MINT_IN_CASE(MINT_CGT_I4)
4536 MINT_IN_CASE(MINT_CGT_I8)
4539 MINT_IN_CASE(MINT_CGT_R8)
4541 if (isunordered (sp [-1].data.f, sp [0].data.f))
4544 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4548 #define RELOP_CAST(datamem, op, type) \
4550 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4553 MINT_IN_CASE(MINT_CGT_UN_I4)
4554 RELOP_CAST(i, >, guint32);
4556 MINT_IN_CASE(MINT_CGT_UN_I8)
4557 RELOP_CAST(l, >, guint64);
4559 MINT_IN_CASE(MINT_CGT_UN_R8)
4561 if (isunordered (sp [-1].data.f, sp [0].data.f))
4564 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4567 MINT_IN_CASE(MINT_CLT_I4)
4570 MINT_IN_CASE(MINT_CLT_I8)
4573 MINT_IN_CASE(MINT_CLT_R8)
4575 if (isunordered (sp [-1].data.f, sp [0].data.f))
4578 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4581 MINT_IN_CASE(MINT_CLT_UN_I4)
4582 RELOP_CAST(i, <, guint32);
4584 MINT_IN_CASE(MINT_CLT_UN_I8)
4585 RELOP_CAST(l, <, guint64);
4587 MINT_IN_CASE(MINT_CLT_UN_R8)
4589 if (isunordered (sp [-1].data.f, sp [0].data.f))
4592 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4595 MINT_IN_CASE(MINT_LDFTN) {
4596 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
4601 MINT_IN_CASE(MINT_LDVIRTFTN) {
4602 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
4606 THROW_EX (mono_get_exception_null_reference (), ip - 2);
4608 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
4613 #define LDARG(datamem, argtype) \
4614 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
4618 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
4619 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
4620 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
4621 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
4622 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
4623 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
4624 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
4625 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
4626 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
4627 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
4629 MINT_IN_CASE(MINT_LDARG_VT)
4631 i32 = READ32(ip + 2);
4632 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
4633 vt_sp += (i32 + 7) & ~7;
4638 #define STARG(datamem, argtype) \
4640 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4643 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
4644 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
4645 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
4646 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
4647 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
4648 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
4649 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
4650 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
4651 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
4652 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
4654 MINT_IN_CASE(MINT_STARG_VT)
4655 i32 = READ32(ip + 2);
4657 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
4658 vt_sp -= (i32 + 7) & ~7;
4662 #define STINARG(datamem, argtype) \
4664 int n = * (guint16 *)(ip + 1); \
4665 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
4669 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
4670 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
4671 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
4672 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
4673 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
4674 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
4675 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
4676 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
4677 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
4678 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
4680 MINT_IN_CASE(MINT_STINARG_VT) {
4681 int n = * (guint16 *)(ip + 1);
4682 i32 = READ32(ip + 2);
4683 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
4688 MINT_IN_CASE(MINT_LDARGA)
4689 sp->data.p = frame->args + * (guint16 *)(ip + 1);
4694 #define LDLOC(datamem, argtype) \
4695 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
4699 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
4700 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
4701 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
4702 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
4703 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
4704 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
4705 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
4706 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
4707 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
4708 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
4710 MINT_IN_CASE(MINT_LDLOC_VT)
4712 i32 = READ32(ip + 2);
4713 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
4714 vt_sp += (i32 + 7) & ~7;
4719 MINT_IN_CASE(MINT_LDLOCA_S)
4720 sp->data.p = locals + * (guint16 *)(ip + 1);
4725 #define STLOC(datamem, argtype) \
4727 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4730 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4731 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4732 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4733 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4734 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4735 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4736 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4737 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4738 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4739 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4741 #define STLOC_NP(datamem, argtype) \
4742 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4745 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4746 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4748 MINT_IN_CASE(MINT_STLOC_VT)
4749 i32 = READ32(ip + 2);
4751 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4752 vt_sp -= (i32 + 7) & ~7;
4756 MINT_IN_CASE(MINT_LOCALLOC) {
4757 if (sp != frame->stack + 1) /*FIX?*/
4758 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4760 int len = sp [-1].data.i;
4761 sp [-1].data.p = alloca (len);
4762 MonoMethodHeader *header = mono_method_get_header_checked (frame->runtime_method->method, &error);
4763 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4764 if (header && header->init_locals)
4765 memset (sp [-1].data.p, 0, len);
4769 MINT_IN_CASE(MINT_ENDFILTER)
4770 /* top of stack is result of filter */
4771 frame->retval = &sp [-1];
4773 MINT_IN_CASE(MINT_INITOBJ)
4775 memset (sp->data.vt, 0, READ32(ip + 1));
4778 MINT_IN_CASE(MINT_CPBLK)
4780 if (!sp [0].data.p || !sp [1].data.p)
4781 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4783 /* FIXME: value and size may be int64... */
4784 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4787 MINT_IN_CASE(MINT_CONSTRAINED_) {
4789 /* FIXME: implement */
4791 token = READ32 (ip);
4796 MINT_IN_CASE(MINT_INITBLK)
4799 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4801 /* FIXME: value and size may be int64... */
4802 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4805 MINT_IN_CASE(MINT_NO_)
4806 /* FIXME: implement */
4810 MINT_IN_CASE(MINT_RETHROW)
4812 * need to clarify what this should actually do:
4813 * start the search from the last found handler in
4814 * this method or continue in the caller or what.
4815 * Also, do we need to run finally/fault handlers after a retrow?
4816 * Well, this implementation will follow the usual search
4817 * for an handler, considering the current ip as throw spot.
4818 * We need to NULL frame->ex_handler for the later code to
4819 * actually run the new found handler.
4821 frame->ex_handler = NULL;
4822 THROW_EX (frame->ex, ip - 1);
4825 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4826 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4830 g_assert_not_reached ();
4832 * Exception handling code.
4833 * The exception object is stored in frame->ex.
4840 MonoInvocation *inv;
4841 MonoExceptionClause *clause;
4847 g_print ("* Handling exception '%s' at IL_%04x\n",
4848 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4849 rtm == NULL ? 0 : frame->ip - rtm->code);
4851 if (die_on_exception)
4854 for (inv = frame; inv; inv = inv->parent) {
4856 if (inv->runtime_method == NULL)
4858 method = inv->runtime_method->method;
4859 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4861 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4863 if (inv->ip == NULL)
4865 ip_offset = inv->ip - inv->runtime_method->code;
4866 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4867 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4868 clause = &inv->runtime_method->clauses [i];
4870 g_print ("* clause [%d]: %p\n", i, clause);
4872 if (!MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4875 if (clause->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
4878 g_print ("* Filter found at '%s'\n", method->name);
4880 MonoInvocation dup_frame;
4882 memcpy (&dup_frame, inv, sizeof (MonoInvocation));
4883 dup_frame.retval = &retval;
4884 ves_exec_method_with_context (&dup_frame, context, inv->runtime_method->code + clause->data.filter_offset, frame->ex, -1);
4885 if (dup_frame.retval->data.i) {
4888 g_print ("* Matched Filter at '%s'\n", method->name);
4890 inv->ex_handler = clause;
4891 goto handle_finally;
4893 } else if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE) {
4894 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4895 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4898 * OK, we found an handler, now we need to execute the finally
4899 * and fault blocks before branching to the handler code.
4903 g_print ("* Found handler at '%s'\n", method->name);
4905 inv->ex_handler = clause;
4906 goto handle_finally;
4912 * If we get here, no handler was found: print a stack trace.
4914 for (inv = frame; inv; inv = inv->parent) {
4915 if (inv->invoke_trap)
4916 goto handle_finally;
4919 ex_obj = (MonoObject *) frame->ex;
4920 mono_unhandled_exception (ex_obj);
4921 MonoJitTlsData *jit_tls = (MonoJitTlsData *) mono_tls_get_jit_tls ();
4922 jit_tls->abort_func (ex_obj);
4923 g_assert_not_reached ();
4929 MonoExceptionClause *clause;
4930 GSList *old_list = finally_ips;
4931 MonoMethod *method = frame->runtime_method->method;
4932 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4933 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4937 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4939 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4940 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4943 ip_offset = frame->ip - rtm->code;
4945 if (endfinally_ip != NULL)
4946 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4947 for (i = 0; i < header->num_clauses; ++i)
4948 if (frame->ex_handler == &rtm->clauses [i])
4952 clause = &rtm->clauses [i];
4953 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4954 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4955 ip = rtm->code + clause->handler_offset;
4956 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4959 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4965 endfinally_ip = NULL;
4967 if (old_list != finally_ips && finally_ips) {
4968 ip = finally_ips->data;
4969 finally_ips = g_slist_remove (finally_ips, ip);
4970 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4975 * If an exception is set, we need to execute the fault handler, too,
4976 * otherwise, we continue normally.
4986 MonoExceptionClause *clause;
4987 MonoMethod *method = frame->runtime_method->method;
4988 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4989 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4993 g_print ("* Handle fault\n");
4995 ip_offset = frame->ip - rtm->code;
4996 for (i = 0; i < header->num_clauses; ++i) {
4997 clause = &rtm->clauses [i];
4998 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4999 ip = rtm->code + clause->handler_offset;
5002 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
5008 * If the handler for the exception was found in this method, we jump
5009 * to it right away, otherwise we return and let the caller run
5010 * the finally, fault and catch blocks.
5011 * This same code should be present in the endfault opcode, but it
5012 * is corrently not assigned in the ECMA specs: LAMESPEC.
5014 if (frame->ex_handler) {
5017 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
5019 ip = rtm->code + frame->ex_handler->handler_offset;
5021 vt_sp = (unsigned char *) sp + rtm->stack_size;
5022 sp->data.p = frame->ex;
5033 ves_exec_method (MonoInvocation *frame)
5035 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5036 ThreadContext context_struct;
5043 mono_unhandled_exception ((MonoObject*)frame->ex);
5046 if (context == NULL) {
5047 context = &context_struct;
5048 context_struct.domain = mono_domain_get ();
5049 context_struct.base_frame = frame;
5050 context_struct.current_frame = NULL;
5051 context_struct.env_frame = frame;
5052 context_struct.current_env = &env;
5053 context_struct.search_for_handler = 0;
5054 context_struct.managed_code = 0;
5055 mono_native_tls_set_value (thread_context_id, context);
5058 frame->parent = context->current_frame;
5059 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
5060 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5061 context->managed_code = 1;
5062 ves_exec_method_with_context (frame, context, NULL, NULL, -1);
5063 context->managed_code = 0;
5065 if (context != &context_struct && context->current_env) {
5066 context->env_frame->ex = frame->ex;
5067 longjmp (*context->current_env, 1);
5070 mono_unhandled_exception ((MonoObject*)frame->ex);
5072 if (context->base_frame == frame)
5073 mono_native_tls_set_value (thread_context_id, NULL);
5075 context->current_frame = frame->parent;
5079 mono_interp_parse_options (const char *options)
5083 args = g_strsplit (options, ",", -1);
5084 for (ptr = args; ptr && *ptr; ptr ++) {
5087 if (strncmp (arg, "jit=", 4) == 0)
5088 jit_classes = g_slist_prepend (jit_classes, arg + 4);
5095 mono_native_tls_alloc (&thread_context_id, NULL);
5096 mono_native_tls_set_value (thread_context_id, NULL);
5098 mono_interp_transform_init ();
5101 typedef int (*TestMethod) (void);
5104 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
5106 int result, expected, failed, cfailed, run;
5107 double elapsed, transform_time;
5109 MonoObject *result_obj;
5110 static gboolean filter_method_init = FALSE;
5111 static const char *filter_method = NULL;
5113 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
5114 cfailed = failed = run = 0;
5115 transform_time = elapsed = 0.0;
5117 g_timer_start (timer);
5118 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5119 MonoObject *exc = NULL;
5121 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5123 mono_error_cleanup (&error); /* FIXME don't swallow the error */
5127 if (!filter_method_init) {
5128 filter_method = g_getenv ("INTERP_FILTER_METHOD");
5129 filter_method_init = TRUE;
5131 gboolean filter = FALSE;
5132 if (filter_method) {
5133 const char *name = filter_method;
5135 if ((strchr (name, '.') > name) || strchr (name, ':')) {
5136 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
5137 filter = mono_method_desc_full_match (desc, method);
5138 mono_method_desc_free (desc);
5140 filter = strcmp (method->name, name) == 0;
5142 } else { /* no filter, check for `Category' attribute on method */
5144 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
5145 mono_error_cleanup (&error);
5149 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
5150 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
5151 if (centry->ctor == NULL)
5154 MonoClass *klass = centry->ctor->klass;
5155 if (strcmp (klass->name, "CategoryAttribute"))
5158 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
5159 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
5160 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
5161 mono_error_cleanup (&error);
5162 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
5163 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
5164 mono_error_cleanup (&error);
5165 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
5166 mono_error_cleanup (&error);
5167 if (!strcmp (utf8_str, "!INTERPRETER")) {
5168 g_print ("skip %s...\n", method->name);
5174 if (strncmp (method->name, "test_", 5) == 0 && filter) {
5175 MonoError interp_error;
5176 MonoObject *exc = NULL;
5178 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
5179 if (!mono_error_ok (&interp_error)) {
5181 g_print ("Test '%s' execution failed.\n", method->name);
5182 } else if (exc != NULL) {
5183 g_print ("Exception in Test '%s' occured:\n", method->name);
5184 mono_object_describe (exc);
5188 result = *(gint32 *) mono_object_unbox (result_obj);
5189 expected = atoi (method->name + 5); // FIXME: oh no.
5192 if (result != expected) {
5194 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
5199 g_timer_stop (timer);
5200 elapsed = g_timer_elapsed (timer, NULL);
5201 if (failed > 0 || cfailed > 0){
5202 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
5203 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
5205 g_print ("Results: total tests: %d, all pass \n", run);
5208 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
5209 elapsed - transform_time, transform_time);
5210 *total += failed + cfailed;
5215 interp_regression (MonoImage *image, int verbose, int *total_run)
5218 GTimer *timer = g_timer_new ();
5219 MonoDomain *domain = mono_domain_get ();
5223 /* load the metadata */
5224 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5226 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5228 mono_error_cleanup (&error);
5231 mono_class_init (method->klass);
5236 interp_regression_step (image, verbose, total_run, &total, timer, domain);
5238 g_timer_destroy (timer);
5243 mono_interp_regression_list (int verbose, int count, char *images [])
5245 int i, total, total_run, run;
5247 total_run = total = 0;
5248 for (i = 0; i < count; ++i) {
5249 MonoAssembly *ass = mono_assembly_open_predicate (images [i], FALSE, FALSE, NULL, NULL, NULL);
5251 g_warning ("failed to load assembly: %s", images [i]);
5254 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
5258 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
5260 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);
5267 * mono_interp_set_resume_state:
5269 * Set the state the interpeter will continue to execute from after execution returns to the interpreter.
5272 mono_interp_set_resume_state (MonoException *ex, StackFrameInfo *frame, gpointer handler_ip)
5274 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5276 context->has_resume_state = TRUE;
5277 context->handler_frame = frame->interp_frame;
5278 /* This is on the stack, so it doesn't need a wbarrier */
5279 context->handler_frame->ex = ex;
5280 context->handler_ip = handler_ip;
5284 * mono_interp_run_finally:
5286 * Run the finally clause identified by CLAUSE_INDEX in the intepreter frame given by
5287 * frame->interp_frame.
5290 mono_interp_run_finally (StackFrameInfo *frame, int clause_index, gpointer handler_ip)
5292 MonoInvocation *iframe = frame->interp_frame;
5293 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5295 ves_exec_method_with_context (iframe, context, handler_ip, NULL, clause_index);
5299 MonoInvocation *current;
5303 * mono_interp_frame_iter_init:
5305 * Initialize an iterator for iterating through interpreted frames.
5308 mono_interp_frame_iter_init (MonoInterpStackIter *iter, gpointer interp_exit_data)
5310 StackIter *stack_iter = (StackIter*)iter;
5312 stack_iter->current = (MonoInvocation*)interp_exit_data;
5316 mono_interp_frame_iter_next (MonoInterpStackIter *iter, StackFrameInfo *frame)
5318 StackIter *stack_iter = (StackIter*)iter;
5319 MonoInvocation *iframe = stack_iter->current;
5321 memset (frame, 0, sizeof (StackFrameInfo));
5322 /* pinvoke frames doesn't have runtime_method set */
5323 while (iframe && !iframe->runtime_method)
5324 iframe = iframe->parent;
5328 frame->type = FRAME_TYPE_INTERP;
5329 frame->interp_frame = iframe;
5330 frame->method = iframe->runtime_method->method;
5331 frame->actual_method = frame->method;
5332 /* This is the offset in the interpreter IR */
5333 frame->native_offset = iframe->ip - iframe->runtime_method->code;
5334 frame->ji = iframe->runtime_method->jinfo;
5336 stack_iter->current = iframe->parent;