3 * PLEASE NOTE: This is a research prototype.
6 * interp.c: Interpreter for CIL byte codes
9 * Paolo Molaro (lupus@ximian.com)
10 * Miguel de Icaza (miguel@ximian.com)
11 * Dietmar Maurer (dietmar@ximian.com)
13 * (C) 2001, 2002 Ximian, Inc.
28 #include <mono/utils/gc_wrapper.h>
34 # define alloca __builtin_alloca
38 /* trim excessive headers */
39 #include <mono/metadata/image.h>
40 #include <mono/metadata/assembly-internals.h>
41 #include <mono/metadata/cil-coff.h>
42 #include <mono/metadata/mono-endian.h>
43 #include <mono/metadata/tabledefs.h>
44 #include <mono/metadata/tokentype.h>
45 #include <mono/metadata/loader.h>
46 #include <mono/metadata/threads.h>
47 #include <mono/metadata/threadpool.h>
48 #include <mono/metadata/profiler-private.h>
49 #include <mono/metadata/appdomain.h>
50 #include <mono/metadata/reflection.h>
51 #include <mono/metadata/reflection-internals.h>
52 #include <mono/metadata/exception.h>
53 #include <mono/metadata/verify.h>
54 #include <mono/metadata/opcodes.h>
55 #include <mono/metadata/debug-helpers.h>
56 #include <mono/metadata/mono-config.h>
57 #include <mono/metadata/marshal.h>
58 #include <mono/metadata/environment.h>
59 #include <mono/metadata/mono-debug.h>
60 #include <mono/utils/atomic.h>
63 #include "interp-internals.h"
67 #include <mono/mini/mini.h>
68 #include <mono/mini/jit-icalls.h>
71 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
74 #define finite _finite
78 #define finite isfinite
83 init_frame (MonoInvocation *frame, MonoInvocation *parent_frame, RuntimeMethod *rmethod, stackval *method_args, stackval *method_retval)
85 frame->parent = parent_frame;
86 frame->stack_args = method_args;
87 frame->retval = method_retval;
88 frame->runtime_method = rmethod;
91 frame->invoke_trap = 0;
94 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) do { \
95 RuntimeMethod *_rmethod = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
96 init_frame ((frame), (parent_frame), _rmethod, (method_args), (method_retval)); \
100 * List of classes whose methods will be executed by transitioning to JITted code.
105 void ves_exec_method (MonoInvocation *frame);
107 static char* dump_stack (stackval *stack, stackval *sp);
108 static char* dump_frame (MonoInvocation *inv);
109 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
110 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception);
112 typedef void (*ICallMethod) (MonoInvocation *frame);
114 static guint32 die_on_exception = 0;
115 static MonoNativeTlsKey thread_context_id;
117 static char* dump_args (MonoInvocation *inv);
119 #define DEBUG_INTERP 0
122 int mono_interp_traceopt = 2;
123 /* If true, then we output the opcodes as we interpret them */
124 static int global_tracing = 2;
126 static int debug_indent_level = 0;
128 static int break_on_method = 0;
129 static int nested_trace = 0;
130 static GList *db_methods = NULL;
137 for (h = 0; h < debug_indent_level; h++)
142 db_match_method (gpointer data, gpointer user_data)
144 MonoMethod *m = (MonoMethod*)user_data;
145 MonoMethodDesc *desc = data;
147 if (mono_method_desc_full_match (desc, m))
151 static void debug_enter (MonoInvocation *frame, int *tracing)
154 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
156 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
160 MonoMethod *method = frame->runtime_method->method;
161 char *mn, *args = dump_args (frame);
162 debug_indent_level++;
164 mn = mono_method_full_name (method, FALSE);
165 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
167 g_print ("%s)\n", args);
170 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
171 mono_profiler_method_enter (frame->runtime_method->method);
175 #define DEBUG_LEAVE() \
178 args = dump_retval (frame); \
180 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
181 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
183 g_print (" => %s\n", args); \
185 debug_indent_level--; \
186 if (tracing == 3) global_tracing = 0; \
188 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
189 mono_profiler_method_leave (frame->runtime_method->method);
193 int mono_interp_traceopt = 0;
194 static void debug_enter (MonoInvocation *frame, int *tracing)
197 #define DEBUG_LEAVE()
202 interp_ex_handler (MonoException *ex) {
204 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
208 stack_trace = dump_frame (context->current_frame);
209 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
210 g_free (stack_trace);
211 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
212 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
213 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
214 fprintf(stderr, "Nothing can catch this exception: ");
215 fprintf(stderr, "%s", ex->object.vtable->klass->name);
216 if (ex->message != NULL) {
217 char *m = mono_string_to_utf8_checked (ex->message, &error);
218 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
219 fprintf(stderr, ": %s", m);
222 fprintf(stderr, "\n%s\n", strace);
224 if (ex->inner_ex != NULL) {
225 ex = (MonoException *)ex->inner_ex;
226 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
227 if (ex->message != NULL) {
228 char *m = mono_string_to_utf8_checked (ex->message, &error);
229 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
230 fprintf(stderr, ": %s", m);
233 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
234 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
235 fprintf(stderr, "\n");
236 fprintf(stderr, "%s\n", strace);
239 /* wait for other threads to also collapse */
240 // Sleep(1000); // TODO: proper sleep
243 context->env_frame->ex = ex;
244 context->search_for_handler = 1;
245 longjmp (*context->current_env, 1);
249 ves_real_abort (int line, MonoMethod *mh,
250 const unsigned short *ip, stackval *stack, stackval *sp)
253 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
254 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
255 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
256 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
257 g_print ("0x%04x %02x\n",
258 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
259 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
261 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
264 #define ves_abort() \
266 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
267 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
271 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
274 MonoJitDomainInfo *info;
275 MonoMethodSignature *sig;
280 info = domain_jit_info (domain);
281 mono_domain_jit_code_hash_lock (domain);
282 rtm = mono_internal_hash_table_lookup (&info->interp_code_hash, method);
283 mono_domain_jit_code_hash_unlock (domain);
287 sig = mono_method_signature (method);
289 rtm = mono_domain_alloc0 (domain, sizeof (RuntimeMethod));
290 rtm->method = method;
291 rtm->param_count = sig->param_count;
292 rtm->hasthis = sig->hasthis;
293 rtm->rtype = mini_get_underlying_type (sig->ret);
294 rtm->param_types = mono_domain_alloc0 (domain, sizeof (MonoType*) * sig->param_count);
295 for (i = 0; i < sig->param_count; ++i)
296 rtm->param_types [i] = mini_get_underlying_type (sig->params [i]);
298 mono_domain_jit_code_hash_lock (domain);
299 if (!mono_internal_hash_table_lookup (&info->interp_code_hash, method))
300 mono_internal_hash_table_insert (&info->interp_code_hash, method, rtm);
301 mono_domain_jit_code_hash_unlock (domain);
307 mono_interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
309 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
310 method = mono_marshal_get_synchronized_wrapper (method);
311 return mono_interp_get_runtime_method (domain, method, error);
314 static inline RuntimeMethod*
315 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
317 MonoMethod *m = runtime_method->method;
320 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
321 RuntimeMethod *ret = NULL;
322 if (mono_object_is_transparent_proxy (obj)) {
323 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
324 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
325 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
326 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
327 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
329 ret = runtime_method;
334 mono_class_setup_vtable (obj->vtable->klass);
336 int slot = mono_method_get_vtable_slot (m);
337 if (mono_class_is_interface (m->klass)) {
338 g_assert (obj->vtable->klass != m->klass);
339 /* TODO: interface offset lookup is slow, go through IMT instead */
340 gboolean non_exact_match;
341 slot += mono_class_interface_offset_with_variance (obj->vtable->klass, m->klass, &non_exact_match);
344 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
345 if (m->is_inflated && mono_method_get_context (m)->method_inst) {
346 MonoGenericContext context = { NULL, NULL };
348 if (mono_class_is_ginst (virtual_method->klass))
349 context.class_inst = mono_class_get_generic_class (virtual_method->klass)->context.class_inst;
350 else if (mono_class_is_gtd (virtual_method->klass))
351 context.class_inst = mono_class_get_generic_container (virtual_method->klass)->context.class_inst;
352 context.method_inst = mono_method_get_context (m)->method_inst;
354 virtual_method = mono_class_inflate_generic_method_checked (virtual_method, &context, &error);
355 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
358 if (virtual_method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
359 virtual_method = mono_marshal_get_synchronized_wrapper (virtual_method);
362 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
363 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
364 return virtual_runtime_method;
368 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
371 switch (type->type) {
372 case MONO_TYPE_OBJECT:
373 case MONO_TYPE_CLASS:
374 case MONO_TYPE_STRING:
375 case MONO_TYPE_ARRAY:
376 case MONO_TYPE_SZARRAY:
381 result->data.p = *(gpointer*)data;
384 switch (type->type) {
388 result->data.i = *(gint8*)data;
391 case MONO_TYPE_BOOLEAN:
392 result->data.i = *(guint8*)data;
395 result->data.i = *(gint16*)data;
399 result->data.i = *(guint16*)data;
402 result->data.i = *(gint32*)data;
406 result->data.nati = *(mono_i*)data;
409 result->data.p = *(gpointer*)data;
412 result->data.i = *(guint32*)data;
415 result->data.f = *(float*)data;
419 result->data.l = *(gint64*)data;
422 result->data.f = *(double*)data;
424 case MONO_TYPE_STRING:
425 case MONO_TYPE_SZARRAY:
426 case MONO_TYPE_CLASS:
427 case MONO_TYPE_OBJECT:
428 case MONO_TYPE_ARRAY:
429 result->data.p = *(gpointer*)data;
431 case MONO_TYPE_VALUETYPE:
432 if (type->data.klass->enumtype) {
433 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
436 mono_value_copy (result->data.vt, data, type->data.klass);
438 case MONO_TYPE_GENERICINST:
439 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
442 g_warning ("got type 0x%02x", type->type);
443 g_assert_not_reached ();
448 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
451 gpointer *p = (gpointer*)data;
455 /* printf ("TODAT0 %p\n", data); */
456 switch (type->type) {
459 guint8 *p = (guint8*)data;
463 case MONO_TYPE_BOOLEAN: {
464 guint8 *p = (guint8*)data;
465 *p = (val->data.i != 0);
470 case MONO_TYPE_CHAR: {
471 guint16 *p = (guint16*)data;
476 mono_i *p = (mono_i*)data;
477 /* In theory the value used by stloc should match the local var type
478 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
479 a native int - both by csc and mcs). Not sure what to do about sign extension
480 as it is outside the spec... doing the obvious */
481 *p = (mono_i)val->data.nati;
485 mono_u *p = (mono_u*)data;
487 *p = (mono_u)val->data.nati;
492 gint32 *p = (gint32*)data;
498 gint64 *p = (gint64*)data;
503 float *p = (float*)data;
508 double *p = (double*)data;
512 case MONO_TYPE_STRING:
513 case MONO_TYPE_SZARRAY:
514 case MONO_TYPE_CLASS:
515 case MONO_TYPE_OBJECT:
516 case MONO_TYPE_ARRAY: {
517 gpointer *p = (gpointer *) data;
518 mono_gc_wbarrier_generic_store (p, val->data.p);
521 case MONO_TYPE_PTR: {
522 gpointer *p = (gpointer *) data;
526 case MONO_TYPE_VALUETYPE:
527 if (type->data.klass->enumtype) {
528 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
531 mono_value_copy (data, val->data.vt, type->data.klass);
533 case MONO_TYPE_GENERICINST: {
534 MonoClass *container_class = type->data.generic_class->container_class;
536 if (container_class->valuetype && !container_class->enumtype) {
537 mono_value_copy (data, val->data.vt, mono_class_from_mono_type (type));
540 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
544 g_warning ("got type %x", type->type);
545 g_assert_not_reached ();
550 fill_in_trace (MonoException *exception, MonoInvocation *frame)
552 char *stack_trace = dump_frame (frame);
553 MonoDomain *domain = mono_domain_get();
554 (exception)->stack_trace = mono_string_new (domain, stack_trace);
555 (exception)->trace_ips = get_trace_ips (domain, frame);
556 g_free (stack_trace);
559 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
561 #define THROW_EX(exception,ex_ip) \
563 frame->ip = (ex_ip); \
564 frame->ex = (MonoException*)(exception); \
565 FILL_IN_TRACE(frame->ex, frame); \
566 goto handle_exception; \
570 ves_array_create (MonoInvocation *frame, MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
573 intptr_t *lower_bounds;
578 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
579 for (i = 0; i < sig->param_count; ++i) {
580 lengths [i] = values->data.i;
583 if (klass->rank == sig->param_count) {
584 /* Only lengths provided. */
587 /* lower bounds are first. */
588 lower_bounds = (intptr_t *) lengths;
589 lengths += klass->rank;
591 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
592 if (!mono_error_ok (&error)) {
593 frame->ex = mono_error_convert_to_exception (&error);
594 FILL_IN_TRACE (frame->ex, frame);
596 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
601 ves_array_calculate_index (MonoArray *ao, stackval *sp, MonoInvocation *frame)
603 g_assert (!frame->ex);
604 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
608 for (gint32 i = 0; i < ac->rank; i++) {
609 guint32 idx = sp [i].data.i;
610 guint32 lower = ao->bounds [i].lower_bound;
611 guint32 len = ao->bounds [i].length;
612 if (idx < lower || (idx - lower) >= len) {
613 frame->ex = mono_get_exception_index_out_of_range ();
614 FILL_IN_TRACE (frame->ex, frame);
617 pos = (pos * len) + idx - lower;
621 if (pos >= ao->max_length) {
622 frame->ex = mono_get_exception_index_out_of_range ();
623 FILL_IN_TRACE (frame->ex, frame);
631 ves_array_set (MonoInvocation *frame)
633 stackval *sp = frame->stack_args + 1;
635 MonoObject *o = frame->stack_args->data.p;
636 MonoArray *ao = (MonoArray *) o;
637 MonoClass *ac = o->vtable->klass;
639 g_assert (ac->rank >= 1);
641 gint32 pos = ves_array_calculate_index (ao, sp, frame);
645 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
647 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
648 mono_error_cleanup (&error);
650 frame->ex = mono_get_exception_array_type_mismatch ();
651 FILL_IN_TRACE (frame->ex, frame);
656 gint32 esize = mono_array_element_size (ac);
657 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
659 MonoType *mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
660 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
664 ves_array_get (MonoInvocation *frame)
666 stackval *sp = frame->stack_args + 1;
668 MonoObject *o = frame->stack_args->data.p;
669 MonoArray *ao = (MonoArray *) o;
670 MonoClass *ac = o->vtable->klass;
672 g_assert (ac->rank >= 1);
674 gint32 pos = ves_array_calculate_index (ao, sp, frame);
678 gint32 esize = mono_array_element_size (ac);
679 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
681 MonoType *mt = mono_method_signature (frame->runtime_method->method)->ret;
682 stackval_from_data (mt, frame->retval, ea, FALSE);
686 ves_array_element_address (MonoInvocation *frame, MonoClass *required_type, MonoArray *ao, stackval *sp, gboolean needs_typecheck)
688 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
690 g_assert (ac->rank >= 1);
692 gint32 pos = ves_array_calculate_index (ao, sp, frame);
696 if (needs_typecheck && !mono_class_is_assignable_from (mono_object_class ((MonoObject *) ao)->element_class, required_type->element_class)) {
697 frame->ex = mono_get_exception_array_type_mismatch ();
698 FILL_IN_TRACE (frame->ex, frame);
701 gint32 esize = mono_array_element_size (ac);
702 return mono_array_addr_with_size (ao, esize, pos);
706 interp_walk_stack_with_ctx (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data)
709 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
714 MonoInvocation *frame = context->current_frame;
717 MonoStackFrameInfo fi;
718 memset (&fi, 0, sizeof (MonoStackFrameInfo));
720 /* TODO: hack to make some asserts happy. */
721 fi.ji = (MonoJitInfo *) frame->runtime_method;
723 if (frame->runtime_method)
724 fi.method = fi.actual_method = frame->runtime_method->method;
726 if (!fi.method || (fi.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (fi.method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
728 fi.type = FRAME_TYPE_MANAGED_TO_NATIVE;
730 MonoMethodHeader *hd = mono_method_get_header_checked (fi.method, &error);
731 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
732 fi.type = FRAME_TYPE_MANAGED;
733 fi.il_offset = frame->ip - (const unsigned short *) hd->code;
734 if (!fi.method->wrapper_type)
738 if (func (&fi, ctx, user_data))
740 frame = frame->parent;
744 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
746 struct _MethodArguments {
755 typedef struct _MethodArguments MethodArguments;
757 // TODO: this function is also arch dependent (register width).
758 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
760 // TODO: don't malloc this data structure.
761 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
766 for (int i = 0; i < sig->param_count; i++) {
767 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
769 case MONO_TYPE_BOOLEAN:
780 case MONO_TYPE_SZARRAY:
781 case MONO_TYPE_CLASS:
782 case MONO_TYPE_OBJECT:
783 case MONO_TYPE_STRING:
785 case MONO_TYPE_VALUETYPE:
786 case MONO_TYPE_GENERICINST:
794 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
799 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
802 margs->fargs = g_malloc0 (sizeof (double) * margs->flen);
804 if (margs->ilen > 12)
805 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs->ilen);
808 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs->flen);
815 margs->iargs [0] = frame->stack_args->data.p;
819 for (int i = 0; i < sig->param_count; i++) {
820 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
822 case MONO_TYPE_BOOLEAN:
833 case MONO_TYPE_SZARRAY:
834 case MONO_TYPE_CLASS:
835 case MONO_TYPE_OBJECT:
836 case MONO_TYPE_STRING:
838 case MONO_TYPE_VALUETYPE:
839 case MONO_TYPE_GENERICINST:
840 margs->iargs [int_i] = frame->stack_args [i].data.p;
842 g_print ("build_args_from_sig: margs->iargs [%d]: %p (frame @ %d)\n", int_i, margs->iargs [int_i], i);
848 if (ptype == MONO_TYPE_R4)
849 * (float *) &(margs->fargs [int_f]) = (float) frame->stack_args [i].data.f;
851 margs->fargs [int_f] = frame->stack_args [i].data.f;
853 g_print ("build_args_from_sig: margs->fargs [%d]: %p (%f) (frame @ %d)\n", int_f, margs->fargs [int_f], margs->fargs [int_f], i);
858 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
862 switch (sig->ret->type) {
863 case MONO_TYPE_BOOLEAN:
874 case MONO_TYPE_SZARRAY:
875 case MONO_TYPE_CLASS:
876 case MONO_TYPE_OBJECT:
877 case MONO_TYPE_STRING:
879 case MONO_TYPE_VALUETYPE:
880 case MONO_TYPE_GENERICINST:
881 margs->retval = &(frame->retval->data.p);
885 margs->retval = &(frame->retval->data.p);
886 margs->is_float_ret = 1;
889 margs->retval = NULL;
892 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig->ret->type);
899 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
902 MonoInvocation *old_frame = context->current_frame;
903 MonoInvocation *old_env_frame = context->env_frame;
904 jmp_buf *old_env = context->current_env;
907 context->current_frame = old_frame;
908 context->env_frame = old_env_frame;
909 context->current_env = old_env;
910 context->managed_code = 1;
915 context->env_frame = frame;
916 context->current_env = &env;
918 g_assert (!frame->runtime_method);
919 if (!mono_interp_enter_icall_trampoline) {
921 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
923 // mono_tramp_info_register (info, NULL);
926 MethodArguments *margs = build_args_from_sig (sig, frame);
928 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
929 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
932 context->current_frame = frame;
933 context->managed_code = 0;
935 mono_interp_enter_icall_trampoline (addr, margs);
937 context->managed_code = 1;
938 /* domain can only be changed by native code */
939 context->domain = mono_domain_get ();
941 if (*mono_thread_interruption_request_flag ()) {
942 MonoException *exc = mono_thread_interruption_checkpoint ();
945 context->search_for_handler = 1;
949 if (!frame->ex && !MONO_TYPE_ISSTRUCT (sig->ret))
950 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
952 context->current_frame = old_frame;
953 context->env_frame = old_env_frame;
954 context->current_env = old_env;
956 g_free (margs->iargs);
957 g_free (margs->fargs);
962 mono_interp_init_delegate (MonoDelegate *del)
966 /* shouldn't need a write barrier because we don't write a MonoObject into the field */
967 del->method = ((RuntimeMethod *) del->method_ptr)->method;
972 * runtime specifies that the implementation of the method is automatically
973 * provided by the runtime and is primarily used for the methods of delegates.
976 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
978 MonoMethod *method = frame->runtime_method->method;
979 const char *name = method->name;
980 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
981 MonoObject *isinst_obj;
984 mono_class_init (method->klass);
986 if (method->klass == mono_defaults.array_class) {
987 if (!strcmp (method->name, "UnsafeMov")) {
988 /* TODO: layout checks */
989 MonoType *mt = mono_method_signature (method)->ret;
990 stackval_from_data (mt, frame->retval, (char *) frame->stack_args, FALSE);
995 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
996 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
997 if (obj && isinst_obj) {
998 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
999 ves_array_set (frame);
1002 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
1003 ves_array_get (frame);
1008 g_error ("Don't know how to exec runtime method %s.%s::%s",
1009 method->klass->name_space, method->klass->name,
1014 dump_stack (stackval *stack, stackval *sp)
1016 stackval *s = stack;
1017 GString *str = g_string_new ("");
1020 return g_string_free (str, FALSE);
1023 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
1026 return g_string_free (str, FALSE);
1030 dump_stackval (GString *str, stackval *s, MonoType *type)
1032 switch (type->type) {
1039 case MONO_TYPE_CHAR:
1040 case MONO_TYPE_BOOLEAN:
1041 g_string_append_printf (str, "[%d] ", s->data.i);
1043 case MONO_TYPE_STRING:
1044 case MONO_TYPE_SZARRAY:
1045 case MONO_TYPE_CLASS:
1046 case MONO_TYPE_OBJECT:
1047 case MONO_TYPE_ARRAY:
1051 g_string_append_printf (str, "[%p] ", s->data.p);
1053 case MONO_TYPE_VALUETYPE:
1054 if (type->data.klass->enumtype)
1055 g_string_append_printf (str, "[%d] ", s->data.i);
1057 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1061 g_string_append_printf (str, "[%g] ", s->data.f);
1066 GString *res = g_string_new ("");
1067 mono_type_get_desc (res, type, TRUE);
1068 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1069 g_string_free (res, TRUE);
1076 dump_args (MonoInvocation *inv)
1078 GString *str = g_string_new ("");
1080 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1082 if (signature->param_count == 0 && !signature->hasthis)
1083 return g_string_free (str, FALSE);
1085 if (signature->hasthis) {
1086 MonoMethod *method = inv->runtime_method->method;
1087 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1090 for (i = 0; i < signature->param_count; ++i)
1091 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1093 return g_string_free (str, FALSE);
1097 dump_retval (MonoInvocation *inv)
1099 GString *str = g_string_new ("");
1100 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1102 if (ret->type != MONO_TYPE_VOID)
1103 dump_stackval (str, inv->retval, ret);
1105 return g_string_free (str, FALSE);
1109 dump_frame (MonoInvocation *inv)
1111 GString *str = g_string_new ("");
1116 for (i = 0; inv; inv = inv->parent) {
1117 if (inv->runtime_method != NULL) {
1118 MonoMethod *method = inv->runtime_method->method;
1122 const char * opname = "";
1124 gchar *source = NULL;
1128 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1129 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1130 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1131 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1135 opname = mono_interp_opname [*inv->ip];
1136 codep = inv->ip - inv->runtime_method->code;
1137 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1142 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1143 source = mono_debug_method_lookup_location (minfo, codep);
1147 args = dump_args (inv);
1148 name = mono_method_full_name (method, TRUE);
1150 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1152 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1159 return g_string_free (str, FALSE);
1163 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1167 MonoInvocation *inv;
1170 for (i = 0, inv = top; inv; inv = inv->parent)
1171 if (inv->runtime_method != NULL)
1174 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1175 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1177 for (i = 0, inv = top; inv; inv = inv->parent)
1178 if (inv->runtime_method != NULL) {
1179 mono_array_set (res, gpointer, i, inv->runtime_method);
1181 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1189 #define MYGUINT64_MAX 18446744073709551615ULL
1190 #define MYGINT64_MAX 9223372036854775807LL
1191 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1193 #define MYGUINT32_MAX 4294967295U
1194 #define MYGINT32_MAX 2147483647
1195 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1197 #define CHECK_ADD_OVERFLOW(a,b) \
1198 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1199 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1201 #define CHECK_SUB_OVERFLOW(a,b) \
1202 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1203 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1205 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1206 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1208 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1209 (guint32)(a) < (guint32)(b) ? -1 : 0
1211 #define CHECK_ADD_OVERFLOW64(a,b) \
1212 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1213 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1215 #define CHECK_SUB_OVERFLOW64(a,b) \
1216 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1217 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1219 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1220 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1222 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1223 (guint64)(a) < (guint64)(b) ? -1 : 0
1225 #if SIZEOF_VOID_P == 4
1226 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1227 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1229 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1230 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1233 /* Resolves to TRUE if the operands would overflow */
1234 #define CHECK_MUL_OVERFLOW(a,b) \
1235 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1236 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1237 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1238 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1239 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1240 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1241 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1243 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1244 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1245 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1247 #define CHECK_MUL_OVERFLOW64(a,b) \
1248 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1249 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1250 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1251 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1252 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1253 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1254 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1256 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1257 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1258 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1260 #if SIZEOF_VOID_P == 4
1261 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1262 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1264 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1265 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1269 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1271 MonoInvocation frame;
1272 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1273 MonoObject *retval = NULL;
1274 MonoMethodSignature *sig = mono_method_signature (method);
1275 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1276 int i, type, isobject = 0;
1279 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1280 ThreadContext context_struct;
1281 MonoInvocation *old_frame = NULL;
1291 if (context != &context_struct) {
1292 context->domain = mono_domain_get ();
1293 context->current_frame = old_frame;
1294 context->managed_code = 0;
1296 mono_native_tls_set_value (thread_context_id, NULL);
1298 *exc = (MonoObject *)frame.ex;
1302 if (context == NULL) {
1303 context = &context_struct;
1304 context_struct.base_frame = &frame;
1305 context_struct.current_frame = NULL;
1306 context_struct.env_frame = &frame;
1307 context_struct.current_env = &env;
1308 context_struct.search_for_handler = 0;
1309 context_struct.managed_code = 0;
1310 mono_native_tls_set_value (thread_context_id, context);
1313 old_frame = context->current_frame;
1315 context->domain = mono_domain_get ();
1317 switch (sig->ret->type) {
1318 case MONO_TYPE_VOID:
1320 case MONO_TYPE_STRING:
1321 case MONO_TYPE_OBJECT:
1322 case MONO_TYPE_CLASS:
1323 case MONO_TYPE_ARRAY:
1324 case MONO_TYPE_SZARRAY:
1327 case MONO_TYPE_VALUETYPE:
1328 retval = mono_object_new_checked (context->domain, klass, error);
1329 ret = mono_object_unbox (retval);
1330 if (!sig->ret->data.klass->enumtype)
1331 result.data.vt = ret;
1333 result.data.vt = alloca (mono_class_instance_size (klass));
1335 case MONO_TYPE_GENERICINST:
1336 if (!MONO_TYPE_IS_REFERENCE (sig->ret)) {
1337 retval = mono_object_new_checked (context->domain, klass, error);
1338 ret = mono_object_unbox (retval);
1339 if (!sig->ret->data.klass->enumtype)
1340 result.data.vt = ret;
1342 result.data.vt = alloca (mono_class_instance_size (klass));
1349 retval = mono_object_new_checked (context->domain, mono_defaults.int_class, error);
1350 ret = mono_object_unbox (retval);
1353 retval = mono_object_new_checked (context->domain, klass, error);
1354 ret = mono_object_unbox (retval);
1359 args [0].data.p = obj;
1361 for (i = 0; i < sig->param_count; ++i) {
1362 int a_index = i + !!sig->hasthis;
1363 if (sig->params [i]->byref) {
1364 args [a_index].data.p = params [i];
1367 type = sig->params [i]->type;
1372 case MONO_TYPE_BOOLEAN:
1373 args [a_index].data.i = *(MonoBoolean*)params [i];
1377 case MONO_TYPE_CHAR:
1378 args [a_index].data.i = *(gint16*)params [i];
1380 #if SIZEOF_VOID_P == 4
1381 case MONO_TYPE_U: /* use VAL_POINTER? */
1386 args [a_index].data.i = *(gint32*)params [i];
1388 #if SIZEOF_VOID_P == 8
1394 args [a_index].data.l = *(gint64*)params [i];
1397 args [a_index].data.f = *(gfloat *) params [i];
1400 args [a_index].data.f = *(gdouble *) params [i];
1402 case MONO_TYPE_VALUETYPE:
1403 if (sig->params [i]->data.klass->enumtype) {
1404 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1407 args [a_index].data.p = params [i];
1410 case MONO_TYPE_STRING:
1412 case MONO_TYPE_CLASS:
1413 case MONO_TYPE_ARRAY:
1414 case MONO_TYPE_SZARRAY:
1415 case MONO_TYPE_OBJECT:
1416 case MONO_TYPE_GENERICINST:
1417 args [a_index].data.p = params [i];
1420 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1424 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1425 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1426 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1428 frame.invoke_trap = 1;
1429 context->managed_code = 1;
1430 ves_exec_method_with_context (&frame, context, NULL, NULL);
1431 context->managed_code = 0;
1432 if (context == &context_struct)
1433 mono_native_tls_set_value (thread_context_id, NULL);
1435 context->current_frame = old_frame;
1436 if (frame.ex != NULL) {
1438 *exc = (MonoObject*) frame.ex;
1441 if (context->current_env != NULL) {
1442 context->env_frame->ex = frame.ex;
1443 longjmp(*context->current_env, 1);
1446 printf("dropped exception...\n");
1448 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1450 if (isobject || method->string_ctor)
1451 return result.data.p;
1452 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1457 RuntimeMethod *rmethod;
1461 gpointer *many_args;
1464 /* Main function for entering the interpreter from compiled code */
1466 interp_entry (InterpEntryData *data)
1468 MonoInvocation frame;
1469 RuntimeMethod *rmethod = data->rmethod;
1470 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
1471 ThreadContext context_struct;
1472 MonoInvocation *old_frame;
1476 MonoMethodSignature *sig;
1480 method = rmethod->method;
1481 sig = mono_method_signature (method);
1483 // FIXME: Optimize this
1485 //printf ("%s\n", mono_method_full_name (method, 1));
1488 if (context == NULL) {
1489 context = &context_struct;
1490 memset (context, 0, sizeof (ThreadContext));
1491 context_struct.base_frame = &frame;
1492 context_struct.env_frame = &frame;
1493 mono_native_tls_set_value (thread_context_id, context);
1496 old_frame = context->current_frame;
1497 context->domain = mono_domain_get ();
1499 args = alloca (sizeof (stackval) * (sig->param_count + (sig->hasthis ? 1 : 0)));
1501 args [0].data.p = data->this_arg;
1504 if (data->many_args)
1505 params = data->many_args;
1507 params = data->args;
1508 for (i = 0; i < sig->param_count; ++i) {
1509 int a_index = i + (sig->hasthis ? 1 : 0);
1510 if (sig->params [i]->byref) {
1511 args [a_index].data.p = params [i];
1514 type = rmethod->param_types [i];
1515 switch (type->type) {
1518 args [a_index].data.i = *(MonoBoolean*)params [i];
1522 args [a_index].data.i = *(gint16*)params [i];
1525 #if SIZEOF_VOID_P == 4
1526 args [a_index].data.p = GINT_TO_POINTER (*(guint32*)params [i]);
1528 args [a_index].data.p = GINT_TO_POINTER (*(guint64*)params [i]);
1532 #if SIZEOF_VOID_P == 4
1533 args [a_index].data.p = GINT_TO_POINTER (*(gint32*)params [i]);
1535 args [a_index].data.p = GINT_TO_POINTER (*(gint64*)params [i]);
1539 args [a_index].data.i = *(guint32*)params [i];
1542 args [a_index].data.i = *(gint32*)params [i];
1545 args [a_index].data.l = *(guint64*)params [i];
1548 args [a_index].data.l = *(gint64*)params [i];
1551 case MONO_TYPE_OBJECT:
1552 args [a_index].data.p = *(MonoObject**)params [i];
1554 case MONO_TYPE_VALUETYPE:
1555 args [a_index].data.p = params [i];
1557 case MONO_TYPE_GENERICINST:
1558 if (MONO_TYPE_IS_REFERENCE (type))
1559 args [a_index].data.p = params [i];
1561 args [a_index].data.vt = params [i];
1564 printf ("%s\n", mono_type_full_name (sig->params [i]));
1570 init_frame (&frame, context->current_frame, data->rmethod, args, &result);
1571 context->managed_code = 1;
1573 type = rmethod->rtype;
1574 switch (type->type) {
1575 case MONO_TYPE_GENERICINST:
1576 if (!MONO_TYPE_IS_REFERENCE (type))
1577 frame.retval->data.vt = data->res;
1579 case MONO_TYPE_VALUETYPE:
1580 frame.retval->data.vt = data->res;
1586 ves_exec_method_with_context (&frame, context, NULL, NULL);
1587 context->managed_code = 0;
1588 if (context == &context_struct)
1589 mono_native_tls_set_value (thread_context_id, NULL);
1591 context->current_frame = old_frame;
1594 g_assert (frame.ex == NULL);
1596 type = rmethod->rtype;
1597 switch (type->type) {
1598 case MONO_TYPE_VOID:
1601 *(gint8*)data->res = frame.retval->data.i;
1604 *(guint8*)data->res = frame.retval->data.i;
1607 *(gint16*)data->res = frame.retval->data.i;
1610 *(guint16*)data->res = frame.retval->data.i;
1613 *(gint32*)data->res = frame.retval->data.i;
1616 *(guint64*)data->res = frame.retval->data.i;
1619 *(gint64*)data->res = frame.retval->data.i;
1622 *(guint64*)data->res = frame.retval->data.i;
1625 #if SIZEOF_VOID_P == 8
1626 *(gint64*)data->res = (gint64)frame.retval->data.p;
1628 *(gint32*)data->res = (gint32)frame.retval->data.p;
1632 #if SIZEOF_VOID_P == 8
1633 *(guint64*)data->res = (guint64)frame.retval->data.p;
1635 *(guint32*)data->res = (guint32)frame.retval->data.p;
1638 case MONO_TYPE_OBJECT:
1639 /* No need for a write barrier */
1640 *(MonoObject**)data->res = (MonoObject*)frame.retval->data.p;
1642 case MONO_TYPE_GENERICINST:
1643 if (MONO_TYPE_IS_REFERENCE (type)) {
1644 *(MonoObject**)data->res = *(MonoObject**)frame.retval->data.p;
1646 /* Already set before the call */
1649 case MONO_TYPE_VALUETYPE:
1650 /* Already set before the call */
1653 printf ("%s\n", mono_type_full_name (sig->ret));
1660 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1662 MonoInvocation *old_frame = context->current_frame;
1663 MonoInvocation *old_env_frame = context->env_frame;
1664 jmp_buf *old_env = context->current_env;
1668 context->current_frame = old_frame;
1669 context->env_frame = old_env_frame;
1670 context->current_env = old_env;
1671 context->managed_code = 1;
1675 context->env_frame = context->current_frame;
1676 context->current_env = &env;
1677 context->managed_code = 0;
1680 case MINT_ICALL_V_V: {
1681 void (*func)() = ptr;
1685 case MINT_ICALL_V_P: {
1686 gpointer (*func)() = ptr;
1688 sp [-1].data.p = func ();
1691 case MINT_ICALL_P_V: {
1692 void (*func)(gpointer) = ptr;
1693 func (sp [-1].data.p);
1697 case MINT_ICALL_P_P: {
1698 gpointer (*func)(gpointer) = ptr;
1699 sp [-1].data.p = func (sp [-1].data.p);
1702 case MINT_ICALL_PP_V: {
1703 void (*func)(gpointer,gpointer) = ptr;
1705 func (sp [0].data.p, sp [1].data.p);
1708 case MINT_ICALL_PI_V: {
1709 void (*func)(gpointer,int) = ptr;
1711 func (sp [0].data.p, sp [1].data.i);
1714 case MINT_ICALL_PP_P: {
1715 gpointer (*func)(gpointer,gpointer) = ptr;
1717 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1720 case MINT_ICALL_PI_P: {
1721 gpointer (*func)(gpointer,int) = ptr;
1723 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1726 case MINT_ICALL_PPP_V: {
1727 void (*func)(gpointer,gpointer,gpointer) = ptr;
1729 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1732 case MINT_ICALL_PPI_V: {
1733 void (*func)(gpointer,gpointer,int) = ptr;
1735 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1739 g_assert_not_reached ();
1742 context->env_frame = old_env_frame;
1743 context->current_env = old_env;
1749 * These functions are the entry points into the interpreter from compiled code.
1750 * They are called by the interp_in wrappers. They have the following signature:
1751 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
1752 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
1753 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
1754 * more wrappers then these functions.
1755 * this/static * ret/void * 16 arguments -> 64 functions.
1758 #define MAX_INTERP_ENTRY_ARGS 8
1760 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
1761 InterpEntryData data; \
1762 (data).rmethod = (_method); \
1763 (data).res = (_res); \
1764 (data).this_arg = (_this_arg); \
1765 (data).many_args = NULL;
1767 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
1768 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1769 interp_entry (&data); \
1771 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
1772 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1773 (data).args [0] = arg1; \
1774 interp_entry (&data); \
1776 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
1777 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1778 (data).args [0] = arg1; \
1779 (data).args [1] = arg2; \
1780 interp_entry (&data); \
1782 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
1783 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1784 (data).args [0] = arg1; \
1785 (data).args [1] = arg2; \
1786 (data).args [2] = arg3; \
1787 interp_entry (&data); \
1789 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
1790 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1791 (data).args [0] = arg1; \
1792 (data).args [1] = arg2; \
1793 (data).args [2] = arg3; \
1794 (data).args [3] = arg4; \
1795 interp_entry (&data); \
1797 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
1798 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1799 (data).args [0] = arg1; \
1800 (data).args [1] = arg2; \
1801 (data).args [2] = arg3; \
1802 (data).args [3] = arg4; \
1803 (data).args [4] = arg5; \
1804 interp_entry (&data); \
1806 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
1807 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1808 (data).args [0] = arg1; \
1809 (data).args [1] = arg2; \
1810 (data).args [2] = arg3; \
1811 (data).args [3] = arg4; \
1812 (data).args [4] = arg5; \
1813 (data).args [5] = arg6; \
1814 interp_entry (&data); \
1816 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
1817 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1818 (data).args [0] = arg1; \
1819 (data).args [1] = arg2; \
1820 (data).args [2] = arg3; \
1821 (data).args [3] = arg4; \
1822 (data).args [4] = arg5; \
1823 (data).args [5] = arg6; \
1824 (data).args [6] = arg7; \
1825 interp_entry (&data); \
1827 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
1828 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1829 (data).args [0] = arg1; \
1830 (data).args [1] = arg2; \
1831 (data).args [2] = arg3; \
1832 (data).args [3] = arg4; \
1833 (data).args [4] = arg5; \
1834 (data).args [5] = arg6; \
1835 (data).args [6] = arg7; \
1836 (data).args [7] = arg8; \
1837 interp_entry (&data); \
1840 #define ARGLIST0 RuntimeMethod *rmethod
1841 #define ARGLIST1 gpointer arg1, RuntimeMethod *rmethod
1842 #define ARGLIST2 gpointer arg1, gpointer arg2, RuntimeMethod *rmethod
1843 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, RuntimeMethod *rmethod
1844 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, RuntimeMethod *rmethod
1845 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, RuntimeMethod *rmethod
1846 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, RuntimeMethod *rmethod
1847 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, RuntimeMethod *rmethod
1848 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, RuntimeMethod *rmethod
1850 static void interp_entry_static_0 (ARGLIST0) INTERP_ENTRY0 (NULL, NULL, rmethod)
1851 static void interp_entry_static_1 (ARGLIST1) INTERP_ENTRY1 (NULL, NULL, rmethod)
1852 static void interp_entry_static_2 (ARGLIST2) INTERP_ENTRY2 (NULL, NULL, rmethod)
1853 static void interp_entry_static_3 (ARGLIST3) INTERP_ENTRY3 (NULL, NULL, rmethod)
1854 static void interp_entry_static_4 (ARGLIST4) INTERP_ENTRY4 (NULL, NULL, rmethod)
1855 static void interp_entry_static_5 (ARGLIST5) INTERP_ENTRY5 (NULL, NULL, rmethod)
1856 static void interp_entry_static_6 (ARGLIST6) INTERP_ENTRY6 (NULL, NULL, rmethod)
1857 static void interp_entry_static_7 (ARGLIST7) INTERP_ENTRY7 (NULL, NULL, rmethod)
1858 static void interp_entry_static_8 (ARGLIST8) INTERP_ENTRY8 (NULL, NULL, rmethod)
1859 static void interp_entry_static_ret_0 (gpointer res, ARGLIST0) INTERP_ENTRY0 (NULL, res, rmethod)
1860 static void interp_entry_static_ret_1 (gpointer res, ARGLIST1) INTERP_ENTRY1 (NULL, res, rmethod)
1861 static void interp_entry_static_ret_2 (gpointer res, ARGLIST2) INTERP_ENTRY2 (NULL, res, rmethod)
1862 static void interp_entry_static_ret_3 (gpointer res, ARGLIST3) INTERP_ENTRY3 (NULL, res, rmethod)
1863 static void interp_entry_static_ret_4 (gpointer res, ARGLIST4) INTERP_ENTRY4 (NULL, res, rmethod)
1864 static void interp_entry_static_ret_5 (gpointer res, ARGLIST5) INTERP_ENTRY5 (NULL, res, rmethod)
1865 static void interp_entry_static_ret_6 (gpointer res, ARGLIST6) INTERP_ENTRY6 (NULL, res, rmethod)
1866 static void interp_entry_static_ret_7 (gpointer res, ARGLIST7) INTERP_ENTRY7 (NULL, res, rmethod)
1867 static void interp_entry_static_ret_8 (gpointer res, ARGLIST8) INTERP_ENTRY8 (NULL, res, rmethod)
1868 static void interp_entry_instance_0 (gpointer this_arg, ARGLIST0) INTERP_ENTRY0 (this_arg, NULL, rmethod)
1869 static void interp_entry_instance_1 (gpointer this_arg, ARGLIST1) INTERP_ENTRY1 (this_arg, NULL, rmethod)
1870 static void interp_entry_instance_2 (gpointer this_arg, ARGLIST2) INTERP_ENTRY2 (this_arg, NULL, rmethod)
1871 static void interp_entry_instance_3 (gpointer this_arg, ARGLIST3) INTERP_ENTRY3 (this_arg, NULL, rmethod)
1872 static void interp_entry_instance_4 (gpointer this_arg, ARGLIST4) INTERP_ENTRY4 (this_arg, NULL, rmethod)
1873 static void interp_entry_instance_5 (gpointer this_arg, ARGLIST5) INTERP_ENTRY5 (this_arg, NULL, rmethod)
1874 static void interp_entry_instance_6 (gpointer this_arg, ARGLIST6) INTERP_ENTRY6 (this_arg, NULL, rmethod)
1875 static void interp_entry_instance_7 (gpointer this_arg, ARGLIST7) INTERP_ENTRY7 (this_arg, NULL, rmethod)
1876 static void interp_entry_instance_8 (gpointer this_arg, ARGLIST8) INTERP_ENTRY8 (this_arg, NULL, rmethod)
1877 static void interp_entry_instance_ret_0 (gpointer this_arg, gpointer res, ARGLIST0) INTERP_ENTRY0 (this_arg, res, rmethod)
1878 static void interp_entry_instance_ret_1 (gpointer this_arg, gpointer res, ARGLIST1) INTERP_ENTRY1 (this_arg, res, rmethod)
1879 static void interp_entry_instance_ret_2 (gpointer this_arg, gpointer res, ARGLIST2) INTERP_ENTRY2 (this_arg, res, rmethod)
1880 static void interp_entry_instance_ret_3 (gpointer this_arg, gpointer res, ARGLIST3) INTERP_ENTRY3 (this_arg, res, rmethod)
1881 static void interp_entry_instance_ret_4 (gpointer this_arg, gpointer res, ARGLIST4) INTERP_ENTRY4 (this_arg, res, rmethod)
1882 static void interp_entry_instance_ret_5 (gpointer this_arg, gpointer res, ARGLIST5) INTERP_ENTRY5 (this_arg, res, rmethod)
1883 static void interp_entry_instance_ret_6 (gpointer this_arg, gpointer res, ARGLIST6) INTERP_ENTRY6 (this_arg, res, rmethod)
1884 static void interp_entry_instance_ret_7 (gpointer this_arg, gpointer res, ARGLIST7) INTERP_ENTRY6 (this_arg, res, rmethod)
1885 static void interp_entry_instance_ret_8 (gpointer this_arg, gpointer res, ARGLIST8) INTERP_ENTRY6 (this_arg, res, rmethod)
1887 #define INTERP_ENTRY_FUNCLIST(type) interp_entry_ ## type ## _0, interp_entry_ ## type ## _1, interp_entry_ ## type ## _2, interp_entry_ ## type ## _3, interp_entry_ ## type ## _4, interp_entry_ ## type ## _5, interp_entry_ ## type ## _6, interp_entry_ ## type ## _7, interp_entry_ ## type ## _8
1889 gpointer entry_funcs_static [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static) };
1890 gpointer entry_funcs_static_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static_ret) };
1891 gpointer entry_funcs_instance [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance) };
1892 gpointer entry_funcs_instance_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance_ret) };
1894 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
1896 interp_entry_general (gpointer this_arg, gpointer res, gpointer *args, gpointer rmethod)
1898 INTERP_ENTRY_BASE (rmethod, this_arg, res);
1899 data.many_args = args;
1900 interp_entry (&data);
1904 * mono_interp_create_method_pointer:
1906 * Return a function pointer which can be used to call METHOD using the
1907 * interpreter. Return NULL for methods which are not supported.
1910 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1913 MonoMethodSignature *sig = mono_method_signature (method);
1914 MonoMethod *wrapper;
1915 RuntimeMethod *rmethod;
1917 /* HACK: method_ptr of delegate should point to a runtime method*/
1918 if (method->wrapper_type && method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD)
1919 return mono_interp_get_runtime_method (mono_domain_get (), method, error);
1921 rmethod = mono_interp_get_runtime_method (mono_domain_get (), method, error);
1922 if (rmethod->jit_entry)
1923 return rmethod->jit_entry;
1924 wrapper = mini_get_interp_in_wrapper (sig);
1926 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, error);
1927 mono_error_assert_ok (error);
1929 //printf ("%s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
1930 gpointer entry_func;
1931 if (sig->param_count > MAX_INTERP_ENTRY_ARGS) {
1932 entry_func = interp_entry_general;
1933 } else if (sig->hasthis) {
1934 if (sig->ret->type == MONO_TYPE_VOID)
1935 entry_func = entry_funcs_instance [sig->param_count];
1937 entry_func = entry_funcs_instance_ret [sig->param_count];
1939 if (sig->ret->type == MONO_TYPE_VOID)
1940 entry_func = entry_funcs_static [sig->param_count];
1942 entry_func = entry_funcs_static_ret [sig->param_count];
1944 g_assert (entry_func);
1946 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
1947 MonoFtnDesc *ftndesc = g_new0 (MonoFtnDesc, 1);
1948 ftndesc->addr = entry_func;
1949 ftndesc->arg = rmethod;
1950 mono_error_assert_ok (error);
1953 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
1954 * rgctx register using a trampoline.
1958 g_assert (!mono_aot_only);
1959 addr = mono_arch_get_static_rgctx_trampoline (ftndesc, jit_wrapper);
1961 mono_memory_barrier ();
1962 rmethod->jit_entry = addr;
1968 static int opcode_counts[512];
1970 #define COUNT_OP(op) opcode_counts[op]++
1972 #define COUNT_OP(op)
1976 #define DUMP_INSTR() \
1977 if (tracing > 1) { \
1979 if (sp > frame->stack) { \
1980 ins = dump_stack (frame->stack, sp); \
1982 ins = g_strdup (""); \
1986 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1987 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1989 mono_interp_dis_mintop(rtm->code, ip); \
1990 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1994 #define DUMP_INSTR()
1998 #define USE_COMPUTED_GOTO 1
2000 #if USE_COMPUTED_GOTO
2001 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
2002 #define MINT_IN_CASE(x) LAB_ ## x:
2004 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
2006 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
2008 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
2010 #define MINT_IN_SWITCH(op) switch (op)
2011 #define MINT_IN_CASE(x) case x:
2012 #define MINT_IN_BREAK break
2013 #define MINT_IN_DEFAULT default:
2017 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception)
2019 MonoInvocation child_frame;
2020 GSList *finally_ips = NULL;
2021 const unsigned short *endfinally_ip = NULL;
2022 const unsigned short *ip = NULL;
2023 register stackval *sp;
2026 gint tracing = global_tracing;
2027 unsigned char *vtalloc;
2030 unsigned char *vt_sp;
2031 unsigned char *locals;
2033 MonoObject *o = NULL;
2035 #if USE_COMPUTED_GOTO
2036 static void *in_labels[] = {
2037 #define OPDEF(a,b,c,d) \
2039 #include "mintops.def"
2044 frame->ex_handler = NULL;
2046 context->current_frame = frame;
2049 debug_enter (frame, &tracing);
2052 if (!frame->runtime_method->transformed) {
2053 context->managed_code = 0;
2055 char *mn = mono_method_full_name (frame->runtime_method->method, TRUE);
2056 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
2059 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
2060 context->managed_code = 1;
2068 rtm = frame->runtime_method;
2069 if (!start_with_ip ) {
2070 frame->args = alloca (rtm->alloca_size);
2071 memset (frame->args, 0, rtm->alloca_size);
2077 sp = frame->stack = (stackval *) ((char *) frame->args + rtm->args_size);
2078 vt_sp = (unsigned char *) sp + rtm->stack_size;
2082 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
2083 child_frame.parent = frame;
2085 if (filter_exception) {
2086 sp->data.p = filter_exception;
2091 * using while (ip < end) may result in a 15% performance drop,
2092 * but it may be useful for debug
2096 /* g_assert (sp >= frame->stack); */
2097 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
2099 MINT_IN_SWITCH (*ip) {
2100 MINT_IN_CASE(MINT_INITLOCALS)
2101 memset (locals, 0, rtm->locals_size);
2104 MINT_IN_CASE(MINT_NOP)
2107 MINT_IN_CASE(MINT_BREAK)
2109 G_BREAKPOINT (); /* this is not portable... */
2111 MINT_IN_CASE(MINT_LDNULL)
2116 MINT_IN_CASE(MINT_VTRESULT) {
2117 int ret_size = * (guint16 *)(ip + 1);
2118 unsigned char *ret_vt_sp = vt_sp;
2119 vt_sp -= READ32(ip + 2);
2121 memmove (vt_sp, ret_vt_sp, ret_size);
2122 sp [-1].data.p = vt_sp;
2123 vt_sp += (ret_size + 7) & ~7;
2128 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
2129 MINT_IN_CASE(MINT_LDC_I4_M1)
2132 MINT_IN_CASE(MINT_LDC_I4_0)
2135 MINT_IN_CASE(MINT_LDC_I4_1)
2138 MINT_IN_CASE(MINT_LDC_I4_2)
2141 MINT_IN_CASE(MINT_LDC_I4_3)
2144 MINT_IN_CASE(MINT_LDC_I4_4)
2147 MINT_IN_CASE(MINT_LDC_I4_5)
2150 MINT_IN_CASE(MINT_LDC_I4_6)
2153 MINT_IN_CASE(MINT_LDC_I4_7)
2156 MINT_IN_CASE(MINT_LDC_I4_8)
2159 MINT_IN_CASE(MINT_LDC_I4_S)
2160 sp->data.i = *(const short *)(ip + 1);
2164 MINT_IN_CASE(MINT_LDC_I4)
2166 sp->data.i = READ32 (ip);
2170 MINT_IN_CASE(MINT_LDC_I8)
2172 sp->data.l = READ64 (ip);
2176 MINT_IN_CASE(MINT_LDC_R4) {
2180 sp->data.f = * (float *)&val;
2185 MINT_IN_CASE(MINT_LDC_R8)
2186 sp->data.l = READ64 (ip + 1); /* note union usage */
2190 MINT_IN_CASE(MINT_DUP)
2195 MINT_IN_CASE(MINT_DUP_VT)
2196 i32 = READ32 (ip + 1);
2198 memcpy(sp->data.p, sp [-1].data.p, i32);
2199 vt_sp += (i32 + 7) & ~7;
2203 MINT_IN_CASE(MINT_POP) {
2204 guint16 u16 = (* (guint16 *)(ip + 1)) + 1;
2206 memmove (sp - u16, sp - 1, (u16 - 1) * sizeof (stackval));
2211 MINT_IN_CASE(MINT_JMP) {
2212 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
2213 if (!new_method->transformed) {
2215 frame->ex = mono_interp_transform_method (new_method, context);
2220 if (new_method->alloca_size > rtm->alloca_size)
2221 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
2222 rtm = frame->runtime_method = new_method;
2223 vt_sp = (unsigned char *) sp + rtm->stack_size;
2227 locals = vt_sp + rtm->vt_stack_size;
2228 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
2231 MINT_IN_CASE(MINT_CALLI) {
2232 MonoMethodSignature *csignature;
2233 stackval *endsp = sp;
2237 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2241 child_frame.runtime_method = sp->data.p;
2244 child_frame.retval = sp;
2245 /* decrement by the actual number of args */
2246 sp -= csignature->param_count;
2247 if (csignature->hasthis)
2249 child_frame.stack_args = sp;
2251 /* `this' can be NULL for string:.ctor */
2252 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2253 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2254 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2255 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
2256 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
2257 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2260 if (csignature->hasthis) {
2261 MonoObject *this_arg = sp->data.p;
2263 if (this_arg->vtable->klass->valuetype) {
2264 gpointer *unboxed = mono_object_unbox (this_arg);
2265 sp [0].data.p = unboxed;
2269 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
2271 context->current_frame = frame;
2273 if (child_frame.ex) {
2275 * An exception occurred, need to run finally, fault and catch handlers..
2277 frame->ex = child_frame.ex;
2278 goto handle_finally;
2281 /* need to handle typedbyref ... */
2282 if (csignature->ret->type != MONO_TYPE_VOID) {
2288 MINT_IN_CASE(MINT_CALLI_NAT) {
2289 MonoMethodSignature *csignature;
2290 stackval *endsp = sp;
2291 unsigned char *code = NULL;
2295 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2300 child_frame.runtime_method = NULL;
2303 child_frame.retval = sp;
2304 /* decrement by the actual number of args */
2305 sp -= csignature->param_count;
2306 if (csignature->hasthis)
2308 child_frame.stack_args = sp;
2309 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
2311 context->current_frame = frame;
2313 if (child_frame.ex) {
2315 * An exception occurred, need to run finally, fault and catch handlers..
2317 frame->ex = child_frame.ex;
2318 if (context->search_for_handler) {
2319 context->search_for_handler = 0;
2320 goto handle_exception;
2322 goto handle_finally;
2325 /* need to handle typedbyref ... */
2326 if (csignature->ret->type != MONO_TYPE_VOID) {
2332 MINT_IN_CASE(MINT_CALL) {
2333 stackval *endsp = sp;
2337 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2340 child_frame.retval = sp;
2341 /* decrement by the actual number of args */
2342 sp -= child_frame.runtime_method->param_count;
2343 if (child_frame.runtime_method->hasthis)
2345 child_frame.stack_args = sp;
2347 /* `this' can be NULL for string:.ctor */
2348 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2349 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2350 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2353 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
2355 context->current_frame = frame;
2357 if (child_frame.ex) {
2359 * An exception occurred, need to run finally, fault and catch handlers..
2361 frame->ex = child_frame.ex;
2362 goto handle_exception;;
2365 /* need to handle typedbyref ... */
2370 MINT_IN_CASE(MINT_VCALL) {
2373 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2377 child_frame.retval = sp;
2378 /* decrement by the actual number of args */
2379 sp -= child_frame.runtime_method->param_count;
2380 if (child_frame.runtime_method->hasthis) {
2382 MonoObject *this_arg = sp->data.p;
2384 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2386 child_frame.stack_args = sp;
2388 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
2389 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2390 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2393 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
2395 context->current_frame = frame;
2397 if (child_frame.ex) {
2399 * An exception occurred, need to run finally, fault and catch handlers..
2401 frame->ex = child_frame.ex;
2402 goto handle_finally;
2407 MINT_IN_CASE(MINT_JIT_CALL) {
2408 MonoMethodSignature *sig;
2409 RuntimeMethod *rmethod = rtm->data_items [* (guint16 *)(ip + 1)];
2410 MonoFtnDesc ftndesc;
2411 guint8 res_buf [256];
2414 //printf ("%s\n", mono_method_full_name (rmethod->method, 1));
2417 * Call JITted code through a gsharedvt_out wrapper. These wrappers receive every argument
2418 * by ref and return a return value using an explicit return value argument.
2420 if (!rmethod->jit_wrapper) {
2421 MonoMethod *method = rmethod->method;
2424 sig = mono_method_signature (method);
2427 MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
2428 //printf ("J: %s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
2430 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, &error);
2431 mono_error_assert_ok (&error);
2433 gpointer addr = mono_jit_compile_method_jit_only (method, &error);
2435 mono_error_assert_ok (&error);
2437 rmethod->jit_addr = addr;
2438 rmethod->jit_sig = sig;
2439 mono_memory_barrier ();
2440 rmethod->jit_wrapper = jit_wrapper;
2443 sig = rmethod->jit_sig;
2448 sp -= sig->param_count;
2452 ftndesc.addr = rmethod->jit_addr;
2455 // FIXME: Optimize this
2459 int stack_index = 0;
2460 if (rmethod->hasthis) {
2461 args [pindex ++] = sp [0].data.p;
2464 type = rmethod->rtype;
2465 if (type->type != MONO_TYPE_VOID) {
2466 if (MONO_TYPE_ISSTRUCT (type))
2467 args [pindex ++] = vt_sp;
2469 args [pindex ++] = res_buf;
2471 for (int i = 0; i < rmethod->param_count; ++i) {
2472 MonoType *t = rmethod->param_types [i];
2473 stackval *sval = &sp [stack_index + i];
2474 if (sig->params [i]->byref) {
2475 args [pindex ++] = sval->data.p;
2476 } else if (MONO_TYPE_ISSTRUCT (t)) {
2477 args [pindex ++] = sval->data.p;
2478 } else if (MONO_TYPE_IS_REFERENCE (t)) {
2479 args [pindex ++] = &sval->data.p;
2488 case MONO_TYPE_VALUETYPE:
2489 args [pindex ++] = &sval->data.i;
2492 case MONO_TYPE_FNPTR:
2495 case MONO_TYPE_OBJECT:
2496 args [pindex ++] = &sval->data.p;
2500 args [pindex ++] = &sval->data.l;
2503 printf ("%s\n", mono_type_full_name (t));
2504 g_assert_not_reached ();
2511 void (*func)(gpointer) = rmethod->jit_wrapper;
2517 void (*func)(gpointer, gpointer) = rmethod->jit_wrapper;
2519 func (args [0], &ftndesc);
2523 void (*func)(gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2525 func (args [0], args [1], &ftndesc);
2529 void (*func)(gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2531 func (args [0], args [1], args [2], &ftndesc);
2535 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2537 func (args [0], args [1], args [2], args [3], &ftndesc);
2541 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2543 func (args [0], args [1], args [2], args [3], args [4], &ftndesc);
2547 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2549 func (args [0], args [1], args [2], args [3], args [4], args [5], &ftndesc);
2553 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2555 func (args [0], args [1], args [2], args [3], args [4], args [5], args [6], &ftndesc);
2559 g_assert_not_reached ();
2563 MonoType *rtype = rmethod->rtype;
2564 switch (rtype->type) {
2565 case MONO_TYPE_VOID:
2566 case MONO_TYPE_OBJECT:
2567 case MONO_TYPE_STRING:
2568 case MONO_TYPE_CLASS:
2569 case MONO_TYPE_ARRAY:
2570 case MONO_TYPE_SZARRAY:
2573 sp->data.p = *(gpointer*)res_buf;
2576 sp->data.i = *(gint8*)res_buf;
2579 sp->data.i = *(guint8*)res_buf;
2582 sp->data.i = *(gint16*)res_buf;
2585 sp->data.i = *(guint16*)res_buf;
2588 sp->data.i = *(gint32*)res_buf;
2591 sp->data.i = *(guint32*)res_buf;
2593 case MONO_TYPE_VALUETYPE:
2594 /* The result was written to vt_sp */
2597 case MONO_TYPE_GENERICINST:
2598 if (MONO_TYPE_IS_REFERENCE (rtype)) {
2599 sp->data.p = *(gpointer*)res_buf;
2601 /* The result was written to vt_sp */
2606 printf ("%s\n", mono_type_full_name (rtype));
2607 g_assert_not_reached ();
2610 if (rtype->type != MONO_TYPE_VOID)
2615 MINT_IN_CASE(MINT_CALLVIRT) {
2616 stackval *endsp = sp;
2617 MonoObject *this_arg;
2622 token = * (unsigned short *)(ip + 1);
2624 child_frame.runtime_method = rtm->data_items [token];
2626 child_frame.retval = sp;
2628 /* decrement by the actual number of args */
2629 sp -= child_frame.runtime_method->param_count + 1;
2630 child_frame.stack_args = sp;
2631 this_arg = sp->data.p;
2633 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2634 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2636 MonoClass *this_class = this_arg->vtable->klass;
2637 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2639 gpointer *unboxed = mono_object_unbox (this_arg);
2640 sp [0].data.p = unboxed;
2643 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
2645 context->current_frame = frame;
2647 if (child_frame.ex) {
2649 * An exception occurred, need to run finally, fault and catch handlers..
2651 frame->ex = child_frame.ex;
2652 if (context->search_for_handler) {
2653 context->search_for_handler = 0;
2654 goto handle_exception;
2656 goto handle_finally;
2659 /* need to handle typedbyref ... */
2664 MINT_IN_CASE(MINT_VCALLVIRT) {
2665 MonoObject *this_arg;
2670 token = * (unsigned short *)(ip + 1);
2672 child_frame.runtime_method = rtm->data_items [token];
2674 child_frame.retval = sp;
2676 /* decrement by the actual number of args */
2677 sp -= child_frame.runtime_method->param_count + 1;
2678 child_frame.stack_args = sp;
2679 this_arg = sp->data.p;
2681 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2682 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2684 MonoClass *this_class = this_arg->vtable->klass;
2685 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2686 gpointer *unboxed = mono_object_unbox (this_arg);
2687 sp [0].data.p = unboxed;
2690 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
2692 context->current_frame = frame;
2694 if (child_frame.ex) {
2696 * An exception occurred, need to run finally, fault and catch handlers..
2698 frame->ex = child_frame.ex;
2699 if (context->search_for_handler) {
2700 context->search_for_handler = 0;
2701 goto handle_exception;
2703 goto handle_finally;
2707 MINT_IN_CASE(MINT_CALLRUN)
2708 ves_runtime_method (frame, context);
2711 goto handle_exception;
2714 MINT_IN_CASE(MINT_RET)
2716 *frame->retval = *sp;
2717 if (sp > frame->stack)
2718 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2720 MINT_IN_CASE(MINT_RET_VOID)
2721 if (sp > frame->stack)
2722 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2724 MINT_IN_CASE(MINT_RET_VT)
2725 i32 = READ32(ip + 1);
2727 memcpy(frame->retval->data.p, sp->data.p, i32);
2728 if (sp > frame->stack)
2729 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2731 MINT_IN_CASE(MINT_BR_S)
2732 ip += (short) *(ip + 1);
2734 MINT_IN_CASE(MINT_BR)
2735 ip += (gint32) READ32(ip + 1);
2737 #define ZEROP_S(datamem, op) \
2739 if (sp->data.datamem op 0) \
2740 ip += * (gint16 *)(ip + 1); \
2744 #define ZEROP(datamem, op) \
2746 if (sp->data.datamem op 0) \
2747 ip += READ32(ip + 1); \
2751 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2754 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2757 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2760 MINT_IN_CASE(MINT_BRFALSE_I4)
2763 MINT_IN_CASE(MINT_BRFALSE_I8)
2766 MINT_IN_CASE(MINT_BRFALSE_R8)
2769 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2772 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2775 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2778 MINT_IN_CASE(MINT_BRTRUE_I4)
2781 MINT_IN_CASE(MINT_BRTRUE_I8)
2784 MINT_IN_CASE(MINT_BRTRUE_R8)
2787 #define CONDBR_S(cond) \
2790 ip += * (gint16 *)(ip + 1); \
2793 #define BRELOP_S(datamem, op) \
2794 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2796 #define CONDBR(cond) \
2799 ip += READ32(ip + 1); \
2803 #define BRELOP(datamem, op) \
2804 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2806 MINT_IN_CASE(MINT_BEQ_I4_S)
2809 MINT_IN_CASE(MINT_BEQ_I8_S)
2812 MINT_IN_CASE(MINT_BEQ_R8_S)
2813 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2815 MINT_IN_CASE(MINT_BEQ_I4)
2818 MINT_IN_CASE(MINT_BEQ_I8)
2821 MINT_IN_CASE(MINT_BEQ_R8)
2822 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2824 MINT_IN_CASE(MINT_BGE_I4_S)
2827 MINT_IN_CASE(MINT_BGE_I8_S)
2830 MINT_IN_CASE(MINT_BGE_R8_S)
2831 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2833 MINT_IN_CASE(MINT_BGE_I4)
2836 MINT_IN_CASE(MINT_BGE_I8)
2839 MINT_IN_CASE(MINT_BGE_R8)
2840 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2842 MINT_IN_CASE(MINT_BGT_I4_S)
2845 MINT_IN_CASE(MINT_BGT_I8_S)
2848 MINT_IN_CASE(MINT_BGT_R8_S)
2849 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2851 MINT_IN_CASE(MINT_BGT_I4)
2854 MINT_IN_CASE(MINT_BGT_I8)
2857 MINT_IN_CASE(MINT_BGT_R8)
2858 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2860 MINT_IN_CASE(MINT_BLT_I4_S)
2863 MINT_IN_CASE(MINT_BLT_I8_S)
2866 MINT_IN_CASE(MINT_BLT_R8_S)
2867 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2869 MINT_IN_CASE(MINT_BLT_I4)
2872 MINT_IN_CASE(MINT_BLT_I8)
2875 MINT_IN_CASE(MINT_BLT_R8)
2876 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2878 MINT_IN_CASE(MINT_BLE_I4_S)
2881 MINT_IN_CASE(MINT_BLE_I8_S)
2884 MINT_IN_CASE(MINT_BLE_R8_S)
2885 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2887 MINT_IN_CASE(MINT_BLE_I4)
2890 MINT_IN_CASE(MINT_BLE_I8)
2893 MINT_IN_CASE(MINT_BLE_R8)
2894 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2896 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2899 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2902 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2903 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2905 MINT_IN_CASE(MINT_BNE_UN_I4)
2908 MINT_IN_CASE(MINT_BNE_UN_I8)
2911 MINT_IN_CASE(MINT_BNE_UN_R8)
2912 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2915 #define BRELOP_S_CAST(datamem, op, type) \
2917 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2918 ip += * (gint16 *)(ip + 1); \
2922 #define BRELOP_CAST(datamem, op, type) \
2924 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2925 ip += READ32(ip + 1); \
2929 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2930 BRELOP_S_CAST(i, >=, guint32);
2932 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2933 BRELOP_S_CAST(l, >=, guint64);
2935 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2936 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2938 MINT_IN_CASE(MINT_BGE_UN_I4)
2939 BRELOP_CAST(i, >=, guint32);
2941 MINT_IN_CASE(MINT_BGE_UN_I8)
2942 BRELOP_CAST(l, >=, guint64);
2944 MINT_IN_CASE(MINT_BGE_UN_R8)
2945 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2947 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2948 BRELOP_S_CAST(i, >, guint32);
2950 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2951 BRELOP_S_CAST(l, >, guint64);
2953 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2954 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2956 MINT_IN_CASE(MINT_BGT_UN_I4)
2957 BRELOP_CAST(i, >, guint32);
2959 MINT_IN_CASE(MINT_BGT_UN_I8)
2960 BRELOP_CAST(l, >, guint64);
2962 MINT_IN_CASE(MINT_BGT_UN_R8)
2963 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2965 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2966 BRELOP_S_CAST(i, <=, guint32);
2968 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2969 BRELOP_S_CAST(l, <=, guint64);
2971 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2972 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2974 MINT_IN_CASE(MINT_BLE_UN_I4)
2975 BRELOP_CAST(i, <=, guint32);
2977 MINT_IN_CASE(MINT_BLE_UN_I8)
2978 BRELOP_CAST(l, <=, guint64);
2980 MINT_IN_CASE(MINT_BLE_UN_R8)
2981 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2983 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2984 BRELOP_S_CAST(i, <, guint32);
2986 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2987 BRELOP_S_CAST(l, <, guint64);
2989 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2990 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2992 MINT_IN_CASE(MINT_BLT_UN_I4)
2993 BRELOP_CAST(i, <, guint32);
2995 MINT_IN_CASE(MINT_BLT_UN_I8)
2996 BRELOP_CAST(l, <, guint64);
2998 MINT_IN_CASE(MINT_BLT_UN_R8)
2999 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
3001 MINT_IN_CASE(MINT_SWITCH) {
3003 const unsigned short *st;
3009 if ((guint32)sp->data.i < n) {
3011 ip += 2 * (guint32)sp->data.i;
3012 offset = READ32 (ip);
3019 MINT_IN_CASE(MINT_LDIND_I1)
3021 sp[-1].data.i = *(gint8*)sp[-1].data.p;
3023 MINT_IN_CASE(MINT_LDIND_U1)
3025 sp[-1].data.i = *(guint8*)sp[-1].data.p;
3027 MINT_IN_CASE(MINT_LDIND_I2)
3029 sp[-1].data.i = *(gint16*)sp[-1].data.p;
3031 MINT_IN_CASE(MINT_LDIND_U2)
3033 sp[-1].data.i = *(guint16*)sp[-1].data.p;
3035 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
3036 MINT_IN_CASE(MINT_LDIND_U4)
3038 sp[-1].data.i = *(gint32*)sp[-1].data.p;
3040 MINT_IN_CASE(MINT_LDIND_I8)
3042 sp[-1].data.l = *(gint64*)sp[-1].data.p;
3044 MINT_IN_CASE(MINT_LDIND_I) {
3045 guint16 offset = * (guint16 *)(ip + 1);
3046 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
3050 MINT_IN_CASE(MINT_LDIND_R4)
3052 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
3054 MINT_IN_CASE(MINT_LDIND_R8)
3056 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
3058 MINT_IN_CASE(MINT_LDIND_REF)
3060 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
3062 MINT_IN_CASE(MINT_STIND_REF)
3065 mono_gc_wbarrier_generic_store (sp->data.p, sp [1].data.p);
3067 MINT_IN_CASE(MINT_STIND_I1)
3070 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
3072 MINT_IN_CASE(MINT_STIND_I2)
3075 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
3077 MINT_IN_CASE(MINT_STIND_I4)
3080 * (gint32 *) sp->data.p = sp[1].data.i;
3082 MINT_IN_CASE(MINT_STIND_I)
3085 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
3087 MINT_IN_CASE(MINT_STIND_I8)
3090 * (gint64 *) sp->data.p = sp[1].data.l;
3092 MINT_IN_CASE(MINT_STIND_R4)
3095 * (float *) sp->data.p = (gfloat)sp[1].data.f;
3097 MINT_IN_CASE(MINT_STIND_R8)
3100 * (double *) sp->data.p = sp[1].data.f;
3102 MINT_IN_CASE(MINT_MONO_ATOMIC_STORE_I4)
3105 InterlockedWrite ((gint32 *) sp->data.p, sp [1].data.i);
3107 #define BINOP(datamem, op) \
3109 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3111 MINT_IN_CASE(MINT_ADD_I4)
3114 MINT_IN_CASE(MINT_ADD_I8)
3117 MINT_IN_CASE(MINT_ADD_R8)
3120 MINT_IN_CASE(MINT_ADD1_I4)
3124 MINT_IN_CASE(MINT_SUB_I4)
3127 MINT_IN_CASE(MINT_SUB_I8)
3130 MINT_IN_CASE(MINT_SUB_R8)
3133 MINT_IN_CASE(MINT_SUB1_I4)
3137 MINT_IN_CASE(MINT_MUL_I4)
3140 MINT_IN_CASE(MINT_MUL_I8)
3143 MINT_IN_CASE(MINT_MUL_R8)
3146 MINT_IN_CASE(MINT_DIV_I4)
3147 if (sp [-1].data.i == 0)
3148 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3149 if (sp [-1].data.i == (-1))
3150 THROW_EX (mono_get_exception_overflow (), ip);
3153 MINT_IN_CASE(MINT_DIV_I8)
3154 if (sp [-1].data.l == 0)
3155 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3156 if (sp [-1].data.l == (-1))
3157 THROW_EX (mono_get_exception_overflow (), ip);
3160 MINT_IN_CASE(MINT_DIV_R8)
3164 #define BINOP_CAST(datamem, op, type) \
3166 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3168 MINT_IN_CASE(MINT_DIV_UN_I4)
3169 if (sp [-1].data.i == 0)
3170 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3171 BINOP_CAST(i, /, guint32);
3173 MINT_IN_CASE(MINT_DIV_UN_I8)
3174 if (sp [-1].data.l == 0)
3175 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3176 BINOP_CAST(l, /, guint64);
3178 MINT_IN_CASE(MINT_REM_I4)
3179 if (sp [-1].data.i == 0)
3180 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3181 if (sp [-1].data.i == (-1))
3182 THROW_EX (mono_get_exception_overflow (), ip);
3185 MINT_IN_CASE(MINT_REM_I8)
3186 if (sp [-1].data.l == 0)
3187 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3188 if (sp [-1].data.l == (-1))
3189 THROW_EX (mono_get_exception_overflow (), ip);
3192 MINT_IN_CASE(MINT_REM_R8)
3193 /* FIXME: what do we actually do here? */
3195 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
3198 MINT_IN_CASE(MINT_REM_UN_I4)
3199 if (sp [-1].data.i == 0)
3200 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3201 BINOP_CAST(i, %, guint32);
3203 MINT_IN_CASE(MINT_REM_UN_I8)
3204 if (sp [-1].data.l == 0)
3205 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3206 BINOP_CAST(l, %, guint64);
3208 MINT_IN_CASE(MINT_AND_I4)
3211 MINT_IN_CASE(MINT_AND_I8)
3214 MINT_IN_CASE(MINT_OR_I4)
3217 MINT_IN_CASE(MINT_OR_I8)
3220 MINT_IN_CASE(MINT_XOR_I4)
3223 MINT_IN_CASE(MINT_XOR_I8)
3227 #define SHIFTOP(datamem, op) \
3229 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
3232 MINT_IN_CASE(MINT_SHL_I4)
3235 MINT_IN_CASE(MINT_SHL_I8)
3238 MINT_IN_CASE(MINT_SHR_I4)
3241 MINT_IN_CASE(MINT_SHR_I8)
3244 MINT_IN_CASE(MINT_SHR_UN_I4)
3246 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
3249 MINT_IN_CASE(MINT_SHR_UN_I8)
3251 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
3254 MINT_IN_CASE(MINT_NEG_I4)
3255 sp [-1].data.i = - sp [-1].data.i;
3258 MINT_IN_CASE(MINT_NEG_I8)
3259 sp [-1].data.l = - sp [-1].data.l;
3262 MINT_IN_CASE(MINT_NEG_R8)
3263 sp [-1].data.f = - sp [-1].data.f;
3266 MINT_IN_CASE(MINT_NOT_I4)
3267 sp [-1].data.i = ~ sp [-1].data.i;
3270 MINT_IN_CASE(MINT_NOT_I8)
3271 sp [-1].data.l = ~ sp [-1].data.l;
3274 MINT_IN_CASE(MINT_CONV_I1_I4)
3275 sp [-1].data.i = (gint8)sp [-1].data.i;
3278 MINT_IN_CASE(MINT_CONV_I1_I8)
3279 sp [-1].data.i = (gint8)sp [-1].data.l;
3282 MINT_IN_CASE(MINT_CONV_I1_R8)
3283 sp [-1].data.i = (gint8)sp [-1].data.f;
3286 MINT_IN_CASE(MINT_CONV_U1_I4)
3287 sp [-1].data.i = (guint8)sp [-1].data.i;
3290 MINT_IN_CASE(MINT_CONV_U1_I8)
3291 sp [-1].data.i = (guint8)sp [-1].data.l;
3294 MINT_IN_CASE(MINT_CONV_U1_R8)
3295 sp [-1].data.i = (guint8)sp [-1].data.f;
3298 MINT_IN_CASE(MINT_CONV_I2_I4)
3299 sp [-1].data.i = (gint16)sp [-1].data.i;
3302 MINT_IN_CASE(MINT_CONV_I2_I8)
3303 sp [-1].data.i = (gint16)sp [-1].data.l;
3306 MINT_IN_CASE(MINT_CONV_I2_R8)
3307 sp [-1].data.i = (gint16)sp [-1].data.f;
3310 MINT_IN_CASE(MINT_CONV_U2_I4)
3311 sp [-1].data.i = (guint16)sp [-1].data.i;
3314 MINT_IN_CASE(MINT_CONV_U2_I8)
3315 sp [-1].data.i = (guint16)sp [-1].data.l;
3318 MINT_IN_CASE(MINT_CONV_U2_R8)
3319 sp [-1].data.i = (guint16)sp [-1].data.f;
3322 MINT_IN_CASE(MINT_CONV_I4_R8)
3323 sp [-1].data.i = (gint32)sp [-1].data.f;
3326 MINT_IN_CASE(MINT_CONV_U4_I8)
3327 MINT_IN_CASE(MINT_CONV_I4_I8)
3328 sp [-1].data.i = (gint32)sp [-1].data.l;
3331 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
3332 sp [-2].data.i = (gint32)sp [-2].data.l;
3335 MINT_IN_CASE(MINT_CONV_U4_R8)
3336 sp [-1].data.i = (guint32)sp [-1].data.f;
3339 MINT_IN_CASE(MINT_CONV_I8_I4)
3340 sp [-1].data.l = sp [-1].data.i;
3343 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
3344 sp [-2].data.l = sp [-2].data.i;
3347 MINT_IN_CASE(MINT_CONV_I8_U4)
3348 sp [-1].data.l = (guint32)sp [-1].data.i;
3351 MINT_IN_CASE(MINT_CONV_I8_R8)
3352 sp [-1].data.l = (gint64)sp [-1].data.f;
3355 MINT_IN_CASE(MINT_CONV_R4_I4)
3356 sp [-1].data.f = (float)sp [-1].data.i;
3359 MINT_IN_CASE(MINT_CONV_R4_I8)
3360 sp [-1].data.f = (float)sp [-1].data.l;
3363 MINT_IN_CASE(MINT_CONV_R4_R8)
3364 sp [-1].data.f = (float)sp [-1].data.f;
3367 MINT_IN_CASE(MINT_CONV_R8_I4)
3368 sp [-1].data.f = (double)sp [-1].data.i;
3371 MINT_IN_CASE(MINT_CONV_R8_I8)
3372 sp [-1].data.f = (double)sp [-1].data.l;
3375 MINT_IN_CASE(MINT_CONV_U8_I4)
3376 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
3379 MINT_IN_CASE(MINT_CONV_U8_R8)
3380 sp [-1].data.l = (guint64)sp [-1].data.f;
3383 MINT_IN_CASE(MINT_CPOBJ) {
3384 c = rtm->data_items[* (guint16 *)(ip + 1)];
3385 g_assert (c->byval_arg.type == MONO_TYPE_VALUETYPE);
3386 /* if this assertion fails, we need to add a write barrier */
3387 g_assert (!MONO_TYPE_IS_REFERENCE (&c->byval_arg));
3388 stackval_from_data (&c->byval_arg, &sp [-2], sp [-1].data.p, FALSE);
3393 MINT_IN_CASE(MINT_LDOBJ) {
3395 c = rtm->data_items[* (guint16 *)(ip + 1)];
3398 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3399 int size = mono_class_value_size (c, NULL);
3400 sp [-1].data.p = vt_sp;
3401 vt_sp += (size + 7) & ~7;
3403 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
3406 MINT_IN_CASE(MINT_LDSTR)
3407 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3411 MINT_IN_CASE(MINT_NEWOBJ) {
3412 MonoClass *newobj_class;
3413 MonoMethodSignature *csig;
3414 stackval valuetype_this;
3420 token = * (guint16 *)(ip + 1);
3423 child_frame.ip = NULL;
3424 child_frame.ex = NULL;
3426 child_frame.runtime_method = rtm->data_items [token];
3427 csig = mono_method_signature (child_frame.runtime_method->method);
3428 newobj_class = child_frame.runtime_method->method->klass;
3429 /*if (profiling_classes) {
3430 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
3432 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
3435 if (newobj_class->parent == mono_defaults.array_class) {
3436 sp -= csig->param_count;
3437 child_frame.stack_args = sp;
3438 o = ves_array_create (&child_frame, context->domain, newobj_class, csig, sp);
3440 THROW_EX (child_frame.ex, ip);
3441 goto array_constructed;
3444 g_assert (csig->hasthis);
3445 if (csig->param_count) {
3446 sp -= csig->param_count;
3447 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
3449 child_frame.stack_args = sp;
3452 * First arg is the object.
3454 if (newobj_class->valuetype) {
3455 MonoType *t = &newobj_class->byval_arg;
3456 memset (&valuetype_this, 0, sizeof (stackval));
3457 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
3459 valuetype_this.data.p = vt_sp;
3461 sp->data.p = &valuetype_this;
3464 if (newobj_class != mono_defaults.string_class) {
3465 context->managed_code = 0;
3466 o = mono_object_new_checked (context->domain, newobj_class, &error);
3467 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3468 context->managed_code = 1;
3469 if (*mono_thread_interruption_request_flag ())
3470 mono_thread_interruption_checkpoint ();
3474 child_frame.retval = &retval;
3478 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
3480 ves_exec_method_with_context (&child_frame, context, NULL, NULL);
3482 context->current_frame = frame;
3484 if (child_frame.ex) {
3486 * An exception occurred, need to run finally, fault and catch handlers..
3488 frame->ex = child_frame.ex;
3489 goto handle_finally;
3492 * a constructor returns void, but we need to return the object we created
3495 if (newobj_class->valuetype && !newobj_class->enumtype) {
3496 *sp = valuetype_this;
3497 } else if (newobj_class == mono_defaults.string_class) {
3505 MINT_IN_CASE(MINT_CASTCLASS)
3506 c = rtm->data_items [*(guint16 *)(ip + 1)];
3507 if ((o = sp [-1].data.p)) {
3508 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3509 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3511 THROW_EX (mono_get_exception_invalid_cast (), ip);
3515 MINT_IN_CASE(MINT_ISINST)
3516 c = rtm->data_items [*(guint16 *)(ip + 1)];
3517 if ((o = sp [-1].data.p)) {
3518 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3519 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3521 sp [-1].data.p = NULL;
3525 MINT_IN_CASE(MINT_CONV_R_UN_I4)
3526 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
3529 MINT_IN_CASE(MINT_CONV_R_UN_I8)
3530 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
3533 MINT_IN_CASE(MINT_UNBOX)
3534 c = rtm->data_items[*(guint16 *)(ip + 1)];
3538 THROW_EX (mono_get_exception_null_reference (), ip);
3540 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3541 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3542 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
3543 THROW_EX (mono_get_exception_invalid_cast (), ip);
3545 sp [-1].data.p = mono_object_unbox (o);
3548 MINT_IN_CASE(MINT_THROW)
3550 frame->ex_handler = NULL;
3552 sp->data.p = mono_get_exception_null_reference ();
3553 THROW_EX ((MonoException *)sp->data.p, ip);
3555 MINT_IN_CASE(MINT_LDFLDA_UNSAFE)
3557 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3560 MINT_IN_CASE(MINT_LDFLDA)
3563 THROW_EX (mono_get_exception_null_reference (), ip);
3564 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3567 MINT_IN_CASE(MINT_CKNULL)
3570 THROW_EX (mono_get_exception_null_reference (), ip);
3574 #define LDFLD(datamem, fieldtype) \
3575 o = sp [-1].data.p; \
3577 THROW_EX (mono_get_exception_null_reference (), ip); \
3578 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
3581 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
3582 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
3583 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
3584 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
3585 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
3586 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
3587 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
3588 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
3589 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
3590 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
3592 MINT_IN_CASE(MINT_LDFLD_VT)
3595 THROW_EX (mono_get_exception_null_reference (), ip);
3596 i32 = READ32(ip + 2);
3597 sp [-1].data.p = vt_sp;
3598 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3599 vt_sp += (i32 + 7) & ~7;
3603 MINT_IN_CASE(MINT_LDRMFLD) {
3605 MonoClassField *field;
3610 THROW_EX (mono_get_exception_null_reference (), ip);
3611 field = rtm->data_items[* (guint16 *)(ip + 1)];
3613 if (mono_object_is_transparent_proxy (o)) {
3614 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3616 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3617 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3619 addr = (char*)o + field->offset;
3622 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3626 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3627 MonoClassField *field;
3633 THROW_EX (mono_get_exception_null_reference (), ip);
3634 field = rtm->data_items[* (guint16 *)(ip + 1)];
3635 i32 = READ32(ip + 2);
3637 if (mono_object_is_transparent_proxy (o)) {
3638 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3639 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3640 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3642 addr = (char*)o + field->offset;
3645 sp [-1].data.p = vt_sp;
3646 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3647 vt_sp += (i32 + 7) & ~7;
3648 memcpy(sp [-1].data.p, addr, i32);
3652 #define STFLD(datamem, fieldtype) \
3653 o = sp [-2].data.p; \
3655 THROW_EX (mono_get_exception_null_reference (), ip); \
3657 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3660 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3661 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3662 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3663 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3664 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3665 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3666 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3667 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3668 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3669 MINT_IN_CASE(MINT_STFLD_O)
3672 THROW_EX (mono_get_exception_null_reference (), ip);
3674 mono_gc_wbarrier_set_field (o, (char *) o + * (guint16 *)(ip + 1), sp [1].data.p);
3678 MINT_IN_CASE(MINT_STFLD_VT)
3681 THROW_EX (mono_get_exception_null_reference (), ip);
3682 i32 = READ32(ip + 2);
3684 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3685 vt_sp -= (i32 + 7) & ~7;
3689 MINT_IN_CASE(MINT_STRMFLD) {
3690 MonoClassField *field;
3694 THROW_EX (mono_get_exception_null_reference (), ip);
3696 field = rtm->data_items[* (guint16 *)(ip + 1)];
3699 if (mono_object_is_transparent_proxy (o)) {
3700 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3701 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3702 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3704 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3709 MINT_IN_CASE(MINT_STRMFLD_VT) {
3710 MonoClassField *field;
3714 THROW_EX (mono_get_exception_null_reference (), ip);
3715 field = rtm->data_items[* (guint16 *)(ip + 1)];
3716 i32 = READ32(ip + 2);
3719 if (mono_object_is_transparent_proxy (o)) {
3720 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3721 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3722 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3724 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3727 vt_sp -= (i32 + 7) & ~7;
3730 MINT_IN_CASE(MINT_LDSFLDA) {
3731 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3732 sp->data.p = mono_class_static_field_address (context->domain, field);
3737 MINT_IN_CASE(MINT_LDSFLD) {
3738 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3739 gpointer addr = mono_class_static_field_address (context->domain, field);
3740 stackval_from_data (field->type, sp, addr, FALSE);
3745 MINT_IN_CASE(MINT_LDSFLD_VT) {
3746 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3747 gpointer addr = mono_class_static_field_address (context->domain, field);
3748 int size = READ32 (ip + 2);
3752 vt_sp += (size + 7) & ~7;
3753 stackval_from_data (field->type, sp, addr, FALSE);
3757 MINT_IN_CASE(MINT_STSFLD) {
3758 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3759 gpointer addr = mono_class_static_field_address (context->domain, field);
3762 stackval_to_data (field->type, sp, addr, FALSE);
3765 MINT_IN_CASE(MINT_STSFLD_VT) {
3766 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3767 gpointer addr = mono_class_static_field_address (context->domain, field);
3768 int size = READ32 (ip + 2);
3772 stackval_to_data (field->type, sp, addr, FALSE);
3773 vt_sp -= (size + 7) & ~7;
3776 MINT_IN_CASE(MINT_STOBJ_VT) {
3778 c = rtm->data_items[* (guint16 *)(ip + 1)];
3780 size = mono_class_value_size (c, NULL);
3781 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3782 vt_sp -= (size + 7) & ~7;
3786 MINT_IN_CASE(MINT_STOBJ) {
3787 c = rtm->data_items[* (guint16 *)(ip + 1)];
3790 g_assert (!c->byval_arg.byref);
3791 if (MONO_TYPE_IS_REFERENCE (&c->byval_arg))
3792 mono_gc_wbarrier_generic_store (sp [-2].data.p, sp [-1].data.p);
3794 stackval_from_data (&c->byval_arg, sp [-2].data.p, (char *) &sp [-1].data.p, FALSE);
3798 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3799 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3800 THROW_EX (mono_get_exception_overflow (), ip);
3801 sp [-1].data.i = (guint32)sp [-1].data.f;
3804 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3805 if (sp [-1].data.i < 0)
3806 THROW_EX (mono_get_exception_overflow (), ip);
3807 sp [-1].data.l = sp [-1].data.i;
3810 MINT_IN_CASE(MINT_CONV_OVF_U8_I8)
3811 if (sp [-1].data.l < 0)
3812 THROW_EX (mono_get_exception_overflow (), ip);
3815 MINT_IN_CASE(MINT_CONV_OVF_I8_U8)
3816 if ((guint64) sp [-1].data.l > MYGINT64_MAX)
3817 THROW_EX (mono_get_exception_overflow (), ip);
3820 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3821 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3822 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGINT64_MAX)
3823 THROW_EX (mono_get_exception_overflow (), ip);
3824 sp [-1].data.l = (guint64)sp [-1].data.f;
3827 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3828 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3829 THROW_EX (mono_get_exception_overflow (), ip);
3830 sp [-1].data.l = (gint64)sp [-1].data.f;
3833 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3834 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3835 THROW_EX (mono_get_exception_overflow (), ip);
3836 sp [-1].data.i = (mono_u)sp [-1].data.l;
3839 MINT_IN_CASE(MINT_BOX) {
3840 c = rtm->data_items [* (guint16 *)(ip + 1)];
3841 guint16 offset = * (guint16 *)(ip + 2);
3843 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3844 int size = mono_class_value_size (c, NULL);
3845 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3846 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3847 size = (size + 7) & ~7;
3850 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3851 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3852 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3857 MINT_IN_CASE(MINT_NEWARR)
3858 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3859 if (!mono_error_ok (&error)) {
3860 THROW_EX (mono_error_convert_to_exception (&error), ip);
3862 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3864 /*if (profiling_classes) {
3865 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3867 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3871 MINT_IN_CASE(MINT_LDLEN)
3874 THROW_EX (mono_get_exception_null_reference (), ip);
3875 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3878 MINT_IN_CASE(MINT_GETCHR) {
3882 THROW_EX (mono_get_exception_null_reference (), ip);
3883 i32 = sp [-1].data.i;
3884 if (i32 < 0 || i32 >= mono_string_length (s))
3885 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3887 sp [-1].data.i = mono_string_chars(s)[i32];
3891 MINT_IN_CASE(MINT_STRLEN)
3895 THROW_EX (mono_get_exception_null_reference (), ip);
3896 sp [-1].data.i = mono_string_length ((MonoString*) o);
3898 MINT_IN_CASE(MINT_ARRAY_RANK)
3901 THROW_EX (mono_get_exception_null_reference (), ip);
3902 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3905 MINT_IN_CASE(MINT_LDELEMA)
3906 MINT_IN_CASE(MINT_LDELEMA_TC) {
3907 gboolean needs_typecheck = *ip == MINT_LDELEMA_TC;
3909 MonoClass *klass = rtm->data_items [*(guint16 *) (ip + 1)];
3910 guint16 numargs = *(guint16 *) (ip + 2);
3915 sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck);
3917 THROW_EX (frame->ex, ip);
3922 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3923 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3924 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3925 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3926 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3927 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3928 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3929 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3930 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3931 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3932 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
3933 MINT_IN_CASE(MINT_LDELEM_VT) {
3941 THROW_EX (mono_get_exception_null_reference (), ip);
3943 aindex = sp [1].data.i;
3944 if (aindex >= mono_array_length (o))
3945 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3948 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3951 case MINT_LDELEM_I1:
3952 sp [0].data.i = mono_array_get (o, gint8, aindex);
3954 case MINT_LDELEM_U1:
3955 sp [0].data.i = mono_array_get (o, guint8, aindex);
3957 case MINT_LDELEM_I2:
3958 sp [0].data.i = mono_array_get (o, gint16, aindex);
3960 case MINT_LDELEM_U2:
3961 sp [0].data.i = mono_array_get (o, guint16, aindex);
3964 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3966 case MINT_LDELEM_I4:
3967 sp [0].data.i = mono_array_get (o, gint32, aindex);
3969 case MINT_LDELEM_U4:
3970 sp [0].data.i = mono_array_get (o, guint32, aindex);
3972 case MINT_LDELEM_I8:
3973 sp [0].data.l = mono_array_get (o, guint64, aindex);
3975 case MINT_LDELEM_R4:
3976 sp [0].data.f = mono_array_get (o, float, aindex);
3978 case MINT_LDELEM_R8:
3979 sp [0].data.f = mono_array_get (o, double, aindex);
3981 case MINT_LDELEM_REF:
3982 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3984 case MINT_LDELEM_VT: {
3985 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3986 i32 = READ32 (ip + 2);
3987 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3988 sp [0].data.vt = vt_sp;
3989 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
3990 vt_sp += (i32 + 7) & ~7;
4002 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
4003 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
4004 MINT_IN_CASE(MINT_STELEM_U1) /* fall through */
4005 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
4006 MINT_IN_CASE(MINT_STELEM_U2) /* fall through */
4007 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
4008 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
4009 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
4010 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
4011 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
4012 MINT_IN_CASE(MINT_STELEM_VT) {
4019 THROW_EX (mono_get_exception_null_reference (), ip);
4021 aindex = sp [1].data.i;
4022 if (aindex >= mono_array_length ((MonoArray *)o))
4023 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4027 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
4029 case MINT_STELEM_I1:
4030 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
4032 case MINT_STELEM_U1:
4033 mono_array_set ((MonoArray *) o, guint8, aindex, sp [2].data.i);
4035 case MINT_STELEM_I2:
4036 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
4038 case MINT_STELEM_U2:
4039 mono_array_set ((MonoArray *)o, guint16, aindex, sp [2].data.i);
4041 case MINT_STELEM_I4:
4042 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
4044 case MINT_STELEM_I8:
4045 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
4047 case MINT_STELEM_R4:
4048 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
4050 case MINT_STELEM_R8:
4051 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
4053 case MINT_STELEM_REF: {
4054 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
4055 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4056 if (sp [2].data.p && !isinst_obj)
4057 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
4058 mono_array_setref ((MonoArray *) o, aindex, sp [2].data.p);
4061 case MINT_STELEM_VT: {
4062 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4063 i32 = READ32 (ip + 2);
4064 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4066 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
4067 vt_sp -= (i32 + 7) & ~7;
4078 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
4079 if (sp [-1].data.i < 0)
4080 THROW_EX (mono_get_exception_overflow (), ip);
4083 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
4084 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
4085 THROW_EX (mono_get_exception_overflow (), ip);
4086 sp [-1].data.i = (gint32) sp [-1].data.l;
4089 MINT_IN_CASE(MINT_CONV_OVF_I4_U8)
4090 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGINT32_MAX)
4091 THROW_EX (mono_get_exception_overflow (), ip);
4092 sp [-1].data.i = (gint32) sp [-1].data.l;
4095 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
4096 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
4097 THROW_EX (mono_get_exception_overflow (), ip);
4098 sp [-1].data.i = (gint32) sp [-1].data.f;
4101 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
4102 if (sp [-1].data.i < 0)
4103 THROW_EX (mono_get_exception_overflow (), ip);
4106 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
4107 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
4108 THROW_EX (mono_get_exception_overflow (), ip);
4109 sp [-1].data.i = (guint32) sp [-1].data.l;
4112 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
4113 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
4114 THROW_EX (mono_get_exception_overflow (), ip);
4115 sp [-1].data.i = (guint32) sp [-1].data.f;
4118 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
4119 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
4120 THROW_EX (mono_get_exception_overflow (), ip);
4123 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
4124 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
4125 THROW_EX (mono_get_exception_overflow (), ip);
4126 sp [-1].data.i = (gint16) sp [-1].data.l;
4129 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
4130 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
4131 THROW_EX (mono_get_exception_overflow (), ip);
4132 sp [-1].data.i = (gint16) sp [-1].data.f;
4135 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
4136 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
4137 THROW_EX (mono_get_exception_overflow (), ip);
4140 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
4141 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
4142 THROW_EX (mono_get_exception_overflow (), ip);
4143 sp [-1].data.i = (guint16) sp [-1].data.l;
4146 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
4147 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
4148 THROW_EX (mono_get_exception_overflow (), ip);
4149 sp [-1].data.i = (guint16) sp [-1].data.f;
4152 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
4153 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
4154 THROW_EX (mono_get_exception_overflow (), ip);
4157 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
4158 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
4159 THROW_EX (mono_get_exception_overflow (), ip);
4160 sp [-1].data.i = (gint8) sp [-1].data.l;
4163 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
4164 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
4165 THROW_EX (mono_get_exception_overflow (), ip);
4166 sp [-1].data.i = (gint8) sp [-1].data.f;
4169 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
4170 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
4171 THROW_EX (mono_get_exception_overflow (), ip);
4174 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
4175 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
4176 THROW_EX (mono_get_exception_overflow (), ip);
4177 sp [-1].data.i = (guint8) sp [-1].data.l;
4180 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
4181 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
4182 THROW_EX (mono_get_exception_overflow (), ip);
4183 sp [-1].data.i = (guint8) sp [-1].data.f;
4187 MINT_IN_CASE(MINT_LDELEM)
4188 MINT_IN_CASE(MINT_STELEM)
4189 MINT_IN_CASE(MINT_UNBOX_ANY)
4191 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
4193 MINT_IN_CASE(MINT_CKFINITE)
4194 if (!isfinite(sp [-1].data.f))
4195 THROW_EX (mono_get_exception_arithmetic (), ip);
4199 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
4201 MINT_IN_CASE(MINT_LDTOKEN)
4204 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
4208 MINT_IN_CASE(MINT_ADD_OVF_I4)
4209 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4210 THROW_EX (mono_get_exception_overflow (), ip);
4213 MINT_IN_CASE(MINT_ADD_OVF_I8)
4214 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4215 THROW_EX (mono_get_exception_overflow (), ip);
4218 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
4219 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4220 THROW_EX (mono_get_exception_overflow (), ip);
4221 BINOP_CAST(i, +, guint32);
4223 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
4224 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4225 THROW_EX (mono_get_exception_overflow (), ip);
4226 BINOP_CAST(l, +, guint64);
4228 MINT_IN_CASE(MINT_MUL_OVF_I4)
4229 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4230 THROW_EX (mono_get_exception_overflow (), ip);
4233 MINT_IN_CASE(MINT_MUL_OVF_I8)
4234 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4235 THROW_EX (mono_get_exception_overflow (), ip);
4238 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
4239 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4240 THROW_EX (mono_get_exception_overflow (), ip);
4241 BINOP_CAST(i, *, guint32);
4243 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
4244 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4245 THROW_EX (mono_get_exception_overflow (), ip);
4246 BINOP_CAST(l, *, guint64);
4248 MINT_IN_CASE(MINT_SUB_OVF_I4)
4249 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4250 THROW_EX (mono_get_exception_overflow (), ip);
4253 MINT_IN_CASE(MINT_SUB_OVF_I8)
4254 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4255 THROW_EX (mono_get_exception_overflow (), ip);
4258 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
4259 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4260 THROW_EX (mono_get_exception_overflow (), ip);
4261 BINOP_CAST(i, -, guint32);
4263 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
4264 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4265 THROW_EX (mono_get_exception_overflow (), ip);
4266 BINOP_CAST(l, -, guint64);
4268 MINT_IN_CASE(MINT_ENDFINALLY)
4269 while (sp > frame->stack) {
4273 ip = finally_ips->data;
4274 finally_ips = g_slist_remove (finally_ips, ip);
4281 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
4282 MINT_IN_CASE(MINT_LEAVE_S)
4283 while (sp > frame->stack) {
4287 if (*ip == MINT_LEAVE_S) {
4288 ip += (short) *(ip + 1);
4290 ip += (gint32) READ32 (ip + 1);
4293 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
4294 frame->ex_handler = NULL;
4297 goto handle_finally;
4299 MINT_IN_CASE(MINT_ICALL_V_V)
4300 MINT_IN_CASE(MINT_ICALL_V_P)
4301 MINT_IN_CASE(MINT_ICALL_P_V)
4302 MINT_IN_CASE(MINT_ICALL_P_P)
4303 MINT_IN_CASE(MINT_ICALL_PP_V)
4304 MINT_IN_CASE(MINT_ICALL_PI_V)
4305 MINT_IN_CASE(MINT_ICALL_PP_P)
4306 MINT_IN_CASE(MINT_ICALL_PI_P)
4307 MINT_IN_CASE(MINT_ICALL_PPP_V)
4308 MINT_IN_CASE(MINT_ICALL_PPI_V)
4309 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
4310 if (*mono_thread_interruption_request_flag ()) {
4311 MonoException *exc = mono_thread_interruption_checkpoint ();
4314 context->search_for_handler = 1;
4317 if (frame->ex != NULL)
4318 goto handle_exception;
4321 MINT_IN_CASE(MINT_MONO_LDPTR)
4322 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
4326 MINT_IN_CASE(MINT_MONO_NEWOBJ)
4327 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
4328 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4332 MINT_IN_CASE(MINT_MONO_FREE)
4335 g_error ("that doesn't seem right");
4336 g_free (sp->data.p);
4338 MINT_IN_CASE(MINT_MONO_RETOBJ)
4341 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
4342 mono_method_signature (frame->runtime_method->method)->pinvoke);
4343 if (sp > frame->stack)
4344 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
4346 MINT_IN_CASE(MINT_MONO_TLS) {
4347 MonoTlsKey key = *(gint32 *)(ip + 1);
4348 sp->data.p = ((gpointer (*)()) mono_tls_get_tls_getter (key, FALSE)) ();
4353 MINT_IN_CASE(MINT_MONO_JIT_ATTACH) {
4356 context->original_domain = NULL;
4357 MonoDomain *tls_domain = (MonoDomain *) ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4358 gpointer tls_jit = ((gpointer (*)()) mono_tls_get_tls_getter (TLS_KEY_DOMAIN, FALSE)) ();
4360 if (tls_domain != context->domain || !tls_jit)
4361 context->original_domain = mono_jit_thread_attach (context->domain);
4364 MINT_IN_CASE(MINT_MONO_JIT_DETACH)
4366 mono_jit_set_domain (context->original_domain);
4369 #define RELOP(datamem, op) \
4371 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
4373 MINT_IN_CASE(MINT_CEQ_I4)
4376 MINT_IN_CASE(MINT_CEQ0_I4)
4377 sp [-1].data.i = (sp [-1].data.i == 0);
4380 MINT_IN_CASE(MINT_CEQ_I8)
4383 MINT_IN_CASE(MINT_CEQ_R8)
4385 if (isunordered (sp [-1].data.f, sp [0].data.f))
4388 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
4391 MINT_IN_CASE(MINT_CGT_I4)
4394 MINT_IN_CASE(MINT_CGT_I8)
4397 MINT_IN_CASE(MINT_CGT_R8)
4399 if (isunordered (sp [-1].data.f, sp [0].data.f))
4402 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4406 #define RELOP_CAST(datamem, op, type) \
4408 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4411 MINT_IN_CASE(MINT_CGT_UN_I4)
4412 RELOP_CAST(i, >, guint32);
4414 MINT_IN_CASE(MINT_CGT_UN_I8)
4415 RELOP_CAST(l, >, guint64);
4417 MINT_IN_CASE(MINT_CGT_UN_R8)
4419 if (isunordered (sp [-1].data.f, sp [0].data.f))
4422 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4425 MINT_IN_CASE(MINT_CLT_I4)
4428 MINT_IN_CASE(MINT_CLT_I8)
4431 MINT_IN_CASE(MINT_CLT_R8)
4433 if (isunordered (sp [-1].data.f, sp [0].data.f))
4436 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4439 MINT_IN_CASE(MINT_CLT_UN_I4)
4440 RELOP_CAST(i, <, guint32);
4442 MINT_IN_CASE(MINT_CLT_UN_I8)
4443 RELOP_CAST(l, <, guint64);
4445 MINT_IN_CASE(MINT_CLT_UN_R8)
4447 if (isunordered (sp [-1].data.f, sp [0].data.f))
4450 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4453 MINT_IN_CASE(MINT_LDFTN) {
4454 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
4459 MINT_IN_CASE(MINT_LDVIRTFTN) {
4460 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
4464 THROW_EX (mono_get_exception_null_reference (), ip - 2);
4466 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
4471 #define LDARG(datamem, argtype) \
4472 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
4476 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
4477 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
4478 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
4479 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
4480 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
4481 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
4482 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
4483 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
4484 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
4485 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
4487 MINT_IN_CASE(MINT_LDARG_VT)
4489 i32 = READ32(ip + 2);
4490 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
4491 vt_sp += (i32 + 7) & ~7;
4496 #define STARG(datamem, argtype) \
4498 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4501 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
4502 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
4503 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
4504 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
4505 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
4506 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
4507 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
4508 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
4509 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
4510 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
4512 MINT_IN_CASE(MINT_STARG_VT)
4513 i32 = READ32(ip + 2);
4515 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
4516 vt_sp -= (i32 + 7) & ~7;
4520 #define STINARG(datamem, argtype) \
4522 int n = * (guint16 *)(ip + 1); \
4523 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
4527 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
4528 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
4529 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
4530 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
4531 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
4532 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
4533 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
4534 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
4535 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
4536 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
4538 MINT_IN_CASE(MINT_STINARG_VT) {
4539 int n = * (guint16 *)(ip + 1);
4540 i32 = READ32(ip + 2);
4541 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
4546 MINT_IN_CASE(MINT_LDARGA)
4547 sp->data.p = frame->args + * (guint16 *)(ip + 1);
4552 #define LDLOC(datamem, argtype) \
4553 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
4557 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
4558 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
4559 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
4560 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
4561 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
4562 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
4563 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
4564 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
4565 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
4566 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
4568 MINT_IN_CASE(MINT_LDLOC_VT)
4570 i32 = READ32(ip + 2);
4571 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
4572 vt_sp += (i32 + 7) & ~7;
4577 MINT_IN_CASE(MINT_LDLOCA_S)
4578 sp->data.p = locals + * (guint16 *)(ip + 1);
4583 #define STLOC(datamem, argtype) \
4585 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4588 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4589 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4590 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4591 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4592 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4593 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4594 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4595 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4596 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4597 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4599 #define STLOC_NP(datamem, argtype) \
4600 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4603 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4604 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4606 MINT_IN_CASE(MINT_STLOC_VT)
4607 i32 = READ32(ip + 2);
4609 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4610 vt_sp -= (i32 + 7) & ~7;
4614 MINT_IN_CASE(MINT_LOCALLOC) {
4615 if (sp != frame->stack + 1) /*FIX?*/
4616 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4618 int len = sp [-1].data.i;
4619 sp [-1].data.p = alloca (len);
4620 MonoMethodHeader *header = mono_method_get_header_checked (frame->runtime_method->method, &error);
4621 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4622 if (header && header->init_locals)
4623 memset (sp [-1].data.p, 0, len);
4627 MINT_IN_CASE(MINT_ENDFILTER)
4628 /* top of stack is result of filter */
4629 frame->retval = &sp [-1];
4631 MINT_IN_CASE(MINT_INITOBJ)
4633 memset (sp->data.vt, 0, READ32(ip + 1));
4636 MINT_IN_CASE(MINT_CPBLK)
4638 if (!sp [0].data.p || !sp [1].data.p)
4639 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4641 /* FIXME: value and size may be int64... */
4642 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4645 MINT_IN_CASE(MINT_CONSTRAINED_) {
4647 /* FIXME: implement */
4649 token = READ32 (ip);
4654 MINT_IN_CASE(MINT_INITBLK)
4657 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4659 /* FIXME: value and size may be int64... */
4660 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4663 MINT_IN_CASE(MINT_NO_)
4664 /* FIXME: implement */
4668 MINT_IN_CASE(MINT_RETHROW)
4670 * need to clarify what this should actually do:
4671 * start the search from the last found handler in
4672 * this method or continue in the caller or what.
4673 * Also, do we need to run finally/fault handlers after a retrow?
4674 * Well, this implementation will follow the usual search
4675 * for an handler, considering the current ip as throw spot.
4676 * We need to NULL frame->ex_handler for the later code to
4677 * actually run the new found handler.
4679 frame->ex_handler = NULL;
4680 THROW_EX (frame->ex, ip - 1);
4683 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4684 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4688 g_assert_not_reached ();
4690 * Exception handling code.
4691 * The exception object is stored in frame->ex.
4698 MonoInvocation *inv;
4699 MonoExceptionClause *clause;
4705 g_print ("* Handling exception '%s' at IL_%04x\n",
4706 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4707 rtm == NULL ? 0 : frame->ip - rtm->code);
4709 if (die_on_exception)
4712 for (inv = frame; inv; inv = inv->parent) {
4714 if (inv->runtime_method == NULL)
4716 method = inv->runtime_method->method;
4717 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4719 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4721 if (inv->ip == NULL)
4723 ip_offset = inv->ip - inv->runtime_method->code;
4724 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4725 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4726 clause = &inv->runtime_method->clauses [i];
4728 g_print ("* clause [%d]: %p\n", i, clause);
4730 if (!MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4733 if (clause->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
4736 g_print ("* Filter found at '%s'\n", method->name);
4738 MonoInvocation dup_frame;
4740 memcpy (&dup_frame, inv, sizeof (MonoInvocation));
4741 dup_frame.retval = &retval;
4742 ves_exec_method_with_context (&dup_frame, context, inv->runtime_method->code + clause->data.filter_offset, frame->ex);
4743 if (dup_frame.retval->data.i) {
4746 g_print ("* Matched Filter at '%s'\n", method->name);
4748 inv->ex_handler = clause;
4749 goto handle_finally;
4751 } else if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE) {
4752 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4753 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4756 * OK, we found an handler, now we need to execute the finally
4757 * and fault blocks before branching to the handler code.
4761 g_print ("* Found handler at '%s'\n", method->name);
4763 inv->ex_handler = clause;
4764 goto handle_finally;
4770 * If we get here, no handler was found: print a stack trace.
4772 for (inv = frame; inv; inv = inv->parent) {
4773 if (inv->invoke_trap)
4774 goto handle_finally;
4777 ex_obj = (MonoObject *) frame->ex;
4778 mono_unhandled_exception (ex_obj);
4779 MonoJitTlsData *jit_tls = (MonoJitTlsData *) mono_tls_get_jit_tls ();
4780 jit_tls->abort_func (ex_obj);
4781 g_assert_not_reached ();
4787 MonoExceptionClause *clause;
4788 GSList *old_list = finally_ips;
4789 MonoMethod *method = frame->runtime_method->method;
4790 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4791 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4795 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4797 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4798 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4801 ip_offset = frame->ip - rtm->code;
4803 if (endfinally_ip != NULL)
4804 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4805 for (i = 0; i < header->num_clauses; ++i)
4806 if (frame->ex_handler == &rtm->clauses [i])
4810 clause = &rtm->clauses [i];
4811 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4812 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4813 ip = rtm->code + clause->handler_offset;
4814 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4817 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4823 endfinally_ip = NULL;
4825 if (old_list != finally_ips && finally_ips) {
4826 ip = finally_ips->data;
4827 finally_ips = g_slist_remove (finally_ips, ip);
4828 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4833 * If an exception is set, we need to execute the fault handler, too,
4834 * otherwise, we continue normally.
4844 MonoExceptionClause *clause;
4845 MonoMethod *method = frame->runtime_method->method;
4846 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4847 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4851 g_print ("* Handle fault\n");
4853 ip_offset = frame->ip - rtm->code;
4854 for (i = 0; i < header->num_clauses; ++i) {
4855 clause = &rtm->clauses [i];
4856 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4857 ip = rtm->code + clause->handler_offset;
4860 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4866 * If the handler for the exception was found in this method, we jump
4867 * to it right away, otherwise we return and let the caller run
4868 * the finally, fault and catch blocks.
4869 * This same code should be present in the endfault opcode, but it
4870 * is corrently not assigned in the ECMA specs: LAMESPEC.
4872 if (frame->ex_handler) {
4875 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4877 ip = rtm->code + frame->ex_handler->handler_offset;
4879 vt_sp = (unsigned char *) sp + rtm->stack_size;
4880 sp->data.p = frame->ex;
4891 ves_exec_method (MonoInvocation *frame)
4893 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4894 ThreadContext context_struct;
4901 mono_unhandled_exception ((MonoObject*)frame->ex);
4904 if (context == NULL) {
4905 context = &context_struct;
4906 context_struct.domain = mono_domain_get ();
4907 context_struct.base_frame = frame;
4908 context_struct.current_frame = NULL;
4909 context_struct.env_frame = frame;
4910 context_struct.current_env = &env;
4911 context_struct.search_for_handler = 0;
4912 context_struct.managed_code = 0;
4913 mono_native_tls_set_value (thread_context_id, context);
4916 frame->parent = context->current_frame;
4917 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4918 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4919 context->managed_code = 1;
4920 ves_exec_method_with_context (frame, context, NULL, NULL);
4921 context->managed_code = 0;
4923 if (context != &context_struct && context->current_env) {
4924 context->env_frame->ex = frame->ex;
4925 longjmp (*context->current_env, 1);
4928 mono_unhandled_exception ((MonoObject*)frame->ex);
4930 if (context->base_frame == frame)
4931 mono_native_tls_set_value (thread_context_id, NULL);
4933 context->current_frame = frame->parent;
4937 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4939 MonoImage *image = mono_assembly_get_image (assembly);
4944 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4945 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4948 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4950 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4951 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4959 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4960 "Usage is: mint [options] executable args...\n\n", VERSION);
4962 "Runtime Debugging:\n"
4967 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4970 " --traceclassinit\n"
4973 " --debug method_name\n"
4980 " --config filename load the specified config file instead of the default\n"
4981 " --workers n maximum number of worker threads\n"
4987 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4988 MonoReflectionMethod **method,
4989 gint32 *iloffset, gint32 *native_offset,
4990 MonoString **file, gint32 *line, gint32 *column)
4992 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4993 MonoInvocation *inv = context->current_frame;
4997 for (i = 0; inv && i < skip; inv = inv->parent)
4998 if (inv->runtime_method != NULL)
5009 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
5010 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5015 if (need_file_info) {
5019 *file = mono_string_new (mono_domain_get (), "unknown");
5026 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
5028 MonoDomain *domain = mono_domain_get ();
5030 MonoArray *ta = exc->trace_ips;
5035 /* Exception is not thrown yet */
5036 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
5037 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5041 len = mono_array_length (ta);
5043 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
5044 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5046 for (i = skip; i < len / 2; i++) {
5047 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
5048 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5049 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
5050 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
5053 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
5054 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5055 sf->native_offset = ip - rtm->code;
5059 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
5061 if (need_file_info) {
5064 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
5066 sf->filename = filename? mono_string_new (domain, filename): NULL;
5073 mono_array_set (res, gpointer, i, sf);
5080 mono_interp_parse_options (const char *options)
5084 args = g_strsplit (options, ",", -1);
5085 for (ptr = args; ptr && *ptr; ptr ++) {
5088 if (strncmp (arg, "jit=", 4) == 0)
5089 jit_classes = g_slist_prepend (jit_classes, arg + 4);
5096 mono_native_tls_alloc (&thread_context_id, NULL);
5097 mono_native_tls_set_value (thread_context_id, NULL);
5099 mono_interp_transform_init ();
5102 typedef int (*TestMethod) (void);
5105 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
5107 int result, expected, failed, cfailed, run;
5108 double elapsed, transform_time;
5110 MonoObject *result_obj;
5111 static gboolean filter_method_init = FALSE;
5112 static const char *filter_method = NULL;
5114 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
5115 cfailed = failed = run = 0;
5116 transform_time = elapsed = 0.0;
5118 g_timer_start (timer);
5119 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5120 MonoObject *exc = NULL;
5122 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5124 mono_error_cleanup (&error); /* FIXME don't swallow the error */
5128 if (!filter_method_init) {
5129 filter_method = g_getenv ("INTERP_FILTER_METHOD");
5130 filter_method_init = TRUE;
5132 gboolean filter = FALSE;
5133 if (filter_method) {
5134 const char *name = filter_method;
5136 if ((strchr (name, '.') > name) || strchr (name, ':')) {
5137 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
5138 filter = mono_method_desc_full_match (desc, method);
5139 mono_method_desc_free (desc);
5141 filter = strcmp (method->name, name) == 0;
5143 } else { /* no filter, check for `Category' attribute on method */
5145 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
5146 mono_error_cleanup (&error);
5150 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
5151 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
5152 if (centry->ctor == NULL)
5155 MonoClass *klass = centry->ctor->klass;
5156 if (strcmp (klass->name, "CategoryAttribute"))
5159 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
5160 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
5161 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
5162 mono_error_cleanup (&error);
5163 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
5164 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
5165 mono_error_cleanup (&error);
5166 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
5167 mono_error_cleanup (&error);
5168 if (!strcmp (utf8_str, "!INTERPRETER")) {
5169 g_print ("skip %s...\n", method->name);
5175 if (strncmp (method->name, "test_", 5) == 0 && filter) {
5176 MonoError interp_error;
5177 MonoObject *exc = NULL;
5179 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
5180 if (!mono_error_ok (&interp_error)) {
5182 g_print ("Test '%s' execution failed.\n", method->name);
5183 } else if (exc != NULL) {
5184 g_print ("Exception in Test '%s' occured:\n", method->name);
5185 mono_object_describe (exc);
5189 result = *(gint32 *) mono_object_unbox (result_obj);
5190 expected = atoi (method->name + 5); // FIXME: oh no.
5193 if (result != expected) {
5195 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
5200 g_timer_stop (timer);
5201 elapsed = g_timer_elapsed (timer, NULL);
5202 if (failed > 0 || cfailed > 0){
5203 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
5204 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
5206 g_print ("Results: total tests: %d, all pass \n", run);
5209 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
5210 elapsed - transform_time, transform_time);
5211 *total += failed + cfailed;
5216 interp_regression (MonoImage *image, int verbose, int *total_run)
5219 GTimer *timer = g_timer_new ();
5220 MonoDomain *domain = mono_domain_get ();
5224 /* load the metadata */
5225 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5227 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5229 mono_error_cleanup (&error);
5232 mono_class_init (method->klass);
5237 interp_regression_step (image, verbose, total_run, &total, timer, domain);
5239 g_timer_destroy (timer);
5244 mono_interp_regression_list (int verbose, int count, char *images [])
5246 int i, total, total_run, run;
5248 total_run = total = 0;
5249 for (i = 0; i < count; ++i) {
5250 MonoAssembly *ass = mono_assembly_open_predicate (images [i], FALSE, FALSE, NULL, NULL, NULL);
5252 g_warning ("failed to load assembly: %s", images [i]);
5255 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
5259 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
5261 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);