2 * PLEASE NOTE: This is a research prototype.
5 * interp.c: Interpreter for CIL byte codes
8 * Paolo Molaro (lupus@ximian.com)
9 * Miguel de Icaza (miguel@ximian.com)
10 * Dietmar Maurer (dietmar@ximian.com)
12 * (C) 2001, 2002 Ximian, Inc.
27 #include <mono/utils/gc_wrapper.h>
33 # define alloca __builtin_alloca
37 /* trim excessive headers */
38 #include <mono/metadata/image.h>
39 #include <mono/metadata/assembly.h>
40 #include <mono/metadata/cil-coff.h>
41 #include <mono/metadata/mono-endian.h>
42 #include <mono/metadata/tabledefs.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/loader.h>
45 #include <mono/metadata/threads.h>
46 #include <mono/metadata/threadpool.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/appdomain.h>
49 #include <mono/metadata/reflection.h>
50 #include <mono/metadata/reflection-internals.h>
51 #include <mono/metadata/exception.h>
52 #include <mono/metadata/verify.h>
53 #include <mono/metadata/opcodes.h>
54 #include <mono/metadata/debug-helpers.h>
55 #include <mono/metadata/mono-config.h>
56 #include <mono/metadata/marshal.h>
57 #include <mono/metadata/environment.h>
58 #include <mono/metadata/mono-debug.h>
61 #include "interp-internals.h"
65 #include <mono/mini/mini.h>
66 #include <mono/mini/jit-icalls.h>
69 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
72 #define finite _finite
76 #define finite isfinite
80 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) \
82 (frame)->parent = (parent_frame); \
83 (frame)->stack_args = (method_args); \
84 (frame)->retval = (method_retval); \
85 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
88 (frame)->invoke_trap = 0; \
91 void ves_exec_method (MonoInvocation *frame);
93 static char* dump_stack (stackval *stack, stackval *sp);
94 static char* dump_frame (MonoInvocation *inv);
95 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
96 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
98 typedef void (*ICallMethod) (MonoInvocation *frame);
100 static guint32 die_on_exception = 0;
101 static MonoNativeTlsKey thread_context_id;
103 static char* dump_args (MonoInvocation *inv);
105 #define DEBUG_INTERP 0
108 int mono_interp_traceopt = 2;
109 /* If true, then we output the opcodes as we interpret them */
110 static int global_tracing = 2;
112 static int debug_indent_level = 0;
114 static int break_on_method = 0;
115 static int nested_trace = 0;
116 static GList *db_methods = NULL;
123 for (h = 0; h < debug_indent_level; h++)
128 db_match_method (gpointer data, gpointer user_data)
130 MonoMethod *m = (MonoMethod*)user_data;
131 MonoMethodDesc *desc = data;
133 if (mono_method_desc_full_match (desc, m))
137 static void debug_enter (MonoInvocation *frame, int *tracing)
140 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
142 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
146 MonoMethod *method = frame->runtime_method->method;
147 char *mn, *args = dump_args (frame);
148 debug_indent_level++;
150 mn = mono_method_full_name (method, FALSE);
151 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
153 g_print ("%s)\n", args);
156 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
157 mono_profiler_method_enter (frame->runtime_method->method);
161 #define DEBUG_LEAVE() \
164 args = dump_retval (frame); \
166 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
167 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
169 g_print (" => %s\n", args); \
171 debug_indent_level--; \
172 if (tracing == 3) global_tracing = 0; \
174 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
175 mono_profiler_method_leave (frame->runtime_method->method);
179 int mono_interp_traceopt = 0;
180 static void debug_enter (MonoInvocation *frame, int *tracing)
183 #define DEBUG_LEAVE()
188 interp_ex_handler (MonoException *ex) {
190 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
194 stack_trace = dump_frame (context->current_frame);
195 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
196 g_free (stack_trace);
197 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
198 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
199 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
200 fprintf(stderr, "Nothing can catch this exception: ");
201 fprintf(stderr, "%s", ex->object.vtable->klass->name);
202 if (ex->message != NULL) {
203 char *m = mono_string_to_utf8_checked (ex->message, &error);
204 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
205 fprintf(stderr, ": %s", m);
208 fprintf(stderr, "\n%s\n", strace);
210 if (ex->inner_ex != NULL) {
211 ex = (MonoException *)ex->inner_ex;
212 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
213 if (ex->message != NULL) {
214 char *m = mono_string_to_utf8_checked (ex->message, &error);
215 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
216 fprintf(stderr, ": %s", m);
219 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
220 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
221 fprintf(stderr, "\n");
222 fprintf(stderr, "%s\n", strace);
225 /* wait for other threads to also collapse */
226 // Sleep(1000); // TODO: proper sleep
229 context->env_frame->ex = ex;
230 context->search_for_handler = 1;
231 longjmp (*context->current_env, 1);
235 ves_real_abort (int line, MonoMethod *mh,
236 const unsigned short *ip, stackval *stack, stackval *sp)
239 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
240 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
241 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
242 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
243 g_print ("0x%04x %02x\n",
244 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
245 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
247 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
250 #define ves_abort() \
252 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
253 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
256 static mono_mutex_t runtime_method_lookup_section;
259 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
264 mono_os_mutex_lock (&runtime_method_lookup_section);
265 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
266 mono_os_mutex_unlock (&runtime_method_lookup_section);
269 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
270 memset (rtm, 0, sizeof (*rtm));
271 rtm->method = method;
272 rtm->param_count = mono_method_signature (method)->param_count;
273 rtm->hasthis = mono_method_signature (method)->hasthis;
274 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
275 mono_os_mutex_unlock (&runtime_method_lookup_section);
281 mono_interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
283 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
284 method = mono_marshal_get_synchronized_wrapper (method);
285 return mono_interp_get_runtime_method (domain, method, error);
288 static inline RuntimeMethod*
289 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
291 MonoMethod *m = runtime_method->method;
294 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
295 RuntimeMethod *ret = NULL;
296 if (mono_object_is_transparent_proxy (obj)) {
297 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
298 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
299 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
300 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
301 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
303 ret = runtime_method;
308 mono_class_setup_vtable (obj->vtable->klass);
310 int slot = mono_method_get_vtable_slot (m);
311 if (mono_class_is_interface (m->klass)) {
312 g_assert (obj->vtable->klass != m->klass);
313 /* TODO: interface offset lookup is slow, go through IMT instead */
314 gboolean non_exact_match;
315 slot += mono_class_interface_offset_with_variance (obj->vtable->klass, m->klass, &non_exact_match);
318 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
319 if (m->is_inflated && mono_method_get_context (m)->method_inst) {
320 MonoGenericContext context = { NULL, NULL };
322 if (mono_class_is_ginst (virtual_method->klass))
323 context.class_inst = mono_class_get_generic_class (virtual_method->klass)->context.class_inst;
324 else if (mono_class_is_gtd (virtual_method->klass))
325 context.class_inst = mono_class_get_generic_container (virtual_method->klass)->context.class_inst;
326 context.method_inst = mono_method_get_context (m)->method_inst;
328 virtual_method = mono_class_inflate_generic_method_checked (virtual_method, &context, &error);
329 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
331 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
332 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
333 return virtual_runtime_method;
337 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
340 switch (type->type) {
341 case MONO_TYPE_OBJECT:
342 case MONO_TYPE_CLASS:
343 case MONO_TYPE_STRING:
344 case MONO_TYPE_ARRAY:
345 case MONO_TYPE_SZARRAY:
350 result->data.p = *(gpointer*)data;
353 switch (type->type) {
357 result->data.i = *(gint8*)data;
360 case MONO_TYPE_BOOLEAN:
361 result->data.i = *(guint8*)data;
364 result->data.i = *(gint16*)data;
368 result->data.i = *(guint16*)data;
371 result->data.i = *(gint32*)data;
375 result->data.nati = *(mono_i*)data;
378 result->data.p = *(gpointer*)data;
381 result->data.i = *(guint32*)data;
384 result->data.f = *(float*)data;
388 result->data.l = *(gint64*)data;
391 result->data.f = *(double*)data;
393 case MONO_TYPE_STRING:
394 case MONO_TYPE_SZARRAY:
395 case MONO_TYPE_CLASS:
396 case MONO_TYPE_OBJECT:
397 case MONO_TYPE_ARRAY:
398 result->data.p = *(gpointer*)data;
400 case MONO_TYPE_VALUETYPE:
401 if (type->data.klass->enumtype) {
402 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
405 mono_value_copy (result->data.vt, data, type->data.klass);
407 case MONO_TYPE_GENERICINST:
408 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 case MONO_TYPE_PTR: {
487 gpointer *p = (gpointer*)data;
491 case MONO_TYPE_VALUETYPE:
492 if (type->data.klass->enumtype) {
493 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
496 mono_value_copy (data, val->data.vt, type->data.klass);
498 case MONO_TYPE_GENERICINST:
499 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
502 g_warning ("got type %x", type->type);
503 g_assert_not_reached ();
508 fill_in_trace (MonoException *exception, MonoInvocation *frame)
510 char *stack_trace = dump_frame (frame);
511 MonoDomain *domain = mono_domain_get();
512 (exception)->stack_trace = mono_string_new (domain, stack_trace);
513 (exception)->trace_ips = get_trace_ips (domain, frame);
514 g_free (stack_trace);
517 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
519 #define THROW_EX(exception,ex_ip) \
521 frame->ip = (ex_ip); \
522 frame->ex = (MonoException*)(exception); \
523 FILL_IN_TRACE(frame->ex, frame); \
524 goto handle_exception; \
528 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
531 intptr_t *lower_bounds;
536 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
537 for (i = 0; i < sig->param_count; ++i) {
538 lengths [i] = values->data.i;
541 if (klass->rank == sig->param_count) {
542 /* Only lengths provided. */
545 /* lower bounds are first. */
546 lower_bounds = (intptr_t *) lengths;
547 lengths += klass->rank;
549 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
550 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
555 ves_array_set (MonoInvocation *frame)
557 stackval *sp = frame->stack_args + 1;
561 gint32 i, t, pos, esize;
565 o = frame->stack_args->data.p;
567 ac = o->vtable->klass;
569 g_assert (ac->rank >= 1);
572 if (ao->bounds != NULL) {
573 pos -= ao->bounds [0].lower_bound;
574 for (i = 1; i < ac->rank; i++) {
575 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
576 ao->bounds [i].length) {
577 frame->ex = mono_get_exception_index_out_of_range ();
578 FILL_IN_TRACE(frame->ex, frame);
581 pos = pos*ao->bounds [i].length + sp [i].data.i -
582 ao->bounds [i].lower_bound;
584 } else if (pos >= ao->max_length) {
585 frame->ex = mono_get_exception_index_out_of_range ();
586 FILL_IN_TRACE(frame->ex, frame);
591 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
593 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
594 mono_error_cleanup (&error);
596 frame->ex = mono_get_exception_array_type_mismatch ();
597 FILL_IN_TRACE (frame->ex, frame);
602 esize = mono_array_element_size (ac);
603 ea = mono_array_addr_with_size (ao, esize, pos);
605 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
606 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
610 ves_array_get (MonoInvocation *frame)
612 stackval *sp = frame->stack_args + 1;
616 gint32 i, t, pos, esize;
620 o = frame->stack_args->data.p;
622 ac = o->vtable->klass;
624 g_assert (ac->rank >= 1);
627 if (ao->bounds != NULL) {
628 pos -= ao->bounds [0].lower_bound;
629 for (i = 1; i < ac->rank; i++) {
630 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
631 ao->bounds [i].length) {
632 frame->ex = mono_get_exception_index_out_of_range ();
633 FILL_IN_TRACE(frame->ex, frame);
637 pos = pos*ao->bounds [i].length + sp [i].data.i -
638 ao->bounds [i].lower_bound;
640 } else if (pos >= ao->max_length) {
641 frame->ex = mono_get_exception_index_out_of_range ();
642 FILL_IN_TRACE(frame->ex, frame);
646 esize = mono_array_element_size (ac);
647 ea = mono_array_addr_with_size (ao, esize, pos);
649 mt = mono_method_signature (frame->runtime_method->method)->ret;
650 stackval_from_data (mt, frame->retval, ea, FALSE);
654 ves_array_element_address (MonoInvocation *frame, MonoClass *required_type, MonoArray *ao, stackval *sp, gboolean needs_typecheck)
656 gint32 i, pos, esize;
657 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
659 g_assert (ac->rank >= 1);
662 if (ao->bounds != NULL) {
663 pos -= ao->bounds [0].lower_bound;
664 for (i = 1; i < ac->rank; i++) {
665 if ((sp [i].data.i - ao->bounds [i].lower_bound) >= ao->bounds [i].length) {
666 frame->ex = mono_get_exception_index_out_of_range ();
667 FILL_IN_TRACE(frame->ex, frame);
670 pos = pos * ao->bounds [i].length + sp [i].data.i - ao->bounds [i].lower_bound;
672 } else if (pos >= ao->max_length) {
673 frame->ex = mono_get_exception_index_out_of_range ();
674 FILL_IN_TRACE(frame->ex, frame);
678 if (needs_typecheck && !mono_class_is_assignable_from (mono_object_class ((MonoObject *) ao)->element_class, required_type->element_class)) {
679 frame->ex = mono_get_exception_array_type_mismatch ();
680 FILL_IN_TRACE (frame->ex, frame);
683 esize = mono_array_element_size (ac);
684 return mono_array_addr_with_size (ao, esize, pos);
688 interp_walk_stack_with_ctx (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data)
691 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
693 MonoInvocation *frame = context->current_frame;
696 MonoStackFrameInfo fi;
697 memset (&fi, 0, sizeof (MonoStackFrameInfo));
699 /* TODO: hack to make some asserts happy. */
700 fi.ji = (MonoJitInfo *) frame->runtime_method;
702 if (frame->runtime_method)
703 fi.method = fi.actual_method = frame->runtime_method->method;
705 if (!fi.method || (fi.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (fi.method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
707 fi.type = FRAME_TYPE_MANAGED_TO_NATIVE;
709 MonoMethodHeader *hd = mono_method_get_header_checked (fi.method, &error);
710 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
711 fi.type = FRAME_TYPE_MANAGED;
712 fi.il_offset = frame->ip - (const unsigned short *) hd->code;
713 if (!fi.method->wrapper_type)
717 if (func (&fi, ctx, user_data))
719 frame = frame->parent;
725 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
727 struct _MethodArguments {
736 typedef struct _MethodArguments MethodArguments;
738 // TODO: this function is also arch dependent (register width).
739 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
741 // TODO: don't malloc this data structure.
742 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
747 for (int i = 0; i < sig->param_count; i++) {
748 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
750 case MONO_TYPE_BOOLEAN:
761 case MONO_TYPE_SZARRAY:
762 case MONO_TYPE_CLASS:
763 case MONO_TYPE_OBJECT:
764 case MONO_TYPE_STRING:
766 case MONO_TYPE_VALUETYPE:
767 case MONO_TYPE_GENERICINST:
775 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
780 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
783 margs->fargs = g_malloc0 (sizeof (double) * margs->flen);
786 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs->ilen);
789 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs->flen);
796 margs->iargs [0] = frame->stack_args->data.p;
800 for (int i = 0; i < sig->param_count; i++) {
801 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
803 case MONO_TYPE_BOOLEAN:
814 case MONO_TYPE_SZARRAY:
815 case MONO_TYPE_CLASS:
816 case MONO_TYPE_OBJECT:
817 case MONO_TYPE_STRING:
819 case MONO_TYPE_VALUETYPE:
820 case MONO_TYPE_GENERICINST:
821 margs->iargs [int_i] = frame->stack_args [i].data.p;
823 g_print ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
829 margs->fargs [int_f] = frame->stack_args [i].data.f;
833 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
837 switch (sig->ret->type) {
838 case MONO_TYPE_BOOLEAN:
849 case MONO_TYPE_SZARRAY:
850 case MONO_TYPE_CLASS:
851 case MONO_TYPE_OBJECT:
852 case MONO_TYPE_STRING:
854 case MONO_TYPE_VALUETYPE:
855 case MONO_TYPE_GENERICINST:
856 margs->retval = &(frame->retval->data.p);
860 margs->retval = &(frame->retval->data.p);
861 margs->is_float_ret = 1;
864 margs->retval = NULL;
867 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig->ret->type);
874 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
877 MonoInvocation *old_frame = context->current_frame;
878 MonoInvocation *old_env_frame = context->env_frame;
879 jmp_buf *old_env = context->current_env;
882 context->current_frame = old_frame;
883 context->env_frame = old_env_frame;
884 context->current_env = old_env;
885 context->managed_code = 1;
890 context->env_frame = frame;
891 context->current_env = &env;
893 g_assert (!frame->runtime_method);
894 if (!mono_interp_enter_icall_trampoline) {
896 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
898 // mono_tramp_info_register (info, NULL);
901 MethodArguments *margs = build_args_from_sig (sig, frame);
903 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
904 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
907 context->current_frame = frame;
908 context->managed_code = 0;
910 mono_interp_enter_icall_trampoline (addr, margs);
912 context->managed_code = 1;
913 /* domain can only be changed by native code */
914 context->domain = mono_domain_get ();
916 if (*mono_thread_interruption_request_flag ()) {
917 MonoException *exc = mono_thread_interruption_checkpoint ();
920 context->search_for_handler = 1;
924 if (!frame->ex && !MONO_TYPE_ISSTRUCT (sig->ret))
925 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
927 context->current_frame = old_frame;
928 context->env_frame = old_env_frame;
929 context->current_env = old_env;
931 g_free (margs->iargs);
932 g_free (margs->fargs);
937 mono_interp_init_delegate (MonoDelegate *del)
940 del->method = ((RuntimeMethod *) del->method_ptr)->method;
945 * runtime specifies that the implementation of the method is automatically
946 * provided by the runtime and is primarily used for the methods of delegates.
949 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
951 MonoMethod *method = frame->runtime_method->method;
952 const char *name = method->name;
953 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
954 MonoObject *isinst_obj;
957 mono_class_init (method->klass);
959 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
960 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
961 if (obj && isinst_obj) {
962 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
963 ves_array_set (frame);
966 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
967 ves_array_get (frame);
972 g_error ("Don't know how to exec runtime method %s.%s::%s",
973 method->klass->name_space, method->klass->name,
978 dump_stack (stackval *stack, stackval *sp)
981 GString *str = g_string_new ("");
984 return g_string_free (str, FALSE);
987 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
990 return g_string_free (str, FALSE);
994 dump_stackval (GString *str, stackval *s, MonoType *type)
996 switch (type->type) {
1003 case MONO_TYPE_CHAR:
1004 case MONO_TYPE_BOOLEAN:
1005 g_string_append_printf (str, "[%d] ", s->data.i);
1007 case MONO_TYPE_STRING:
1008 case MONO_TYPE_SZARRAY:
1009 case MONO_TYPE_CLASS:
1010 case MONO_TYPE_OBJECT:
1011 case MONO_TYPE_ARRAY:
1015 g_string_append_printf (str, "[%p] ", s->data.p);
1017 case MONO_TYPE_VALUETYPE:
1018 if (type->data.klass->enumtype)
1019 g_string_append_printf (str, "[%d] ", s->data.i);
1021 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1025 g_string_append_printf (str, "[%g] ", s->data.f);
1030 GString *res = g_string_new ("");
1031 mono_type_get_desc (res, type, TRUE);
1032 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1033 g_string_free (res, TRUE);
1040 dump_args (MonoInvocation *inv)
1042 GString *str = g_string_new ("");
1044 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1046 if (signature->param_count == 0 && !signature->hasthis)
1047 return g_string_free (str, FALSE);
1049 if (signature->hasthis) {
1050 MonoMethod *method = inv->runtime_method->method;
1051 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1054 for (i = 0; i < signature->param_count; ++i)
1055 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1057 return g_string_free (str, FALSE);
1061 dump_retval (MonoInvocation *inv)
1063 GString *str = g_string_new ("");
1064 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1066 if (ret->type != MONO_TYPE_VOID)
1067 dump_stackval (str, inv->retval, ret);
1069 return g_string_free (str, FALSE);
1073 dump_frame (MonoInvocation *inv)
1075 GString *str = g_string_new ("");
1080 for (i = 0; inv; inv = inv->parent) {
1081 if (inv->runtime_method != NULL) {
1082 MonoMethod *method = inv->runtime_method->method;
1086 const char * opname = "";
1088 gchar *source = NULL;
1092 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1093 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1094 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1095 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1099 opname = mono_interp_opname [*inv->ip];
1100 codep = inv->ip - inv->runtime_method->code;
1101 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1106 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1107 source = mono_debug_method_lookup_location (minfo, codep);
1111 args = dump_args (inv);
1112 name = mono_method_full_name (method, TRUE);
1114 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1116 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1123 return g_string_free (str, FALSE);
1127 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1131 MonoInvocation *inv;
1134 for (i = 0, inv = top; inv; inv = inv->parent)
1135 if (inv->runtime_method != NULL)
1138 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1139 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1141 for (i = 0, inv = top; inv; inv = inv->parent)
1142 if (inv->runtime_method != NULL) {
1143 mono_array_set (res, gpointer, i, inv->runtime_method);
1145 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1153 #define MYGUINT64_MAX 18446744073709551615ULL
1154 #define MYGINT64_MAX 9223372036854775807LL
1155 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1157 #define MYGUINT32_MAX 4294967295U
1158 #define MYGINT32_MAX 2147483647
1159 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1161 #define CHECK_ADD_OVERFLOW(a,b) \
1162 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1163 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1165 #define CHECK_SUB_OVERFLOW(a,b) \
1166 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1167 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1169 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1170 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1172 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1173 (guint32)(a) < (guint32)(b) ? -1 : 0
1175 #define CHECK_ADD_OVERFLOW64(a,b) \
1176 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1177 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1179 #define CHECK_SUB_OVERFLOW64(a,b) \
1180 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1181 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1183 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1184 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1186 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1187 (guint64)(a) < (guint64)(b) ? -1 : 0
1189 #if SIZEOF_VOID_P == 4
1190 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1191 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1193 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1194 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1197 /* Resolves to TRUE if the operands would overflow */
1198 #define CHECK_MUL_OVERFLOW(a,b) \
1199 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1200 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1201 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1202 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1203 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1204 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1205 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1207 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1208 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1209 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1211 #define CHECK_MUL_OVERFLOW64(a,b) \
1212 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1213 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1214 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1215 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1216 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1217 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1218 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1220 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1221 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1222 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1224 #if SIZEOF_VOID_P == 4
1225 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1226 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1228 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1229 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1233 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1235 MonoInvocation frame;
1236 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1237 MonoObject *retval = NULL;
1238 MonoMethodSignature *sig = mono_method_signature (method);
1239 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1240 int i, type, isobject = 0;
1243 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1244 ThreadContext context_struct;
1245 MonoInvocation *old_frame = NULL;
1253 if (context != &context_struct) {
1254 context->domain = mono_domain_get ();
1255 context->current_frame = old_frame;
1256 context->managed_code = 0;
1258 mono_native_tls_set_value (thread_context_id, NULL);
1260 *exc = (MonoObject *)frame.ex;
1264 if (context == NULL) {
1265 context = &context_struct;
1266 context_struct.base_frame = &frame;
1267 context_struct.current_frame = NULL;
1268 context_struct.env_frame = &frame;
1269 context_struct.current_env = &env;
1270 context_struct.search_for_handler = 0;
1271 context_struct.managed_code = 0;
1272 mono_native_tls_set_value (thread_context_id, context);
1275 old_frame = context->current_frame;
1277 context->domain = mono_domain_get ();
1279 switch (sig->ret->type) {
1280 case MONO_TYPE_VOID:
1282 case MONO_TYPE_STRING:
1283 case MONO_TYPE_OBJECT:
1284 case MONO_TYPE_CLASS:
1285 case MONO_TYPE_ARRAY:
1286 case MONO_TYPE_SZARRAY:
1289 case MONO_TYPE_VALUETYPE:
1290 retval = mono_object_new_checked (context->domain, klass, error);
1291 ret = ((char*)retval) + sizeof (MonoObject);
1292 if (!sig->ret->data.klass->enumtype)
1293 result.data.vt = ret;
1296 retval = mono_object_new_checked (context->domain, klass, error);
1297 ret = ((char*)retval) + sizeof (MonoObject);
1302 args [0].data.p = obj;
1304 for (i = 0; i < sig->param_count; ++i) {
1305 int a_index = i + !!sig->hasthis;
1306 if (sig->params [i]->byref) {
1307 args [a_index].data.p = params [i];
1310 type = sig->params [i]->type;
1315 case MONO_TYPE_BOOLEAN:
1316 args [a_index].data.i = *(MonoBoolean*)params [i];
1320 case MONO_TYPE_CHAR:
1321 args [a_index].data.i = *(gint16*)params [i];
1323 #if SIZEOF_VOID_P == 4
1324 case MONO_TYPE_U: /* use VAL_POINTER? */
1329 args [a_index].data.i = *(gint32*)params [i];
1331 #if SIZEOF_VOID_P == 8
1337 args [a_index].data.l = *(gint64*)params [i];
1339 case MONO_TYPE_VALUETYPE:
1340 if (sig->params [i]->data.klass->enumtype) {
1341 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1344 args [a_index].data.p = params [i];
1347 case MONO_TYPE_STRING:
1348 case MONO_TYPE_CLASS:
1349 case MONO_TYPE_ARRAY:
1350 case MONO_TYPE_SZARRAY:
1351 case MONO_TYPE_OBJECT:
1352 args [a_index].data.p = params [i];
1355 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1359 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1360 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1361 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1363 frame.invoke_trap = 1;
1364 context->managed_code = 1;
1365 ves_exec_method_with_context (&frame, context);
1366 context->managed_code = 0;
1367 if (context == &context_struct)
1368 mono_native_tls_set_value (thread_context_id, NULL);
1370 context->current_frame = old_frame;
1371 if (frame.ex != NULL) {
1373 *exc = (MonoObject*) frame.ex;
1376 if (context->current_env != NULL) {
1377 context->env_frame->ex = frame.ex;
1378 longjmp(*context->current_env, 1);
1381 printf("dropped exception...\n");
1383 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1385 if (isobject || method->string_ctor)
1386 return result.data.p;
1387 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1392 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1394 MonoInvocation *old_frame = context->current_frame;
1395 MonoInvocation *old_env_frame = context->env_frame;
1396 jmp_buf *old_env = context->current_env;
1400 context->current_frame = old_frame;
1401 context->env_frame = old_env_frame;
1402 context->current_env = old_env;
1403 context->managed_code = 1;
1407 context->env_frame = context->current_frame;
1408 context->current_env = &env;
1409 context->managed_code = 0;
1412 case MINT_ICALL_V_V: {
1413 void (*func)() = ptr;
1417 case MINT_ICALL_V_P: {
1418 gpointer (*func)() = ptr;
1420 sp [-1].data.p = func ();
1423 case MINT_ICALL_P_V: {
1424 void (*func)(gpointer) = ptr;
1425 func (sp [-1].data.p);
1429 case MINT_ICALL_P_P: {
1430 gpointer (*func)(gpointer) = ptr;
1431 sp [-1].data.p = func (sp [-1].data.p);
1434 case MINT_ICALL_PP_V: {
1435 void (*func)(gpointer,gpointer) = ptr;
1437 func (sp [0].data.p, sp [1].data.p);
1440 case MINT_ICALL_PI_V: {
1441 void (*func)(gpointer,int) = ptr;
1443 func (sp [0].data.p, sp [1].data.i);
1446 case MINT_ICALL_PP_P: {
1447 gpointer (*func)(gpointer,gpointer) = ptr;
1449 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1452 case MINT_ICALL_PI_P: {
1453 gpointer (*func)(gpointer,int) = ptr;
1455 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1458 case MINT_ICALL_PPP_V: {
1459 void (*func)(gpointer,gpointer,gpointer) = ptr;
1461 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1464 case MINT_ICALL_PPI_V: {
1465 void (*func)(gpointer,gpointer,int) = ptr;
1467 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1471 g_assert_not_reached ();
1474 context->env_frame = old_env_frame;
1475 context->current_env = old_env;
1480 static mono_mutex_t create_method_pointer_mutex;
1482 static GHashTable *method_pointer_hash = NULL;
1484 static MonoMethod *method_pointers [2] = {0};
1487 mp_tramp_0 (MonoObject *this_obj, void **params, MonoObject **exc, void *compiled_method) {
1489 void *params_real[] = {this_obj, ¶ms, &exc, &compiled_method};
1490 MonoObject *ret = mono_interp_runtime_invoke (method_pointers [0], NULL, params_real, NULL, &error);
1491 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1496 mp_tramp_1 (MonoObject *this_obj, void **params, MonoObject **exc, void *compiled_method) {
1498 void *params_real[] = {this_obj, ¶ms, &exc, &compiled_method};
1499 MonoObject *ret = mono_interp_runtime_invoke (method_pointers [1], NULL, params_real, NULL, &error);
1500 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1504 gpointer *mp_tramps[] = {(gpointer) mp_tramp_0, (gpointer) mp_tramp_1};
1506 static int tramps_used = 0;
1509 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1514 mono_os_mutex_lock (&create_method_pointer_mutex);
1515 if (!method_pointer_hash) {
1516 // FIXME: is registering method table as GC root really necessary?
1517 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1518 method_pointer_hash = g_hash_table_new (NULL, NULL);
1520 addr = g_hash_table_lookup (method_pointer_hash, method);
1522 mono_os_mutex_unlock (&create_method_pointer_mutex);
1527 * If it is a static P/Invoke method, we can just return the pointer
1528 * to the method implementation.
1530 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1531 ji = g_new0 (MonoJitInfo, 1);
1532 ji->d.method = method;
1534 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1536 mono_jit_info_table_add (mono_get_root_domain (), ji);
1539 g_assert (method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE);
1540 g_assert (tramps_used < 2);
1542 /* FIXME: needs locking */
1543 method_pointers [tramps_used] = method;
1544 addr = mp_tramps [tramps_used];
1548 g_hash_table_insert (method_pointer_hash, method, addr);
1549 mono_os_mutex_unlock (&create_method_pointer_mutex);
1555 static int opcode_counts[512];
1557 #define COUNT_OP(op) opcode_counts[op]++
1559 #define COUNT_OP(op)
1563 #define DUMP_INSTR() \
1564 if (tracing > 1) { \
1566 if (sp > frame->stack) { \
1567 ins = dump_stack (frame->stack, sp); \
1569 ins = g_strdup (""); \
1573 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1574 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1576 mono_interp_dis_mintop(rtm->code, ip); \
1577 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1581 #define DUMP_INSTR()
1585 #define USE_COMPUTED_GOTO 1
1587 #if USE_COMPUTED_GOTO
1588 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1589 #define MINT_IN_CASE(x) LAB_ ## x:
1591 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1593 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1595 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1597 #define MINT_IN_SWITCH(op) switch (op)
1598 #define MINT_IN_CASE(x) case x:
1599 #define MINT_IN_BREAK break
1600 #define MINT_IN_DEFAULT default:
1604 * Defining this causes register allocation errors in some versions of gcc:
1605 * error: unable to find a register to spill in class `SIREG'
1607 /* #define MINT_USE_DEDICATED_IP_REG */
1610 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1612 MonoInvocation child_frame;
1613 GSList *finally_ips = NULL;
1614 const unsigned short *endfinally_ip = NULL;
1615 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1616 register const unsigned short *ip asm ("%esi");
1618 register const unsigned short *ip;
1620 register stackval *sp;
1623 gint tracing = global_tracing;
1624 unsigned char *vtalloc;
1627 unsigned char *vt_sp;
1628 unsigned char *locals;
1630 MonoObject *o = NULL;
1632 #if USE_COMPUTED_GOTO
1633 static void *in_labels[] = {
1634 #define OPDEF(a,b,c,d) \
1636 #include "mintops.def"
1641 frame->ex_handler = NULL;
1643 context->current_frame = frame;
1646 debug_enter (frame, &tracing);
1649 if (!frame->runtime_method->transformed) {
1650 context->managed_code = 0;
1652 char *mn = mono_method_full_name (frame->runtime_method->method, TRUE);
1653 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
1656 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1657 context->managed_code = 1;
1665 rtm = frame->runtime_method;
1666 frame->args = alloca (rtm->alloca_size);
1667 memset (frame->args, 0, rtm->alloca_size);
1669 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1670 memset (sp, 0, rtm->stack_size);
1672 vt_sp = (unsigned char *) sp + rtm->stack_size;
1673 memset (vt_sp, 0, rtm->vt_stack_size);
1678 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1679 memset (vt_sp, 0, rtm->locals_size);
1681 child_frame.parent = frame;
1687 * using while (ip < end) may result in a 15% performance drop,
1688 * but it may be useful for debug
1692 /* g_assert (sp >= frame->stack); */
1693 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1695 MINT_IN_SWITCH (*ip) {
1696 MINT_IN_CASE(MINT_INITLOCALS)
1697 memset (locals, 0, rtm->locals_size);
1700 MINT_IN_CASE(MINT_NOP)
1703 MINT_IN_CASE(MINT_BREAK)
1705 G_BREAKPOINT (); /* this is not portable... */
1707 MINT_IN_CASE(MINT_LDNULL)
1712 MINT_IN_CASE(MINT_VTRESULT) {
1713 int ret_size = * (guint16 *)(ip + 1);
1714 unsigned char *ret_vt_sp = vt_sp;
1715 vt_sp -= READ32(ip + 2);
1717 memmove (vt_sp, ret_vt_sp, ret_size);
1718 sp [-1].data.p = vt_sp;
1719 vt_sp += (ret_size + 7) & ~7;
1724 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1725 MINT_IN_CASE(MINT_LDC_I4_M1)
1728 MINT_IN_CASE(MINT_LDC_I4_0)
1731 MINT_IN_CASE(MINT_LDC_I4_1)
1734 MINT_IN_CASE(MINT_LDC_I4_2)
1737 MINT_IN_CASE(MINT_LDC_I4_3)
1740 MINT_IN_CASE(MINT_LDC_I4_4)
1743 MINT_IN_CASE(MINT_LDC_I4_5)
1746 MINT_IN_CASE(MINT_LDC_I4_6)
1749 MINT_IN_CASE(MINT_LDC_I4_7)
1752 MINT_IN_CASE(MINT_LDC_I4_8)
1755 MINT_IN_CASE(MINT_LDC_I4_S)
1756 sp->data.i = *(const short *)(ip + 1);
1760 MINT_IN_CASE(MINT_LDC_I4)
1762 sp->data.i = READ32 (ip);
1766 MINT_IN_CASE(MINT_LDC_I8)
1768 sp->data.l = READ64 (ip);
1772 MINT_IN_CASE(MINT_LDC_R4) {
1776 sp->data.f = * (float *)&val;
1781 MINT_IN_CASE(MINT_LDC_R8)
1782 sp->data.l = READ64 (ip + 1); /* note union usage */
1786 MINT_IN_CASE(MINT_DUP)
1791 MINT_IN_CASE(MINT_DUP_VT)
1792 i32 = READ32 (ip + 1);
1794 memcpy(sp->data.p, sp [-1].data.p, i32);
1795 vt_sp += (i32 + 7) & ~7;
1799 MINT_IN_CASE(MINT_POP) {
1800 guint16 u16 = (* (guint16 *)(ip + 1)) + 1;
1802 memmove (sp - u16, sp - 1, (u16 - 1) * sizeof (stackval));
1807 MINT_IN_CASE(MINT_JMP) {
1808 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1809 if (!new_method->transformed) {
1811 frame->ex = mono_interp_transform_method (new_method, context);
1816 if (new_method->alloca_size > rtm->alloca_size)
1817 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1818 rtm = frame->runtime_method = new_method;
1819 vt_sp = (unsigned char *) sp + rtm->stack_size;
1823 locals = vt_sp + rtm->vt_stack_size;
1824 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1827 MINT_IN_CASE(MINT_CALLI) {
1828 MonoMethodSignature *csignature;
1829 stackval *endsp = sp;
1833 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1837 child_frame.runtime_method = sp->data.p;
1840 child_frame.retval = sp;
1841 /* decrement by the actual number of args */
1842 sp -= csignature->param_count;
1843 if (csignature->hasthis)
1845 child_frame.stack_args = sp;
1847 /* `this' can be NULL for string:.ctor */
1848 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
1849 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1850 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1851 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1852 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1853 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1856 if (csignature->hasthis) {
1857 MonoObject *this_arg = sp->data.p;
1859 if (this_arg->vtable->klass->valuetype) {
1860 gpointer *unboxed = mono_object_unbox (this_arg);
1861 sp [0].data.p = unboxed;
1865 ves_exec_method_with_context (&child_frame, context);
1867 context->current_frame = frame;
1869 if (child_frame.ex) {
1871 * An exception occurred, need to run finally, fault and catch handlers..
1873 frame->ex = child_frame.ex;
1874 goto handle_finally;
1877 /* need to handle typedbyref ... */
1878 if (csignature->ret->type != MONO_TYPE_VOID) {
1884 MINT_IN_CASE(MINT_CALLI_NAT) {
1885 MonoMethodSignature *csignature;
1886 stackval *endsp = sp;
1887 unsigned char *code = NULL;
1891 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1896 child_frame.runtime_method = NULL;
1899 child_frame.retval = sp;
1900 /* decrement by the actual number of args */
1901 sp -= csignature->param_count;
1902 if (csignature->hasthis)
1904 child_frame.stack_args = sp;
1905 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1907 context->current_frame = frame;
1909 if (child_frame.ex) {
1911 * An exception occurred, need to run finally, fault and catch handlers..
1913 frame->ex = child_frame.ex;
1914 if (context->search_for_handler) {
1915 context->search_for_handler = 0;
1916 goto handle_exception;
1918 goto handle_finally;
1921 /* need to handle typedbyref ... */
1922 if (csignature->ret->type != MONO_TYPE_VOID) {
1928 MINT_IN_CASE(MINT_CALL) {
1929 stackval *endsp = sp;
1933 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1936 child_frame.retval = sp;
1937 /* decrement by the actual number of args */
1938 sp -= child_frame.runtime_method->param_count;
1939 if (child_frame.runtime_method->hasthis)
1941 child_frame.stack_args = sp;
1943 /* `this' can be NULL for string:.ctor */
1944 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
1945 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1946 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1948 ves_exec_method_with_context (&child_frame, context);
1950 context->current_frame = frame;
1952 if (child_frame.ex) {
1954 * An exception occurred, need to run finally, fault and catch handlers..
1956 frame->ex = child_frame.ex;
1957 goto handle_finally;
1960 /* need to handle typedbyref ... */
1965 MINT_IN_CASE(MINT_VCALL) {
1968 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1972 child_frame.retval = sp;
1973 /* decrement by the actual number of args */
1974 sp -= child_frame.runtime_method->param_count;
1975 if (child_frame.runtime_method->hasthis) {
1977 MonoObject *this_arg = sp->data.p;
1979 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1981 child_frame.stack_args = sp;
1983 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1984 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1985 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1988 ves_exec_method_with_context (&child_frame, context);
1990 context->current_frame = frame;
1992 if (child_frame.ex) {
1994 * An exception occurred, need to run finally, fault and catch handlers..
1996 frame->ex = child_frame.ex;
1997 goto handle_finally;
2001 MINT_IN_CASE(MINT_CALLVIRT) {
2002 stackval *endsp = sp;
2003 MonoObject *this_arg;
2008 token = * (unsigned short *)(ip + 1);
2010 child_frame.runtime_method = rtm->data_items [token];
2012 child_frame.retval = sp;
2014 /* decrement by the actual number of args */
2015 sp -= child_frame.runtime_method->param_count + 1;
2016 child_frame.stack_args = sp;
2017 this_arg = sp->data.p;
2019 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2020 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2022 MonoClass *this_class = this_arg->vtable->klass;
2023 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2025 gpointer *unboxed = mono_object_unbox (this_arg);
2026 sp [0].data.p = unboxed;
2029 ves_exec_method_with_context (&child_frame, context);
2031 context->current_frame = frame;
2033 if (child_frame.ex) {
2035 * An exception occurred, need to run finally, fault and catch handlers..
2037 frame->ex = child_frame.ex;
2038 if (context->search_for_handler) {
2039 context->search_for_handler = 0;
2040 goto handle_exception;
2042 goto handle_finally;
2045 /* need to handle typedbyref ... */
2050 MINT_IN_CASE(MINT_VCALLVIRT) {
2051 MonoObject *this_arg;
2056 token = * (unsigned short *)(ip + 1);
2058 child_frame.runtime_method = rtm->data_items [token];
2060 child_frame.retval = sp;
2062 /* decrement by the actual number of args */
2063 sp -= child_frame.runtime_method->param_count + 1;
2064 child_frame.stack_args = sp;
2065 this_arg = sp->data.p;
2067 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2068 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2070 MonoClass *this_class = this_arg->vtable->klass;
2071 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2072 gpointer *unboxed = mono_object_unbox (this_arg);
2073 sp [0].data.p = unboxed;
2076 ves_exec_method_with_context (&child_frame, context);
2078 context->current_frame = frame;
2080 if (child_frame.ex) {
2082 * An exception occurred, need to run finally, fault and catch handlers..
2084 frame->ex = child_frame.ex;
2085 if (context->search_for_handler) {
2086 context->search_for_handler = 0;
2087 goto handle_exception;
2089 goto handle_finally;
2093 MINT_IN_CASE(MINT_CALLRUN)
2094 ves_runtime_method (frame, context);
2097 goto handle_exception;
2100 MINT_IN_CASE(MINT_RET)
2102 *frame->retval = *sp;
2103 if (sp > frame->stack)
2104 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2106 MINT_IN_CASE(MINT_RET_VOID)
2107 if (sp > frame->stack)
2108 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2110 MINT_IN_CASE(MINT_RET_VT)
2111 i32 = READ32(ip + 1);
2113 memcpy(frame->retval->data.p, sp->data.p, i32);
2114 if (sp > frame->stack)
2115 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2117 MINT_IN_CASE(MINT_BR_S)
2118 ip += (short) *(ip + 1);
2120 MINT_IN_CASE(MINT_BR)
2121 ip += (gint32) READ32(ip + 1);
2123 #define ZEROP_S(datamem, op) \
2125 if (sp->data.datamem op 0) \
2126 ip += * (gint16 *)(ip + 1); \
2130 #define ZEROP(datamem, op) \
2132 if (sp->data.datamem op 0) \
2133 ip += READ32(ip + 1); \
2137 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2140 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2143 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2146 MINT_IN_CASE(MINT_BRFALSE_I4)
2149 MINT_IN_CASE(MINT_BRFALSE_I8)
2152 MINT_IN_CASE(MINT_BRFALSE_R8)
2155 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2158 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2161 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2164 MINT_IN_CASE(MINT_BRTRUE_I4)
2167 MINT_IN_CASE(MINT_BRTRUE_I8)
2170 MINT_IN_CASE(MINT_BRTRUE_R8)
2173 #define CONDBR_S(cond) \
2176 ip += * (gint16 *)(ip + 1); \
2179 #define BRELOP_S(datamem, op) \
2180 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2182 #define CONDBR(cond) \
2185 ip += READ32(ip + 1); \
2189 #define BRELOP(datamem, op) \
2190 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2192 MINT_IN_CASE(MINT_BEQ_I4_S)
2195 MINT_IN_CASE(MINT_BEQ_I8_S)
2198 MINT_IN_CASE(MINT_BEQ_R8_S)
2199 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2201 MINT_IN_CASE(MINT_BEQ_I4)
2204 MINT_IN_CASE(MINT_BEQ_I8)
2207 MINT_IN_CASE(MINT_BEQ_R8)
2208 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2210 MINT_IN_CASE(MINT_BGE_I4_S)
2213 MINT_IN_CASE(MINT_BGE_I8_S)
2216 MINT_IN_CASE(MINT_BGE_R8_S)
2217 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2219 MINT_IN_CASE(MINT_BGE_I4)
2222 MINT_IN_CASE(MINT_BGE_I8)
2225 MINT_IN_CASE(MINT_BGE_R8)
2226 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2228 MINT_IN_CASE(MINT_BGT_I4_S)
2231 MINT_IN_CASE(MINT_BGT_I8_S)
2234 MINT_IN_CASE(MINT_BGT_R8_S)
2235 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2237 MINT_IN_CASE(MINT_BGT_I4)
2240 MINT_IN_CASE(MINT_BGT_I8)
2243 MINT_IN_CASE(MINT_BGT_R8)
2244 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2246 MINT_IN_CASE(MINT_BLT_I4_S)
2249 MINT_IN_CASE(MINT_BLT_I8_S)
2252 MINT_IN_CASE(MINT_BLT_R8_S)
2253 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2255 MINT_IN_CASE(MINT_BLT_I4)
2258 MINT_IN_CASE(MINT_BLT_I8)
2261 MINT_IN_CASE(MINT_BLT_R8)
2262 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2264 MINT_IN_CASE(MINT_BLE_I4_S)
2267 MINT_IN_CASE(MINT_BLE_I8_S)
2270 MINT_IN_CASE(MINT_BLE_R8_S)
2271 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2273 MINT_IN_CASE(MINT_BLE_I4)
2276 MINT_IN_CASE(MINT_BLE_I8)
2279 MINT_IN_CASE(MINT_BLE_R8)
2280 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2282 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2285 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2288 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2289 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2291 MINT_IN_CASE(MINT_BNE_UN_I4)
2294 MINT_IN_CASE(MINT_BNE_UN_I8)
2297 MINT_IN_CASE(MINT_BNE_UN_R8)
2298 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2301 #define BRELOP_S_CAST(datamem, op, type) \
2303 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2304 ip += * (gint16 *)(ip + 1); \
2308 #define BRELOP_CAST(datamem, op, type) \
2310 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2311 ip += READ32(ip + 1); \
2315 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2316 BRELOP_S_CAST(i, >=, guint32);
2318 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2319 BRELOP_S_CAST(l, >=, guint64);
2321 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2322 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2324 MINT_IN_CASE(MINT_BGE_UN_I4)
2325 BRELOP_CAST(i, >=, guint32);
2327 MINT_IN_CASE(MINT_BGE_UN_I8)
2328 BRELOP_CAST(l, >=, guint64);
2330 MINT_IN_CASE(MINT_BGE_UN_R8)
2331 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2333 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2334 BRELOP_S_CAST(i, >, guint32);
2336 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2337 BRELOP_S_CAST(l, >, guint64);
2339 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2340 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2342 MINT_IN_CASE(MINT_BGT_UN_I4)
2343 BRELOP_CAST(i, >, guint32);
2345 MINT_IN_CASE(MINT_BGT_UN_I8)
2346 BRELOP_CAST(l, >, guint64);
2348 MINT_IN_CASE(MINT_BGT_UN_R8)
2349 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2351 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2352 BRELOP_S_CAST(i, <=, guint32);
2354 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2355 BRELOP_S_CAST(l, <=, guint64);
2357 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2358 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2360 MINT_IN_CASE(MINT_BLE_UN_I4)
2361 BRELOP_CAST(i, <=, guint32);
2363 MINT_IN_CASE(MINT_BLE_UN_I8)
2364 BRELOP_CAST(l, <=, guint64);
2366 MINT_IN_CASE(MINT_BLE_UN_R8)
2367 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2369 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2370 BRELOP_S_CAST(i, <, guint32);
2372 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2373 BRELOP_S_CAST(l, <, guint64);
2375 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2376 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2378 MINT_IN_CASE(MINT_BLT_UN_I4)
2379 BRELOP_CAST(i, <, guint32);
2381 MINT_IN_CASE(MINT_BLT_UN_I8)
2382 BRELOP_CAST(l, <, guint64);
2384 MINT_IN_CASE(MINT_BLT_UN_R8)
2385 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2387 MINT_IN_CASE(MINT_SWITCH) {
2389 const unsigned short *st;
2395 if ((guint32)sp->data.i < n) {
2397 ip += 2 * (guint32)sp->data.i;
2398 offset = READ32 (ip);
2405 MINT_IN_CASE(MINT_LDIND_I1)
2407 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2409 MINT_IN_CASE(MINT_LDIND_U1)
2411 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2413 MINT_IN_CASE(MINT_LDIND_I2)
2415 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2417 MINT_IN_CASE(MINT_LDIND_U2)
2419 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2421 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2422 MINT_IN_CASE(MINT_LDIND_U4)
2424 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2426 MINT_IN_CASE(MINT_LDIND_I8)
2428 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2430 MINT_IN_CASE(MINT_LDIND_I) {
2431 guint16 offset = * (guint16 *)(ip + 1);
2432 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
2436 MINT_IN_CASE(MINT_LDIND_R4)
2438 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2440 MINT_IN_CASE(MINT_LDIND_R8)
2442 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2444 MINT_IN_CASE(MINT_LDIND_REF)
2446 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2448 MINT_IN_CASE(MINT_STIND_REF)
2451 * (gpointer *) sp->data.p = sp[1].data.p;
2453 MINT_IN_CASE(MINT_STIND_I1)
2456 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2458 MINT_IN_CASE(MINT_STIND_I2)
2461 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2463 MINT_IN_CASE(MINT_STIND_I4)
2466 * (gint32 *) sp->data.p = sp[1].data.i;
2468 MINT_IN_CASE(MINT_STIND_I)
2471 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2473 MINT_IN_CASE(MINT_STIND_I8)
2476 * (gint64 *) sp->data.p = sp[1].data.l;
2478 MINT_IN_CASE(MINT_STIND_R4)
2481 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2483 MINT_IN_CASE(MINT_STIND_R8)
2486 * (double *) sp->data.p = sp[1].data.f;
2488 #define BINOP(datamem, op) \
2490 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2492 MINT_IN_CASE(MINT_ADD_I4)
2495 MINT_IN_CASE(MINT_ADD_I8)
2498 MINT_IN_CASE(MINT_ADD_R8)
2501 MINT_IN_CASE(MINT_ADD1_I4)
2505 MINT_IN_CASE(MINT_SUB_I4)
2508 MINT_IN_CASE(MINT_SUB_I8)
2511 MINT_IN_CASE(MINT_SUB_R8)
2514 MINT_IN_CASE(MINT_SUB1_I4)
2518 MINT_IN_CASE(MINT_MUL_I4)
2521 MINT_IN_CASE(MINT_MUL_I8)
2524 MINT_IN_CASE(MINT_MUL_R8)
2527 MINT_IN_CASE(MINT_DIV_I4)
2528 if (sp [-1].data.i == 0)
2529 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2530 if (sp [-1].data.i == (-1))
2531 THROW_EX (mono_get_exception_overflow (), ip);
2534 MINT_IN_CASE(MINT_DIV_I8)
2535 if (sp [-1].data.l == 0)
2536 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2537 if (sp [-1].data.l == (-1))
2538 THROW_EX (mono_get_exception_overflow (), ip);
2541 MINT_IN_CASE(MINT_DIV_R8)
2545 #define BINOP_CAST(datamem, op, type) \
2547 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2549 MINT_IN_CASE(MINT_DIV_UN_I4)
2550 if (sp [-1].data.i == 0)
2551 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2552 BINOP_CAST(i, /, guint32);
2554 MINT_IN_CASE(MINT_DIV_UN_I8)
2555 if (sp [-1].data.l == 0)
2556 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2557 BINOP_CAST(l, /, guint64);
2559 MINT_IN_CASE(MINT_REM_I4)
2560 if (sp [-1].data.i == 0)
2561 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2562 if (sp [-1].data.i == (-1))
2563 THROW_EX (mono_get_exception_overflow (), ip);
2566 MINT_IN_CASE(MINT_REM_I8)
2567 if (sp [-1].data.l == 0)
2568 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2569 if (sp [-1].data.l == (-1))
2570 THROW_EX (mono_get_exception_overflow (), ip);
2573 MINT_IN_CASE(MINT_REM_R8)
2574 /* FIXME: what do we actually do here? */
2576 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2579 MINT_IN_CASE(MINT_REM_UN_I4)
2580 if (sp [-1].data.i == 0)
2581 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2582 BINOP_CAST(i, %, guint32);
2584 MINT_IN_CASE(MINT_REM_UN_I8)
2585 if (sp [-1].data.l == 0)
2586 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2587 BINOP_CAST(l, %, guint64);
2589 MINT_IN_CASE(MINT_AND_I4)
2592 MINT_IN_CASE(MINT_AND_I8)
2595 MINT_IN_CASE(MINT_OR_I4)
2598 MINT_IN_CASE(MINT_OR_I8)
2601 MINT_IN_CASE(MINT_XOR_I4)
2604 MINT_IN_CASE(MINT_XOR_I8)
2608 #define SHIFTOP(datamem, op) \
2610 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2613 MINT_IN_CASE(MINT_SHL_I4)
2616 MINT_IN_CASE(MINT_SHL_I8)
2619 MINT_IN_CASE(MINT_SHR_I4)
2622 MINT_IN_CASE(MINT_SHR_I8)
2625 MINT_IN_CASE(MINT_SHR_UN_I4)
2627 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2630 MINT_IN_CASE(MINT_SHR_UN_I8)
2632 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2635 MINT_IN_CASE(MINT_NEG_I4)
2636 sp [-1].data.i = - sp [-1].data.i;
2639 MINT_IN_CASE(MINT_NEG_I8)
2640 sp [-1].data.l = - sp [-1].data.l;
2643 MINT_IN_CASE(MINT_NEG_R8)
2644 sp [-1].data.f = - sp [-1].data.f;
2647 MINT_IN_CASE(MINT_NOT_I4)
2648 sp [-1].data.i = ~ sp [-1].data.i;
2651 MINT_IN_CASE(MINT_NOT_I8)
2652 sp [-1].data.l = ~ sp [-1].data.l;
2655 MINT_IN_CASE(MINT_CONV_I1_I4)
2656 sp [-1].data.i = (gint8)sp [-1].data.i;
2659 MINT_IN_CASE(MINT_CONV_I1_I8)
2660 sp [-1].data.i = (gint8)sp [-1].data.l;
2663 MINT_IN_CASE(MINT_CONV_I1_R8)
2664 sp [-1].data.i = (gint8)sp [-1].data.f;
2667 MINT_IN_CASE(MINT_CONV_U1_I4)
2668 sp [-1].data.i = (guint8)sp [-1].data.i;
2671 MINT_IN_CASE(MINT_CONV_U1_I8)
2672 sp [-1].data.i = (guint8)sp [-1].data.l;
2675 MINT_IN_CASE(MINT_CONV_U1_R8)
2676 sp [-1].data.i = (guint8)sp [-1].data.f;
2679 MINT_IN_CASE(MINT_CONV_I2_I4)
2680 sp [-1].data.i = (gint16)sp [-1].data.i;
2683 MINT_IN_CASE(MINT_CONV_I2_I8)
2684 sp [-1].data.i = (gint16)sp [-1].data.l;
2687 MINT_IN_CASE(MINT_CONV_I2_R8)
2688 sp [-1].data.i = (gint16)sp [-1].data.f;
2691 MINT_IN_CASE(MINT_CONV_U2_I4)
2692 sp [-1].data.i = (guint16)sp [-1].data.i;
2695 MINT_IN_CASE(MINT_CONV_U2_I8)
2696 sp [-1].data.i = (guint16)sp [-1].data.l;
2699 MINT_IN_CASE(MINT_CONV_U2_R8)
2700 sp [-1].data.i = (guint16)sp [-1].data.f;
2703 MINT_IN_CASE(MINT_CONV_I4_R8)
2704 sp [-1].data.i = (gint32)sp [-1].data.f;
2707 MINT_IN_CASE(MINT_CONV_U4_I8)
2708 MINT_IN_CASE(MINT_CONV_I4_I8)
2709 sp [-1].data.i = (gint32)sp [-1].data.l;
2712 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2713 sp [-2].data.i = (gint32)sp [-2].data.l;
2716 MINT_IN_CASE(MINT_CONV_U4_R8)
2717 sp [-1].data.i = (guint32)sp [-1].data.f;
2720 MINT_IN_CASE(MINT_CONV_I8_I4)
2721 sp [-1].data.l = sp [-1].data.i;
2724 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2725 sp [-2].data.l = sp [-2].data.i;
2728 MINT_IN_CASE(MINT_CONV_I8_U4)
2729 sp [-1].data.l = (guint32)sp [-1].data.i;
2732 MINT_IN_CASE(MINT_CONV_I8_R8)
2733 sp [-1].data.l = (gint64)sp [-1].data.f;
2736 MINT_IN_CASE(MINT_CONV_R4_I4)
2737 sp [-1].data.f = (float)sp [-1].data.i;
2740 MINT_IN_CASE(MINT_CONV_R4_I8)
2741 sp [-1].data.f = (float)sp [-1].data.l;
2744 MINT_IN_CASE(MINT_CONV_R4_R8)
2745 sp [-1].data.f = (float)sp [-1].data.f;
2748 MINT_IN_CASE(MINT_CONV_R8_I4)
2749 sp [-1].data.f = (double)sp [-1].data.i;
2752 MINT_IN_CASE(MINT_CONV_R8_I8)
2753 sp [-1].data.f = (double)sp [-1].data.l;
2756 MINT_IN_CASE(MINT_CONV_U8_I4)
2757 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2760 MINT_IN_CASE(MINT_CONV_U8_R8)
2761 sp [-1].data.l = (guint64)sp [-1].data.f;
2764 MINT_IN_CASE(MINT_CPOBJ) {
2765 c = rtm->data_items[* (guint16 *)(ip + 1)];
2766 g_assert (c->byval_arg.type == MONO_TYPE_VALUETYPE);
2767 stackval_from_data (&c->byval_arg, &sp [-2], sp [-1].data.p, FALSE);
2772 MINT_IN_CASE(MINT_LDOBJ) {
2774 c = rtm->data_items[* (guint16 *)(ip + 1)];
2777 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2778 int size = mono_class_value_size (c, NULL);
2779 sp [-1].data.p = vt_sp;
2780 vt_sp += (size + 7) & ~7;
2782 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2785 MINT_IN_CASE(MINT_LDSTR)
2786 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2790 MINT_IN_CASE(MINT_NEWOBJ) {
2791 MonoClass *newobj_class;
2792 MonoMethodSignature *csig;
2793 stackval valuetype_this;
2799 token = * (guint16 *)(ip + 1);
2802 child_frame.runtime_method = rtm->data_items [token];
2803 csig = mono_method_signature (child_frame.runtime_method->method);
2804 newobj_class = child_frame.runtime_method->method->klass;
2805 /*if (profiling_classes) {
2806 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2808 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2811 if (newobj_class->parent == mono_defaults.array_class) {
2812 sp -= csig->param_count;
2813 o = ves_array_create (context->domain, newobj_class, csig, sp);
2814 goto array_constructed;
2817 g_assert (csig->hasthis);
2818 if (csig->param_count) {
2819 sp -= csig->param_count;
2820 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
2822 child_frame.stack_args = sp;
2825 * First arg is the object.
2827 if (newobj_class->valuetype) {
2828 MonoType *t = &newobj_class->byval_arg;
2829 memset (&valuetype_this, 0, sizeof (stackval));
2830 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2832 valuetype_this.data.p = vt_sp;
2834 sp->data.p = &valuetype_this;
2837 if (newobj_class != mono_defaults.string_class) {
2838 context->managed_code = 0;
2839 o = mono_object_new_checked (context->domain, newobj_class, &error);
2840 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2841 context->managed_code = 1;
2842 if (*mono_thread_interruption_request_flag ())
2843 mono_thread_interruption_checkpoint ();
2847 child_frame.retval = &retval;
2851 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2853 child_frame.ip = NULL;
2854 child_frame.ex = NULL;
2856 ves_exec_method_with_context (&child_frame, context);
2858 context->current_frame = frame;
2860 if (child_frame.ex) {
2862 * An exception occurred, need to run finally, fault and catch handlers..
2864 frame->ex = child_frame.ex;
2865 goto handle_finally;
2868 * a constructor returns void, but we need to return the object we created
2871 if (newobj_class->valuetype && !newobj_class->enumtype) {
2872 *sp = valuetype_this;
2873 } else if (newobj_class == mono_defaults.string_class) {
2881 MINT_IN_CASE(MINT_CASTCLASS)
2882 c = rtm->data_items [*(guint16 *)(ip + 1)];
2883 if ((o = sp [-1].data.p)) {
2884 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2885 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2887 THROW_EX (mono_get_exception_invalid_cast (), ip);
2891 MINT_IN_CASE(MINT_ISINST)
2892 c = rtm->data_items [*(guint16 *)(ip + 1)];
2893 if ((o = sp [-1].data.p)) {
2894 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2895 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2897 sp [-1].data.p = NULL;
2901 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2902 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2905 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2906 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2909 MINT_IN_CASE(MINT_UNBOX)
2910 c = rtm->data_items[*(guint16 *)(ip + 1)];
2914 THROW_EX (mono_get_exception_null_reference (), ip);
2916 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2917 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2918 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2919 THROW_EX (mono_get_exception_invalid_cast (), ip);
2921 sp [-1].data.p = mono_object_unbox (o);
2924 MINT_IN_CASE(MINT_THROW)
2926 frame->ex_handler = NULL;
2928 sp->data.p = mono_get_exception_null_reference ();
2929 THROW_EX ((MonoException *)sp->data.p, ip);
2931 MINT_IN_CASE(MINT_LDFLDA)
2934 THROW_EX (mono_get_exception_null_reference (), ip);
2935 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2938 MINT_IN_CASE(MINT_CKNULL)
2941 THROW_EX (mono_get_exception_null_reference (), ip);
2945 #define LDFLD(datamem, fieldtype) \
2946 o = sp [-1].data.p; \
2948 THROW_EX (mono_get_exception_null_reference (), ip); \
2949 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2952 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2953 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2954 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2955 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2956 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2957 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2958 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2959 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2960 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2961 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2963 MINT_IN_CASE(MINT_LDFLD_VT)
2966 THROW_EX (mono_get_exception_null_reference (), ip);
2967 i32 = READ32(ip + 2);
2968 sp [-1].data.p = vt_sp;
2969 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2970 vt_sp += (i32 + 7) & ~7;
2974 MINT_IN_CASE(MINT_LDRMFLD) {
2976 MonoClassField *field;
2981 THROW_EX (mono_get_exception_null_reference (), ip);
2982 field = rtm->data_items[* (guint16 *)(ip + 1)];
2984 if (mono_object_is_transparent_proxy (o)) {
2985 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2987 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2988 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2990 addr = (char*)o + field->offset;
2993 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2997 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2998 MonoClassField *field;
3004 THROW_EX (mono_get_exception_null_reference (), ip);
3005 field = rtm->data_items[* (guint16 *)(ip + 1)];
3006 i32 = READ32(ip + 2);
3008 if (mono_object_is_transparent_proxy (o)) {
3009 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3010 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3011 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3013 addr = (char*)o + field->offset;
3016 sp [-1].data.p = vt_sp;
3017 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3018 vt_sp += (i32 + 7) & ~7;
3019 memcpy(sp [-1].data.p, addr, i32);
3023 #define STFLD(datamem, fieldtype) \
3024 o = sp [-2].data.p; \
3026 THROW_EX (mono_get_exception_null_reference (), ip); \
3028 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3031 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3032 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3033 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3034 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3035 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3036 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3037 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3038 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3039 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
3040 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3042 MINT_IN_CASE(MINT_STFLD_VT)
3045 THROW_EX (mono_get_exception_null_reference (), ip);
3046 i32 = READ32(ip + 2);
3048 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3049 vt_sp -= (i32 + 7) & ~7;
3053 MINT_IN_CASE(MINT_STRMFLD) {
3054 MonoClassField *field;
3058 THROW_EX (mono_get_exception_null_reference (), ip);
3060 field = rtm->data_items[* (guint16 *)(ip + 1)];
3063 if (mono_object_is_transparent_proxy (o)) {
3064 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3065 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3066 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3068 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3073 MINT_IN_CASE(MINT_STRMFLD_VT) {
3074 MonoClassField *field;
3078 THROW_EX (mono_get_exception_null_reference (), ip);
3079 field = rtm->data_items[* (guint16 *)(ip + 1)];
3080 i32 = READ32(ip + 2);
3083 if (mono_object_is_transparent_proxy (o)) {
3084 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3085 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3086 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3088 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3091 vt_sp -= (i32 + 7) & ~7;
3094 MINT_IN_CASE(MINT_LDSFLDA) {
3095 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3096 sp->data.p = mono_class_static_field_address (context->domain, field);
3101 MINT_IN_CASE(MINT_LDSFLD) {
3102 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3103 gpointer addr = mono_class_static_field_address (context->domain, field);
3104 stackval_from_data (field->type, sp, addr, FALSE);
3109 MINT_IN_CASE(MINT_LDSFLD_VT) {
3110 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3111 gpointer addr = mono_class_static_field_address (context->domain, field);
3112 int size = READ32 (ip + 2);
3116 vt_sp += (size + 7) & ~7;
3117 stackval_from_data (field->type, sp, addr, FALSE);
3121 MINT_IN_CASE(MINT_STSFLD) {
3122 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3123 gpointer addr = mono_class_static_field_address (context->domain, field);
3126 stackval_to_data (field->type, sp, addr, FALSE);
3129 MINT_IN_CASE(MINT_STSFLD_VT) {
3130 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3131 gpointer addr = mono_class_static_field_address (context->domain, field);
3132 int size = READ32 (ip + 2);
3136 stackval_to_data (field->type, sp, addr, FALSE);
3137 vt_sp -= (size + 7) & ~7;
3140 MINT_IN_CASE(MINT_STOBJ_VT) {
3142 c = rtm->data_items[* (guint16 *)(ip + 1)];
3144 size = mono_class_value_size (c, NULL);
3145 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3146 vt_sp -= (size + 7) & ~7;
3150 MINT_IN_CASE(MINT_STOBJ) {
3152 c = rtm->data_items[* (guint16 *)(ip + 1)];
3154 size = mono_class_value_size (c, NULL);
3155 memcpy(sp [-2].data.p, &sp [-1].data, size);
3159 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3160 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3161 THROW_EX (mono_get_exception_overflow (), ip);
3162 sp [-1].data.i = (guint32)sp [-1].data.f;
3165 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3166 if (sp [-1].data.i < 0)
3167 THROW_EX (mono_get_exception_overflow (), ip);
3168 sp [-1].data.l = sp [-1].data.i;
3171 MINT_IN_CASE(MINT_CONV_OVF_U8_I8)
3172 if (sp [-1].data.l < 0)
3173 THROW_EX (mono_get_exception_overflow (), ip);
3176 MINT_IN_CASE(MINT_CONV_OVF_I8_U8)
3177 if ((guint64) sp [-1].data.l > MYGINT64_MAX)
3178 THROW_EX (mono_get_exception_overflow (), ip);
3181 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3182 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3183 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGINT64_MAX)
3184 THROW_EX (mono_get_exception_overflow (), ip);
3185 sp [-1].data.l = (guint64)sp [-1].data.f;
3188 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3189 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3190 THROW_EX (mono_get_exception_overflow (), ip);
3191 sp [-1].data.l = (gint64)sp [-1].data.f;
3194 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3195 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3196 THROW_EX (mono_get_exception_overflow (), ip);
3197 sp [-1].data.i = (mono_u)sp [-1].data.l;
3200 MINT_IN_CASE(MINT_BOX) {
3201 c = rtm->data_items [* (guint16 *)(ip + 1)];
3202 guint16 offset = * (guint16 *)(ip + 2);
3204 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3205 int size = mono_class_value_size (c, NULL);
3206 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3207 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3208 size = (size + 7) & ~7;
3211 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3212 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3213 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3218 MINT_IN_CASE(MINT_NEWARR)
3219 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3220 if (!mono_error_ok (&error)) {
3221 THROW_EX (mono_error_convert_to_exception (&error), ip);
3223 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3225 /*if (profiling_classes) {
3226 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3228 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3232 MINT_IN_CASE(MINT_LDLEN)
3235 THROW_EX (mono_get_exception_null_reference (), ip);
3236 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3239 MINT_IN_CASE(MINT_GETCHR) {
3243 THROW_EX (mono_get_exception_null_reference (), ip);
3244 i32 = sp [-1].data.i;
3245 if (i32 < 0 || i32 >= mono_string_length (s))
3246 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3248 sp [-1].data.i = mono_string_chars(s)[i32];
3252 MINT_IN_CASE(MINT_STRLEN)
3254 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3256 MINT_IN_CASE(MINT_ARRAY_RANK)
3259 THROW_EX (mono_get_exception_null_reference (), ip);
3260 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3263 MINT_IN_CASE(MINT_LDELEMA)
3264 MINT_IN_CASE(MINT_LDELEMA_TC) {
3265 gboolean needs_typecheck = *ip == MINT_LDELEMA_TC;
3267 MonoClass *klass = rtm->data_items [*(guint16 *) (ip + 1)];
3268 guint16 numargs = *(guint16 *) (ip + 2);
3273 sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck);
3275 THROW_EX (frame->ex, ip);
3280 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3281 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3282 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3283 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3284 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3285 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3286 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3287 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3288 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3289 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3290 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
3291 MINT_IN_CASE(MINT_LDELEM_VT) {
3299 THROW_EX (mono_get_exception_null_reference (), ip);
3301 aindex = sp [1].data.i;
3302 if (aindex >= mono_array_length (o))
3303 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3306 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3309 case MINT_LDELEM_I1:
3310 sp [0].data.i = mono_array_get (o, gint8, aindex);
3312 case MINT_LDELEM_U1:
3313 sp [0].data.i = mono_array_get (o, guint8, aindex);
3315 case MINT_LDELEM_I2:
3316 sp [0].data.i = mono_array_get (o, gint16, aindex);
3318 case MINT_LDELEM_U2:
3319 sp [0].data.i = mono_array_get (o, guint16, aindex);
3322 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3324 case MINT_LDELEM_I4:
3325 sp [0].data.i = mono_array_get (o, gint32, aindex);
3327 case MINT_LDELEM_U4:
3328 sp [0].data.i = mono_array_get (o, guint32, aindex);
3330 case MINT_LDELEM_I8:
3331 sp [0].data.l = mono_array_get (o, guint64, aindex);
3333 case MINT_LDELEM_R4:
3334 sp [0].data.f = mono_array_get (o, float, aindex);
3336 case MINT_LDELEM_R8:
3337 sp [0].data.f = mono_array_get (o, double, aindex);
3339 case MINT_LDELEM_REF:
3340 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3342 case MINT_LDELEM_VT: {
3343 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3344 i32 = READ32 (ip + 2);
3345 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3346 sp [0].data.vt = vt_sp;
3347 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
3348 vt_sp += (i32 + 7) & ~7;
3360 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3361 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3362 MINT_IN_CASE(MINT_STELEM_U1) /* fall through */
3363 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3364 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3365 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3366 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3367 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3368 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
3369 MINT_IN_CASE(MINT_STELEM_VT) {
3376 THROW_EX (mono_get_exception_null_reference (), ip);
3378 aindex = sp [1].data.i;
3379 if (aindex >= mono_array_length ((MonoArray *)o))
3380 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3384 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3386 case MINT_STELEM_I1:
3387 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3389 case MINT_STELEM_U1:
3390 mono_array_set ((MonoArray *) o, guint8, aindex, sp [2].data.i);
3392 case MINT_STELEM_I2:
3393 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3395 case MINT_STELEM_I4:
3396 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3398 case MINT_STELEM_I8:
3399 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3401 case MINT_STELEM_R4:
3402 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3404 case MINT_STELEM_R8:
3405 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3407 case MINT_STELEM_REF: {
3408 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3409 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3410 if (sp [2].data.p && !isinst_obj)
3411 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3412 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3415 case MINT_STELEM_VT: {
3416 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3417 i32 = READ32 (ip + 2);
3418 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3420 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
3421 vt_sp -= (i32 + 7) & ~7;
3432 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3433 if (sp [-1].data.i < 0)
3434 THROW_EX (mono_get_exception_overflow (), ip);
3437 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3438 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3439 THROW_EX (mono_get_exception_overflow (), ip);
3440 sp [-1].data.i = (gint32) sp [-1].data.l;
3443 MINT_IN_CASE(MINT_CONV_OVF_I4_U8)
3444 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGINT32_MAX)
3445 THROW_EX (mono_get_exception_overflow (), ip);
3446 sp [-1].data.i = (gint32) sp [-1].data.l;
3449 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3450 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3451 THROW_EX (mono_get_exception_overflow (), ip);
3452 sp [-1].data.i = (gint32) sp [-1].data.f;
3455 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3456 if (sp [-1].data.i < 0)
3457 THROW_EX (mono_get_exception_overflow (), ip);
3460 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3461 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3462 THROW_EX (mono_get_exception_overflow (), ip);
3463 sp [-1].data.i = (guint32) sp [-1].data.l;
3466 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3467 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3468 THROW_EX (mono_get_exception_overflow (), ip);
3469 sp [-1].data.i = (guint32) sp [-1].data.f;
3472 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3473 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3474 THROW_EX (mono_get_exception_overflow (), ip);
3477 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3478 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3479 THROW_EX (mono_get_exception_overflow (), ip);
3480 sp [-1].data.i = (gint16) sp [-1].data.l;
3483 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3484 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3485 THROW_EX (mono_get_exception_overflow (), ip);
3486 sp [-1].data.i = (gint16) sp [-1].data.f;
3489 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3490 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3491 THROW_EX (mono_get_exception_overflow (), ip);
3494 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3495 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3496 THROW_EX (mono_get_exception_overflow (), ip);
3497 sp [-1].data.i = (guint16) sp [-1].data.l;
3500 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3501 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3502 THROW_EX (mono_get_exception_overflow (), ip);
3503 sp [-1].data.i = (guint16) sp [-1].data.f;
3506 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3507 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3508 THROW_EX (mono_get_exception_overflow (), ip);
3511 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3512 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3513 THROW_EX (mono_get_exception_overflow (), ip);
3514 sp [-1].data.i = (gint8) sp [-1].data.l;
3517 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3518 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3519 THROW_EX (mono_get_exception_overflow (), ip);
3520 sp [-1].data.i = (gint8) sp [-1].data.f;
3523 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3524 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3525 THROW_EX (mono_get_exception_overflow (), ip);
3528 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3529 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3530 THROW_EX (mono_get_exception_overflow (), ip);
3531 sp [-1].data.i = (guint8) sp [-1].data.l;
3534 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3535 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3536 THROW_EX (mono_get_exception_overflow (), ip);
3537 sp [-1].data.i = (guint8) sp [-1].data.f;
3541 MINT_IN_CASE(MINT_LDELEM)
3542 MINT_IN_CASE(MINT_STELEM)
3543 MINT_IN_CASE(MINT_UNBOX_ANY)
3545 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3547 MINT_IN_CASE(MINT_CKFINITE)
3548 if (!isfinite(sp [-1].data.f))
3549 THROW_EX (mono_get_exception_arithmetic (), ip);
3553 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3555 MINT_IN_CASE(MINT_LDTOKEN)
3558 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3562 MINT_IN_CASE(MINT_ADD_OVF_I4)
3563 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3564 THROW_EX (mono_get_exception_overflow (), ip);
3567 MINT_IN_CASE(MINT_ADD_OVF_I8)
3568 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3569 THROW_EX (mono_get_exception_overflow (), ip);
3572 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3573 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3574 THROW_EX (mono_get_exception_overflow (), ip);
3575 BINOP_CAST(i, +, guint32);
3577 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3578 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3579 THROW_EX (mono_get_exception_overflow (), ip);
3580 BINOP_CAST(l, +, guint64);
3582 MINT_IN_CASE(MINT_MUL_OVF_I4)
3583 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3584 THROW_EX (mono_get_exception_overflow (), ip);
3587 MINT_IN_CASE(MINT_MUL_OVF_I8)
3588 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3589 THROW_EX (mono_get_exception_overflow (), ip);
3592 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3593 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3594 THROW_EX (mono_get_exception_overflow (), ip);
3595 BINOP_CAST(i, *, guint32);
3597 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3598 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3599 THROW_EX (mono_get_exception_overflow (), ip);
3600 BINOP_CAST(l, *, guint64);
3602 MINT_IN_CASE(MINT_SUB_OVF_I4)
3603 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3604 THROW_EX (mono_get_exception_overflow (), ip);
3607 MINT_IN_CASE(MINT_SUB_OVF_I8)
3608 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3609 THROW_EX (mono_get_exception_overflow (), ip);
3612 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3613 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3614 THROW_EX (mono_get_exception_overflow (), ip);
3615 BINOP_CAST(i, -, guint32);
3617 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3618 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3619 THROW_EX (mono_get_exception_overflow (), ip);
3620 BINOP_CAST(l, -, guint64);
3622 MINT_IN_CASE(MINT_ENDFINALLY)
3624 ip = finally_ips->data;
3625 finally_ips = g_slist_remove (finally_ips, ip);
3632 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3633 MINT_IN_CASE(MINT_LEAVE_S)
3634 while (sp > frame->stack) {
3638 if (*ip == MINT_LEAVE_S) {
3639 ip += (short) *(ip + 1);
3641 ip += (gint32) READ32 (ip + 1);
3644 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3645 frame->ex_handler = NULL;
3648 goto handle_finally;
3650 MINT_IN_CASE(MINT_ICALL_V_V)
3651 MINT_IN_CASE(MINT_ICALL_V_P)
3652 MINT_IN_CASE(MINT_ICALL_P_V)
3653 MINT_IN_CASE(MINT_ICALL_P_P)
3654 MINT_IN_CASE(MINT_ICALL_PP_V)
3655 MINT_IN_CASE(MINT_ICALL_PI_V)
3656 MINT_IN_CASE(MINT_ICALL_PP_P)
3657 MINT_IN_CASE(MINT_ICALL_PI_P)
3658 MINT_IN_CASE(MINT_ICALL_PPP_V)
3659 MINT_IN_CASE(MINT_ICALL_PPI_V)
3660 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3661 if (frame->ex != NULL)
3662 goto handle_exception;
3665 MINT_IN_CASE(MINT_MONO_LDPTR)
3666 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3670 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3671 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3672 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3676 MINT_IN_CASE(MINT_MONO_FREE)
3679 g_error ("that doesn't seem right");
3680 g_free (sp->data.p);
3682 MINT_IN_CASE(MINT_MONO_RETOBJ)
3685 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3686 mono_method_signature (frame->runtime_method->method)->pinvoke);
3687 if (sp > frame->stack)
3688 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3691 #define RELOP(datamem, op) \
3693 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3695 MINT_IN_CASE(MINT_CEQ_I4)
3698 MINT_IN_CASE(MINT_CEQ0_I4)
3699 sp [-1].data.i = (sp [-1].data.i == 0);
3702 MINT_IN_CASE(MINT_CEQ_I8)
3705 MINT_IN_CASE(MINT_CEQ_R8)
3707 if (isunordered (sp [-1].data.f, sp [0].data.f))
3710 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3713 MINT_IN_CASE(MINT_CGT_I4)
3716 MINT_IN_CASE(MINT_CGT_I8)
3719 MINT_IN_CASE(MINT_CGT_R8)
3721 if (isunordered (sp [-1].data.f, sp [0].data.f))
3724 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3728 #define RELOP_CAST(datamem, op, type) \
3730 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3733 MINT_IN_CASE(MINT_CGT_UN_I4)
3734 RELOP_CAST(i, >, guint32);
3736 MINT_IN_CASE(MINT_CGT_UN_I8)
3737 RELOP_CAST(l, >, guint64);
3739 MINT_IN_CASE(MINT_CGT_UN_R8)
3741 if (isunordered (sp [-1].data.f, sp [0].data.f))
3744 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3747 MINT_IN_CASE(MINT_CLT_I4)
3750 MINT_IN_CASE(MINT_CLT_I8)
3753 MINT_IN_CASE(MINT_CLT_R8)
3755 if (isunordered (sp [-1].data.f, sp [0].data.f))
3758 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3761 MINT_IN_CASE(MINT_CLT_UN_I4)
3762 RELOP_CAST(i, <, guint32);
3764 MINT_IN_CASE(MINT_CLT_UN_I8)
3765 RELOP_CAST(l, <, guint64);
3767 MINT_IN_CASE(MINT_CLT_UN_R8)
3769 if (isunordered (sp [-1].data.f, sp [0].data.f))
3772 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3775 MINT_IN_CASE(MINT_LDFTN) {
3776 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3781 MINT_IN_CASE(MINT_LDVIRTFTN) {
3782 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3786 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3788 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3793 MINT_IN_CASE(MINT_LDTHISA)
3794 g_error ("should not happen");
3795 // sp->data.p = &frame->obj;
3800 #define LDARG(datamem, argtype) \
3801 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3805 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3806 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3807 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3808 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3809 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3810 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3811 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3812 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3813 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3814 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3816 MINT_IN_CASE(MINT_LDARG_VT)
3818 i32 = READ32(ip + 2);
3819 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3820 vt_sp += (i32 + 7) & ~7;
3825 #define STARG(datamem, argtype) \
3827 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3830 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3831 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3832 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3833 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3834 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3835 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3836 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3837 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3838 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3839 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3841 MINT_IN_CASE(MINT_STARG_VT)
3842 i32 = READ32(ip + 2);
3844 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3845 vt_sp -= (i32 + 7) & ~7;
3849 #define STINARG(datamem, argtype) \
3851 int n = * (guint16 *)(ip + 1); \
3852 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3856 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3857 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3858 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3859 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3860 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3861 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3862 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3863 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3864 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3865 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3867 MINT_IN_CASE(MINT_STINARG_VT) {
3868 int n = * (guint16 *)(ip + 1);
3869 i32 = READ32(ip + 2);
3870 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3875 MINT_IN_CASE(MINT_LDARGA)
3876 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3881 #define LDLOC(datamem, argtype) \
3882 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3886 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3887 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3888 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3889 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3890 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3891 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3892 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3893 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3894 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3895 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3897 MINT_IN_CASE(MINT_LDLOC_VT)
3899 i32 = READ32(ip + 2);
3900 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3901 vt_sp += (i32 + 7) & ~7;
3906 MINT_IN_CASE(MINT_LDLOCA_S)
3907 sp->data.p = locals + * (guint16 *)(ip + 1);
3912 #define STLOC(datamem, argtype) \
3914 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3917 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3918 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3919 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3920 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3921 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3922 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3923 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3924 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3925 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3926 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3928 #define STLOC_NP(datamem, argtype) \
3929 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3932 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3933 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3935 MINT_IN_CASE(MINT_STLOC_VT)
3936 i32 = READ32(ip + 2);
3938 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3939 vt_sp -= (i32 + 7) & ~7;
3943 MINT_IN_CASE(MINT_LOCALLOC) {
3944 if (sp != frame->stack + 1) /*FIX?*/
3945 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3947 int len = sp [-1].data.i;
3948 sp [-1].data.p = alloca (len);
3949 MonoMethodHeader *header = mono_method_get_header_checked (frame->runtime_method->method, &error);
3950 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3951 if (header->init_locals)
3952 memset (sp [-1].data.p, 0, len);
3957 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3959 MINT_IN_CASE(MINT_INITOBJ)
3961 memset (sp->data.vt, 0, READ32(ip + 1));
3964 MINT_IN_CASE(MINT_CPBLK)
3966 if (!sp [0].data.p || !sp [1].data.p)
3967 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3969 /* FIXME: value and size may be int64... */
3970 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3973 MINT_IN_CASE(MINT_CONSTRAINED_) {
3975 /* FIXME: implement */
3977 token = READ32 (ip);
3982 MINT_IN_CASE(MINT_INITBLK)
3985 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3987 /* FIXME: value and size may be int64... */
3988 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3991 MINT_IN_CASE(MINT_NO_)
3992 /* FIXME: implement */
3996 MINT_IN_CASE(MINT_RETHROW)
3998 * need to clarify what this should actually do:
3999 * start the search from the last found handler in
4000 * this method or continue in the caller or what.
4001 * Also, do we need to run finally/fault handlers after a retrow?
4002 * Well, this implementation will follow the usual search
4003 * for an handler, considering the current ip as throw spot.
4004 * We need to NULL frame->ex_handler for the later code to
4005 * actually run the new found handler.
4007 frame->ex_handler = NULL;
4008 THROW_EX (frame->ex, ip - 1);
4011 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4012 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4016 g_assert_not_reached ();
4018 * Exception handling code.
4019 * The exception object is stored in frame->ex.
4026 MonoInvocation *inv;
4027 MonoExceptionClause *clause;
4033 g_print ("* Handling exception '%s' at IL_%04x\n",
4034 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4035 rtm == NULL ? 0 : frame->ip - rtm->code);
4037 if (die_on_exception)
4040 for (inv = frame; inv; inv = inv->parent) {
4042 if (inv->runtime_method == NULL)
4044 method = inv->runtime_method->method;
4045 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4047 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4049 if (inv->ip == NULL)
4051 ip_offset = inv->ip - inv->runtime_method->code;
4052 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4053 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4054 clause = &inv->runtime_method->clauses [i];
4055 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4056 if (!clause->flags) {
4057 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4058 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4061 * OK, we found an handler, now we need to execute the finally
4062 * and fault blocks before branching to the handler code.
4064 inv->ex_handler = clause;
4067 g_print ("* Found handler at '%s'\n", method->name);
4069 goto handle_finally;
4072 g_error ("FIXME: handle filter clause");
4078 * If we get here, no handler was found: print a stack trace.
4080 for (inv = frame; inv; inv = inv->parent) {
4081 if (inv->invoke_trap)
4082 goto handle_finally;
4085 ex_obj = (MonoObject*)frame->ex;
4086 mono_unhandled_exception (ex_obj);
4093 MonoExceptionClause *clause;
4094 GSList *old_list = finally_ips;
4095 MonoMethod *method = frame->runtime_method->method;
4096 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4097 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4101 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4103 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4104 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4107 ip_offset = frame->ip - rtm->code;
4109 if (endfinally_ip != NULL)
4110 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4111 for (i = 0; i < header->num_clauses; ++i)
4112 if (frame->ex_handler == &rtm->clauses [i])
4116 clause = &rtm->clauses [i];
4117 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4118 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4119 ip = rtm->code + clause->handler_offset;
4120 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4123 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4129 endfinally_ip = NULL;
4131 if (old_list != finally_ips && finally_ips) {
4132 ip = finally_ips->data;
4133 finally_ips = g_slist_remove (finally_ips, ip);
4134 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4139 * If an exception is set, we need to execute the fault handler, too,
4140 * otherwise, we continue normally.
4150 MonoExceptionClause *clause;
4151 MonoMethod *method = frame->runtime_method->method;
4152 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4153 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4157 g_print ("* Handle fault\n");
4159 ip_offset = frame->ip - rtm->code;
4160 for (i = 0; i < header->num_clauses; ++i) {
4161 clause = &rtm->clauses [i];
4162 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4163 ip = rtm->code + clause->handler_offset;
4166 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4172 * If the handler for the exception was found in this method, we jump
4173 * to it right away, otherwise we return and let the caller run
4174 * the finally, fault and catch blocks.
4175 * This same code should be present in the endfault opcode, but it
4176 * is corrently not assigned in the ECMA specs: LAMESPEC.
4178 if (frame->ex_handler) {
4181 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4183 ip = rtm->code + frame->ex_handler->handler_offset;
4185 vt_sp = (unsigned char *) sp + rtm->stack_size;
4186 sp->data.p = frame->ex;
4197 ves_exec_method (MonoInvocation *frame)
4199 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4200 ThreadContext context_struct;
4207 mono_unhandled_exception ((MonoObject*)frame->ex);
4210 if (context == NULL) {
4211 context = &context_struct;
4212 context_struct.domain = mono_domain_get ();
4213 context_struct.base_frame = frame;
4214 context_struct.current_frame = NULL;
4215 context_struct.env_frame = frame;
4216 context_struct.current_env = &env;
4217 context_struct.search_for_handler = 0;
4218 context_struct.managed_code = 0;
4219 mono_native_tls_set_value (thread_context_id, context);
4222 frame->parent = context->current_frame;
4223 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4224 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4225 context->managed_code = 1;
4226 ves_exec_method_with_context (frame, context);
4227 context->managed_code = 0;
4229 if (context != &context_struct && context->current_env) {
4230 context->env_frame->ex = frame->ex;
4231 longjmp (*context->current_env, 1);
4234 mono_unhandled_exception ((MonoObject*)frame->ex);
4236 if (context->base_frame == frame)
4237 mono_native_tls_set_value (thread_context_id, NULL);
4239 context->current_frame = frame->parent;
4243 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4245 MonoImage *image = mono_assembly_get_image (assembly);
4250 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4251 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4254 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4256 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4257 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4265 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4266 "Usage is: mint [options] executable args...\n\n", VERSION);
4268 "Runtime Debugging:\n"
4273 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4276 " --traceclassinit\n"
4279 " --debug method_name\n"
4286 " --config filename load the specified config file instead of the default\n"
4287 " --workers n maximum number of worker threads\n"
4293 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4294 MonoReflectionMethod **method,
4295 gint32 *iloffset, gint32 *native_offset,
4296 MonoString **file, gint32 *line, gint32 *column)
4298 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4299 MonoInvocation *inv = context->current_frame;
4303 for (i = 0; inv && i < skip; inv = inv->parent)
4304 if (inv->runtime_method != NULL)
4315 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4316 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4321 if (need_file_info) {
4325 *file = mono_string_new (mono_domain_get (), "unknown");
4332 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4334 MonoDomain *domain = mono_domain_get ();
4336 MonoArray *ta = exc->trace_ips;
4341 /* Exception is not thrown yet */
4342 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4343 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4347 len = mono_array_length (ta);
4349 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4350 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4352 for (i = skip; i < len / 2; i++) {
4353 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4354 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4355 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4356 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4359 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4360 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4361 sf->native_offset = ip - rtm->code;
4365 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4367 if (need_file_info) {
4370 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4372 sf->filename = filename? mono_string_new (domain, filename): NULL;
4379 mono_array_set (res, gpointer, i, sf);
4388 mono_native_tls_alloc (&thread_context_id, NULL);
4389 mono_native_tls_set_value (thread_context_id, NULL);
4390 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4391 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4393 mono_interp_transform_init ();
4396 typedef int (*TestMethod) (void);
4399 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4401 int result, expected, failed, cfailed, run;
4402 double elapsed, transform_time;
4404 MonoObject *result_obj;
4405 static gboolean filter_method_init = FALSE;
4406 static const char *filter_method = NULL;
4408 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4409 cfailed = failed = run = 0;
4410 transform_time = elapsed = 0.0;
4413 /* fixme: ugly hack - delete all previously compiled methods */
4414 if (domain_jit_info (domain)) {
4415 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4416 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4417 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4418 mono_jit_code_hash_init (&(domain->jit_code_hash));
4422 g_timer_start (timer);
4423 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4424 MonoObject *exc = NULL;
4426 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4428 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4432 if (!filter_method_init) {
4433 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4434 filter_method_init = TRUE;
4436 gboolean filter = FALSE;
4437 if (filter_method) {
4438 const char *name = filter_method;
4440 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4441 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4442 filter = mono_method_desc_full_match (desc, method);
4443 mono_method_desc_free (desc);
4445 filter = strcmp (method->name, name) == 0;
4447 } else { /* no filter, check for `Category' attribute on method */
4449 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
4450 mono_error_cleanup (&error);
4454 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
4455 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
4456 if (centry->ctor == NULL)
4459 MonoClass *klass = centry->ctor->klass;
4460 if (strcmp (klass->name, "CategoryAttribute"))
4463 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
4464 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
4465 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
4466 mono_error_cleanup (&error);
4467 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
4468 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
4469 mono_error_cleanup (&error);
4470 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
4471 mono_error_cleanup (&error);
4472 if (!strcmp (utf8_str, "!INTERPRETER")) {
4473 g_print ("skip %s...\n", method->name);
4479 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4480 MonoError interp_error;
4481 MonoObject *exc = NULL;
4483 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4484 if (!mono_error_ok (&interp_error)) {
4486 g_print ("Test '%s' execution failed.\n", method->name);
4487 } else if (exc != NULL) {
4488 g_print ("Exception in Test '%s' occured:\n", method->name);
4489 mono_object_describe (exc);
4493 result = *(gint32 *) mono_object_unbox (result_obj);
4494 expected = atoi (method->name + 5); // FIXME: oh no.
4497 if (result != expected) {
4499 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4504 g_timer_stop (timer);
4505 elapsed = g_timer_elapsed (timer, NULL);
4506 if (failed > 0 || cfailed > 0){
4507 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4508 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4510 g_print ("Results: total tests: %d, all pass \n", run);
4513 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4514 elapsed - transform_time, transform_time);
4515 *total += failed + cfailed;
4519 interp_regression (MonoImage *image, int verbose, int *total_run)
4522 GTimer *timer = g_timer_new ();
4523 MonoDomain *domain = mono_domain_get ();
4527 /* load the metadata */
4528 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4530 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4532 mono_error_cleanup (&error);
4535 mono_class_init (method->klass);
4540 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4542 g_timer_destroy (timer);
4547 mono_interp_regression_list (int verbose, int count, char *images [])
4549 int i, total, total_run, run;
4551 total_run = total = 0;
4552 for (i = 0; i < count; ++i) {
4553 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4555 g_warning ("failed to load assembly: %s", images [i]);
4558 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4562 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4564 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);