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 if (mono_type_generic_inst_is_valuetype (type)) {
404 mono_value_copy (result->data.vt, data, mono_class_from_mono_type (type));
407 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
411 g_warning ("got type 0x%02x", type->type);
412 g_assert_not_reached ();
417 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
420 gpointer *p = (gpointer*)data;
424 /* printf ("TODAT0 %p\n", data); */
425 switch (type->type) {
428 guint8 *p = (guint8*)data;
432 case MONO_TYPE_BOOLEAN: {
433 guint8 *p = (guint8*)data;
434 *p = (val->data.i != 0);
439 case MONO_TYPE_CHAR: {
440 guint16 *p = (guint16*)data;
445 mono_i *p = (mono_i*)data;
446 /* In theory the value used by stloc should match the local var type
447 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
448 a native int - both by csc and mcs). Not sure what to do about sign extension
449 as it is outside the spec... doing the obvious */
450 *p = (mono_i)val->data.nati;
454 mono_u *p = (mono_u*)data;
456 *p = (mono_u)val->data.nati;
461 gint32 *p = (gint32*)data;
467 gint64 *p = (gint64*)data;
472 float *p = (float*)data;
477 double *p = (double*)data;
481 case MONO_TYPE_STRING:
482 case MONO_TYPE_SZARRAY:
483 case MONO_TYPE_CLASS:
484 case MONO_TYPE_OBJECT:
485 case MONO_TYPE_ARRAY: {
486 gpointer *p = (gpointer *) data;
487 mono_gc_wbarrier_generic_store (p, val->data.p);
490 case MONO_TYPE_PTR: {
491 gpointer *p = (gpointer *) data;
495 case MONO_TYPE_VALUETYPE:
496 if (type->data.klass->enumtype) {
497 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
500 mono_value_copy (data, val->data.vt, type->data.klass);
502 case MONO_TYPE_GENERICINST: {
503 MonoClass *container_class = type->data.generic_class->container_class;
505 if (container_class->valuetype && !container_class->enumtype) {
506 mono_value_copy (data, val->data.vt, mono_class_from_mono_type (type));
509 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
513 g_warning ("got type %x", type->type);
514 g_assert_not_reached ();
519 fill_in_trace (MonoException *exception, MonoInvocation *frame)
522 char *stack_trace = dump_frame (frame);
523 MonoDomain *domain = mono_domain_get();
524 (exception)->stack_trace = mono_string_new_checked (domain, stack_trace, &error);
525 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
526 (exception)->trace_ips = get_trace_ips (domain, frame);
527 g_free (stack_trace);
530 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
532 #define THROW_EX(exception,ex_ip) \
534 frame->ip = (ex_ip); \
535 frame->ex = (MonoException*)(exception); \
536 FILL_IN_TRACE(frame->ex, frame); \
537 goto handle_exception; \
541 ves_array_create (MonoInvocation *frame, MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
544 intptr_t *lower_bounds;
549 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
550 for (i = 0; i < sig->param_count; ++i) {
551 lengths [i] = values->data.i;
554 if (klass->rank == sig->param_count) {
555 /* Only lengths provided. */
558 /* lower bounds are first. */
559 lower_bounds = (intptr_t *) lengths;
560 lengths += klass->rank;
562 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
563 if (!mono_error_ok (&error)) {
564 frame->ex = mono_error_convert_to_exception (&error);
565 FILL_IN_TRACE (frame->ex, frame);
567 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
572 ves_array_calculate_index (MonoArray *ao, stackval *sp, MonoInvocation *frame, gboolean safe)
574 g_assert (!frame->ex);
575 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
579 for (gint32 i = 0; i < ac->rank; i++) {
580 guint32 idx = sp [i].data.i;
581 guint32 lower = ao->bounds [i].lower_bound;
582 guint32 len = ao->bounds [i].length;
583 if (safe && (idx < lower || (idx - lower) >= len)) {
584 frame->ex = mono_get_exception_index_out_of_range ();
585 FILL_IN_TRACE (frame->ex, frame);
588 pos = (pos * len) + idx - lower;
592 if (safe && pos >= ao->max_length) {
593 frame->ex = mono_get_exception_index_out_of_range ();
594 FILL_IN_TRACE (frame->ex, frame);
602 ves_array_set (MonoInvocation *frame)
604 stackval *sp = frame->stack_args + 1;
606 MonoObject *o = frame->stack_args->data.p;
607 MonoArray *ao = (MonoArray *) o;
608 MonoClass *ac = o->vtable->klass;
610 g_assert (ac->rank >= 1);
612 gint32 pos = ves_array_calculate_index (ao, sp, frame, TRUE);
616 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
618 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
619 mono_error_cleanup (&error);
621 frame->ex = mono_get_exception_array_type_mismatch ();
622 FILL_IN_TRACE (frame->ex, frame);
627 gint32 esize = mono_array_element_size (ac);
628 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
630 MonoType *mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
631 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
635 ves_array_get (MonoInvocation *frame, gboolean safe)
637 stackval *sp = frame->stack_args + 1;
639 MonoObject *o = frame->stack_args->data.p;
640 MonoArray *ao = (MonoArray *) o;
641 MonoClass *ac = o->vtable->klass;
643 g_assert (ac->rank >= 1);
645 gint32 pos = ves_array_calculate_index (ao, sp, frame, safe);
649 gint32 esize = mono_array_element_size (ac);
650 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
652 MonoType *mt = mono_method_signature (frame->runtime_method->method)->ret;
653 stackval_from_data (mt, frame->retval, ea, FALSE);
657 ves_array_element_address (MonoInvocation *frame, MonoClass *required_type, MonoArray *ao, stackval *sp, gboolean needs_typecheck)
659 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
661 g_assert (ac->rank >= 1);
663 gint32 pos = ves_array_calculate_index (ao, sp, frame, TRUE);
667 if (needs_typecheck && !mono_class_is_assignable_from (mono_object_class ((MonoObject *) ao)->element_class, required_type->element_class)) {
668 frame->ex = mono_get_exception_array_type_mismatch ();
669 FILL_IN_TRACE (frame->ex, frame);
672 gint32 esize = mono_array_element_size (ac);
673 return mono_array_addr_with_size (ao, esize, pos);
677 interp_walk_stack_with_ctx (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data)
680 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
685 MonoInvocation *frame = context->current_frame;
688 MonoStackFrameInfo fi;
689 memset (&fi, 0, sizeof (MonoStackFrameInfo));
691 /* TODO: hack to make some asserts happy. */
692 fi.ji = (MonoJitInfo *) frame->runtime_method;
694 if (frame->runtime_method)
695 fi.method = fi.actual_method = frame->runtime_method->method;
697 if (!fi.method || (fi.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (fi.method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
699 fi.type = FRAME_TYPE_MANAGED_TO_NATIVE;
701 MonoMethodHeader *hd = mono_method_get_header_checked (fi.method, &error);
702 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
703 fi.type = FRAME_TYPE_MANAGED;
704 fi.il_offset = frame->ip - (const unsigned short *) hd->code;
705 if (!fi.method->wrapper_type)
709 if (func (&fi, ctx, user_data))
711 frame = frame->parent;
715 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
717 static InterpMethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
719 InterpMethodArguments *margs = g_malloc0 (sizeof (InterpMethodArguments));
724 for (int i = 0; i < sig->param_count; i++) {
725 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
727 case MONO_TYPE_BOOLEAN:
738 case MONO_TYPE_SZARRAY:
739 case MONO_TYPE_CLASS:
740 case MONO_TYPE_OBJECT:
741 case MONO_TYPE_STRING:
742 case MONO_TYPE_VALUETYPE:
743 case MONO_TYPE_GENERICINST:
744 #if SIZEOF_VOID_P == 8
749 #if SIZEOF_VOID_P == 4
752 /* pairs begin at even registers */
760 #if SIZEOF_VOID_P == 8
765 #if SIZEOF_VOID_P == 4
771 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
776 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
779 margs->fargs = g_malloc0 (sizeof (double) * margs->flen);
781 if (margs->ilen > INTERP_ICALL_TRAMP_IARGS)
782 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs->ilen);
784 if (margs->flen > INTERP_ICALL_TRAMP_FARGS)
785 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs->flen);
792 margs->iargs [0] = frame->stack_args->data.p;
796 for (int i = 0; i < sig->param_count; i++) {
797 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
799 case MONO_TYPE_BOOLEAN:
810 case MONO_TYPE_SZARRAY:
811 case MONO_TYPE_CLASS:
812 case MONO_TYPE_OBJECT:
813 case MONO_TYPE_STRING:
814 case MONO_TYPE_VALUETYPE:
815 case MONO_TYPE_GENERICINST:
816 #if SIZEOF_VOID_P == 8
819 margs->iargs [int_i] = frame->stack_args [i].data.p;
821 g_print ("build_args_from_sig: margs->iargs [%d]: %p (frame @ %d)\n", int_i, margs->iargs [int_i], i);
825 #if SIZEOF_VOID_P == 4
827 stackval *sarg = &frame->stack_args [i];
829 /* pairs begin at even registers */
833 margs->iargs [int_i] = (gpointer) sarg->data.pair.lo;
835 margs->iargs [int_i] = (gpointer) sarg->data.pair.hi;
837 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);
845 if (ptype == MONO_TYPE_R4)
846 * (float *) &(margs->fargs [int_f]) = (float) frame->stack_args [i].data.f;
848 margs->fargs [int_f] = frame->stack_args [i].data.f;
850 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);
852 #if SIZEOF_VOID_P == 4
859 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
863 switch (sig->ret->type) {
864 case MONO_TYPE_BOOLEAN:
875 case MONO_TYPE_SZARRAY:
876 case MONO_TYPE_CLASS:
877 case MONO_TYPE_OBJECT:
878 case MONO_TYPE_STRING:
880 case MONO_TYPE_VALUETYPE:
881 case MONO_TYPE_GENERICINST:
882 margs->retval = &(frame->retval->data.p);
883 margs->is_float_ret = 0;
887 margs->retval = &(frame->retval->data.p);
888 margs->is_float_ret = 1;
891 margs->retval = NULL;
894 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig->ret->type);
901 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
904 MonoInvocation *old_frame = context->current_frame;
905 MonoInvocation *old_env_frame = context->env_frame;
906 jmp_buf *old_env = context->current_env;
910 context->current_frame = old_frame;
911 context->env_frame = old_env_frame;
912 context->current_env = old_env;
913 context->managed_code = 1;
918 context->env_frame = frame;
919 context->current_env = &env;
921 g_assert (!frame->runtime_method);
922 if (!mono_interp_enter_icall_trampoline) {
924 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
926 // mono_tramp_info_register (info, NULL);
929 InterpMethodArguments *margs = build_args_from_sig (sig, frame);
931 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
932 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
935 context->current_frame = frame;
936 context->managed_code = 0;
939 * Push an LMF frame on the LMF stack
940 * to mark the transition to native code.
942 memset (&ext, 0, sizeof (ext));
943 ext.interp_exit = TRUE;
944 ext.interp_exit_data = frame;
946 mono_push_lmf (&ext);
948 mono_interp_enter_icall_trampoline (addr, margs);
950 mono_pop_lmf (&ext.lmf);
952 context->managed_code = 1;
953 /* domain can only be changed by native code */
954 context->domain = mono_domain_get ();
956 if (*mono_thread_interruption_request_flag ()) {
957 MonoException *exc = mono_thread_interruption_checkpoint ();
960 context->search_for_handler = 1;
964 if (!frame->ex && !MONO_TYPE_ISSTRUCT (sig->ret))
965 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
967 context->current_frame = old_frame;
968 context->env_frame = old_env_frame;
969 context->current_env = old_env;
971 g_free (margs->iargs);
972 g_free (margs->fargs);
977 mono_interp_init_delegate (MonoDelegate *del)
981 /* shouldn't need a write barrier because we don't write a MonoObject into the field */
982 del->method = ((RuntimeMethod *) del->method_ptr)->method;
987 * runtime specifies that the implementation of the method is automatically
988 * provided by the runtime and is primarily used for the methods of delegates.
991 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
993 MonoMethod *method = frame->runtime_method->method;
994 const char *name = method->name;
995 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
996 MonoObject *isinst_obj;
999 mono_class_init (method->klass);
1001 if (method->klass == mono_defaults.array_class) {
1002 if (!strcmp (method->name, "UnsafeMov")) {
1003 /* TODO: layout checks */
1004 MonoType *mt = mono_method_signature (method)->ret;
1005 stackval_from_data (mt, frame->retval, (char *) frame->stack_args, FALSE);
1008 if (!strcmp (method->name, "UnsafeLoad")) {
1009 ves_array_get (frame, FALSE);
1014 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
1015 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1016 if (obj && isinst_obj) {
1017 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
1018 ves_array_set (frame);
1021 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
1022 ves_array_get (frame, TRUE);
1027 g_error ("Don't know how to exec runtime method %s.%s::%s",
1028 method->klass->name_space, method->klass->name,
1034 dump_stack (stackval *stack, stackval *sp)
1036 stackval *s = stack;
1037 GString *str = g_string_new ("");
1040 return g_string_free (str, FALSE);
1043 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
1046 return g_string_free (str, FALSE);
1051 dump_stackval (GString *str, stackval *s, MonoType *type)
1053 switch (type->type) {
1060 case MONO_TYPE_CHAR:
1061 case MONO_TYPE_BOOLEAN:
1062 g_string_append_printf (str, "[%d] ", s->data.i);
1064 case MONO_TYPE_STRING:
1065 case MONO_TYPE_SZARRAY:
1066 case MONO_TYPE_CLASS:
1067 case MONO_TYPE_OBJECT:
1068 case MONO_TYPE_ARRAY:
1072 g_string_append_printf (str, "[%p] ", s->data.p);
1074 case MONO_TYPE_VALUETYPE:
1075 if (type->data.klass->enumtype)
1076 g_string_append_printf (str, "[%d] ", s->data.i);
1078 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1082 g_string_append_printf (str, "[%g] ", s->data.f);
1087 GString *res = g_string_new ("");
1088 mono_type_get_desc (res, type, TRUE);
1089 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1090 g_string_free (res, TRUE);
1098 dump_retval (MonoInvocation *inv)
1100 GString *str = g_string_new ("");
1101 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1103 if (ret->type != MONO_TYPE_VOID)
1104 dump_stackval (str, inv->retval, ret);
1106 return g_string_free (str, FALSE);
1111 dump_args (MonoInvocation *inv)
1113 GString *str = g_string_new ("");
1115 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1117 if (signature->param_count == 0 && !signature->hasthis)
1118 return g_string_free (str, FALSE);
1120 if (signature->hasthis) {
1121 MonoMethod *method = inv->runtime_method->method;
1122 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1125 for (i = 0; i < signature->param_count; ++i)
1126 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1128 return g_string_free (str, FALSE);
1132 dump_frame (MonoInvocation *inv)
1134 GString *str = g_string_new ("");
1139 for (i = 0; inv; inv = inv->parent) {
1140 if (inv->runtime_method != NULL) {
1141 MonoMethod *method = inv->runtime_method->method;
1145 const char * opname = "";
1147 gchar *source = NULL;
1151 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1152 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1153 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1154 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1158 opname = mono_interp_opname [*inv->ip];
1159 codep = inv->ip - inv->runtime_method->code;
1160 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1165 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1166 source = mono_debug_method_lookup_location (minfo, codep);
1170 args = dump_args (inv);
1171 name = mono_method_full_name (method, TRUE);
1173 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1175 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1182 return g_string_free (str, FALSE);
1186 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1190 MonoInvocation *inv;
1193 for (i = 0, inv = top; inv; inv = inv->parent)
1194 if (inv->runtime_method != NULL)
1197 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1198 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1200 for (i = 0, inv = top; inv; inv = inv->parent)
1201 if (inv->runtime_method != NULL) {
1202 mono_array_set (res, gpointer, i, inv->runtime_method);
1204 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1212 #define MYGUINT64_MAX 18446744073709551615ULL
1213 #define MYGINT64_MAX 9223372036854775807LL
1214 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1216 #define MYGUINT32_MAX 4294967295U
1217 #define MYGINT32_MAX 2147483647
1218 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1220 #define CHECK_ADD_OVERFLOW(a,b) \
1221 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1222 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1224 #define CHECK_SUB_OVERFLOW(a,b) \
1225 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1226 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1228 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1229 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1231 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1232 (guint32)(a) < (guint32)(b) ? -1 : 0
1234 #define CHECK_ADD_OVERFLOW64(a,b) \
1235 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1236 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1238 #define CHECK_SUB_OVERFLOW64(a,b) \
1239 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1240 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1242 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1243 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1245 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1246 (guint64)(a) < (guint64)(b) ? -1 : 0
1248 #if SIZEOF_VOID_P == 4
1249 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1250 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1252 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1253 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1256 /* Resolves to TRUE if the operands would overflow */
1257 #define CHECK_MUL_OVERFLOW(a,b) \
1258 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1259 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1260 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1261 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1262 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1263 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1264 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1266 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1267 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1268 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1270 #define CHECK_MUL_OVERFLOW64(a,b) \
1271 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1272 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1273 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1274 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1275 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1276 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1277 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1279 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1280 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1281 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1283 #if SIZEOF_VOID_P == 4
1284 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1285 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1287 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1288 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1292 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1294 MonoInvocation frame;
1295 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1296 MonoObject *retval = NULL;
1297 MonoMethodSignature *sig = mono_method_signature (method);
1298 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1299 int i, type, isobject = 0;
1302 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1303 ThreadContext context_struct;
1304 MonoInvocation *old_frame = NULL;
1314 if (context != &context_struct) {
1315 context->domain = mono_domain_get ();
1316 context->current_frame = old_frame;
1317 context->managed_code = 0;
1319 mono_native_tls_set_value (thread_context_id, NULL);
1321 *exc = (MonoObject *)frame.ex;
1325 if (context == NULL) {
1326 context = &context_struct;
1327 memset (context, 0, sizeof (ThreadContext));
1328 context_struct.base_frame = &frame;
1329 context_struct.env_frame = &frame;
1330 context_struct.current_env = &env;
1331 mono_native_tls_set_value (thread_context_id, context);
1334 old_frame = context->current_frame;
1336 context->domain = mono_domain_get ();
1338 switch (sig->ret->type) {
1339 case MONO_TYPE_VOID:
1341 case MONO_TYPE_STRING:
1342 case MONO_TYPE_OBJECT:
1343 case MONO_TYPE_CLASS:
1344 case MONO_TYPE_ARRAY:
1345 case MONO_TYPE_SZARRAY:
1348 case MONO_TYPE_VALUETYPE:
1349 retval = mono_object_new_checked (context->domain, klass, error);
1350 ret = mono_object_unbox (retval);
1351 if (!sig->ret->data.klass->enumtype)
1352 result.data.vt = ret;
1354 result.data.vt = alloca (mono_class_instance_size (klass));
1356 case MONO_TYPE_GENERICINST:
1357 if (!MONO_TYPE_IS_REFERENCE (sig->ret)) {
1358 retval = mono_object_new_checked (context->domain, klass, error);
1359 ret = mono_object_unbox (retval);
1360 if (!sig->ret->data.klass->enumtype)
1361 result.data.vt = ret;
1363 result.data.vt = alloca (mono_class_instance_size (klass));
1370 retval = mono_object_new_checked (context->domain, mono_defaults.int_class, error);
1371 ret = mono_object_unbox (retval);
1374 retval = mono_object_new_checked (context->domain, klass, error);
1375 ret = mono_object_unbox (retval);
1380 args [0].data.p = obj;
1382 for (i = 0; i < sig->param_count; ++i) {
1383 int a_index = i + !!sig->hasthis;
1384 if (sig->params [i]->byref) {
1385 args [a_index].data.p = params [i];
1388 type = sig->params [i]->type;
1393 case MONO_TYPE_BOOLEAN:
1394 args [a_index].data.i = *(MonoBoolean*)params [i];
1398 case MONO_TYPE_CHAR:
1399 args [a_index].data.i = *(gint16*)params [i];
1401 #if SIZEOF_VOID_P == 4
1402 case MONO_TYPE_U: /* use VAL_POINTER? */
1407 args [a_index].data.i = *(gint32*)params [i];
1409 #if SIZEOF_VOID_P == 8
1415 args [a_index].data.l = *(gint64*)params [i];
1418 args [a_index].data.f = *(gfloat *) params [i];
1421 args [a_index].data.f = *(gdouble *) params [i];
1423 case MONO_TYPE_VALUETYPE:
1424 if (sig->params [i]->data.klass->enumtype) {
1425 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1428 args [a_index].data.p = params [i];
1431 case MONO_TYPE_STRING:
1433 case MONO_TYPE_CLASS:
1434 case MONO_TYPE_ARRAY:
1435 case MONO_TYPE_SZARRAY:
1436 case MONO_TYPE_OBJECT:
1437 case MONO_TYPE_GENERICINST:
1438 args [a_index].data.p = params [i];
1441 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1445 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1446 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1447 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1449 frame.invoke_trap = 1;
1450 context->managed_code = 1;
1451 ves_exec_method_with_context (&frame, context, NULL, NULL, -1);
1452 context->managed_code = 0;
1453 if (context == &context_struct)
1454 mono_native_tls_set_value (thread_context_id, NULL);
1456 context->current_frame = old_frame;
1457 if (frame.ex != NULL) {
1459 *exc = (MonoObject*) frame.ex;
1462 if (context->current_env != NULL) {
1463 context->env_frame->ex = frame.ex;
1464 longjmp(*context->current_env, 1);
1467 printf("dropped exception...\n");
1469 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1471 if (isobject || method->string_ctor)
1472 return result.data.p;
1473 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1478 RuntimeMethod *rmethod;
1482 gpointer *many_args;
1485 /* Main function for entering the interpreter from compiled code */
1487 interp_entry (InterpEntryData *data)
1489 MonoInvocation frame;
1490 RuntimeMethod *rmethod = data->rmethod;
1491 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
1492 ThreadContext context_struct;
1493 MonoInvocation *old_frame;
1497 MonoMethodSignature *sig;
1501 method = rmethod->method;
1502 sig = mono_method_signature (method);
1504 // FIXME: Optimize this
1506 //printf ("%s\n", mono_method_full_name (method, 1));
1509 if (context == NULL) {
1510 context = &context_struct;
1511 memset (context, 0, sizeof (ThreadContext));
1512 context_struct.base_frame = &frame;
1513 context_struct.env_frame = &frame;
1514 mono_native_tls_set_value (thread_context_id, context);
1517 old_frame = context->current_frame;
1518 context->domain = mono_domain_get ();
1520 args = alloca (sizeof (stackval) * (sig->param_count + (sig->hasthis ? 1 : 0)));
1522 args [0].data.p = data->this_arg;
1525 if (data->many_args)
1526 params = data->many_args;
1528 params = data->args;
1529 for (i = 0; i < sig->param_count; ++i) {
1530 int a_index = i + (sig->hasthis ? 1 : 0);
1531 if (sig->params [i]->byref) {
1532 args [a_index].data.p = params [i];
1535 type = rmethod->param_types [i];
1536 switch (type->type) {
1539 args [a_index].data.i = *(MonoBoolean*)params [i];
1543 args [a_index].data.i = *(gint16*)params [i];
1546 #if SIZEOF_VOID_P == 4
1547 args [a_index].data.p = GINT_TO_POINTER (*(guint32*)params [i]);
1549 args [a_index].data.p = GINT_TO_POINTER (*(guint64*)params [i]);
1553 #if SIZEOF_VOID_P == 4
1554 args [a_index].data.p = GINT_TO_POINTER (*(gint32*)params [i]);
1556 args [a_index].data.p = GINT_TO_POINTER (*(gint64*)params [i]);
1560 args [a_index].data.i = *(guint32*)params [i];
1563 args [a_index].data.i = *(gint32*)params [i];
1566 args [a_index].data.l = *(guint64*)params [i];
1569 args [a_index].data.l = *(gint64*)params [i];
1572 case MONO_TYPE_OBJECT:
1573 args [a_index].data.p = *(MonoObject**)params [i];
1575 case MONO_TYPE_VALUETYPE:
1576 args [a_index].data.p = params [i];
1578 case MONO_TYPE_GENERICINST:
1579 if (MONO_TYPE_IS_REFERENCE (type))
1580 args [a_index].data.p = params [i];
1582 args [a_index].data.vt = params [i];
1585 printf ("%s\n", mono_type_full_name (sig->params [i]));
1591 init_frame (&frame, NULL, data->rmethod, args, &result);
1592 context->managed_code = 1;
1594 type = rmethod->rtype;
1595 switch (type->type) {
1596 case MONO_TYPE_GENERICINST:
1597 if (!MONO_TYPE_IS_REFERENCE (type))
1598 frame.retval->data.vt = data->res;
1600 case MONO_TYPE_VALUETYPE:
1601 frame.retval->data.vt = data->res;
1607 ves_exec_method_with_context (&frame, context, NULL, NULL, -1);
1608 context->managed_code = 0;
1609 if (context == &context_struct)
1610 mono_native_tls_set_value (thread_context_id, NULL);
1612 context->current_frame = old_frame;
1615 g_assert (frame.ex == NULL);
1617 type = rmethod->rtype;
1618 switch (type->type) {
1619 case MONO_TYPE_VOID:
1622 *(gint8*)data->res = frame.retval->data.i;
1625 *(guint8*)data->res = frame.retval->data.i;
1628 *(gint16*)data->res = frame.retval->data.i;
1631 *(guint16*)data->res = frame.retval->data.i;
1634 *(gint32*)data->res = frame.retval->data.i;
1637 *(guint64*)data->res = frame.retval->data.i;
1640 *(gint64*)data->res = frame.retval->data.i;
1643 *(guint64*)data->res = frame.retval->data.i;
1646 #if SIZEOF_VOID_P == 8
1647 *(gint64*)data->res = (gint64)frame.retval->data.p;
1649 *(gint32*)data->res = (gint32)frame.retval->data.p;
1653 #if SIZEOF_VOID_P == 8
1654 *(guint64*)data->res = (guint64)frame.retval->data.p;
1656 *(guint32*)data->res = (guint32)frame.retval->data.p;
1659 case MONO_TYPE_OBJECT:
1660 /* No need for a write barrier */
1661 *(MonoObject**)data->res = (MonoObject*)frame.retval->data.p;
1663 case MONO_TYPE_GENERICINST:
1664 if (MONO_TYPE_IS_REFERENCE (type)) {
1665 *(MonoObject**)data->res = *(MonoObject**)frame.retval->data.p;
1667 /* Already set before the call */
1670 case MONO_TYPE_VALUETYPE:
1671 /* Already set before the call */
1674 printf ("%s\n", mono_type_full_name (sig->ret));
1681 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1683 MonoInvocation *old_frame = context->current_frame;
1684 MonoInvocation *old_env_frame = context->env_frame;
1685 jmp_buf *old_env = context->current_env;
1689 context->current_frame = old_frame;
1690 context->env_frame = old_env_frame;
1691 context->current_env = old_env;
1692 context->managed_code = 1;
1696 context->env_frame = context->current_frame;
1697 context->current_env = &env;
1698 context->managed_code = 0;
1701 case MINT_ICALL_V_V: {
1702 void (*func)(void) = ptr;
1706 case MINT_ICALL_V_P: {
1707 gpointer (*func)(void) = ptr;
1709 sp [-1].data.p = func ();
1712 case MINT_ICALL_P_V: {
1713 void (*func)(gpointer) = ptr;
1714 func (sp [-1].data.p);
1718 case MINT_ICALL_P_P: {
1719 gpointer (*func)(gpointer) = ptr;
1720 sp [-1].data.p = func (sp [-1].data.p);
1723 case MINT_ICALL_PP_V: {
1724 void (*func)(gpointer,gpointer) = ptr;
1726 func (sp [0].data.p, sp [1].data.p);
1729 case MINT_ICALL_PI_V: {
1730 void (*func)(gpointer,int) = ptr;
1732 func (sp [0].data.p, sp [1].data.i);
1735 case MINT_ICALL_PP_P: {
1736 gpointer (*func)(gpointer,gpointer) = ptr;
1738 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1741 case MINT_ICALL_PI_P: {
1742 gpointer (*func)(gpointer,int) = ptr;
1744 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1747 case MINT_ICALL_PPP_V: {
1748 void (*func)(gpointer,gpointer,gpointer) = ptr;
1750 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1753 case MINT_ICALL_PPI_V: {
1754 void (*func)(gpointer,gpointer,int) = ptr;
1756 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1760 g_assert_not_reached ();
1763 context->env_frame = old_env_frame;
1764 context->current_env = old_env;
1770 * These functions are the entry points into the interpreter from compiled code.
1771 * They are called by the interp_in wrappers. They have the following signature:
1772 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
1773 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
1774 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
1775 * more wrappers then these functions.
1776 * this/static * ret/void * 16 arguments -> 64 functions.
1779 #define MAX_INTERP_ENTRY_ARGS 8
1781 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
1782 InterpEntryData data; \
1783 (data).rmethod = (_method); \
1784 (data).res = (_res); \
1785 (data).this_arg = (_this_arg); \
1786 (data).many_args = NULL;
1788 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
1789 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1790 interp_entry (&data); \
1792 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
1793 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1794 (data).args [0] = arg1; \
1795 interp_entry (&data); \
1797 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
1798 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1799 (data).args [0] = arg1; \
1800 (data).args [1] = arg2; \
1801 interp_entry (&data); \
1803 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
1804 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1805 (data).args [0] = arg1; \
1806 (data).args [1] = arg2; \
1807 (data).args [2] = arg3; \
1808 interp_entry (&data); \
1810 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
1811 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1812 (data).args [0] = arg1; \
1813 (data).args [1] = arg2; \
1814 (data).args [2] = arg3; \
1815 (data).args [3] = arg4; \
1816 interp_entry (&data); \
1818 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
1819 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1820 (data).args [0] = arg1; \
1821 (data).args [1] = arg2; \
1822 (data).args [2] = arg3; \
1823 (data).args [3] = arg4; \
1824 (data).args [4] = arg5; \
1825 interp_entry (&data); \
1827 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
1828 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1829 (data).args [0] = arg1; \
1830 (data).args [1] = arg2; \
1831 (data).args [2] = arg3; \
1832 (data).args [3] = arg4; \
1833 (data).args [4] = arg5; \
1834 (data).args [5] = arg6; \
1835 interp_entry (&data); \
1837 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
1838 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1839 (data).args [0] = arg1; \
1840 (data).args [1] = arg2; \
1841 (data).args [2] = arg3; \
1842 (data).args [3] = arg4; \
1843 (data).args [4] = arg5; \
1844 (data).args [5] = arg6; \
1845 (data).args [6] = arg7; \
1846 interp_entry (&data); \
1848 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
1849 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1850 (data).args [0] = arg1; \
1851 (data).args [1] = arg2; \
1852 (data).args [2] = arg3; \
1853 (data).args [3] = arg4; \
1854 (data).args [4] = arg5; \
1855 (data).args [5] = arg6; \
1856 (data).args [6] = arg7; \
1857 (data).args [7] = arg8; \
1858 interp_entry (&data); \
1861 #define ARGLIST0 RuntimeMethod *rmethod
1862 #define ARGLIST1 gpointer arg1, RuntimeMethod *rmethod
1863 #define ARGLIST2 gpointer arg1, gpointer arg2, RuntimeMethod *rmethod
1864 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, RuntimeMethod *rmethod
1865 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, RuntimeMethod *rmethod
1866 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, RuntimeMethod *rmethod
1867 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, RuntimeMethod *rmethod
1868 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, RuntimeMethod *rmethod
1869 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, RuntimeMethod *rmethod
1871 static void interp_entry_static_0 (ARGLIST0) INTERP_ENTRY0 (NULL, NULL, rmethod)
1872 static void interp_entry_static_1 (ARGLIST1) INTERP_ENTRY1 (NULL, NULL, rmethod)
1873 static void interp_entry_static_2 (ARGLIST2) INTERP_ENTRY2 (NULL, NULL, rmethod)
1874 static void interp_entry_static_3 (ARGLIST3) INTERP_ENTRY3 (NULL, NULL, rmethod)
1875 static void interp_entry_static_4 (ARGLIST4) INTERP_ENTRY4 (NULL, NULL, rmethod)
1876 static void interp_entry_static_5 (ARGLIST5) INTERP_ENTRY5 (NULL, NULL, rmethod)
1877 static void interp_entry_static_6 (ARGLIST6) INTERP_ENTRY6 (NULL, NULL, rmethod)
1878 static void interp_entry_static_7 (ARGLIST7) INTERP_ENTRY7 (NULL, NULL, rmethod)
1879 static void interp_entry_static_8 (ARGLIST8) INTERP_ENTRY8 (NULL, NULL, rmethod)
1880 static void interp_entry_static_ret_0 (gpointer res, ARGLIST0) INTERP_ENTRY0 (NULL, res, rmethod)
1881 static void interp_entry_static_ret_1 (gpointer res, ARGLIST1) INTERP_ENTRY1 (NULL, res, rmethod)
1882 static void interp_entry_static_ret_2 (gpointer res, ARGLIST2) INTERP_ENTRY2 (NULL, res, rmethod)
1883 static void interp_entry_static_ret_3 (gpointer res, ARGLIST3) INTERP_ENTRY3 (NULL, res, rmethod)
1884 static void interp_entry_static_ret_4 (gpointer res, ARGLIST4) INTERP_ENTRY4 (NULL, res, rmethod)
1885 static void interp_entry_static_ret_5 (gpointer res, ARGLIST5) INTERP_ENTRY5 (NULL, res, rmethod)
1886 static void interp_entry_static_ret_6 (gpointer res, ARGLIST6) INTERP_ENTRY6 (NULL, res, rmethod)
1887 static void interp_entry_static_ret_7 (gpointer res, ARGLIST7) INTERP_ENTRY7 (NULL, res, rmethod)
1888 static void interp_entry_static_ret_8 (gpointer res, ARGLIST8) INTERP_ENTRY8 (NULL, res, rmethod)
1889 static void interp_entry_instance_0 (gpointer this_arg, ARGLIST0) INTERP_ENTRY0 (this_arg, NULL, rmethod)
1890 static void interp_entry_instance_1 (gpointer this_arg, ARGLIST1) INTERP_ENTRY1 (this_arg, NULL, rmethod)
1891 static void interp_entry_instance_2 (gpointer this_arg, ARGLIST2) INTERP_ENTRY2 (this_arg, NULL, rmethod)
1892 static void interp_entry_instance_3 (gpointer this_arg, ARGLIST3) INTERP_ENTRY3 (this_arg, NULL, rmethod)
1893 static void interp_entry_instance_4 (gpointer this_arg, ARGLIST4) INTERP_ENTRY4 (this_arg, NULL, rmethod)
1894 static void interp_entry_instance_5 (gpointer this_arg, ARGLIST5) INTERP_ENTRY5 (this_arg, NULL, rmethod)
1895 static void interp_entry_instance_6 (gpointer this_arg, ARGLIST6) INTERP_ENTRY6 (this_arg, NULL, rmethod)
1896 static void interp_entry_instance_7 (gpointer this_arg, ARGLIST7) INTERP_ENTRY7 (this_arg, NULL, rmethod)
1897 static void interp_entry_instance_8 (gpointer this_arg, ARGLIST8) INTERP_ENTRY8 (this_arg, NULL, rmethod)
1898 static void interp_entry_instance_ret_0 (gpointer this_arg, gpointer res, ARGLIST0) INTERP_ENTRY0 (this_arg, res, rmethod)
1899 static void interp_entry_instance_ret_1 (gpointer this_arg, gpointer res, ARGLIST1) INTERP_ENTRY1 (this_arg, res, rmethod)
1900 static void interp_entry_instance_ret_2 (gpointer this_arg, gpointer res, ARGLIST2) INTERP_ENTRY2 (this_arg, res, rmethod)
1901 static void interp_entry_instance_ret_3 (gpointer this_arg, gpointer res, ARGLIST3) INTERP_ENTRY3 (this_arg, res, rmethod)
1902 static void interp_entry_instance_ret_4 (gpointer this_arg, gpointer res, ARGLIST4) INTERP_ENTRY4 (this_arg, res, rmethod)
1903 static void interp_entry_instance_ret_5 (gpointer this_arg, gpointer res, ARGLIST5) INTERP_ENTRY5 (this_arg, res, rmethod)
1904 static void interp_entry_instance_ret_6 (gpointer this_arg, gpointer res, ARGLIST6) INTERP_ENTRY6 (this_arg, res, rmethod)
1905 static void interp_entry_instance_ret_7 (gpointer this_arg, gpointer res, ARGLIST7) INTERP_ENTRY6 (this_arg, res, rmethod)
1906 static void interp_entry_instance_ret_8 (gpointer this_arg, gpointer res, ARGLIST8) INTERP_ENTRY6 (this_arg, res, rmethod)
1908 #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
1910 gpointer entry_funcs_static [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static) };
1911 gpointer entry_funcs_static_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static_ret) };
1912 gpointer entry_funcs_instance [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance) };
1913 gpointer entry_funcs_instance_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance_ret) };
1915 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
1917 interp_entry_general (gpointer this_arg, gpointer res, gpointer *args, gpointer rmethod)
1919 INTERP_ENTRY_BASE (rmethod, this_arg, res);
1920 data.many_args = args;
1921 interp_entry (&data);
1925 * mono_interp_create_method_pointer:
1927 * Return a function pointer which can be used to call METHOD using the
1928 * interpreter. Return NULL for methods which are not supported.
1931 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1934 MonoMethodSignature *sig = mono_method_signature (method);
1935 MonoMethod *wrapper;
1936 RuntimeMethod *rmethod;
1938 /* HACK: method_ptr of delegate should point to a runtime method*/
1939 if (method->wrapper_type && method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD)
1940 return mono_interp_get_runtime_method (mono_domain_get (), method, error);
1942 rmethod = mono_interp_get_runtime_method (mono_domain_get (), method, error);
1943 if (rmethod->jit_entry)
1944 return rmethod->jit_entry;
1945 wrapper = mini_get_interp_in_wrapper (sig);
1947 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, error);
1948 mono_error_assert_ok (error);
1950 //printf ("%s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
1951 gpointer entry_func;
1952 if (sig->param_count > MAX_INTERP_ENTRY_ARGS) {
1953 entry_func = interp_entry_general;
1954 } else if (sig->hasthis) {
1955 if (sig->ret->type == MONO_TYPE_VOID)
1956 entry_func = entry_funcs_instance [sig->param_count];
1958 entry_func = entry_funcs_instance_ret [sig->param_count];
1960 if (sig->ret->type == MONO_TYPE_VOID)
1961 entry_func = entry_funcs_static [sig->param_count];
1963 entry_func = entry_funcs_static_ret [sig->param_count];
1965 g_assert (entry_func);
1967 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
1968 MonoFtnDesc *ftndesc = g_new0 (MonoFtnDesc, 1);
1969 ftndesc->addr = entry_func;
1970 ftndesc->arg = rmethod;
1971 mono_error_assert_ok (error);
1974 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
1975 * rgctx register using a trampoline.
1979 g_assert (!mono_aot_only);
1980 addr = mono_arch_get_static_rgctx_trampoline (ftndesc, jit_wrapper);
1982 mono_memory_barrier ();
1983 rmethod->jit_entry = addr;
1989 static int opcode_counts[512];
1991 #define COUNT_OP(op) opcode_counts[op]++
1993 #define COUNT_OP(op)
1997 #define DUMP_INSTR() \
1998 if (tracing > 1) { \
2000 if (sp > frame->stack) { \
2001 ins = dump_stack (frame->stack, sp); \
2003 ins = g_strdup (""); \
2007 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
2008 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
2010 mono_interp_dis_mintop(rtm->code, ip); \
2011 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
2015 #define DUMP_INSTR()
2019 #define USE_COMPUTED_GOTO 1
2021 #if USE_COMPUTED_GOTO
2022 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
2023 #define MINT_IN_CASE(x) LAB_ ## x:
2025 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
2027 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
2029 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
2031 #define MINT_IN_SWITCH(op) switch (op)
2032 #define MINT_IN_CASE(x) case x:
2033 #define MINT_IN_BREAK break
2034 #define MINT_IN_DEFAULT default:
2038 * If EXIT_AT_FINALLY is not -1, exit after exiting the finally clause with that index.
2041 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception, int exit_at_finally)
2043 MonoInvocation child_frame;
2044 GSList *finally_ips = NULL;
2045 const unsigned short *endfinally_ip = NULL;
2046 const unsigned short *ip = NULL;
2047 register stackval *sp;
2050 gint tracing = global_tracing;
2051 unsigned char *vtalloc;
2056 unsigned char *vt_sp;
2057 unsigned char *locals;
2059 MonoObject *o = NULL;
2061 #if USE_COMPUTED_GOTO
2062 static void *in_labels[] = {
2063 #define OPDEF(a,b,c,d) \
2065 #include "mintops.def"
2070 frame->ex_handler = NULL;
2072 context->current_frame = frame;
2074 debug_enter (frame, &tracing);
2076 if (!frame->runtime_method->transformed) {
2077 context->managed_code = 0;
2079 char *mn = mono_method_full_name (frame->runtime_method->method, TRUE);
2080 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
2083 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
2084 context->managed_code = 1;
2092 rtm = frame->runtime_method;
2093 if (!start_with_ip ) {
2094 frame->args = alloca (rtm->alloca_size);
2095 memset (frame->args, 0, rtm->alloca_size);
2101 sp = frame->stack = (stackval *) ((char *) frame->args + rtm->args_size);
2102 vt_sp = (unsigned char *) sp + rtm->stack_size;
2106 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
2107 child_frame.parent = frame;
2109 if (filter_exception) {
2110 sp->data.p = filter_exception;
2115 * using while (ip < end) may result in a 15% performance drop,
2116 * but it may be useful for debug
2120 /* g_assert (sp >= frame->stack); */
2121 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
2123 MINT_IN_SWITCH (*ip) {
2124 MINT_IN_CASE(MINT_INITLOCALS)
2125 memset (locals, 0, rtm->locals_size);
2128 MINT_IN_CASE(MINT_NOP)
2131 MINT_IN_CASE(MINT_BREAK)
2133 G_BREAKPOINT (); /* this is not portable... */
2135 MINT_IN_CASE(MINT_LDNULL)
2140 MINT_IN_CASE(MINT_VTRESULT) {
2141 int ret_size = * (guint16 *)(ip + 1);
2142 unsigned char *ret_vt_sp = vt_sp;
2143 vt_sp -= READ32(ip + 2);
2145 memmove (vt_sp, ret_vt_sp, ret_size);
2146 sp [-1].data.p = vt_sp;
2147 vt_sp += (ret_size + 7) & ~7;
2152 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
2153 MINT_IN_CASE(MINT_LDC_I4_M1)
2156 MINT_IN_CASE(MINT_LDC_I4_0)
2159 MINT_IN_CASE(MINT_LDC_I4_1)
2162 MINT_IN_CASE(MINT_LDC_I4_2)
2165 MINT_IN_CASE(MINT_LDC_I4_3)
2168 MINT_IN_CASE(MINT_LDC_I4_4)
2171 MINT_IN_CASE(MINT_LDC_I4_5)
2174 MINT_IN_CASE(MINT_LDC_I4_6)
2177 MINT_IN_CASE(MINT_LDC_I4_7)
2180 MINT_IN_CASE(MINT_LDC_I4_8)
2183 MINT_IN_CASE(MINT_LDC_I4_S)
2184 sp->data.i = *(const short *)(ip + 1);
2188 MINT_IN_CASE(MINT_LDC_I4)
2190 sp->data.i = READ32 (ip);
2194 MINT_IN_CASE(MINT_LDC_I8)
2196 sp->data.l = READ64 (ip);
2200 MINT_IN_CASE(MINT_LDC_R4) {
2204 sp->data.f = * (float *)&val;
2209 MINT_IN_CASE(MINT_LDC_R8)
2210 sp->data.l = READ64 (ip + 1); /* note union usage */
2214 MINT_IN_CASE(MINT_DUP)
2219 MINT_IN_CASE(MINT_DUP_VT)
2220 i32 = READ32 (ip + 1);
2222 memcpy(sp->data.p, sp [-1].data.p, i32);
2223 vt_sp += (i32 + 7) & ~7;
2227 MINT_IN_CASE(MINT_POP) {
2228 guint16 u16 = (* (guint16 *)(ip + 1)) + 1;
2230 memmove (sp - u16, sp - 1, (u16 - 1) * sizeof (stackval));
2235 MINT_IN_CASE(MINT_JMP) {
2236 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
2237 if (!new_method->transformed) {
2239 frame->ex = mono_interp_transform_method (new_method, context);
2244 if (new_method->alloca_size > rtm->alloca_size)
2245 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
2246 rtm = frame->runtime_method = new_method;
2247 vt_sp = (unsigned char *) sp + rtm->stack_size;
2251 locals = vt_sp + rtm->vt_stack_size;
2252 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
2255 MINT_IN_CASE(MINT_CALLI) {
2256 MonoMethodSignature *csignature;
2257 stackval *endsp = sp;
2261 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2265 child_frame.runtime_method = sp->data.p;
2268 child_frame.retval = sp;
2269 /* decrement by the actual number of args */
2270 sp -= csignature->param_count;
2271 if (csignature->hasthis)
2273 child_frame.stack_args = sp;
2275 /* `this' can be NULL for string:.ctor */
2276 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2277 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2278 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2279 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
2280 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
2281 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2284 if (csignature->hasthis) {
2285 MonoObject *this_arg = sp->data.p;
2287 if (this_arg->vtable->klass->valuetype) {
2288 gpointer *unboxed = mono_object_unbox (this_arg);
2289 sp [0].data.p = unboxed;
2293 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2295 context->current_frame = frame;
2297 if (context->has_resume_state) {
2298 if (frame == context->handler_frame)
2299 SET_RESUME_STATE (context);
2304 if (child_frame.ex) {
2306 * An exception occurred, need to run finally, fault and catch handlers..
2308 frame->ex = child_frame.ex;
2309 goto handle_finally;
2312 /* need to handle typedbyref ... */
2313 if (csignature->ret->type != MONO_TYPE_VOID) {
2319 MINT_IN_CASE(MINT_CALLI_NAT) {
2320 MonoMethodSignature *csignature;
2321 stackval *endsp = sp;
2322 unsigned char *code = NULL;
2326 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2331 child_frame.runtime_method = NULL;
2334 child_frame.retval = sp;
2335 /* decrement by the actual number of args */
2336 sp -= csignature->param_count;
2337 if (csignature->hasthis)
2339 child_frame.stack_args = sp;
2340 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
2342 context->current_frame = frame;
2344 if (context->has_resume_state) {
2345 if (frame == context->handler_frame)
2346 SET_RESUME_STATE (context);
2351 if (child_frame.ex) {
2353 * An exception occurred, need to run finally, fault and catch handlers..
2355 frame->ex = child_frame.ex;
2356 if (context->search_for_handler) {
2357 context->search_for_handler = 0;
2358 goto handle_exception;
2360 goto handle_finally;
2363 /* need to handle typedbyref ... */
2364 if (csignature->ret->type != MONO_TYPE_VOID) {
2370 MINT_IN_CASE(MINT_CALL) {
2371 stackval *endsp = sp;
2375 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2378 child_frame.retval = sp;
2379 /* decrement by the actual number of args */
2380 sp -= child_frame.runtime_method->param_count;
2381 if (child_frame.runtime_method->hasthis)
2383 child_frame.stack_args = sp;
2385 /* `this' can be NULL for string:.ctor */
2386 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2387 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2388 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2391 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2393 context->current_frame = frame;
2395 if (context->has_resume_state) {
2396 if (frame == context->handler_frame)
2397 SET_RESUME_STATE (context);
2402 if (child_frame.ex) {
2404 * An exception occurred, need to run finally, fault and catch handlers..
2406 frame->ex = child_frame.ex;
2407 goto handle_exception;;
2410 /* need to handle typedbyref ... */
2415 MINT_IN_CASE(MINT_VCALL) {
2418 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2422 child_frame.retval = sp;
2423 /* decrement by the actual number of args */
2424 sp -= child_frame.runtime_method->param_count;
2425 if (child_frame.runtime_method->hasthis) {
2427 MonoObject *this_arg = sp->data.p;
2429 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2431 child_frame.stack_args = sp;
2433 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
2434 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2435 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2438 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2440 context->current_frame = frame;
2442 if (context->has_resume_state) {
2443 if (frame == context->handler_frame)
2444 SET_RESUME_STATE (context);
2449 if (child_frame.ex) {
2451 * An exception occurred, need to run finally, fault and catch handlers..
2453 frame->ex = child_frame.ex;
2454 goto handle_finally;
2459 MINT_IN_CASE(MINT_JIT_CALL) {
2460 MonoMethodSignature *sig;
2461 RuntimeMethod *rmethod = rtm->data_items [* (guint16 *)(ip + 1)];
2462 MonoFtnDesc ftndesc;
2463 guint8 res_buf [256];
2467 //printf ("%s\n", mono_method_full_name (rmethod->method, 1));
2470 * Call JITted code through a gsharedvt_out wrapper. These wrappers receive every argument
2471 * by ref and return a return value using an explicit return value argument.
2473 if (!rmethod->jit_wrapper) {
2474 MonoMethod *method = rmethod->method;
2477 sig = mono_method_signature (method);
2480 MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
2481 //printf ("J: %s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
2483 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, &error);
2484 mono_error_assert_ok (&error);
2486 gpointer addr = mono_jit_compile_method_jit_only (method, &error);
2488 mono_error_assert_ok (&error);
2490 rmethod->jit_addr = addr;
2491 rmethod->jit_sig = sig;
2492 mono_memory_barrier ();
2493 rmethod->jit_wrapper = jit_wrapper;
2496 sig = rmethod->jit_sig;
2501 sp -= sig->param_count;
2505 ftndesc.addr = rmethod->jit_addr;
2508 // FIXME: Optimize this
2512 int stack_index = 0;
2513 if (rmethod->hasthis) {
2514 args [pindex ++] = sp [0].data.p;
2517 type = rmethod->rtype;
2518 if (type->type != MONO_TYPE_VOID) {
2519 if (MONO_TYPE_ISSTRUCT (type))
2520 args [pindex ++] = vt_sp;
2522 args [pindex ++] = res_buf;
2524 for (int i = 0; i < rmethod->param_count; ++i) {
2525 MonoType *t = rmethod->param_types [i];
2526 stackval *sval = &sp [stack_index + i];
2527 if (sig->params [i]->byref) {
2528 args [pindex ++] = sval->data.p;
2529 } else if (MONO_TYPE_ISSTRUCT (t)) {
2530 args [pindex ++] = sval->data.p;
2531 } else if (MONO_TYPE_IS_REFERENCE (t)) {
2532 args [pindex ++] = &sval->data.p;
2541 case MONO_TYPE_VALUETYPE:
2542 args [pindex ++] = &sval->data.i;
2545 case MONO_TYPE_FNPTR:
2548 case MONO_TYPE_OBJECT:
2549 args [pindex ++] = &sval->data.p;
2553 args [pindex ++] = &sval->data.l;
2556 printf ("%s\n", mono_type_full_name (t));
2557 g_assert_not_reached ();
2563 * Push an LMF frame on the LMF stack
2564 * to mark the transition to compiled code.
2566 memset (&ext, 0, sizeof (ext));
2567 ext.interp_exit = TRUE;
2568 ext.interp_exit_data = frame;
2570 mono_push_lmf (&ext);
2574 void (*func)(gpointer) = rmethod->jit_wrapper;
2580 void (*func)(gpointer, gpointer) = rmethod->jit_wrapper;
2582 func (args [0], &ftndesc);
2586 void (*func)(gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2588 func (args [0], args [1], &ftndesc);
2592 void (*func)(gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2594 func (args [0], args [1], args [2], &ftndesc);
2598 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2600 func (args [0], args [1], args [2], args [3], &ftndesc);
2604 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2606 func (args [0], args [1], args [2], args [3], args [4], &ftndesc);
2610 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2612 func (args [0], args [1], args [2], args [3], args [4], args [5], &ftndesc);
2616 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2618 func (args [0], args [1], args [2], args [3], args [4], args [5], args [6], &ftndesc);
2622 g_assert_not_reached ();
2626 mono_pop_lmf (&ext.lmf);
2628 if (context->has_resume_state) {
2630 * If this bit is set, it means the call has thrown the exception, and we
2631 * reached this point because the EH code in mono_handle_exception ()
2632 * unwound all the JITted frames below us. mono_interp_set_resume_state ()
2633 * has set the fields in context to indicate where we have to resume execution.
2635 if (frame == context->handler_frame)
2636 SET_RESUME_STATE (context);
2641 MonoType *rtype = rmethod->rtype;
2642 switch (rtype->type) {
2643 case MONO_TYPE_VOID:
2644 case MONO_TYPE_OBJECT:
2645 case MONO_TYPE_STRING:
2646 case MONO_TYPE_CLASS:
2647 case MONO_TYPE_ARRAY:
2648 case MONO_TYPE_SZARRAY:
2651 sp->data.p = *(gpointer*)res_buf;
2654 sp->data.i = *(gint8*)res_buf;
2657 sp->data.i = *(guint8*)res_buf;
2660 sp->data.i = *(gint16*)res_buf;
2663 sp->data.i = *(guint16*)res_buf;
2666 sp->data.i = *(gint32*)res_buf;
2669 sp->data.i = *(guint32*)res_buf;
2671 case MONO_TYPE_VALUETYPE:
2672 /* The result was written to vt_sp */
2675 case MONO_TYPE_GENERICINST:
2676 if (MONO_TYPE_IS_REFERENCE (rtype)) {
2677 sp->data.p = *(gpointer*)res_buf;
2679 /* The result was written to vt_sp */
2684 printf ("%s\n", mono_type_full_name (rtype));
2685 g_assert_not_reached ();
2688 if (rtype->type != MONO_TYPE_VOID)
2693 MINT_IN_CASE(MINT_CALLVIRT) {
2694 stackval *endsp = sp;
2695 MonoObject *this_arg;
2700 token = * (unsigned short *)(ip + 1);
2702 child_frame.runtime_method = rtm->data_items [token];
2704 child_frame.retval = sp;
2706 /* decrement by the actual number of args */
2707 sp -= child_frame.runtime_method->param_count + 1;
2708 child_frame.stack_args = sp;
2709 this_arg = sp->data.p;
2711 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2712 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2714 MonoClass *this_class = this_arg->vtable->klass;
2715 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2717 gpointer *unboxed = mono_object_unbox (this_arg);
2718 sp [0].data.p = unboxed;
2721 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2723 context->current_frame = frame;
2725 if (context->has_resume_state) {
2726 if (frame == context->handler_frame)
2727 SET_RESUME_STATE (context);
2732 if (child_frame.ex) {
2734 * An exception occurred, need to run finally, fault and catch handlers..
2736 frame->ex = child_frame.ex;
2737 if (context->search_for_handler) {
2738 context->search_for_handler = 0;
2739 goto handle_exception;
2741 goto handle_finally;
2744 /* need to handle typedbyref ... */
2749 MINT_IN_CASE(MINT_VCALLVIRT) {
2750 MonoObject *this_arg;
2755 token = * (unsigned short *)(ip + 1);
2757 child_frame.runtime_method = rtm->data_items [token];
2759 child_frame.retval = sp;
2761 /* decrement by the actual number of args */
2762 sp -= child_frame.runtime_method->param_count + 1;
2763 child_frame.stack_args = sp;
2764 this_arg = sp->data.p;
2766 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2767 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2769 MonoClass *this_class = this_arg->vtable->klass;
2770 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2771 gpointer *unboxed = mono_object_unbox (this_arg);
2772 sp [0].data.p = unboxed;
2775 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
2777 context->current_frame = frame;
2779 if (context->has_resume_state) {
2780 if (frame == context->handler_frame)
2781 SET_RESUME_STATE (context);
2786 if (child_frame.ex) {
2788 * An exception occurred, need to run finally, fault and catch handlers..
2790 frame->ex = child_frame.ex;
2791 if (context->search_for_handler) {
2792 context->search_for_handler = 0;
2793 goto handle_exception;
2795 goto handle_finally;
2799 MINT_IN_CASE(MINT_CALLRUN)
2800 ves_runtime_method (frame, context);
2803 goto handle_exception;
2806 MINT_IN_CASE(MINT_RET)
2808 *frame->retval = *sp;
2809 if (sp > frame->stack)
2810 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2812 MINT_IN_CASE(MINT_RET_VOID)
2813 if (sp > frame->stack)
2814 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2816 MINT_IN_CASE(MINT_RET_VT)
2817 i32 = READ32(ip + 1);
2819 memcpy(frame->retval->data.p, sp->data.p, i32);
2820 if (sp > frame->stack)
2821 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2823 MINT_IN_CASE(MINT_BR_S)
2824 ip += (short) *(ip + 1);
2826 MINT_IN_CASE(MINT_BR)
2827 ip += (gint32) READ32(ip + 1);
2829 #define ZEROP_S(datamem, op) \
2831 if (sp->data.datamem op 0) \
2832 ip += * (gint16 *)(ip + 1); \
2836 #define ZEROP(datamem, op) \
2838 if (sp->data.datamem op 0) \
2839 ip += READ32(ip + 1); \
2843 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2846 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2849 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2852 MINT_IN_CASE(MINT_BRFALSE_I4)
2855 MINT_IN_CASE(MINT_BRFALSE_I8)
2858 MINT_IN_CASE(MINT_BRFALSE_R8)
2861 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2864 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2867 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2870 MINT_IN_CASE(MINT_BRTRUE_I4)
2873 MINT_IN_CASE(MINT_BRTRUE_I8)
2876 MINT_IN_CASE(MINT_BRTRUE_R8)
2879 #define CONDBR_S(cond) \
2882 ip += * (gint16 *)(ip + 1); \
2885 #define BRELOP_S(datamem, op) \
2886 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2888 #define CONDBR(cond) \
2891 ip += READ32(ip + 1); \
2895 #define BRELOP(datamem, op) \
2896 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2898 MINT_IN_CASE(MINT_BEQ_I4_S)
2901 MINT_IN_CASE(MINT_BEQ_I8_S)
2904 MINT_IN_CASE(MINT_BEQ_R8_S)
2905 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2907 MINT_IN_CASE(MINT_BEQ_I4)
2910 MINT_IN_CASE(MINT_BEQ_I8)
2913 MINT_IN_CASE(MINT_BEQ_R8)
2914 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2916 MINT_IN_CASE(MINT_BGE_I4_S)
2919 MINT_IN_CASE(MINT_BGE_I8_S)
2922 MINT_IN_CASE(MINT_BGE_R8_S)
2923 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2925 MINT_IN_CASE(MINT_BGE_I4)
2928 MINT_IN_CASE(MINT_BGE_I8)
2931 MINT_IN_CASE(MINT_BGE_R8)
2932 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2934 MINT_IN_CASE(MINT_BGT_I4_S)
2937 MINT_IN_CASE(MINT_BGT_I8_S)
2940 MINT_IN_CASE(MINT_BGT_R8_S)
2941 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2943 MINT_IN_CASE(MINT_BGT_I4)
2946 MINT_IN_CASE(MINT_BGT_I8)
2949 MINT_IN_CASE(MINT_BGT_R8)
2950 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2952 MINT_IN_CASE(MINT_BLT_I4_S)
2955 MINT_IN_CASE(MINT_BLT_I8_S)
2958 MINT_IN_CASE(MINT_BLT_R8_S)
2959 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2961 MINT_IN_CASE(MINT_BLT_I4)
2964 MINT_IN_CASE(MINT_BLT_I8)
2967 MINT_IN_CASE(MINT_BLT_R8)
2968 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2970 MINT_IN_CASE(MINT_BLE_I4_S)
2973 MINT_IN_CASE(MINT_BLE_I8_S)
2976 MINT_IN_CASE(MINT_BLE_R8_S)
2977 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2979 MINT_IN_CASE(MINT_BLE_I4)
2982 MINT_IN_CASE(MINT_BLE_I8)
2985 MINT_IN_CASE(MINT_BLE_R8)
2986 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2988 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2991 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2994 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2995 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2997 MINT_IN_CASE(MINT_BNE_UN_I4)
3000 MINT_IN_CASE(MINT_BNE_UN_I8)
3003 MINT_IN_CASE(MINT_BNE_UN_R8)
3004 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
3007 #define BRELOP_S_CAST(datamem, op, type) \
3009 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3010 ip += * (gint16 *)(ip + 1); \
3014 #define BRELOP_CAST(datamem, op, type) \
3016 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3017 ip += READ32(ip + 1); \
3021 MINT_IN_CASE(MINT_BGE_UN_I4_S)
3022 BRELOP_S_CAST(i, >=, guint32);
3024 MINT_IN_CASE(MINT_BGE_UN_I8_S)
3025 BRELOP_S_CAST(l, >=, guint64);
3027 MINT_IN_CASE(MINT_BGE_UN_R8_S)
3028 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
3030 MINT_IN_CASE(MINT_BGE_UN_I4)
3031 BRELOP_CAST(i, >=, guint32);
3033 MINT_IN_CASE(MINT_BGE_UN_I8)
3034 BRELOP_CAST(l, >=, guint64);
3036 MINT_IN_CASE(MINT_BGE_UN_R8)
3037 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
3039 MINT_IN_CASE(MINT_BGT_UN_I4_S)
3040 BRELOP_S_CAST(i, >, guint32);
3042 MINT_IN_CASE(MINT_BGT_UN_I8_S)
3043 BRELOP_S_CAST(l, >, guint64);
3045 MINT_IN_CASE(MINT_BGT_UN_R8_S)
3046 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
3048 MINT_IN_CASE(MINT_BGT_UN_I4)
3049 BRELOP_CAST(i, >, guint32);
3051 MINT_IN_CASE(MINT_BGT_UN_I8)
3052 BRELOP_CAST(l, >, guint64);
3054 MINT_IN_CASE(MINT_BGT_UN_R8)
3055 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
3057 MINT_IN_CASE(MINT_BLE_UN_I4_S)
3058 BRELOP_S_CAST(i, <=, guint32);
3060 MINT_IN_CASE(MINT_BLE_UN_I8_S)
3061 BRELOP_S_CAST(l, <=, guint64);
3063 MINT_IN_CASE(MINT_BLE_UN_R8_S)
3064 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
3066 MINT_IN_CASE(MINT_BLE_UN_I4)
3067 BRELOP_CAST(i, <=, guint32);
3069 MINT_IN_CASE(MINT_BLE_UN_I8)
3070 BRELOP_CAST(l, <=, guint64);
3072 MINT_IN_CASE(MINT_BLE_UN_R8)
3073 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
3075 MINT_IN_CASE(MINT_BLT_UN_I4_S)
3076 BRELOP_S_CAST(i, <, guint32);
3078 MINT_IN_CASE(MINT_BLT_UN_I8_S)
3079 BRELOP_S_CAST(l, <, guint64);
3081 MINT_IN_CASE(MINT_BLT_UN_R8_S)
3082 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
3084 MINT_IN_CASE(MINT_BLT_UN_I4)
3085 BRELOP_CAST(i, <, guint32);
3087 MINT_IN_CASE(MINT_BLT_UN_I8)
3088 BRELOP_CAST(l, <, guint64);
3090 MINT_IN_CASE(MINT_BLT_UN_R8)
3091 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
3093 MINT_IN_CASE(MINT_SWITCH) {
3095 const unsigned short *st;
3101 if ((guint32)sp->data.i < n) {
3103 ip += 2 * (guint32)sp->data.i;
3104 offset = READ32 (ip);
3111 MINT_IN_CASE(MINT_LDIND_I1)
3113 sp[-1].data.i = *(gint8*)sp[-1].data.p;
3115 MINT_IN_CASE(MINT_LDIND_U1)
3117 sp[-1].data.i = *(guint8*)sp[-1].data.p;
3119 MINT_IN_CASE(MINT_LDIND_I2)
3121 sp[-1].data.i = *(gint16*)sp[-1].data.p;
3123 MINT_IN_CASE(MINT_LDIND_U2)
3125 sp[-1].data.i = *(guint16*)sp[-1].data.p;
3127 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
3128 MINT_IN_CASE(MINT_LDIND_U4)
3130 sp[-1].data.i = *(gint32*)sp[-1].data.p;
3132 MINT_IN_CASE(MINT_LDIND_I8)
3134 sp[-1].data.l = *(gint64*)sp[-1].data.p;
3136 MINT_IN_CASE(MINT_LDIND_I) {
3137 guint16 offset = * (guint16 *)(ip + 1);
3138 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
3142 MINT_IN_CASE(MINT_LDIND_R4)
3144 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
3146 MINT_IN_CASE(MINT_LDIND_R8)
3148 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
3150 MINT_IN_CASE(MINT_LDIND_REF)
3152 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
3154 MINT_IN_CASE(MINT_STIND_REF)
3157 mono_gc_wbarrier_generic_store (sp->data.p, sp [1].data.p);
3159 MINT_IN_CASE(MINT_STIND_I1)
3162 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
3164 MINT_IN_CASE(MINT_STIND_I2)
3167 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
3169 MINT_IN_CASE(MINT_STIND_I4)
3172 * (gint32 *) sp->data.p = sp[1].data.i;
3174 MINT_IN_CASE(MINT_STIND_I)
3177 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
3179 MINT_IN_CASE(MINT_STIND_I8)
3182 * (gint64 *) sp->data.p = sp[1].data.l;
3184 MINT_IN_CASE(MINT_STIND_R4)
3187 * (float *) sp->data.p = (gfloat)sp[1].data.f;
3189 MINT_IN_CASE(MINT_STIND_R8)
3192 * (double *) sp->data.p = sp[1].data.f;
3194 MINT_IN_CASE(MINT_MONO_ATOMIC_STORE_I4)
3197 InterlockedWrite ((gint32 *) sp->data.p, sp [1].data.i);
3199 #define BINOP(datamem, op) \
3201 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3203 MINT_IN_CASE(MINT_ADD_I4)
3206 MINT_IN_CASE(MINT_ADD_I8)
3209 MINT_IN_CASE(MINT_ADD_R8)
3212 MINT_IN_CASE(MINT_ADD1_I4)
3216 MINT_IN_CASE(MINT_SUB_I4)
3219 MINT_IN_CASE(MINT_SUB_I8)
3222 MINT_IN_CASE(MINT_SUB_R8)
3225 MINT_IN_CASE(MINT_SUB1_I4)
3229 MINT_IN_CASE(MINT_MUL_I4)
3232 MINT_IN_CASE(MINT_MUL_I8)
3235 MINT_IN_CASE(MINT_MUL_R8)
3238 MINT_IN_CASE(MINT_DIV_I4)
3239 if (sp [-1].data.i == 0)
3240 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3241 if (sp [-1].data.i == (-1))
3242 THROW_EX (mono_get_exception_overflow (), ip);
3245 MINT_IN_CASE(MINT_DIV_I8)
3246 if (sp [-1].data.l == 0)
3247 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3248 if (sp [-1].data.l == (-1))
3249 THROW_EX (mono_get_exception_overflow (), ip);
3252 MINT_IN_CASE(MINT_DIV_R8)
3256 #define BINOP_CAST(datamem, op, type) \
3258 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3260 MINT_IN_CASE(MINT_DIV_UN_I4)
3261 if (sp [-1].data.i == 0)
3262 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3263 BINOP_CAST(i, /, guint32);
3265 MINT_IN_CASE(MINT_DIV_UN_I8)
3266 if (sp [-1].data.l == 0)
3267 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3268 BINOP_CAST(l, /, guint64);
3270 MINT_IN_CASE(MINT_REM_I4)
3271 if (sp [-1].data.i == 0)
3272 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3273 if (sp [-1].data.i == (-1))
3274 THROW_EX (mono_get_exception_overflow (), ip);
3277 MINT_IN_CASE(MINT_REM_I8)
3278 if (sp [-1].data.l == 0)
3279 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3280 if (sp [-1].data.l == (-1))
3281 THROW_EX (mono_get_exception_overflow (), ip);
3284 MINT_IN_CASE(MINT_REM_R8)
3285 /* FIXME: what do we actually do here? */
3287 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
3290 MINT_IN_CASE(MINT_REM_UN_I4)
3291 if (sp [-1].data.i == 0)
3292 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3293 BINOP_CAST(i, %, guint32);
3295 MINT_IN_CASE(MINT_REM_UN_I8)
3296 if (sp [-1].data.l == 0)
3297 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3298 BINOP_CAST(l, %, guint64);
3300 MINT_IN_CASE(MINT_AND_I4)
3303 MINT_IN_CASE(MINT_AND_I8)
3306 MINT_IN_CASE(MINT_OR_I4)
3309 MINT_IN_CASE(MINT_OR_I8)
3312 MINT_IN_CASE(MINT_XOR_I4)
3315 MINT_IN_CASE(MINT_XOR_I8)
3319 #define SHIFTOP(datamem, op) \
3321 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
3324 MINT_IN_CASE(MINT_SHL_I4)
3327 MINT_IN_CASE(MINT_SHL_I8)
3330 MINT_IN_CASE(MINT_SHR_I4)
3333 MINT_IN_CASE(MINT_SHR_I8)
3336 MINT_IN_CASE(MINT_SHR_UN_I4)
3338 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
3341 MINT_IN_CASE(MINT_SHR_UN_I8)
3343 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
3346 MINT_IN_CASE(MINT_NEG_I4)
3347 sp [-1].data.i = - sp [-1].data.i;
3350 MINT_IN_CASE(MINT_NEG_I8)
3351 sp [-1].data.l = - sp [-1].data.l;
3354 MINT_IN_CASE(MINT_NEG_R8)
3355 sp [-1].data.f = - sp [-1].data.f;
3358 MINT_IN_CASE(MINT_NOT_I4)
3359 sp [-1].data.i = ~ sp [-1].data.i;
3362 MINT_IN_CASE(MINT_NOT_I8)
3363 sp [-1].data.l = ~ sp [-1].data.l;
3366 MINT_IN_CASE(MINT_CONV_I1_I4)
3367 sp [-1].data.i = (gint8)sp [-1].data.i;
3370 MINT_IN_CASE(MINT_CONV_I1_I8)
3371 sp [-1].data.i = (gint8)sp [-1].data.l;
3374 MINT_IN_CASE(MINT_CONV_I1_R8)
3375 sp [-1].data.i = (gint8)sp [-1].data.f;
3378 MINT_IN_CASE(MINT_CONV_U1_I4)
3379 sp [-1].data.i = (guint8)sp [-1].data.i;
3382 MINT_IN_CASE(MINT_CONV_U1_I8)
3383 sp [-1].data.i = (guint8)sp [-1].data.l;
3386 MINT_IN_CASE(MINT_CONV_U1_R8)
3387 sp [-1].data.i = (guint8)sp [-1].data.f;
3390 MINT_IN_CASE(MINT_CONV_I2_I4)
3391 sp [-1].data.i = (gint16)sp [-1].data.i;
3394 MINT_IN_CASE(MINT_CONV_I2_I8)
3395 sp [-1].data.i = (gint16)sp [-1].data.l;
3398 MINT_IN_CASE(MINT_CONV_I2_R8)
3399 sp [-1].data.i = (gint16)sp [-1].data.f;
3402 MINT_IN_CASE(MINT_CONV_U2_I4)
3403 sp [-1].data.i = (guint16)sp [-1].data.i;
3406 MINT_IN_CASE(MINT_CONV_U2_I8)
3407 sp [-1].data.i = (guint16)sp [-1].data.l;
3410 MINT_IN_CASE(MINT_CONV_U2_R8)
3411 sp [-1].data.i = (guint16)sp [-1].data.f;
3414 MINT_IN_CASE(MINT_CONV_I4_R8)
3415 sp [-1].data.i = (gint32)sp [-1].data.f;
3418 MINT_IN_CASE(MINT_CONV_U4_I8)
3419 MINT_IN_CASE(MINT_CONV_I4_I8)
3420 sp [-1].data.i = (gint32)sp [-1].data.l;
3423 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
3424 sp [-2].data.i = (gint32)sp [-2].data.l;
3427 MINT_IN_CASE(MINT_CONV_U4_R8)
3428 /* needed on arm64 */
3429 if (isinf (sp [-1].data.f))
3432 sp [-1].data.i = (guint32)sp [-1].data.f;
3435 MINT_IN_CASE(MINT_CONV_I8_I4)
3436 sp [-1].data.l = sp [-1].data.i;
3439 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
3440 sp [-2].data.l = sp [-2].data.i;
3443 MINT_IN_CASE(MINT_CONV_I8_U4)
3444 sp [-1].data.l = (guint32)sp [-1].data.i;
3447 MINT_IN_CASE(MINT_CONV_I8_R8)
3448 sp [-1].data.l = (gint64)sp [-1].data.f;
3451 MINT_IN_CASE(MINT_CONV_R4_I4)
3452 sp [-1].data.f = (float)sp [-1].data.i;
3455 MINT_IN_CASE(MINT_CONV_R4_I8)
3456 sp [-1].data.f = (float)sp [-1].data.l;
3459 MINT_IN_CASE(MINT_CONV_R4_R8)
3460 sp [-1].data.f = (float)sp [-1].data.f;
3463 MINT_IN_CASE(MINT_CONV_R8_I4)
3464 sp [-1].data.f = (double)sp [-1].data.i;
3467 MINT_IN_CASE(MINT_CONV_R8_I8)
3468 sp [-1].data.f = (double)sp [-1].data.l;
3471 MINT_IN_CASE(MINT_CONV_U8_I4)
3472 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
3475 MINT_IN_CASE(MINT_CONV_U8_R8)
3476 sp [-1].data.l = (guint64)sp [-1].data.f;
3479 MINT_IN_CASE(MINT_CPOBJ) {
3480 c = rtm->data_items[* (guint16 *)(ip + 1)];
3481 g_assert (c->byval_arg.type == MONO_TYPE_VALUETYPE);
3482 /* if this assertion fails, we need to add a write barrier */
3483 g_assert (!MONO_TYPE_IS_REFERENCE (&c->byval_arg));
3484 stackval_from_data (&c->byval_arg, &sp [-2], sp [-1].data.p, FALSE);
3489 MINT_IN_CASE(MINT_LDOBJ) {
3491 c = rtm->data_items[* (guint16 *)(ip + 1)];
3494 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3495 int size = mono_class_value_size (c, NULL);
3496 sp [-1].data.p = vt_sp;
3497 vt_sp += (size + 7) & ~7;
3499 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
3502 MINT_IN_CASE(MINT_LDSTR)
3503 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3507 MINT_IN_CASE(MINT_NEWOBJ) {
3508 MonoClass *newobj_class;
3509 MonoMethodSignature *csig;
3510 stackval valuetype_this;
3516 token = * (guint16 *)(ip + 1);
3519 child_frame.ip = NULL;
3520 child_frame.ex = NULL;
3522 child_frame.runtime_method = rtm->data_items [token];
3523 csig = mono_method_signature (child_frame.runtime_method->method);
3524 newobj_class = child_frame.runtime_method->method->klass;
3525 /*if (profiling_classes) {
3526 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
3528 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
3531 if (newobj_class->parent == mono_defaults.array_class) {
3532 sp -= csig->param_count;
3533 child_frame.stack_args = sp;
3534 o = ves_array_create (&child_frame, context->domain, newobj_class, csig, sp);
3536 THROW_EX (child_frame.ex, ip);
3537 goto array_constructed;
3540 g_assert (csig->hasthis);
3541 if (csig->param_count) {
3542 sp -= csig->param_count;
3543 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
3545 child_frame.stack_args = sp;
3548 * First arg is the object.
3550 if (newobj_class->valuetype) {
3551 MonoType *t = &newobj_class->byval_arg;
3552 memset (&valuetype_this, 0, sizeof (stackval));
3553 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
3555 valuetype_this.data.p = vt_sp;
3557 sp->data.p = &valuetype_this;
3560 if (newobj_class != mono_defaults.string_class) {
3561 context->managed_code = 0;
3562 o = mono_object_new_checked (context->domain, newobj_class, &error);
3563 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3564 context->managed_code = 1;
3565 if (*mono_thread_interruption_request_flag ())
3566 mono_thread_interruption_checkpoint ();
3570 child_frame.retval = &retval;
3574 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
3576 ves_exec_method_with_context (&child_frame, context, NULL, NULL, -1);
3578 context->current_frame = frame;
3580 if (context->has_resume_state) {
3581 if (frame == context->handler_frame)
3582 SET_RESUME_STATE (context);
3587 if (child_frame.ex) {
3589 * An exception occurred, need to run finally, fault and catch handlers..
3591 frame->ex = child_frame.ex;
3592 goto handle_finally;
3595 * a constructor returns void, but we need to return the object we created
3598 if (newobj_class->valuetype && !newobj_class->enumtype) {
3599 *sp = valuetype_this;
3600 } else if (newobj_class == mono_defaults.string_class) {
3608 MINT_IN_CASE(MINT_CASTCLASS)
3609 c = rtm->data_items [*(guint16 *)(ip + 1)];
3610 if ((o = sp [-1].data.p)) {
3611 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3612 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3614 THROW_EX (mono_get_exception_invalid_cast (), ip);
3618 MINT_IN_CASE(MINT_ISINST)
3619 c = rtm->data_items [*(guint16 *)(ip + 1)];
3620 if ((o = sp [-1].data.p)) {
3621 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3622 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3624 sp [-1].data.p = NULL;
3628 MINT_IN_CASE(MINT_CONV_R_UN_I4)
3629 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
3632 MINT_IN_CASE(MINT_CONV_R_UN_I8)
3633 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
3636 MINT_IN_CASE(MINT_UNBOX)
3637 c = rtm->data_items[*(guint16 *)(ip + 1)];
3641 THROW_EX (mono_get_exception_null_reference (), ip);
3643 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3644 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3645 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
3646 THROW_EX (mono_get_exception_invalid_cast (), ip);
3648 sp [-1].data.p = mono_object_unbox (o);
3651 MINT_IN_CASE(MINT_THROW)
3653 frame->ex_handler = NULL;
3655 sp->data.p = mono_get_exception_null_reference ();
3656 THROW_EX ((MonoException *)sp->data.p, ip);
3658 MINT_IN_CASE(MINT_LDFLDA_UNSAFE)
3660 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3663 MINT_IN_CASE(MINT_LDFLDA)
3666 THROW_EX (mono_get_exception_null_reference (), ip);
3667 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3670 MINT_IN_CASE(MINT_CKNULL)
3673 THROW_EX (mono_get_exception_null_reference (), ip);
3677 #define LDFLD(datamem, fieldtype) \
3678 o = sp [-1].data.p; \
3680 THROW_EX (mono_get_exception_null_reference (), ip); \
3681 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
3684 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
3685 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
3686 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
3687 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
3688 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
3689 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
3690 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
3691 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
3692 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
3693 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
3695 MINT_IN_CASE(MINT_LDFLD_VT)
3698 THROW_EX (mono_get_exception_null_reference (), ip);
3699 i32 = READ32(ip + 2);
3700 sp [-1].data.p = vt_sp;
3701 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3702 vt_sp += (i32 + 7) & ~7;
3706 MINT_IN_CASE(MINT_LDRMFLD) {
3708 MonoClassField *field;
3713 THROW_EX (mono_get_exception_null_reference (), ip);
3714 field = rtm->data_items[* (guint16 *)(ip + 1)];
3716 if (mono_object_is_transparent_proxy (o)) {
3717 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3719 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3720 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3722 addr = (char*)o + field->offset;
3725 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3729 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3730 MonoClassField *field;
3736 THROW_EX (mono_get_exception_null_reference (), ip);
3737 field = rtm->data_items[* (guint16 *)(ip + 1)];
3738 i32 = READ32(ip + 2);
3740 if (mono_object_is_transparent_proxy (o)) {
3741 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3742 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3743 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3745 addr = (char*)o + field->offset;
3748 sp [-1].data.p = vt_sp;
3749 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3750 vt_sp += (i32 + 7) & ~7;
3751 memcpy(sp [-1].data.p, addr, i32);
3755 #define STFLD(datamem, fieldtype) \
3756 o = sp [-2].data.p; \
3758 THROW_EX (mono_get_exception_null_reference (), ip); \
3760 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3763 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3764 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3765 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3766 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3767 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3768 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3769 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3770 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3771 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3772 MINT_IN_CASE(MINT_STFLD_O)
3775 THROW_EX (mono_get_exception_null_reference (), ip);
3777 mono_gc_wbarrier_set_field (o, (char *) o + * (guint16 *)(ip + 1), sp [1].data.p);
3781 MINT_IN_CASE(MINT_STFLD_VT)
3784 THROW_EX (mono_get_exception_null_reference (), ip);
3785 i32 = READ32(ip + 2);
3787 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3788 vt_sp -= (i32 + 7) & ~7;
3792 MINT_IN_CASE(MINT_STRMFLD) {
3793 MonoClassField *field;
3797 THROW_EX (mono_get_exception_null_reference (), ip);
3799 field = rtm->data_items[* (guint16 *)(ip + 1)];
3802 if (mono_object_is_transparent_proxy (o)) {
3803 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3804 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3805 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3807 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3812 MINT_IN_CASE(MINT_STRMFLD_VT) {
3813 MonoClassField *field;
3817 THROW_EX (mono_get_exception_null_reference (), ip);
3818 field = rtm->data_items[* (guint16 *)(ip + 1)];
3819 i32 = READ32(ip + 2);
3822 if (mono_object_is_transparent_proxy (o)) {
3823 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3824 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3825 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3827 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3830 vt_sp -= (i32 + 7) & ~7;
3833 MINT_IN_CASE(MINT_LDSFLDA) {
3834 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3835 sp->data.p = mono_class_static_field_address (context->domain, field);
3840 MINT_IN_CASE(MINT_LDSFLD) {
3841 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3842 gpointer addr = mono_class_static_field_address (context->domain, field);
3843 stackval_from_data (field->type, sp, addr, FALSE);
3848 MINT_IN_CASE(MINT_LDSFLD_VT) {
3849 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3850 gpointer addr = mono_class_static_field_address (context->domain, field);
3851 int size = READ32 (ip + 2);
3855 vt_sp += (size + 7) & ~7;
3856 stackval_from_data (field->type, sp, addr, FALSE);
3860 MINT_IN_CASE(MINT_STSFLD) {
3861 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3862 gpointer addr = mono_class_static_field_address (context->domain, field);
3865 stackval_to_data (field->type, sp, addr, FALSE);
3868 MINT_IN_CASE(MINT_STSFLD_VT) {
3869 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3870 gpointer addr = mono_class_static_field_address (context->domain, field);
3871 int size = READ32 (ip + 2);
3875 stackval_to_data (field->type, sp, addr, FALSE);
3876 vt_sp -= (size + 7) & ~7;
3879 MINT_IN_CASE(MINT_STOBJ_VT) {
3881 c = rtm->data_items[* (guint16 *)(ip + 1)];
3883 size = mono_class_value_size (c, NULL);
3884 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3885 vt_sp -= (size + 7) & ~7;
3889 MINT_IN_CASE(MINT_STOBJ) {
3890 c = rtm->data_items[* (guint16 *)(ip + 1)];
3893 g_assert (!c->byval_arg.byref);
3894 if (MONO_TYPE_IS_REFERENCE (&c->byval_arg))
3895 mono_gc_wbarrier_generic_store (sp [-2].data.p, sp [-1].data.p);
3897 stackval_from_data (&c->byval_arg, sp [-2].data.p, (char *) &sp [-1].data.p, FALSE);
3901 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3902 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3903 THROW_EX (mono_get_exception_overflow (), ip);
3904 sp [-1].data.i = (guint32)sp [-1].data.f;
3907 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3908 if (sp [-1].data.i < 0)
3909 THROW_EX (mono_get_exception_overflow (), ip);
3910 sp [-1].data.l = sp [-1].data.i;
3913 MINT_IN_CASE(MINT_CONV_OVF_U8_I8)
3914 if (sp [-1].data.l < 0)
3915 THROW_EX (mono_get_exception_overflow (), ip);
3918 MINT_IN_CASE(MINT_CONV_OVF_I8_U8)
3919 if ((guint64) sp [-1].data.l > MYGINT64_MAX)
3920 THROW_EX (mono_get_exception_overflow (), ip);
3923 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3924 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3925 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGINT64_MAX)
3926 THROW_EX (mono_get_exception_overflow (), ip);
3927 sp [-1].data.l = (guint64)sp [-1].data.f;
3930 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3931 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3932 THROW_EX (mono_get_exception_overflow (), ip);
3933 sp [-1].data.l = (gint64)sp [-1].data.f;
3936 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3937 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3938 THROW_EX (mono_get_exception_overflow (), ip);
3939 sp [-1].data.i = (mono_u)sp [-1].data.l;
3942 MINT_IN_CASE(MINT_BOX) {
3943 c = rtm->data_items [* (guint16 *)(ip + 1)];
3944 guint16 offset = * (guint16 *)(ip + 2);
3946 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3947 int size = mono_class_value_size (c, NULL);
3948 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3949 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3950 size = (size + 7) & ~7;
3953 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3954 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3955 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3960 MINT_IN_CASE(MINT_NEWARR)
3961 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3962 if (!mono_error_ok (&error)) {
3963 THROW_EX (mono_error_convert_to_exception (&error), ip);
3965 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3967 /*if (profiling_classes) {
3968 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3970 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3974 MINT_IN_CASE(MINT_LDLEN)
3977 THROW_EX (mono_get_exception_null_reference (), ip);
3978 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3981 MINT_IN_CASE(MINT_GETCHR) {
3985 THROW_EX (mono_get_exception_null_reference (), ip);
3986 i32 = sp [-1].data.i;
3987 if (i32 < 0 || i32 >= mono_string_length (s))
3988 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3990 sp [-1].data.i = mono_string_chars(s)[i32];
3994 MINT_IN_CASE(MINT_STRLEN)
3998 THROW_EX (mono_get_exception_null_reference (), ip);
3999 sp [-1].data.i = mono_string_length ((MonoString*) o);
4001 MINT_IN_CASE(MINT_ARRAY_RANK)
4004 THROW_EX (mono_get_exception_null_reference (), ip);
4005 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
4008 MINT_IN_CASE(MINT_LDELEMA)
4009 MINT_IN_CASE(MINT_LDELEMA_TC) {
4010 gboolean needs_typecheck = *ip == MINT_LDELEMA_TC;
4012 MonoClass *klass = rtm->data_items [*(guint16 *) (ip + 1)];
4013 guint16 numargs = *(guint16 *) (ip + 2);
4018 sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck);
4020 THROW_EX (frame->ex, ip);
4025 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
4026 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
4027 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
4028 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
4029 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
4030 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
4031 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
4032 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
4033 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
4034 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
4035 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
4036 MINT_IN_CASE(MINT_LDELEM_VT) {
4044 THROW_EX (mono_get_exception_null_reference (), ip);
4046 aindex = sp [1].data.i;
4047 if (aindex >= mono_array_length (o))
4048 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4051 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
4054 case MINT_LDELEM_I1:
4055 sp [0].data.i = mono_array_get (o, gint8, aindex);
4057 case MINT_LDELEM_U1:
4058 sp [0].data.i = mono_array_get (o, guint8, aindex);
4060 case MINT_LDELEM_I2:
4061 sp [0].data.i = mono_array_get (o, gint16, aindex);
4063 case MINT_LDELEM_U2:
4064 sp [0].data.i = mono_array_get (o, guint16, aindex);
4067 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
4069 case MINT_LDELEM_I4:
4070 sp [0].data.i = mono_array_get (o, gint32, aindex);
4072 case MINT_LDELEM_U4:
4073 sp [0].data.i = mono_array_get (o, guint32, aindex);
4075 case MINT_LDELEM_I8:
4076 sp [0].data.l = mono_array_get (o, guint64, aindex);
4078 case MINT_LDELEM_R4:
4079 sp [0].data.f = mono_array_get (o, float, aindex);
4081 case MINT_LDELEM_R8:
4082 sp [0].data.f = mono_array_get (o, double, aindex);
4084 case MINT_LDELEM_REF:
4085 sp [0].data.p = mono_array_get (o, gpointer, aindex);
4087 case MINT_LDELEM_VT: {
4088 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4089 i32 = READ32 (ip + 2);
4090 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4091 sp [0].data.vt = vt_sp;
4092 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
4093 vt_sp += (i32 + 7) & ~7;
4105 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
4106 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
4107 MINT_IN_CASE(MINT_STELEM_U1) /* fall through */
4108 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
4109 MINT_IN_CASE(MINT_STELEM_U2) /* fall through */
4110 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
4111 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
4112 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
4113 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
4114 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
4115 MINT_IN_CASE(MINT_STELEM_VT) {
4122 THROW_EX (mono_get_exception_null_reference (), ip);
4124 aindex = sp [1].data.i;
4125 if (aindex >= mono_array_length ((MonoArray *)o))
4126 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4130 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
4132 case MINT_STELEM_I1:
4133 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
4135 case MINT_STELEM_U1:
4136 mono_array_set ((MonoArray *) o, guint8, aindex, sp [2].data.i);
4138 case MINT_STELEM_I2:
4139 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
4141 case MINT_STELEM_U2:
4142 mono_array_set ((MonoArray *)o, guint16, aindex, sp [2].data.i);
4144 case MINT_STELEM_I4:
4145 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
4147 case MINT_STELEM_I8:
4148 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
4150 case MINT_STELEM_R4:
4151 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
4153 case MINT_STELEM_R8:
4154 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
4156 case MINT_STELEM_REF: {
4157 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
4158 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4159 if (sp [2].data.p && !isinst_obj)
4160 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
4161 mono_array_setref ((MonoArray *) o, aindex, sp [2].data.p);
4164 case MINT_STELEM_VT: {
4165 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4166 i32 = READ32 (ip + 2);
4167 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4169 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
4170 vt_sp -= (i32 + 7) & ~7;
4181 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
4182 if (sp [-1].data.i < 0)
4183 THROW_EX (mono_get_exception_overflow (), ip);
4186 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
4187 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
4188 THROW_EX (mono_get_exception_overflow (), ip);
4189 sp [-1].data.i = (gint32) sp [-1].data.l;
4192 MINT_IN_CASE(MINT_CONV_OVF_I4_U8)
4193 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGINT32_MAX)
4194 THROW_EX (mono_get_exception_overflow (), ip);
4195 sp [-1].data.i = (gint32) sp [-1].data.l;
4198 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
4199 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
4200 THROW_EX (mono_get_exception_overflow (), ip);
4201 sp [-1].data.i = (gint32) sp [-1].data.f;
4204 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
4205 if (sp [-1].data.i < 0)
4206 THROW_EX (mono_get_exception_overflow (), ip);
4209 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
4210 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
4211 THROW_EX (mono_get_exception_overflow (), ip);
4212 sp [-1].data.i = (guint32) sp [-1].data.l;
4215 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
4216 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
4217 THROW_EX (mono_get_exception_overflow (), ip);
4218 sp [-1].data.i = (guint32) sp [-1].data.f;
4221 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
4222 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
4223 THROW_EX (mono_get_exception_overflow (), ip);
4226 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
4227 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
4228 THROW_EX (mono_get_exception_overflow (), ip);
4229 sp [-1].data.i = (gint16) sp [-1].data.l;
4232 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
4233 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
4234 THROW_EX (mono_get_exception_overflow (), ip);
4235 sp [-1].data.i = (gint16) sp [-1].data.f;
4238 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
4239 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
4240 THROW_EX (mono_get_exception_overflow (), ip);
4243 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
4244 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
4245 THROW_EX (mono_get_exception_overflow (), ip);
4246 sp [-1].data.i = (guint16) sp [-1].data.l;
4249 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
4250 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
4251 THROW_EX (mono_get_exception_overflow (), ip);
4252 sp [-1].data.i = (guint16) sp [-1].data.f;
4255 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
4256 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
4257 THROW_EX (mono_get_exception_overflow (), ip);
4260 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
4261 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
4262 THROW_EX (mono_get_exception_overflow (), ip);
4263 sp [-1].data.i = (gint8) sp [-1].data.l;
4266 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
4267 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
4268 THROW_EX (mono_get_exception_overflow (), ip);
4269 sp [-1].data.i = (gint8) sp [-1].data.f;
4272 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
4273 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
4274 THROW_EX (mono_get_exception_overflow (), ip);
4277 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
4278 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
4279 THROW_EX (mono_get_exception_overflow (), ip);
4280 sp [-1].data.i = (guint8) sp [-1].data.l;
4283 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
4284 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
4285 THROW_EX (mono_get_exception_overflow (), ip);
4286 sp [-1].data.i = (guint8) sp [-1].data.f;
4290 MINT_IN_CASE(MINT_LDELEM)
4291 MINT_IN_CASE(MINT_STELEM)
4292 MINT_IN_CASE(MINT_UNBOX_ANY)
4294 MINT_IN_CASE(MINT_CKFINITE)
4295 if (!isfinite(sp [-1].data.f))
4296 THROW_EX (mono_get_exception_arithmetic (), ip);
4299 MINT_IN_CASE(MINT_MKREFANY) {
4300 c = rtm->data_items [*(guint16 *)(ip + 1)];
4302 /* The value address is on the stack */
4303 gpointer addr = sp [-1].data.p;
4304 /* Push the typedref value on the stack */
4305 sp [-1].data.p = vt_sp;
4306 vt_sp += sizeof (MonoTypedRef);
4308 MonoTypedRef *tref = sp [-1].data.p;
4310 tref->type = &c->byval_arg;
4316 MINT_IN_CASE(MINT_REFANYTYPE) {
4317 MonoTypedRef *tref = sp [-1].data.p;
4318 MonoType *type = tref->type;
4320 vt_sp -= sizeof (MonoTypedRef);
4321 sp [-1].data.p = vt_sp;
4323 *(gpointer*)sp [-1].data.p = type;
4327 MINT_IN_CASE(MINT_REFANYVAL) {
4328 MonoTypedRef *tref = sp [-1].data.p;
4329 gpointer addr = tref->value;
4331 vt_sp -= sizeof (MonoTypedRef);
4333 sp [-1].data.p = addr;
4337 MINT_IN_CASE(MINT_LDTOKEN)
4340 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
4344 MINT_IN_CASE(MINT_ADD_OVF_I4)
4345 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4346 THROW_EX (mono_get_exception_overflow (), ip);
4349 MINT_IN_CASE(MINT_ADD_OVF_I8)
4350 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4351 THROW_EX (mono_get_exception_overflow (), ip);
4354 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
4355 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4356 THROW_EX (mono_get_exception_overflow (), ip);
4357 BINOP_CAST(i, +, guint32);
4359 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
4360 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4361 THROW_EX (mono_get_exception_overflow (), ip);
4362 BINOP_CAST(l, +, guint64);
4364 MINT_IN_CASE(MINT_MUL_OVF_I4)
4365 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4366 THROW_EX (mono_get_exception_overflow (), ip);
4369 MINT_IN_CASE(MINT_MUL_OVF_I8)
4370 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4371 THROW_EX (mono_get_exception_overflow (), ip);
4374 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
4375 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4376 THROW_EX (mono_get_exception_overflow (), ip);
4377 BINOP_CAST(i, *, guint32);
4379 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
4380 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4381 THROW_EX (mono_get_exception_overflow (), ip);
4382 BINOP_CAST(l, *, guint64);
4384 MINT_IN_CASE(MINT_SUB_OVF_I4)
4385 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4386 THROW_EX (mono_get_exception_overflow (), ip);
4389 MINT_IN_CASE(MINT_SUB_OVF_I8)
4390 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4391 THROW_EX (mono_get_exception_overflow (), ip);
4394 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
4395 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4396 THROW_EX (mono_get_exception_overflow (), ip);
4397 BINOP_CAST(i, -, guint32);
4399 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
4400 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4401 THROW_EX (mono_get_exception_overflow (), ip);
4402 BINOP_CAST(l, -, guint64);
4404 MINT_IN_CASE(MINT_ENDFINALLY)
4406 int clause_index = *ip;
4407 if (clause_index == exit_at_finally)
4409 while (sp > frame->stack) {
4413 ip = finally_ips->data;
4414 finally_ips = g_slist_remove (finally_ips, ip);
4421 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
4422 MINT_IN_CASE(MINT_LEAVE_S)
4423 while (sp > frame->stack) {
4427 if (*ip == MINT_LEAVE_S) {
4428 ip += (short) *(ip + 1);
4430 ip += (gint32) READ32 (ip + 1);
4433 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
4434 frame->ex_handler = NULL;
4437 goto handle_finally;
4439 MINT_IN_CASE(MINT_ICALL_V_V)
4440 MINT_IN_CASE(MINT_ICALL_V_P)
4441 MINT_IN_CASE(MINT_ICALL_P_V)
4442 MINT_IN_CASE(MINT_ICALL_P_P)
4443 MINT_IN_CASE(MINT_ICALL_PP_V)
4444 MINT_IN_CASE(MINT_ICALL_PI_V)
4445 MINT_IN_CASE(MINT_ICALL_PP_P)
4446 MINT_IN_CASE(MINT_ICALL_PI_P)
4447 MINT_IN_CASE(MINT_ICALL_PPP_V)
4448 MINT_IN_CASE(MINT_ICALL_PPI_V)
4449 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
4450 if (*mono_thread_interruption_request_flag ()) {
4451 MonoException *exc = mono_thread_interruption_checkpoint ();
4454 context->search_for_handler = 1;
4457 if (frame->ex != NULL)
4458 goto handle_exception;
4461 MINT_IN_CASE(MINT_MONO_LDPTR)
4462 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
4466 MINT_IN_CASE(MINT_MONO_NEWOBJ)
4467 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
4468 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4472 MINT_IN_CASE(MINT_MONO_FREE)
4475 g_error ("that doesn't seem right");
4476 g_free (sp->data.p);
4478 MINT_IN_CASE(MINT_MONO_RETOBJ)
4481 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
4482 mono_method_signature (frame->runtime_method->method)->pinvoke);
4483 if (sp > frame->stack)
4484 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
4486 MINT_IN_CASE(MINT_MONO_TLS) {
4487 MonoTlsKey key = *(gint32 *)(ip + 1);
4488 sp->data.p = ((gpointer (*)()) mono_tls_get_tls_getter (key, FALSE)) ();
4493 MINT_IN_CASE(MINT_MONO_JIT_ATTACH) {
4496 context->original_domain = NULL;
4497 MonoDomain *tls_domain = (MonoDomain *) ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4498 gpointer tls_jit = ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4500 if (tls_domain != context->domain || !tls_jit)
4501 context->original_domain = mono_jit_thread_attach (context->domain);
4504 MINT_IN_CASE(MINT_MONO_JIT_DETACH)
4506 mono_jit_set_domain (context->original_domain);
4509 #define RELOP(datamem, op) \
4511 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
4513 MINT_IN_CASE(MINT_CEQ_I4)
4516 MINT_IN_CASE(MINT_CEQ0_I4)
4517 sp [-1].data.i = (sp [-1].data.i == 0);
4520 MINT_IN_CASE(MINT_CEQ_I8)
4523 MINT_IN_CASE(MINT_CEQ_R8)
4525 if (isunordered (sp [-1].data.f, sp [0].data.f))
4528 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
4531 MINT_IN_CASE(MINT_CGT_I4)
4534 MINT_IN_CASE(MINT_CGT_I8)
4537 MINT_IN_CASE(MINT_CGT_R8)
4539 if (isunordered (sp [-1].data.f, sp [0].data.f))
4542 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4546 #define RELOP_CAST(datamem, op, type) \
4548 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4551 MINT_IN_CASE(MINT_CGT_UN_I4)
4552 RELOP_CAST(i, >, guint32);
4554 MINT_IN_CASE(MINT_CGT_UN_I8)
4555 RELOP_CAST(l, >, guint64);
4557 MINT_IN_CASE(MINT_CGT_UN_R8)
4559 if (isunordered (sp [-1].data.f, sp [0].data.f))
4562 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4565 MINT_IN_CASE(MINT_CLT_I4)
4568 MINT_IN_CASE(MINT_CLT_I8)
4571 MINT_IN_CASE(MINT_CLT_R8)
4573 if (isunordered (sp [-1].data.f, sp [0].data.f))
4576 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4579 MINT_IN_CASE(MINT_CLT_UN_I4)
4580 RELOP_CAST(i, <, guint32);
4582 MINT_IN_CASE(MINT_CLT_UN_I8)
4583 RELOP_CAST(l, <, guint64);
4585 MINT_IN_CASE(MINT_CLT_UN_R8)
4587 if (isunordered (sp [-1].data.f, sp [0].data.f))
4590 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4593 MINT_IN_CASE(MINT_LDFTN) {
4594 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
4599 MINT_IN_CASE(MINT_LDVIRTFTN) {
4600 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
4604 THROW_EX (mono_get_exception_null_reference (), ip - 2);
4606 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
4611 #define LDARG(datamem, argtype) \
4612 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
4616 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
4617 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
4618 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
4619 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
4620 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
4621 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
4622 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
4623 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
4624 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
4625 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
4627 MINT_IN_CASE(MINT_LDARG_VT)
4629 i32 = READ32(ip + 2);
4630 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
4631 vt_sp += (i32 + 7) & ~7;
4636 #define STARG(datamem, argtype) \
4638 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4641 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
4642 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
4643 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
4644 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
4645 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
4646 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
4647 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
4648 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
4649 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
4650 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
4652 MINT_IN_CASE(MINT_STARG_VT)
4653 i32 = READ32(ip + 2);
4655 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
4656 vt_sp -= (i32 + 7) & ~7;
4660 #define STINARG(datamem, argtype) \
4662 int n = * (guint16 *)(ip + 1); \
4663 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
4667 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
4668 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
4669 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
4670 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
4671 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
4672 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
4673 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
4674 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
4675 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
4676 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
4678 MINT_IN_CASE(MINT_STINARG_VT) {
4679 int n = * (guint16 *)(ip + 1);
4680 i32 = READ32(ip + 2);
4681 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
4686 MINT_IN_CASE(MINT_LDARGA)
4687 sp->data.p = frame->args + * (guint16 *)(ip + 1);
4692 #define LDLOC(datamem, argtype) \
4693 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
4697 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
4698 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
4699 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
4700 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
4701 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
4702 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
4703 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
4704 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
4705 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
4706 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
4708 MINT_IN_CASE(MINT_LDLOC_VT)
4710 i32 = READ32(ip + 2);
4711 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
4712 vt_sp += (i32 + 7) & ~7;
4717 MINT_IN_CASE(MINT_LDLOCA_S)
4718 sp->data.p = locals + * (guint16 *)(ip + 1);
4723 #define STLOC(datamem, argtype) \
4725 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4728 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4729 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4730 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4731 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4732 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4733 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4734 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4735 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4736 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4737 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4739 #define STLOC_NP(datamem, argtype) \
4740 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4743 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4744 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4746 MINT_IN_CASE(MINT_STLOC_VT)
4747 i32 = READ32(ip + 2);
4749 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4750 vt_sp -= (i32 + 7) & ~7;
4754 MINT_IN_CASE(MINT_LOCALLOC) {
4755 if (sp != frame->stack + 1) /*FIX?*/
4756 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4758 int len = sp [-1].data.i;
4759 sp [-1].data.p = alloca (len);
4760 MonoMethodHeader *header = mono_method_get_header_checked (frame->runtime_method->method, &error);
4761 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4762 if (header && header->init_locals)
4763 memset (sp [-1].data.p, 0, len);
4767 MINT_IN_CASE(MINT_ENDFILTER)
4768 /* top of stack is result of filter */
4769 frame->retval = &sp [-1];
4771 MINT_IN_CASE(MINT_INITOBJ)
4773 memset (sp->data.vt, 0, READ32(ip + 1));
4776 MINT_IN_CASE(MINT_CPBLK)
4778 if (!sp [0].data.p || !sp [1].data.p)
4779 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4781 /* FIXME: value and size may be int64... */
4782 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4785 MINT_IN_CASE(MINT_CONSTRAINED_) {
4787 /* FIXME: implement */
4789 token = READ32 (ip);
4794 MINT_IN_CASE(MINT_INITBLK)
4797 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4799 /* FIXME: value and size may be int64... */
4800 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4803 MINT_IN_CASE(MINT_NO_)
4804 /* FIXME: implement */
4808 MINT_IN_CASE(MINT_RETHROW)
4810 * need to clarify what this should actually do:
4811 * start the search from the last found handler in
4812 * this method or continue in the caller or what.
4813 * Also, do we need to run finally/fault handlers after a retrow?
4814 * Well, this implementation will follow the usual search
4815 * for an handler, considering the current ip as throw spot.
4816 * We need to NULL frame->ex_handler for the later code to
4817 * actually run the new found handler.
4819 frame->ex_handler = NULL;
4820 THROW_EX (frame->ex, ip - 1);
4823 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4824 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4828 g_assert_not_reached ();
4830 * Exception handling code.
4831 * The exception object is stored in frame->ex.
4838 MonoInvocation *inv;
4839 MonoExceptionClause *clause;
4845 g_print ("* Handling exception '%s' at IL_%04x\n",
4846 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4847 rtm == NULL ? 0 : frame->ip - rtm->code);
4849 if (die_on_exception)
4852 for (inv = frame; inv; inv = inv->parent) {
4854 if (inv->runtime_method == NULL)
4856 method = inv->runtime_method->method;
4857 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4859 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4861 if (inv->ip == NULL)
4863 ip_offset = inv->ip - inv->runtime_method->code;
4864 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4865 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4866 clause = &inv->runtime_method->clauses [i];
4868 g_print ("* clause [%d]: %p\n", i, clause);
4870 if (!MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4873 if (clause->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
4876 g_print ("* Filter found at '%s'\n", method->name);
4878 MonoInvocation dup_frame;
4880 memcpy (&dup_frame, inv, sizeof (MonoInvocation));
4881 dup_frame.retval = &retval;
4882 ves_exec_method_with_context (&dup_frame, context, inv->runtime_method->code + clause->data.filter_offset, frame->ex, -1);
4883 if (dup_frame.retval->data.i) {
4886 g_print ("* Matched Filter at '%s'\n", method->name);
4888 inv->ex_handler = clause;
4889 goto handle_finally;
4891 } else if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE) {
4892 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4893 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4896 * OK, we found an handler, now we need to execute the finally
4897 * and fault blocks before branching to the handler code.
4901 g_print ("* Found handler at '%s'\n", method->name);
4903 inv->ex_handler = clause;
4904 goto handle_finally;
4910 * If we get here, no handler was found: print a stack trace.
4912 for (inv = frame; inv; inv = inv->parent) {
4913 if (inv->invoke_trap)
4914 goto handle_finally;
4917 ex_obj = (MonoObject *) frame->ex;
4918 mono_unhandled_exception (ex_obj);
4919 MonoJitTlsData *jit_tls = (MonoJitTlsData *) mono_tls_get_jit_tls ();
4920 jit_tls->abort_func (ex_obj);
4921 g_assert_not_reached ();
4927 MonoExceptionClause *clause;
4928 GSList *old_list = finally_ips;
4929 MonoMethod *method = frame->runtime_method->method;
4930 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4931 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4935 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4937 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4938 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4941 ip_offset = frame->ip - rtm->code;
4943 if (endfinally_ip != NULL)
4944 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4945 for (i = 0; i < header->num_clauses; ++i)
4946 if (frame->ex_handler == &rtm->clauses [i])
4950 clause = &rtm->clauses [i];
4951 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4952 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4953 ip = rtm->code + clause->handler_offset;
4954 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4957 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4963 endfinally_ip = NULL;
4965 if (old_list != finally_ips && finally_ips) {
4966 ip = finally_ips->data;
4967 finally_ips = g_slist_remove (finally_ips, ip);
4968 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4973 * If an exception is set, we need to execute the fault handler, too,
4974 * otherwise, we continue normally.
4984 MonoExceptionClause *clause;
4985 MonoMethod *method = frame->runtime_method->method;
4986 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4987 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4991 g_print ("* Handle fault\n");
4993 ip_offset = frame->ip - rtm->code;
4994 for (i = 0; i < header->num_clauses; ++i) {
4995 clause = &rtm->clauses [i];
4996 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4997 ip = rtm->code + clause->handler_offset;
5000 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
5006 * If the handler for the exception was found in this method, we jump
5007 * to it right away, otherwise we return and let the caller run
5008 * the finally, fault and catch blocks.
5009 * This same code should be present in the endfault opcode, but it
5010 * is corrently not assigned in the ECMA specs: LAMESPEC.
5012 if (frame->ex_handler) {
5015 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
5017 ip = rtm->code + frame->ex_handler->handler_offset;
5019 vt_sp = (unsigned char *) sp + rtm->stack_size;
5020 sp->data.p = frame->ex;
5031 ves_exec_method (MonoInvocation *frame)
5033 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5034 ThreadContext context_struct;
5041 mono_unhandled_exception ((MonoObject*)frame->ex);
5044 if (context == NULL) {
5045 context = &context_struct;
5046 context_struct.domain = mono_domain_get ();
5047 context_struct.base_frame = frame;
5048 context_struct.current_frame = NULL;
5049 context_struct.env_frame = frame;
5050 context_struct.current_env = &env;
5051 context_struct.search_for_handler = 0;
5052 context_struct.managed_code = 0;
5053 mono_native_tls_set_value (thread_context_id, context);
5056 frame->parent = context->current_frame;
5057 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
5058 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5059 context->managed_code = 1;
5060 ves_exec_method_with_context (frame, context, NULL, NULL, -1);
5061 context->managed_code = 0;
5063 if (context != &context_struct && context->current_env) {
5064 context->env_frame->ex = frame->ex;
5065 longjmp (*context->current_env, 1);
5068 mono_unhandled_exception ((MonoObject*)frame->ex);
5070 if (context->base_frame == frame)
5071 mono_native_tls_set_value (thread_context_id, NULL);
5073 context->current_frame = frame->parent;
5077 mono_interp_parse_options (const char *options)
5081 args = g_strsplit (options, ",", -1);
5082 for (ptr = args; ptr && *ptr; ptr ++) {
5085 if (strncmp (arg, "jit=", 4) == 0)
5086 jit_classes = g_slist_prepend (jit_classes, arg + 4);
5093 mono_native_tls_alloc (&thread_context_id, NULL);
5094 mono_native_tls_set_value (thread_context_id, NULL);
5096 mono_interp_transform_init ();
5099 typedef int (*TestMethod) (void);
5102 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
5104 int result, expected, failed, cfailed, run;
5105 double elapsed, transform_time;
5107 MonoObject *result_obj;
5108 static gboolean filter_method_init = FALSE;
5109 static const char *filter_method = NULL;
5111 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
5112 cfailed = failed = run = 0;
5113 transform_time = elapsed = 0.0;
5115 g_timer_start (timer);
5116 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5117 MonoObject *exc = NULL;
5119 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5121 mono_error_cleanup (&error); /* FIXME don't swallow the error */
5125 if (!filter_method_init) {
5126 filter_method = g_getenv ("INTERP_FILTER_METHOD");
5127 filter_method_init = TRUE;
5129 gboolean filter = FALSE;
5130 if (filter_method) {
5131 const char *name = filter_method;
5133 if ((strchr (name, '.') > name) || strchr (name, ':')) {
5134 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
5135 filter = mono_method_desc_full_match (desc, method);
5136 mono_method_desc_free (desc);
5138 filter = strcmp (method->name, name) == 0;
5140 } else { /* no filter, check for `Category' attribute on method */
5142 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
5143 mono_error_cleanup (&error);
5147 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
5148 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
5149 if (centry->ctor == NULL)
5152 MonoClass *klass = centry->ctor->klass;
5153 if (strcmp (klass->name, "CategoryAttribute"))
5156 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
5157 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
5158 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
5159 mono_error_cleanup (&error);
5160 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
5161 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
5162 mono_error_cleanup (&error);
5163 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
5164 mono_error_cleanup (&error);
5165 if (!strcmp (utf8_str, "!INTERPRETER")) {
5166 g_print ("skip %s...\n", method->name);
5172 if (strncmp (method->name, "test_", 5) == 0 && filter) {
5173 MonoError interp_error;
5174 MonoObject *exc = NULL;
5176 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
5177 if (!mono_error_ok (&interp_error)) {
5179 g_print ("Test '%s' execution failed.\n", method->name);
5180 } else if (exc != NULL) {
5181 g_print ("Exception in Test '%s' occured:\n", method->name);
5182 mono_object_describe (exc);
5186 result = *(gint32 *) mono_object_unbox (result_obj);
5187 expected = atoi (method->name + 5); // FIXME: oh no.
5190 if (result != expected) {
5192 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
5197 g_timer_stop (timer);
5198 elapsed = g_timer_elapsed (timer, NULL);
5199 if (failed > 0 || cfailed > 0){
5200 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
5201 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
5203 g_print ("Results: total tests: %d, all pass \n", run);
5206 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
5207 elapsed - transform_time, transform_time);
5208 *total += failed + cfailed;
5213 interp_regression (MonoImage *image, int verbose, int *total_run)
5216 GTimer *timer = g_timer_new ();
5217 MonoDomain *domain = mono_domain_get ();
5221 /* load the metadata */
5222 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5224 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5226 mono_error_cleanup (&error);
5229 mono_class_init (method->klass);
5234 interp_regression_step (image, verbose, total_run, &total, timer, domain);
5236 g_timer_destroy (timer);
5241 mono_interp_regression_list (int verbose, int count, char *images [])
5243 int i, total, total_run, run;
5245 total_run = total = 0;
5246 for (i = 0; i < count; ++i) {
5247 MonoAssembly *ass = mono_assembly_open_predicate (images [i], FALSE, FALSE, NULL, NULL, NULL);
5249 g_warning ("failed to load assembly: %s", images [i]);
5252 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
5256 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
5258 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);
5265 * mono_interp_set_resume_state:
5267 * Set the state the interpeter will continue to execute from after execution returns to the interpreter.
5270 mono_interp_set_resume_state (MonoException *ex, StackFrameInfo *frame, gpointer handler_ip)
5272 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5274 context->has_resume_state = TRUE;
5275 context->handler_frame = frame->interp_frame;
5276 /* This is on the stack, so it doesn't need a wbarrier */
5277 context->handler_frame->ex = ex;
5278 context->handler_ip = handler_ip;
5282 * mono_interp_run_finally:
5284 * Run the finally clause identified by CLAUSE_INDEX in the intepreter frame given by
5285 * frame->interp_frame.
5288 mono_interp_run_finally (StackFrameInfo *frame, int clause_index, gpointer handler_ip)
5290 MonoInvocation *iframe = frame->interp_frame;
5291 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
5293 ves_exec_method_with_context (iframe, context, handler_ip, NULL, clause_index);
5297 MonoInvocation *current;
5301 * mono_interp_frame_iter_init:
5303 * Initialize an iterator for iterating through interpreted frames.
5306 mono_interp_frame_iter_init (MonoInterpStackIter *iter, gpointer interp_exit_data)
5308 StackIter *stack_iter = (StackIter*)iter;
5310 stack_iter->current = (MonoInvocation*)interp_exit_data;
5314 mono_interp_frame_iter_next (MonoInterpStackIter *iter, StackFrameInfo *frame)
5316 StackIter *stack_iter = (StackIter*)iter;
5317 MonoInvocation *iframe = stack_iter->current;
5319 memset (frame, 0, sizeof (StackFrameInfo));
5320 /* pinvoke frames doesn't have runtime_method set */
5321 while (iframe && !iframe->runtime_method)
5322 iframe = iframe->parent;
5326 frame->type = FRAME_TYPE_INTERP;
5327 frame->interp_frame = iframe;
5328 frame->method = iframe->runtime_method->method;
5329 frame->actual_method = frame->method;
5330 /* This is the offset in the interpreter IR */
5331 frame->native_offset = iframe->ip - iframe->runtime_method->code;
5332 frame->ji = iframe->runtime_method->jinfo;
5334 stack_iter->current = iframe->parent;