4 * interp.c: Interpreter for CIL byte codes
7 * Paolo Molaro (lupus@ximian.com)
8 * Miguel de Icaza (miguel@ximian.com)
9 * Dietmar Maurer (dietmar@ximian.com)
11 * (C) 2001, 2002 Ximian, Inc.
25 #include <mono/utils/gc_wrapper.h>
26 #include <mono/utils/mono-math.h>
27 #include <mono/utils/mono-counters.h>
33 # define alloca __builtin_alloca
37 /* trim excessive headers */
38 #include <mono/metadata/image.h>
39 #include <mono/metadata/assembly-internals.h>
40 #include <mono/metadata/cil-coff.h>
41 #include <mono/metadata/mono-endian.h>
42 #include <mono/metadata/tabledefs.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/loader.h>
45 #include <mono/metadata/threads.h>
46 #include <mono/metadata/threadpool.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/appdomain.h>
49 #include <mono/metadata/reflection.h>
50 #include <mono/metadata/exception.h>
51 #include <mono/metadata/verify.h>
52 #include <mono/metadata/opcodes.h>
53 #include <mono/metadata/debug-helpers.h>
54 #include <mono/metadata/mono-config.h>
55 #include <mono/metadata/marshal.h>
56 #include <mono/metadata/environment.h>
57 #include <mono/metadata/mono-debug.h>
58 #include <mono/metadata/gc-internals.h>
59 #include <mono/utils/atomic.h>
62 #include "interp-internals.h"
65 #include <mono/mini/mini.h>
66 #include <mono/mini/mini-runtime.h>
67 #include <mono/mini/aot-runtime.h>
68 #include <mono/mini/llvm-runtime.h>
69 #include <mono/mini/llvmonly-runtime.h>
70 #include <mono/mini/jit-icalls.h>
71 #include <mono/mini/debugger-agent.h>
72 #include <mono/mini/ee.h>
73 #include <mono/mini/trace.h>
76 #include <mono/mini/mini-arm.h>
78 #include <mono/metadata/icall-decl.h>
81 #pragma warning(disable:4102) // label' : unreferenced label
84 /* Arguments that are passed when invoking only a finally/filter clause from the frame */
86 /* Where we start the frame execution from */
87 guint16
*start_with_ip
;
89 * End ip of the exit_clause. We need it so we know whether the resume
90 * state is for this frame (which is called from EH) or for the original
91 * frame further down the stack.
94 /* When exiting this clause we also exit the frame */
96 /* Exception that we are filtering */
97 MonoException
*filter_exception
;
98 InterpFrame
*base_frame
;
102 init_frame (InterpFrame
*frame
, InterpFrame
*parent_frame
, InterpMethod
*rmethod
, stackval
*method_args
, stackval
*method_retval
)
104 frame
->parent
= parent_frame
;
105 frame
->stack_args
= method_args
;
106 frame
->retval
= method_retval
;
107 frame
->imethod
= rmethod
;
112 #define interp_exec_method(frame, context, error) interp_exec_method_full ((frame), (context), NULL, error)
115 * List of classes whose methods will be executed by transitioning to JITted code.
118 GSList
*mono_interp_jit_classes
;
119 /* Optimizations enabled with interpreter */
120 int mono_interp_opt
= INTERP_OPT_INLINE
;
121 /* If TRUE, interpreted code will be interrupted at function entry/backward branches */
122 static gboolean ss_enabled
;
124 static gboolean interp_init_done
= FALSE
;
126 static void interp_exec_method_full (InterpFrame
*frame
, ThreadContext
*context
, FrameClauseArgs
*clause_args
, MonoError
*error
);
127 static InterpMethod
* lookup_method_pointer (gpointer addr
);
129 typedef void (*ICallMethod
) (InterpFrame
*frame
);
131 static MonoNativeTlsKey thread_context_id
;
133 #define DEBUG_INTERP 0
137 int mono_interp_traceopt
= 2;
138 /* If true, then we output the opcodes as we interpret them */
139 static int global_tracing
= 2;
141 static int debug_indent_level
= 0;
143 static int break_on_method
= 0;
144 static int nested_trace
= 0;
145 static GList
*db_methods
= NULL
;
146 static char* dump_args (InterpFrame
*inv
);
153 for (h
= 0; h
< debug_indent_level
; h
++)
158 db_match_method (gpointer data
, gpointer user_data
)
160 MonoMethod
*m
= (MonoMethod
*)user_data
;
161 MonoMethodDesc
*desc
= data
;
163 if (mono_method_desc_full_match (desc
, m
))
168 debug_enter (InterpFrame
*frame
, int *tracing
)
171 g_list_foreach (db_methods
, db_match_method
, (gpointer
)frame
->imethod
->method
);
173 *tracing
= nested_trace
? (global_tracing
= 2, 3) : 2;
177 MonoMethod
*method
= frame
->imethod
->method
;
178 char *mn
, *args
= dump_args (frame
);
179 debug_indent_level
++;
181 mn
= mono_method_full_name (method
, FALSE
);
182 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn
);
184 g_print ("%s)\n", args
);
190 #define DEBUG_LEAVE() \
193 args = dump_retval (frame); \
195 mn = mono_method_full_name (frame->imethod->method, FALSE); \
196 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
198 g_print (" => %s\n", args); \
200 debug_indent_level--; \
201 if (tracing == 3) global_tracing = 0; \
206 int mono_interp_traceopt
= 0;
207 #define DEBUG_LEAVE()
211 #if defined(__GNUC__) && !defined(TARGET_WASM)
212 #define USE_COMPUTED_GOTO 1
214 #if USE_COMPUTED_GOTO
215 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
216 #define MINT_IN_CASE(x) LAB_ ## x:
217 #define MINT_IN_DISPATCH(op) goto *in_labels[op];
219 #define MINT_IN_BREAK if (tracing > 1) { MINT_IN_DISPATCH(*ip); } else { COUNT_OP(*ip); goto *in_labels[*ip]; }
221 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
223 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
225 #define MINT_IN_SWITCH(op) switch (op)
226 #define MINT_IN_CASE(x) case x:
227 #define MINT_IN_DISPATCH(op) goto main_loop;
228 #define MINT_IN_BREAK break
229 #define MINT_IN_DEFAULT default:
232 static MONO_NEVER_INLINE
void // Inlining this causes caller to use more stack.
233 set_resume_state (ThreadContext
*context
, InterpFrame
*frame
)
235 /* We have thrown an exception from a finally block. Some of the leave targets were unwinded already */
236 while (frame
->finally_ips
&&
237 frame
->finally_ips
->data
>= context
->handler_ei
->try_start
&&
238 frame
->finally_ips
->data
< context
->handler_ei
->try_end
)
239 frame
->finally_ips
= g_slist_remove (frame
->finally_ips
, frame
->finally_ips
->data
);
241 context
->has_resume_state
= 0;
242 context
->handler_frame
= NULL
;
243 context
->handler_ei
= NULL
;
246 /* Set the current execution state to the resume state in context */
247 #define SET_RESUME_STATE(context) do { \
248 ip = (const guint16*)(context)->handler_ip; \
249 /* spec says stack should be empty at endfinally so it should be at the start too */ \
251 vt_sp = (unsigned char *) sp + imethod->stack_size; \
253 sp->data.p = frame->ex; \
256 set_resume_state ((context), (frame)); \
257 MINT_IN_DISPATCH(*ip); \
261 * If this bit is set, it means the call has thrown the exception, and we
262 * reached this point because the EH code in mono_handle_exception ()
263 * unwound all the JITted frames below us. mono_interp_set_resume_state ()
264 * has set the fields in context to indicate where we have to resume execution.
266 #define CHECK_RESUME_STATE(context) do { \
267 if ((context)->has_resume_state) { \
268 if (frame == (context)->handler_frame && (!clause_args || (context)->handler_ip < clause_args->end_at_ip)) \
269 SET_RESUME_STATE (context); \
276 set_context (ThreadContext
*context
)
278 mono_native_tls_set_value (thread_context_id
, context
);
283 MonoJitTlsData
*jit_tls
= mono_tls_get_jit_tls ();
284 g_assertf (jit_tls
, "ThreadContext needs initialized JIT TLS");
286 /* jit_tls assumes ownership of 'context' */
287 jit_tls
->interp_context
= context
;
290 static ThreadContext
*
293 ThreadContext
*context
= (ThreadContext
*) mono_native_tls_get_value (thread_context_id
);
294 if (context
== NULL
) {
295 context
= g_new0 (ThreadContext
, 1);
296 set_context (context
);
301 static MONO_NEVER_INLINE
void
302 ves_real_abort (int line
, MonoMethod
*mh
,
303 const unsigned short *ip
, stackval
*stack
, stackval
*sp
)
306 MonoMethodHeader
*header
= mono_method_get_header_checked (mh
, error
);
307 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
308 g_printerr ("Execution aborted in method: %s::%s\n", m_class_get_name (mh
->klass
), mh
->name
);
309 g_printerr ("Line=%d IP=0x%04lx, Aborted execution\n", line
, ip
-(const unsigned short *) header
->code
);
310 g_printerr ("0x%04x %02x\n", ip
-(const unsigned short *) header
->code
, *ip
);
311 mono_metadata_free_mh (header
);
314 #define ves_abort() \
316 ves_real_abort(__LINE__, frame->imethod->method, ip, frame->stack, sp); \
317 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
321 lookup_imethod (MonoDomain
*domain
, MonoMethod
*method
)
323 InterpMethod
*imethod
;
324 MonoJitDomainInfo
*info
;
326 info
= domain_jit_info (domain
);
327 mono_domain_jit_code_hash_lock (domain
);
328 imethod
= (InterpMethod
*)mono_internal_hash_table_lookup (&info
->interp_code_hash
, method
);
329 mono_domain_jit_code_hash_unlock (domain
);
334 interp_get_remoting_invoke (MonoMethod
*method
, gpointer addr
, MonoError
*error
)
336 #ifndef DISABLE_REMOTING
337 InterpMethod
*imethod
;
340 imethod
= lookup_method_pointer (addr
);
343 imethod
= mono_interp_get_imethod (mono_domain_get (), method
, error
);
344 return_val_if_nok (error
, NULL
);
347 g_assert (mono_use_interpreter
);
349 MonoMethod
*remoting_invoke_method
= mono_marshal_get_remoting_invoke (imethod
->method
, error
);
350 return_val_if_nok (error
, NULL
);
351 return mono_interp_get_imethod (mono_domain_get (), remoting_invoke_method
, error
);
353 g_assert_not_reached ();
359 mono_interp_get_imethod (MonoDomain
*domain
, MonoMethod
*method
, MonoError
*error
)
361 InterpMethod
*imethod
;
362 MonoJitDomainInfo
*info
;
363 MonoMethodSignature
*sig
;
368 info
= domain_jit_info (domain
);
369 mono_domain_jit_code_hash_lock (domain
);
370 imethod
= (InterpMethod
*)mono_internal_hash_table_lookup (&info
->interp_code_hash
, method
);
371 mono_domain_jit_code_hash_unlock (domain
);
375 sig
= mono_method_signature_internal (method
);
377 imethod
= (InterpMethod
*)mono_domain_alloc0 (domain
, sizeof (InterpMethod
));
378 imethod
->method
= method
;
379 imethod
->domain
= domain
;
380 imethod
->param_count
= sig
->param_count
;
381 imethod
->hasthis
= sig
->hasthis
;
382 imethod
->vararg
= sig
->call_convention
== MONO_CALL_VARARG
;
383 imethod
->rtype
= mini_get_underlying_type (sig
->ret
);
384 imethod
->param_types
= (MonoType
**)mono_domain_alloc0 (domain
, sizeof (MonoType
*) * sig
->param_count
);
385 for (i
= 0; i
< sig
->param_count
; ++i
)
386 imethod
->param_types
[i
] = mini_get_underlying_type (sig
->params
[i
]);
388 mono_domain_jit_code_hash_lock (domain
);
389 if (!mono_internal_hash_table_lookup (&info
->interp_code_hash
, method
))
390 mono_internal_hash_table_insert (&info
->interp_code_hash
, method
, imethod
);
391 mono_domain_jit_code_hash_unlock (domain
);
393 imethod
->prof_flags
= mono_profiler_get_call_instrumentation_flags (imethod
->method
);
398 #if defined (MONO_CROSS_COMPILE) || defined (HOST_WASM)
399 #define INTERP_PUSH_LMF_WITH_CTX_BODY(ext, exit_label) \
400 (ext).kind = MONO_LMFEXT_INTERP_EXIT;
402 #elif defined(MONO_ARCH_HAS_NO_PROPER_MONOCTX)
403 /* some platforms, e.g. appleTV, don't provide us a precise MonoContext
404 * (registers are not accurate), thus resuming to the label does not work. */
405 #define INTERP_PUSH_LMF_WITH_CTX_BODY(ext, exit_label) \
406 (ext).kind = MONO_LMFEXT_INTERP_EXIT;
407 #elif defined (_MSC_VER)
408 #define INTERP_PUSH_LMF_WITH_CTX_BODY(ext, exit_label) \
409 (ext).kind = MONO_LMFEXT_INTERP_EXIT_WITH_CTX; \
410 (ext).interp_exit_label_set = FALSE; \
411 MONO_CONTEXT_GET_CURRENT ((ext).ctx); \
412 if ((ext).interp_exit_label_set == FALSE) \
413 mono_arch_do_ip_adjustment (&(ext).ctx); \
414 if ((ext).interp_exit_label_set == TRUE) \
416 (ext).interp_exit_label_set = TRUE;
417 #elif defined(MONO_ARCH_HAS_MONO_CONTEXT)
418 #define INTERP_PUSH_LMF_WITH_CTX_BODY(ext, exit_label) \
419 (ext).kind = MONO_LMFEXT_INTERP_EXIT_WITH_CTX; \
420 MONO_CONTEXT_GET_CURRENT ((ext).ctx); \
421 MONO_CONTEXT_SET_IP (&(ext).ctx, (&&exit_label)); \
422 mono_arch_do_ip_adjustment (&(ext).ctx);
424 #define INTERP_PUSH_LMF_WITH_CTX_BODY(ext, exit_label) g_error ("requires working mono-context");
427 /* INTERP_PUSH_LMF_WITH_CTX:
429 * same as interp_push_lmf, but retrieving and attaching MonoContext to it.
430 * This is needed to resume into the interp when the exception is thrown from
431 * native code (see ./mono/tests/install_eh_callback.exe).
433 * This must be a macro in order to retrieve the right register values for
436 #define INTERP_PUSH_LMF_WITH_CTX(frame, ext, exit_label) \
437 memset (&(ext), 0, sizeof (MonoLMFExt)); \
438 (ext).interp_exit_data = (frame); \
439 INTERP_PUSH_LMF_WITH_CTX_BODY ((ext), exit_label); \
440 mono_push_lmf (&(ext));
445 * Push an LMF frame on the LMF stack
446 * to mark the transition to native code.
447 * This is needed for the native code to
448 * be able to do stack walks.
451 interp_push_lmf (MonoLMFExt
*ext
, InterpFrame
*frame
)
453 memset (ext
, 0, sizeof (MonoLMFExt
));
454 ext
->kind
= MONO_LMFEXT_INTERP_EXIT
;
455 ext
->interp_exit_data
= frame
;
461 interp_pop_lmf (MonoLMFExt
*ext
)
463 mono_pop_lmf (&ext
->lmf
);
466 static MONO_NEVER_INLINE InterpMethod
*
467 get_virtual_method (InterpMethod
*imethod
, MonoVTable
*vtable
)
469 MonoMethod
*m
= imethod
->method
;
470 MonoDomain
*domain
= imethod
->domain
;
471 InterpMethod
*ret
= NULL
;
474 #ifndef DISABLE_REMOTING
475 if (mono_class_is_transparent_proxy (vtable
->klass
)) {
476 MonoMethod
*remoting_invoke_method
= mono_marshal_get_remoting_invoke_with_check (m
, error
);
477 mono_error_assert_ok (error
);
478 ret
= mono_interp_get_imethod (domain
, remoting_invoke_method
, error
);
479 mono_error_assert_ok (error
);
484 if ((m
->flags
& METHOD_ATTRIBUTE_FINAL
) || !(m
->flags
& METHOD_ATTRIBUTE_VIRTUAL
)) {
485 if (m
->iflags
& METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED
) {
486 ret
= mono_interp_get_imethod (domain
, mono_marshal_get_synchronized_wrapper (m
), error
);
487 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
494 mono_class_setup_vtable (vtable
->klass
);
496 int slot
= mono_method_get_vtable_slot (m
);
497 if (mono_class_is_interface (m
->klass
)) {
498 g_assert (vtable
->klass
!= m
->klass
);
499 /* TODO: interface offset lookup is slow, go through IMT instead */
500 gboolean non_exact_match
;
501 slot
+= mono_class_interface_offset_with_variance (vtable
->klass
, m
->klass
, &non_exact_match
);
504 MonoMethod
*virtual_method
= m_class_get_vtable (vtable
->klass
) [slot
];
505 if (m
->is_inflated
&& mono_method_get_context (m
)->method_inst
) {
506 MonoGenericContext context
= { NULL
, NULL
};
508 if (mono_class_is_ginst (virtual_method
->klass
))
509 context
.class_inst
= mono_class_get_generic_class (virtual_method
->klass
)->context
.class_inst
;
510 else if (mono_class_is_gtd (virtual_method
->klass
))
511 context
.class_inst
= mono_class_get_generic_container (virtual_method
->klass
)->context
.class_inst
;
512 context
.method_inst
= mono_method_get_context (m
)->method_inst
;
514 virtual_method
= mono_class_inflate_generic_method_checked (virtual_method
, &context
, error
);
515 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
518 if (virtual_method
->iflags
& METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
) {
519 virtual_method
= mono_marshal_get_native_wrapper (virtual_method
, FALSE
, FALSE
);
522 if (virtual_method
->iflags
& METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED
) {
523 virtual_method
= mono_marshal_get_synchronized_wrapper (virtual_method
);
526 InterpMethod
*virtual_imethod
= mono_interp_get_imethod (domain
, virtual_method
, error
);
527 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
528 return virtual_imethod
;
532 InterpMethod
*imethod
;
533 InterpMethod
*target_imethod
;
536 /* domain lock must be held */
538 append_imethod (MonoDomain
*domain
, GSList
*list
, InterpMethod
*imethod
, InterpMethod
*target_imethod
)
541 InterpVTableEntry
*entry
;
543 entry
= (InterpVTableEntry
*) mono_mempool_alloc (domain
->mp
, sizeof (InterpVTableEntry
));
544 entry
->imethod
= imethod
;
545 entry
->target_imethod
= target_imethod
;
546 ret
= g_slist_append_mempool (domain
->mp
, list
, entry
);
552 get_target_imethod (GSList
*list
, InterpMethod
*imethod
)
554 while (list
!= NULL
) {
555 InterpVTableEntry
*entry
= (InterpVTableEntry
*) list
->data
;
556 if (entry
->imethod
== imethod
)
557 return entry
->target_imethod
;
564 get_method_table (MonoVTable
*vtable
, int offset
)
567 return vtable
->interp_vtable
;
569 return (gpointer
*)vtable
;
573 alloc_method_table (MonoVTable
*vtable
, int offset
)
578 table
= mono_domain_alloc0 (vtable
->domain
, m_class_get_vtable_size (vtable
->klass
) * sizeof (gpointer
));
579 vtable
->interp_vtable
= table
;
581 table
= (gpointer
*)vtable
;
588 get_virtual_method_fast (InterpMethod
*imethod
, MonoVTable
*vtable
, int offset
)
592 #ifndef DISABLE_REMOTING
594 if (mono_class_is_transparent_proxy (vtable
->klass
))
595 return get_virtual_method (imethod
, vtable
);
598 table
= get_method_table (vtable
, offset
);
601 /* Lazily allocate method table */
602 mono_domain_lock (vtable
->domain
);
603 table
= get_method_table (vtable
, offset
);
605 table
= alloc_method_table (vtable
, offset
);
606 mono_domain_unlock (vtable
->domain
);
609 if (!table
[offset
]) {
610 InterpMethod
*target_imethod
= get_virtual_method (imethod
, vtable
);
611 /* Lazily initialize the method table slot */
612 mono_domain_lock (vtable
->domain
);
613 if (!table
[offset
]) {
614 if (imethod
->method
->is_inflated
|| offset
< 0)
615 table
[offset
] = append_imethod (vtable
->domain
, NULL
, imethod
, target_imethod
);
617 table
[offset
] = (gpointer
) ((gsize
)target_imethod
| 0x1);
619 mono_domain_unlock (vtable
->domain
);
622 if ((gsize
)table
[offset
] & 0x1) {
623 /* Non generic virtual call. Only one method in slot */
624 return (InterpMethod
*) ((gsize
)table
[offset
] & ~0x1);
626 /* Virtual generic or interface call. Multiple methods in slot */
627 InterpMethod
*target_imethod
= get_target_imethod ((GSList
*)table
[offset
], imethod
);
629 if (!target_imethod
) {
630 target_imethod
= get_virtual_method (imethod
, vtable
);
631 mono_domain_lock (vtable
->domain
);
632 if (!get_target_imethod ((GSList
*)table
[offset
], imethod
))
633 table
[offset
] = append_imethod (vtable
->domain
, (GSList
*)table
[offset
], imethod
, target_imethod
);
634 mono_domain_unlock (vtable
->domain
);
636 return target_imethod
;
641 stackval_from_data (MonoType
*type_
, stackval
*result
, void *data
, gboolean pinvoke
)
643 MonoType
*type
= mini_native_type_replace_type (type_
);
645 switch (type
->type
) {
646 case MONO_TYPE_OBJECT
:
647 case MONO_TYPE_CLASS
:
648 case MONO_TYPE_STRING
:
649 case MONO_TYPE_ARRAY
:
650 case MONO_TYPE_SZARRAY
:
655 result
->data
.p
= *(gpointer
*)data
;
658 switch (type
->type
) {
662 result
->data
.i
= *(gint8
*)data
;
665 case MONO_TYPE_BOOLEAN
:
666 result
->data
.i
= *(guint8
*)data
;
669 result
->data
.i
= *(gint16
*)data
;
673 result
->data
.i
= *(guint16
*)data
;
676 result
->data
.i
= *(gint32
*)data
;
680 result
->data
.nati
= *(mono_i
*)data
;
683 result
->data
.p
= *(gpointer
*)data
;
686 result
->data
.i
= *(guint32
*)data
;
689 /* memmove handles unaligned case */
690 memmove (&result
->data
.f_r4
, data
, sizeof (float));
694 memmove (&result
->data
.l
, data
, sizeof (gint64
));
697 memmove (&result
->data
.f
, data
, sizeof (double));
699 case MONO_TYPE_STRING
:
700 case MONO_TYPE_SZARRAY
:
701 case MONO_TYPE_CLASS
:
702 case MONO_TYPE_OBJECT
:
703 case MONO_TYPE_ARRAY
:
704 result
->data
.p
= *(gpointer
*)data
;
706 case MONO_TYPE_VALUETYPE
:
707 if (m_class_is_enumtype (type
->data
.klass
)) {
708 stackval_from_data (mono_class_enum_basetype_internal (type
->data
.klass
), result
, data
, pinvoke
);
710 } else if (pinvoke
) {
711 memcpy (result
->data
.vt
, data
, mono_class_native_size (type
->data
.klass
, NULL
));
713 mono_value_copy_internal (result
->data
.vt
, data
, type
->data
.klass
);
716 case MONO_TYPE_GENERICINST
: {
717 if (mono_type_generic_inst_is_valuetype (type
)) {
718 mono_value_copy_internal (result
->data
.vt
, data
, mono_class_from_mono_type_internal (type
));
721 stackval_from_data (m_class_get_byval_arg (type
->data
.generic_class
->container_class
), result
, data
, pinvoke
);
725 g_error ("got type 0x%02x", type
->type
);
730 stackval_to_data (MonoType
*type_
, stackval
*val
, void *data
, gboolean pinvoke
)
732 MonoType
*type
= mini_native_type_replace_type (type_
);
734 gpointer
*p
= (gpointer
*)data
;
738 /* printf ("TODAT0 %p\n", data); */
739 switch (type
->type
) {
742 guint8
*p
= (guint8
*)data
;
746 case MONO_TYPE_BOOLEAN
: {
747 guint8
*p
= (guint8
*)data
;
748 *p
= (val
->data
.i
!= 0);
753 case MONO_TYPE_CHAR
: {
754 guint16
*p
= (guint16
*)data
;
759 mono_i
*p
= (mono_i
*)data
;
760 /* In theory the value used by stloc should match the local var type
761 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
762 a native int - both by csc and mcs). Not sure what to do about sign extension
763 as it is outside the spec... doing the obvious */
764 *p
= (mono_i
)val
->data
.nati
;
768 mono_u
*p
= (mono_u
*)data
;
770 *p
= (mono_u
)val
->data
.nati
;
775 gint32
*p
= (gint32
*)data
;
781 memmove (data
, &val
->data
.l
, sizeof (gint64
));
785 /* memmove handles unaligned case */
786 memmove (data
, &val
->data
.f_r4
, sizeof (float));
790 memmove (data
, &val
->data
.f
, sizeof (double));
793 case MONO_TYPE_STRING
:
794 case MONO_TYPE_SZARRAY
:
795 case MONO_TYPE_CLASS
:
796 case MONO_TYPE_OBJECT
:
797 case MONO_TYPE_ARRAY
: {
798 gpointer
*p
= (gpointer
*) data
;
799 mono_gc_wbarrier_generic_store_internal (p
, val
->data
.o
);
802 case MONO_TYPE_PTR
: {
803 gpointer
*p
= (gpointer
*) data
;
807 case MONO_TYPE_VALUETYPE
:
808 if (m_class_is_enumtype (type
->data
.klass
)) {
809 stackval_to_data (mono_class_enum_basetype_internal (type
->data
.klass
), val
, data
, pinvoke
);
811 } else if (pinvoke
) {
812 memcpy (data
, val
->data
.vt
, mono_class_native_size (type
->data
.klass
, NULL
));
814 mono_value_copy_internal (data
, val
->data
.vt
, type
->data
.klass
);
817 case MONO_TYPE_GENERICINST
: {
818 MonoClass
*container_class
= type
->data
.generic_class
->container_class
;
820 if (m_class_is_valuetype (container_class
) && !m_class_is_enumtype (container_class
)) {
821 mono_value_copy_internal (data
, val
->data
.vt
, mono_class_from_mono_type_internal (type
));
824 stackval_to_data (m_class_get_byval_arg (type
->data
.generic_class
->container_class
), val
, data
, pinvoke
);
828 g_error ("got type %x", type
->type
);
833 * Same as stackval_to_data but return address of storage instead
834 * of copying the value.
837 stackval_to_data_addr (MonoType
*type_
, stackval
*val
)
839 MonoType
*type
= mini_native_type_replace_type (type_
);
843 switch (type
->type
) {
846 case MONO_TYPE_BOOLEAN
:
855 return &val
->data
.nati
;
860 return &val
->data
.f_r4
;
863 case MONO_TYPE_STRING
:
864 case MONO_TYPE_SZARRAY
:
865 case MONO_TYPE_CLASS
:
866 case MONO_TYPE_OBJECT
:
867 case MONO_TYPE_ARRAY
:
870 case MONO_TYPE_VALUETYPE
:
871 if (m_class_is_enumtype (type
->data
.klass
))
872 return stackval_to_data_addr (mono_class_enum_basetype_internal (type
->data
.klass
), val
);
875 case MONO_TYPE_TYPEDBYREF
:
877 case MONO_TYPE_GENERICINST
: {
878 MonoClass
*container_class
= type
->data
.generic_class
->container_class
;
880 if (m_class_is_valuetype (container_class
) && !m_class_is_enumtype (container_class
))
882 return stackval_to_data_addr (m_class_get_byval_arg (type
->data
.generic_class
->container_class
), val
);
885 g_error ("got type %x", type
->type
);
891 * Throw an exception from the interpreter.
893 static MONO_NEVER_INLINE
void
894 interp_throw (ThreadContext
*context
, MonoException
*ex
, InterpFrame
*frame
, gconstpointer ip
, gboolean rethrow
)
899 interp_push_lmf (&ext
, frame
);
900 frame
->ip
= (const guint16
*)ip
;
903 if (mono_object_isinst_checked ((MonoObject
*) ex
, mono_defaults
.exception_class
, error
)) {
904 MonoException
*mono_ex
= (MonoException
*) ex
;
906 mono_ex
->stack_trace
= NULL
;
907 mono_ex
->trace_ips
= NULL
;
910 mono_error_assert_ok (error
);
913 memset (&ctx
, 0, sizeof (MonoContext
));
914 MONO_CONTEXT_SET_SP (&ctx
, frame
);
917 * Call the JIT EH code. The EH code will call back to us using:
918 * - mono_interp_set_resume_state ()/run_finally ()/run_filter ().
919 * Since ctx.ip is 0, this will start unwinding from the LMF frame
920 * pushed above, which points to our frames.
922 mono_handle_exception (&ctx
, (MonoObject
*)ex
);
923 if (MONO_CONTEXT_GET_IP (&ctx
) != 0) {
924 /* We need to unwind into non-interpreter code */
925 mono_restore_context (&ctx
);
926 g_assert_not_reached ();
929 interp_pop_lmf (&ext
);
931 g_assert (context
->has_resume_state
);
934 #define THROW_EX_GENERAL(exception,ex_ip, rethrow) \
936 interp_throw (context, (exception), (frame), (ex_ip), (rethrow)); \
937 CHECK_RESUME_STATE(context); \
940 #define THROW_EX(exception,ex_ip) THROW_EX_GENERAL ((exception), (ex_ip), FALSE)
942 #define THROW_EX_OVF(ip) THROW_EX (mono_get_exception_overflow (), ip)
944 #define THROW_EX_DIV_ZERO(ip) THROW_EX (mono_get_exception_divide_by_zero (), ip)
946 #define NULL_CHECK(o) do { \
947 if (G_UNLIKELY (!(o))) \
948 THROW_EX (mono_get_exception_null_reference (), ip); \
951 #define EXCEPTION_CHECKPOINT \
953 if (*mono_thread_interruption_request_flag () && !mono_threads_is_critical_method (imethod->method)) { \
954 MonoException *exc = mono_thread_interruption_checkpoint (); \
956 THROW_EX (exc, ip); \
962 ves_array_create (MonoDomain
*domain
, MonoClass
*klass
, int param_count
, stackval
*values
, MonoError
*error
)
965 intptr_t *lower_bounds
;
968 lengths
= g_newa (uintptr_t, m_class_get_rank (klass
) * 2);
969 for (i
= 0; i
< param_count
; ++i
) {
970 lengths
[i
] = values
->data
.i
;
973 if (m_class_get_rank (klass
) == param_count
) {
974 /* Only lengths provided. */
977 /* lower bounds are first. */
978 lower_bounds
= (intptr_t *) lengths
;
979 lengths
+= m_class_get_rank (klass
);
981 return (MonoObject
*) mono_array_new_full_checked (domain
, klass
, lengths
, lower_bounds
, error
);
985 ves_array_calculate_index (MonoArray
*ao
, stackval
*sp
, InterpFrame
*frame
, gboolean safe
)
987 g_assert (!frame
->ex
);
988 MonoClass
*ac
= ((MonoObject
*) ao
)->vtable
->klass
;
992 for (gint32 i
= 0; i
< m_class_get_rank (ac
); i
++) {
993 guint32 idx
= sp
[i
].data
.i
;
994 guint32 lower
= ao
->bounds
[i
].lower_bound
;
995 guint32 len
= ao
->bounds
[i
].length
;
996 if (safe
&& (idx
< lower
|| (idx
- lower
) >= len
)) {
997 frame
->ex
= mono_get_exception_index_out_of_range ();
1000 pos
= (pos
* len
) + idx
- lower
;
1003 pos
= sp
[0].data
.i
;
1004 if (safe
&& pos
>= ao
->max_length
) {
1005 frame
->ex
= mono_get_exception_index_out_of_range ();
1012 static MONO_NEVER_INLINE
void
1013 ves_array_set (InterpFrame
*frame
, stackval
*sp
, MonoMethodSignature
*sig
)
1015 MonoObject
*o
= sp
->data
.o
;
1016 MonoArray
*ao
= (MonoArray
*) o
;
1017 MonoClass
*ac
= o
->vtable
->klass
;
1019 g_assert (m_class_get_rank (ac
) >= 1);
1021 gint32 pos
= ves_array_calculate_index (ao
, sp
+ 1, frame
, TRUE
);
1025 int val_index
= 1 + m_class_get_rank (ac
);
1026 if (sp
[val_index
].data
.p
&& !m_class_is_valuetype (m_class_get_element_class (mono_object_class (o
)))) {
1028 MonoObject
*isinst
= mono_object_isinst_checked (sp
[val_index
].data
.o
, m_class_get_element_class (mono_object_class (o
)), error
);
1029 mono_error_cleanup (error
);
1031 frame
->ex
= mono_get_exception_array_type_mismatch ();
1036 gint32 esize
= mono_array_element_size (ac
);
1037 gpointer ea
= mono_array_addr_with_size_fast (ao
, esize
, pos
);
1039 MonoType
*mt
= sig
->params
[m_class_get_rank (ac
)];
1040 stackval_to_data (mt
, &sp
[val_index
], ea
, FALSE
);
1044 ves_array_get (InterpFrame
*frame
, stackval
*sp
, stackval
*retval
, MonoMethodSignature
*sig
, gboolean safe
)
1046 MonoObject
*o
= sp
->data
.o
;
1047 MonoArray
*ao
= (MonoArray
*) o
;
1048 MonoClass
*ac
= o
->vtable
->klass
;
1050 g_assert (m_class_get_rank (ac
) >= 1);
1052 gint32 pos
= ves_array_calculate_index (ao
, sp
+ 1, frame
, safe
);
1056 gint32 esize
= mono_array_element_size (ac
);
1057 gpointer ea
= mono_array_addr_with_size_fast (ao
, esize
, pos
);
1059 MonoType
*mt
= sig
->ret
;
1060 stackval_from_data (mt
, retval
, ea
, FALSE
);
1064 ves_array_element_address (InterpFrame
*frame
, MonoClass
*required_type
, MonoArray
*ao
, stackval
*sp
, gboolean needs_typecheck
)
1066 MonoClass
*ac
= ((MonoObject
*) ao
)->vtable
->klass
;
1068 g_assert (m_class_get_rank (ac
) >= 1);
1070 gint32 pos
= ves_array_calculate_index (ao
, sp
, frame
, TRUE
);
1074 if (needs_typecheck
&& !mono_class_is_assignable_from_internal (m_class_get_element_class (mono_object_class ((MonoObject
*) ao
)), required_type
)) {
1075 frame
->ex
= mono_get_exception_array_type_mismatch ();
1078 gint32 esize
= mono_array_element_size (ac
);
1079 return mono_array_addr_with_size_fast (ao
, esize
, pos
);
1082 #ifdef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
1083 static MonoFuncV mono_native_to_interp_trampoline
= NULL
;
1086 #ifndef MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP
1087 static InterpMethodArguments
* build_args_from_sig (MonoMethodSignature
*sig
, InterpFrame
*frame
)
1089 InterpMethodArguments
*margs
= g_malloc0 (sizeof (InterpMethodArguments
));
1092 g_assert (mono_arm_eabi_supported ());
1093 int i8_align
= mono_arm_i8_align ();
1103 for (int i
= 0; i
< sig
->param_count
; i
++) {
1104 guint32 ptype
= sig
->params
[i
]->byref
? MONO_TYPE_PTR
: sig
->params
[i
]->type
;
1106 case MONO_TYPE_BOOLEAN
:
1107 case MONO_TYPE_CHAR
:
1117 case MONO_TYPE_SZARRAY
:
1118 case MONO_TYPE_CLASS
:
1119 case MONO_TYPE_OBJECT
:
1120 case MONO_TYPE_STRING
:
1121 case MONO_TYPE_VALUETYPE
:
1122 case MONO_TYPE_GENERICINST
:
1123 #if SIZEOF_VOID_P == 8
1129 #if SIZEOF_VOID_P == 4
1133 /* pairs begin at even registers */
1134 if (i8_align
== 8 && margs
->ilen
& 1)
1141 #if SIZEOF_VOID_P == 8
1146 #if SIZEOF_VOID_P == 4
1152 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype
);
1156 if (margs
->ilen
> 0)
1157 margs
->iargs
= g_malloc0 (sizeof (gpointer
) * margs
->ilen
);
1159 if (margs
->flen
> 0)
1160 margs
->fargs
= g_malloc0 (sizeof (double) * margs
->flen
);
1162 if (margs
->ilen
> INTERP_ICALL_TRAMP_IARGS
)
1163 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs
->ilen
);
1165 if (margs
->flen
> INTERP_ICALL_TRAMP_FARGS
)
1166 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs
->flen
);
1173 margs
->iargs
[0] = frame
->stack_args
->data
.p
;
1177 for (int i
= 0; i
< sig
->param_count
; i
++) {
1178 guint32 ptype
= sig
->params
[i
]->byref
? MONO_TYPE_PTR
: sig
->params
[i
]->type
;
1180 case MONO_TYPE_BOOLEAN
:
1181 case MONO_TYPE_CHAR
:
1191 case MONO_TYPE_SZARRAY
:
1192 case MONO_TYPE_CLASS
:
1193 case MONO_TYPE_OBJECT
:
1194 case MONO_TYPE_STRING
:
1195 case MONO_TYPE_VALUETYPE
:
1196 case MONO_TYPE_GENERICINST
:
1197 #if SIZEOF_VOID_P == 8
1201 margs
->iargs
[int_i
] = frame
->stack_args
[i
].data
.p
;
1203 g_print ("build_args_from_sig: margs->iargs [%d]: %p (frame @ %d)\n", int_i
, margs
->iargs
[int_i
], i
);
1207 #if SIZEOF_VOID_P == 4
1209 case MONO_TYPE_U8
: {
1210 stackval
*sarg
= &frame
->stack_args
[i
];
1212 /* pairs begin at even registers */
1213 if (i8_align
== 8 && int_i
& 1)
1216 margs
->iargs
[int_i
] = (gpointer
) sarg
->data
.pair
.lo
;
1218 margs
->iargs
[int_i
] = (gpointer
) sarg
->data
.pair
.hi
;
1220 g_print ("build_args_from_sig: margs->iargs [%d/%d]: 0x%016llx, hi=0x%08x lo=0x%08x (frame @ %d)\n", int_i
- 1, int_i
, *((guint64
*) &margs
->iargs
[int_i
- 1]), sarg
->data
.pair
.hi
, sarg
->data
.pair
.lo
, i
);
1228 if (ptype
== MONO_TYPE_R4
)
1229 * (float *) &(margs
->fargs
[int_f
]) = frame
->stack_args
[i
].data
.f_r4
;
1231 margs
->fargs
[int_f
] = frame
->stack_args
[i
].data
.f
;
1233 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
);
1235 #if SIZEOF_VOID_P == 4
1242 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype
);
1246 switch (sig
->ret
->type
) {
1247 case MONO_TYPE_BOOLEAN
:
1248 case MONO_TYPE_CHAR
:
1258 case MONO_TYPE_SZARRAY
:
1259 case MONO_TYPE_CLASS
:
1260 case MONO_TYPE_OBJECT
:
1261 case MONO_TYPE_STRING
:
1264 case MONO_TYPE_VALUETYPE
:
1265 case MONO_TYPE_GENERICINST
:
1266 margs
->retval
= &(frame
->retval
->data
.p
);
1267 margs
->is_float_ret
= 0;
1271 margs
->retval
= &(frame
->retval
->data
.p
);
1272 margs
->is_float_ret
= 1;
1274 case MONO_TYPE_VOID
:
1275 margs
->retval
= NULL
;
1278 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig
->ret
->type
);
1286 interp_frame_arg_to_data (MonoInterpFrameHandle frame
, MonoMethodSignature
*sig
, int index
, gpointer data
)
1288 InterpFrame
*iframe
= (InterpFrame
*)frame
;
1291 stackval_to_data (sig
->ret
, iframe
->retval
, data
, sig
->pinvoke
);
1293 stackval_to_data (sig
->params
[index
], &iframe
->stack_args
[index
], data
, sig
->pinvoke
);
1297 interp_data_to_frame_arg (MonoInterpFrameHandle frame
, MonoMethodSignature
*sig
, int index
, gpointer data
)
1299 InterpFrame
*iframe
= (InterpFrame
*)frame
;
1302 stackval_from_data (sig
->ret
, iframe
->retval
, data
, sig
->pinvoke
);
1303 else if (sig
->hasthis
&& index
== 0)
1304 iframe
->stack_args
[index
].data
.p
= *(gpointer
*)data
;
1306 stackval_from_data (sig
->params
[index
- sig
->hasthis
], &iframe
->stack_args
[index
], data
, sig
->pinvoke
);
1310 interp_frame_arg_to_storage (MonoInterpFrameHandle frame
, MonoMethodSignature
*sig
, int index
)
1312 InterpFrame
*iframe
= (InterpFrame
*)frame
;
1315 return stackval_to_data_addr (sig
->ret
, iframe
->retval
);
1317 return stackval_to_data_addr (sig
->params
[index
], &iframe
->stack_args
[index
]);
1321 interp_frame_arg_set_storage (MonoInterpFrameHandle frame
, MonoMethodSignature
*sig
, int index
, gpointer storage
)
1323 InterpFrame
*iframe
= (InterpFrame
*)frame
;
1324 stackval
*val
= (index
== -1) ? iframe
->retval
: &iframe
->stack_args
[index
];
1325 MonoType
*type
= (index
== -1) ? sig
->ret
: sig
->params
[index
];
1327 switch (type
->type
) {
1328 case MONO_TYPE_GENERICINST
:
1329 if (!MONO_TYPE_IS_REFERENCE (type
))
1330 val
->data
.vt
= storage
;
1332 case MONO_TYPE_VALUETYPE
:
1333 val
->data
.vt
= storage
;
1336 g_assert_not_reached ();
1341 get_interp_to_native_trampoline (void)
1343 static MonoPIFunc trampoline
= NULL
;
1346 if (mono_ee_features
.use_aot_trampolines
) {
1347 trampoline
= (MonoPIFunc
) mono_aot_get_trampoline ("interp_to_native_trampoline");
1349 MonoTrampInfo
*info
;
1350 trampoline
= (MonoPIFunc
) mono_arch_get_interp_to_native_trampoline (&info
);
1351 mono_tramp_info_register (info
, NULL
);
1353 mono_memory_barrier ();
1359 interp_to_native_trampoline (gpointer addr
, gpointer ccontext
)
1361 get_interp_to_native_trampoline () (addr
, ccontext
);
1364 /* MONO_NO_OPTIMIATION is needed due to usage of INTERP_PUSH_LMF_WITH_CTX. */
1366 #pragma optimize ("", off)
1368 static MONO_NO_OPTIMIZATION MONO_NEVER_INLINE
void
1369 ves_pinvoke_method (InterpFrame
*frame
, MonoMethodSignature
*sig
, MonoFuncV addr
, gboolean string_ctor
, ThreadContext
*context
, gboolean save_last_error
)
1376 g_assert (!frame
->imethod
);
1378 static MonoPIFunc entry_func
= NULL
;
1380 #ifdef MONO_ARCH_HAS_NO_PROPER_MONOCTX
1382 entry_func
= (MonoPIFunc
) mono_jit_compile_method_jit_only (mini_get_interp_lmf_wrapper ("mono_interp_to_native_trampoline", (gpointer
) mono_interp_to_native_trampoline
), error
);
1383 mono_error_assert_ok (error
);
1385 entry_func
= get_interp_to_native_trampoline ();
1387 mono_memory_barrier ();
1390 #ifdef ENABLE_NETCORE
1391 if (save_last_error
) {
1392 mono_marshal_clear_last_error ();
1396 #ifdef MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP
1397 CallContext ccontext
;
1398 mono_arch_set_native_call_context_args (&ccontext
, frame
, sig
);
1401 InterpMethodArguments
*margs
= build_args_from_sig (sig
, frame
);
1405 INTERP_PUSH_LMF_WITH_CTX (frame
, ext
, exit_pinvoke
);
1406 entry_func ((gpointer
) addr
, args
);
1407 if (save_last_error
)
1408 mono_marshal_set_last_error ();
1409 interp_pop_lmf (&ext
);
1411 #ifdef MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP
1413 mono_arch_get_native_call_context_ret (&ccontext
, frame
, sig
);
1415 if (ccontext
.stack
!= NULL
)
1416 g_free (ccontext
.stack
);
1418 if (!frame
->ex
&& !MONO_TYPE_ISSTRUCT (sig
->ret
))
1419 stackval_from_data (sig
->ret
, frame
->retval
, (char*)&frame
->retval
->data
.p
, sig
->pinvoke
);
1421 g_free (margs
->iargs
);
1422 g_free (margs
->fargs
);
1425 goto exit_pinvoke
; // prevent unused label warning in some configurations
1430 #pragma optimize ("", on)
1434 * interp_init_delegate:
1436 * Initialize del->interp_method.
1439 interp_init_delegate (MonoDelegate
*del
, MonoError
*error
)
1443 if (del
->interp_method
) {
1444 /* Delegate created by a call to ves_icall_mono_delegate_ctor_interp () */
1445 del
->method
= ((InterpMethod
*)del
->interp_method
)->method
;
1446 } else if (del
->method
) {
1447 /* Delegate created dynamically */
1448 del
->interp_method
= mono_interp_get_imethod (del
->object
.vtable
->domain
, del
->method
, error
);
1450 /* Created from JITted code */
1451 g_assert_not_reached ();
1454 method
= ((InterpMethod
*)del
->interp_method
)->method
;
1457 method
->flags
& METHOD_ATTRIBUTE_VIRTUAL
&&
1458 method
->flags
& METHOD_ATTRIBUTE_ABSTRACT
&&
1459 mono_class_is_abstract (method
->klass
))
1460 del
->interp_method
= get_virtual_method ((InterpMethod
*)del
->interp_method
, del
->target
->vtable
);
1462 method
= ((InterpMethod
*)del
->interp_method
)->method
;
1463 if (method
&& m_class_get_parent (method
->klass
) == mono_defaults
.multicastdelegate_class
) {
1464 const char *name
= method
->name
;
1465 if (*name
== 'I' && (strcmp (name
, "Invoke") == 0)) {
1467 * When invoking the delegate interp_method is executed directly. If it's an
1468 * invoke make sure we replace it with the appropriate delegate invoke wrapper.
1470 * FIXME We should do this later, when we also know the delegate on which the
1471 * target method is called.
1473 del
->interp_method
= mono_interp_get_imethod (del
->object
.vtable
->domain
, mono_marshal_get_delegate_invoke (method
, NULL
), error
);
1474 mono_error_assert_ok (error
);
1478 if (!((InterpMethod
*) del
->interp_method
)->transformed
&& method_is_dynamic (method
)) {
1479 /* Return any errors from method compilation */
1480 mono_interp_transform_method ((InterpMethod
*) del
->interp_method
, get_context (), error
);
1481 return_if_nok (error
);
1486 interp_delegate_ctor (MonoObjectHandle this_obj
, MonoObjectHandle target
, gpointer addr
, MonoError
*error
)
1489 * addr is the result of an LDFTN opcode, i.e. an InterpMethod
1491 InterpMethod
*imethod
= (InterpMethod
*)addr
;
1493 if (!(imethod
->method
->flags
& METHOD_ATTRIBUTE_STATIC
)) {
1494 MonoMethod
*invoke
= mono_get_delegate_invoke_internal (mono_handle_class (this_obj
));
1495 /* virtual invoke delegates must not have null check */
1496 if (mono_method_signature_internal (imethod
->method
)->param_count
== mono_method_signature_internal (invoke
)->param_count
1497 && MONO_HANDLE_IS_NULL (target
)) {
1498 mono_error_set_argument (error
, "this", "Delegate to an instance method cannot have null 'this'");
1503 g_assert (imethod
->method
);
1504 gpointer entry
= mini_get_interp_callbacks ()->create_method_pointer (imethod
->method
, FALSE
, error
);
1505 return_if_nok (error
);
1507 MONO_HANDLE_SETVAL (MONO_HANDLE_CAST (MonoDelegate
, this_obj
), interp_method
, gpointer
, imethod
);
1509 mono_delegate_ctor (this_obj
, target
, entry
, error
);
1514 * runtime specifies that the implementation of the method is automatically
1515 * provided by the runtime and is primarily used for the methods of delegates.
1517 static MONO_NEVER_INLINE
void
1518 ves_imethod (InterpFrame
*frame
, MonoMethod
*method
, MonoMethodSignature
*sig
, stackval
*sp
, stackval
*retval
)
1520 const char *name
= method
->name
;
1521 mono_class_init_internal (method
->klass
);
1523 if (method
->klass
== mono_defaults
.array_class
) {
1524 if (!strcmp (name
, "UnsafeMov")) {
1525 /* TODO: layout checks */
1526 stackval_from_data (sig
->ret
, retval
, (char*) sp
, FALSE
);
1529 if (!strcmp (name
, "UnsafeLoad")) {
1530 ves_array_get (frame
, sp
, retval
, sig
, FALSE
);
1533 } else if (mini_class_is_system_array (method
->klass
)) {
1534 MonoObject
*obj
= (MonoObject
*) sp
->data
.p
;
1536 frame
->ex
= mono_get_exception_null_reference ();
1539 if (*name
== 'S' && (strcmp (name
, "Set") == 0)) {
1540 ves_array_set (frame
, sp
, sig
);
1543 if (*name
== 'G' && (strcmp (name
, "Get") == 0)) {
1544 ves_array_get (frame
, sp
, retval
, sig
, TRUE
);
1549 g_error ("Don't know how to exec runtime method %s.%s::%s",
1550 m_class_get_name_space (method
->klass
), m_class_get_name (method
->klass
),
1556 dump_stack (stackval
*stack
, stackval
*sp
)
1558 stackval
*s
= stack
;
1559 GString
*str
= g_string_new ("");
1562 return g_string_free (str
, FALSE
);
1565 g_string_append_printf (str
, "[%p (%lld)] ", s
->data
.l
, s
->data
.l
);
1568 return g_string_free (str
, FALSE
);
1572 dump_stackval (GString
*str
, stackval
*s
, MonoType
*type
)
1574 switch (type
->type
) {
1581 case MONO_TYPE_CHAR
:
1582 case MONO_TYPE_BOOLEAN
:
1583 g_string_append_printf (str
, "[%d] ", s
->data
.i
);
1585 case MONO_TYPE_STRING
:
1586 case MONO_TYPE_SZARRAY
:
1587 case MONO_TYPE_CLASS
:
1588 case MONO_TYPE_OBJECT
:
1589 case MONO_TYPE_ARRAY
:
1593 g_string_append_printf (str
, "[%p] ", s
->data
.p
);
1595 case MONO_TYPE_VALUETYPE
:
1596 if (m_class_is_enumtype (type
->data
.klass
))
1597 g_string_append_printf (str
, "[%d] ", s
->data
.i
);
1599 g_string_append_printf (str
, "[vt:%p] ", s
->data
.p
);
1602 g_string_append_printf (str
, "[%g] ", s
->data
.f_r4
);
1605 g_string_append_printf (str
, "[%g] ", s
->data
.f
);
1610 GString
*res
= g_string_new ("");
1611 mono_type_get_desc (res
, type
, TRUE
);
1612 g_string_append_printf (str
, "[{%s} %lld/0x%0llx] ", res
->str
, s
->data
.l
, s
->data
.l
);
1613 g_string_free (res
, TRUE
);
1620 dump_retval (InterpFrame
*inv
)
1622 GString
*str
= g_string_new ("");
1623 MonoType
*ret
= mono_method_signature_internal (inv
->imethod
->method
)->ret
;
1625 if (ret
->type
!= MONO_TYPE_VOID
)
1626 dump_stackval (str
, inv
->retval
, ret
);
1628 return g_string_free (str
, FALSE
);
1632 dump_args (InterpFrame
*inv
)
1634 GString
*str
= g_string_new ("");
1636 MonoMethodSignature
*signature
= mono_method_signature_internal (inv
->imethod
->method
);
1638 if (signature
->param_count
== 0 && !signature
->hasthis
)
1639 return g_string_free (str
, FALSE
);
1641 if (signature
->hasthis
) {
1642 MonoMethod
*method
= inv
->imethod
->method
;
1643 dump_stackval (str
, inv
->stack_args
, m_class_get_byval_arg (method
->klass
));
1646 for (i
= 0; i
< signature
->param_count
; ++i
)
1647 dump_stackval (str
, inv
->stack_args
+ (!!signature
->hasthis
) + i
, signature
->params
[i
]);
1649 return g_string_free (str
, FALSE
);
1653 #define CHECK_ADD_OVERFLOW(a,b) \
1654 (gint32)(b) >= 0 ? (gint32)(G_MAXINT32) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1655 : (gint32)(G_MININT32) - (gint32)(b) > (gint32)(a) ? +1 : 0
1657 #define CHECK_SUB_OVERFLOW(a,b) \
1658 (gint32)(b) < 0 ? (gint32)(G_MAXINT32) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1659 : (gint32)(G_MININT32) + (gint32)(b) > (gint32)(a) ? +1 : 0
1661 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1662 (guint32)(G_MAXUINT32) - (guint32)(b) < (guint32)(a) ? -1 : 0
1664 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1665 (guint32)(a) < (guint32)(b) ? -1 : 0
1667 #define CHECK_ADD_OVERFLOW64(a,b) \
1668 (gint64)(b) >= 0 ? (gint64)(G_MAXINT64) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1669 : (gint64)(G_MININT64) - (gint64)(b) > (gint64)(a) ? +1 : 0
1671 #define CHECK_SUB_OVERFLOW64(a,b) \
1672 (gint64)(b) < 0 ? (gint64)(G_MAXINT64) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1673 : (gint64)(G_MININT64) + (gint64)(b) > (gint64)(a) ? +1 : 0
1675 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1676 (guint64)(G_MAXUINT64) - (guint64)(b) < (guint64)(a) ? -1 : 0
1678 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1679 (guint64)(a) < (guint64)(b) ? -1 : 0
1681 #if SIZEOF_VOID_P == 4
1682 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1683 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1685 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1686 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1689 /* Resolves to TRUE if the operands would overflow */
1690 #define CHECK_MUL_OVERFLOW(a,b) \
1691 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1692 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1693 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == G_MININT32) : \
1694 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((G_MAXINT32) / (gint32)(b)) : \
1695 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((G_MININT32) / (gint32)(b)) : \
1696 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((G_MININT32) / (gint32)(b)) : \
1697 (gint32)(a) < ((G_MAXINT32) / (gint32)(b))
1699 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1700 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1701 (guint32)(b) > ((G_MAXUINT32) / (guint32)(a))
1703 #define CHECK_MUL_OVERFLOW64(a,b) \
1704 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1705 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1706 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == G_MININT64) : \
1707 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((G_MAXINT64) / (gint64)(b)) : \
1708 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((G_MININT64) / (gint64)(b)) : \
1709 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((G_MININT64) / (gint64)(b)) : \
1710 (gint64)(a) < ((G_MAXINT64) / (gint64)(b))
1712 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1713 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1714 (guint64)(b) > ((G_MAXUINT64) / (guint64)(a))
1716 #if SIZEOF_VOID_P == 4
1717 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1718 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1720 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1721 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1725 interp_runtime_invoke (MonoMethod
*method
, void *obj
, void **params
, MonoObject
**exc
, MonoError
*error
)
1728 ThreadContext
*context
= get_context ();
1729 MonoMethodSignature
*sig
= mono_method_signature_internal (method
);
1730 MonoClass
*klass
= mono_class_from_mono_type_internal (sig
->ret
);
1732 MonoMethod
*target_method
= method
;
1740 MonoDomain
*domain
= mono_domain_get ();
1742 if (method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
)
1743 target_method
= mono_marshal_get_native_wrapper (target_method
, FALSE
, FALSE
);
1744 MonoMethod
*invoke_wrapper
= mono_marshal_get_runtime_invoke_full (target_method
, FALSE
, TRUE
);
1746 //* <code>MonoObject *runtime_invoke (MonoObject *this_obj, void **params, MonoObject **exc, void* method)</code>
1748 result
.data
.vt
= alloca (mono_class_instance_size (klass
));
1752 args
[0].data
.p
= obj
;
1754 args
[0].data
.p
= NULL
;
1755 args
[1].data
.p
= params
;
1756 args
[2].data
.p
= exc
;
1757 args
[3].data
.p
= target_method
;
1759 InterpMethod
*imethod
= mono_interp_get_imethod (domain
, invoke_wrapper
, error
);
1760 mono_error_assert_ok (error
);
1761 init_frame (&frame
, NULL
, imethod
, args
, &result
);
1763 interp_exec_method (&frame
, context
, error
);
1767 *exc
= (MonoObject
*) frame
.ex
;
1770 mono_error_set_exception_instance (error
, frame
.ex
);
1773 return (MonoObject
*)result
.data
.p
;
1777 InterpMethod
*rmethod
;
1781 gpointer
*many_args
;
1784 /* Main function for entering the interpreter from compiled code */
1786 interp_entry (InterpEntryData
*data
)
1789 InterpMethod
*rmethod
;
1790 ThreadContext
*context
;
1794 MonoMethodSignature
*sig
;
1796 gpointer orig_domain
= NULL
, attach_cookie
;
1799 if ((gsize
)data
->rmethod
& 1) {
1801 data
->this_arg
= mono_object_unbox_internal ((MonoObject
*)data
->this_arg
);
1802 data
->rmethod
= (InterpMethod
*)(gpointer
)((gsize
)data
->rmethod
& ~1);
1804 rmethod
= data
->rmethod
;
1806 if (rmethod
->needs_thread_attach
)
1807 orig_domain
= mono_threads_attach_coop (mono_domain_get (), &attach_cookie
);
1809 context
= get_context ();
1811 method
= rmethod
->method
;
1812 sig
= mono_method_signature_internal (method
);
1814 // FIXME: Optimize this
1816 //printf ("%s\n", mono_method_full_name (method, 1));
1820 args
= g_newa (stackval
, sig
->param_count
+ (sig
->hasthis
? 1 : 0));
1822 args
[0].data
.p
= data
->this_arg
;
1825 if (data
->many_args
)
1826 params
= data
->many_args
;
1828 params
= data
->args
;
1829 for (i
= 0; i
< sig
->param_count
; ++i
) {
1830 int a_index
= i
+ (sig
->hasthis
? 1 : 0);
1831 if (sig
->params
[i
]->byref
) {
1832 args
[a_index
].data
.p
= params
[i
];
1835 type
= rmethod
->param_types
[i
];
1836 switch (type
->type
) {
1837 case MONO_TYPE_VALUETYPE
:
1838 args
[a_index
].data
.p
= params
[i
];
1840 case MONO_TYPE_GENERICINST
:
1841 if (MONO_TYPE_IS_REFERENCE (type
))
1842 args
[a_index
].data
.p
= *(gpointer
*)params
[i
];
1844 args
[a_index
].data
.vt
= params
[i
];
1847 stackval_from_data (type
, &args
[a_index
], params
[i
], FALSE
);
1852 memset (&result
, 0, sizeof (result
));
1853 init_frame (&frame
, NULL
, data
->rmethod
, args
, &result
);
1855 type
= rmethod
->rtype
;
1856 switch (type
->type
) {
1857 case MONO_TYPE_GENERICINST
:
1858 if (!MONO_TYPE_IS_REFERENCE (type
))
1859 frame
.retval
->data
.vt
= data
->res
;
1861 case MONO_TYPE_VALUETYPE
:
1862 frame
.retval
->data
.vt
= data
->res
;
1869 interp_exec_method (&frame
, context
, error
);
1871 if (rmethod
->needs_thread_attach
)
1872 mono_threads_detach_coop (orig_domain
, &attach_cookie
);
1874 if (mono_llvm_only
) {
1876 mono_llvm_reraise_exception (frame
.ex
);
1878 g_assert (frame
.ex
== NULL
);
1881 type
= rmethod
->rtype
;
1882 switch (type
->type
) {
1883 case MONO_TYPE_VOID
:
1885 case MONO_TYPE_OBJECT
:
1886 /* No need for a write barrier */
1887 *(MonoObject
**)data
->res
= (MonoObject
*)frame
.retval
->data
.p
;
1889 case MONO_TYPE_GENERICINST
:
1890 if (MONO_TYPE_IS_REFERENCE (type
)) {
1891 *(MonoObject
**)data
->res
= (MonoObject
*)frame
.retval
->data
.p
;
1893 /* Already set before the call */
1896 case MONO_TYPE_VALUETYPE
:
1897 /* Already set before the call */
1900 stackval_to_data (type
, frame
.retval
, data
->res
, FALSE
);
1906 do_icall (InterpFrame
*frame
, MonoMethodSignature
*sig
, int op
, stackval
*sp
, gpointer ptr
, gboolean save_last_error
)
1908 #ifdef ENABLE_NETCORE
1909 if (save_last_error
)
1910 mono_marshal_clear_last_error ();
1914 case MINT_ICALL_V_V
: {
1915 typedef void (*T
)(void);
1920 case MINT_ICALL_V_P
: {
1921 typedef gpointer (*T
)(void);
1924 sp
[-1].data
.p
= func ();
1927 case MINT_ICALL_P_V
: {
1928 typedef void (*T
)(gpointer
);
1930 func (sp
[-1].data
.p
);
1934 case MINT_ICALL_P_P
: {
1935 typedef gpointer (*T
)(gpointer
);
1937 sp
[-1].data
.p
= func (sp
[-1].data
.p
);
1940 case MINT_ICALL_PP_V
: {
1941 typedef void (*T
)(gpointer
,gpointer
);
1944 func (sp
[0].data
.p
, sp
[1].data
.p
);
1947 case MINT_ICALL_PP_P
: {
1948 typedef gpointer (*T
)(gpointer
,gpointer
);
1951 sp
[-1].data
.p
= func (sp
[-1].data
.p
, sp
[0].data
.p
);
1954 case MINT_ICALL_PPP_V
: {
1955 typedef void (*T
)(gpointer
,gpointer
,gpointer
);
1958 func (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
);
1961 case MINT_ICALL_PPP_P
: {
1962 typedef gpointer (*T
)(gpointer
,gpointer
,gpointer
);
1965 sp
[-1].data
.p
= func (sp
[-1].data
.p
, sp
[0].data
.p
, sp
[1].data
.p
);
1968 case MINT_ICALL_PPPP_V
: {
1969 typedef void (*T
)(gpointer
,gpointer
,gpointer
,gpointer
);
1972 func (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
, sp
[3].data
.p
);
1975 case MINT_ICALL_PPPP_P
: {
1976 typedef gpointer (*T
)(gpointer
,gpointer
,gpointer
,gpointer
);
1979 sp
[-1].data
.p
= func (sp
[-1].data
.p
, sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
);
1982 case MINT_ICALL_PPPPP_V
: {
1983 typedef void (*T
)(gpointer
,gpointer
,gpointer
,gpointer
,gpointer
);
1986 func (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
, sp
[3].data
.p
, sp
[4].data
.p
);
1989 case MINT_ICALL_PPPPP_P
: {
1990 typedef gpointer (*T
)(gpointer
,gpointer
,gpointer
,gpointer
,gpointer
);
1993 sp
[-1].data
.p
= func (sp
[-1].data
.p
, sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
, sp
[3].data
.p
);
1996 case MINT_ICALL_PPPPPP_V
: {
1997 typedef void (*T
)(gpointer
,gpointer
,gpointer
,gpointer
,gpointer
,gpointer
);
2000 func (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
, sp
[3].data
.p
, sp
[4].data
.p
, sp
[5].data
.p
);
2003 case MINT_ICALL_PPPPPP_P
: {
2004 typedef gpointer (*T
)(gpointer
,gpointer
,gpointer
,gpointer
,gpointer
,gpointer
);
2007 sp
[-1].data
.p
= func (sp
[-1].data
.p
, sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.p
, sp
[3].data
.p
, sp
[4].data
.p
);
2011 g_assert_not_reached ();
2014 if (save_last_error
)
2015 mono_marshal_set_last_error ();
2017 /* convert the native representation to the stackval representation */
2019 stackval_from_data (sig
->ret
, &sp
[-1], (char*) &sp
[-1].data
.p
, sig
->pinvoke
);
2024 /* MONO_NO_OPTIMIATION is needed due to usage of INTERP_PUSH_LMF_WITH_CTX. */
2026 #pragma optimize ("", off)
2028 static MONO_NO_OPTIMIZATION MONO_NEVER_INLINE stackval
*
2029 do_icall_wrapper (InterpFrame
*frame
, MonoMethodSignature
*sig
, int op
, stackval
*sp
, gpointer ptr
, gboolean save_last_error
)
2032 INTERP_PUSH_LMF_WITH_CTX (frame
, ext
, exit_icall
);
2034 sp
= do_icall (frame
, sig
, op
, sp
, ptr
, save_last_error
);
2036 interp_pop_lmf (&ext
);
2038 goto exit_icall
; // prevent unused label warning in some configurations
2043 #pragma optimize ("", on)
2048 gpointer jit_wrapper
;
2050 MonoFtnDesc
*ftndesc
;
2054 jit_call_cb (gpointer arg
)
2056 JitCallCbData
*cb_data
= (JitCallCbData
*)arg
;
2057 gpointer jit_wrapper
= cb_data
->jit_wrapper
;
2058 int pindex
= cb_data
->pindex
;
2059 gpointer
*args
= cb_data
->args
;
2060 MonoFtnDesc ftndesc
= *cb_data
->ftndesc
;
2064 typedef void (*T
)(gpointer
);
2065 T func
= (T
)jit_wrapper
;
2071 typedef void (*T
)(gpointer
, gpointer
);
2072 T func
= (T
)jit_wrapper
;
2074 func (args
[0], &ftndesc
);
2078 typedef void (*T
)(gpointer
, gpointer
, gpointer
);
2079 T func
= (T
)jit_wrapper
;
2081 func (args
[0], args
[1], &ftndesc
);
2085 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
);
2086 T func
= (T
)jit_wrapper
;
2088 func (args
[0], args
[1], args
[2], &ftndesc
);
2092 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
, gpointer
);
2093 T func
= (T
)jit_wrapper
;
2095 func (args
[0], args
[1], args
[2], args
[3], &ftndesc
);
2099 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
);
2100 T func
= (T
)jit_wrapper
;
2102 func (args
[0], args
[1], args
[2], args
[3], args
[4], &ftndesc
);
2106 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
);
2107 T func
= (T
)jit_wrapper
;
2109 func (args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], &ftndesc
);
2113 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
);
2114 T func
= (T
)jit_wrapper
;
2116 func (args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6], &ftndesc
);
2120 typedef void (*T
)(gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
, gpointer
);
2121 T func
= (T
)jit_wrapper
;
2123 func (args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6], args
[7], &ftndesc
);
2127 g_assert_not_reached ();
2132 static MONO_NEVER_INLINE stackval
*
2133 do_jit_call (stackval
*sp
, unsigned char *vt_sp
, ThreadContext
*context
, InterpFrame
*frame
, InterpMethod
*rmethod
, MonoError
*error
)
2135 MonoMethodSignature
*sig
;
2136 MonoFtnDesc ftndesc
;
2137 guint8 res_buf
[256];
2141 //printf ("jit_call: %s\n", mono_method_full_name (rmethod->method, 1));
2144 * Call JITted code through a gsharedvt_out wrapper. These wrappers receive every argument
2145 * by ref and return a return value using an explicit return value argument.
2147 if (!rmethod
->jit_wrapper
) {
2148 MonoMethod
*method
= rmethod
->method
;
2150 sig
= mono_method_signature_internal (method
);
2153 MonoMethod
*wrapper
= mini_get_gsharedvt_out_sig_wrapper (sig
);
2154 //printf ("J: %s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
2156 gpointer jit_wrapper
= mono_jit_compile_method_jit_only (wrapper
, error
);
2157 mono_error_assert_ok (error
);
2159 gpointer addr
= mono_jit_compile_method_jit_only (method
, error
);
2160 return_val_if_nok (error
, NULL
);
2163 rmethod
->jit_addr
= addr
;
2164 rmethod
->jit_sig
= sig
;
2165 mono_memory_barrier ();
2166 rmethod
->jit_wrapper
= jit_wrapper
;
2169 sig
= rmethod
->jit_sig
;
2172 sp
-= sig
->param_count
;
2176 ftndesc
.addr
= rmethod
->jit_addr
;
2179 // FIXME: Optimize this
2183 int stack_index
= 0;
2184 if (rmethod
->hasthis
) {
2185 args
[pindex
++] = sp
[0].data
.p
;
2188 type
= rmethod
->rtype
;
2189 if (type
->type
!= MONO_TYPE_VOID
) {
2190 if (MONO_TYPE_ISSTRUCT (type
))
2191 args
[pindex
++] = vt_sp
;
2193 args
[pindex
++] = res_buf
;
2195 for (int i
= 0; i
< rmethod
->param_count
; ++i
) {
2196 MonoType
*t
= rmethod
->param_types
[i
];
2197 stackval
*sval
= &sp
[stack_index
+ i
];
2198 if (sig
->params
[i
]->byref
) {
2199 args
[pindex
++] = sval
->data
.p
;
2200 } else if (MONO_TYPE_ISSTRUCT (t
)) {
2201 args
[pindex
++] = sval
->data
.p
;
2202 } else if (MONO_TYPE_IS_REFERENCE (t
)) {
2203 args
[pindex
++] = &sval
->data
.p
;
2212 case MONO_TYPE_VALUETYPE
:
2213 args
[pindex
++] = &sval
->data
.i
;
2216 case MONO_TYPE_FNPTR
:
2219 case MONO_TYPE_OBJECT
:
2220 args
[pindex
++] = &sval
->data
.p
;
2224 args
[pindex
++] = &sval
->data
.l
;
2227 args
[pindex
++] = &sval
->data
.f_r4
;
2230 args
[pindex
++] = &sval
->data
.f
;
2233 printf ("%s\n", mono_type_full_name (t
));
2234 g_assert_not_reached ();
2239 interp_push_lmf (&ext
, frame
);
2241 JitCallCbData cb_data
;
2242 memset (&cb_data
, 0, sizeof (cb_data
));
2243 cb_data
.jit_wrapper
= rmethod
->jit_wrapper
;
2244 cb_data
.pindex
= pindex
;
2245 cb_data
.args
= args
;
2246 cb_data
.ftndesc
= &ftndesc
;
2248 if (mono_aot_mode
== MONO_AOT_MODE_LLVMONLY_INTERP
) {
2249 /* Catch the exception thrown by the native code using a try-catch */
2250 gboolean thrown
= FALSE
;
2251 mono_llvm_cpp_catch_exception (jit_call_cb
, &cb_data
, &thrown
);
2252 interp_pop_lmf (&ext
);
2254 MonoObject
*obj
= mono_llvm_load_exception ();
2256 mono_error_set_exception_instance (error
, (MonoException
*)obj
);
2260 jit_call_cb (&cb_data
);
2261 interp_pop_lmf (&ext
);
2264 MonoType
*rtype
= rmethod
->rtype
;
2265 switch (rtype
->type
) {
2266 case MONO_TYPE_VOID
:
2267 case MONO_TYPE_OBJECT
:
2268 case MONO_TYPE_STRING
:
2269 case MONO_TYPE_CLASS
:
2270 case MONO_TYPE_ARRAY
:
2271 case MONO_TYPE_SZARRAY
:
2275 sp
->data
.p
= *(gpointer
*)res_buf
;
2278 sp
->data
.i
= *(gint8
*)res_buf
;
2281 sp
->data
.i
= *(guint8
*)res_buf
;
2284 sp
->data
.i
= *(gint16
*)res_buf
;
2287 sp
->data
.i
= *(guint16
*)res_buf
;
2290 sp
->data
.i
= *(gint32
*)res_buf
;
2293 sp
->data
.i
= *(guint32
*)res_buf
;
2296 sp
->data
.l
= *(gint64
*)res_buf
;
2299 sp
->data
.l
= *(guint64
*)res_buf
;
2302 sp
->data
.f_r4
= *(float*)res_buf
;
2305 sp
->data
.f
= *(double*)res_buf
;
2307 case MONO_TYPE_TYPEDBYREF
:
2308 case MONO_TYPE_VALUETYPE
:
2309 /* The result was written to vt_sp */
2312 case MONO_TYPE_GENERICINST
:
2313 if (MONO_TYPE_IS_REFERENCE (rtype
)) {
2314 sp
->data
.p
= *(gpointer
*)res_buf
;
2316 /* The result was written to vt_sp */
2321 g_print ("%s\n", mono_type_full_name (rtype
));
2322 g_assert_not_reached ();
2329 static MONO_NEVER_INLINE
void
2330 do_debugger_tramp (void (*tramp
) (void), InterpFrame
*frame
)
2333 interp_push_lmf (&ext
, frame
);
2335 interp_pop_lmf (&ext
);
2338 static MONO_NEVER_INLINE
void
2339 do_transform_method (InterpFrame
*frame
, ThreadContext
*context
)
2342 /* Don't push lmf if we have no interp data */
2343 gboolean push_lmf
= frame
->parent
!= NULL
;
2346 /* Use the parent frame as the current frame is not complete yet */
2348 interp_push_lmf (&ext
, frame
->parent
);
2350 mono_interp_transform_method (frame
->imethod
, context
, error
);
2351 frame
->ex
= mono_error_convert_to_exception (error
);
2354 interp_pop_lmf (&ext
);
2357 static MONO_NEVER_INLINE
void
2358 copy_varargs_vtstack (MonoMethodSignature
*csig
, stackval
*sp
, unsigned char **vt_sp
)
2360 char *vt
= *(char**)vt_sp
;
2361 stackval
*first_arg
= sp
- csig
->param_count
;
2364 * We need to have the varargs linearly on the stack so the ArgIterator
2365 * can iterate over them. We pass the signature first and then copy them
2366 * one by one on the vtstack.
2368 *(gpointer
*)vt
= csig
;
2369 vt
+= sizeof (gpointer
);
2371 for (int i
= csig
->sentinelpos
; i
< csig
->param_count
; i
++) {
2372 int align
, arg_size
;
2373 arg_size
= mono_type_stack_size (csig
->params
[i
], &align
);
2374 vt
= (char*)ALIGN_PTR_TO (vt
, align
);
2376 stackval_to_data (csig
->params
[i
], &first_arg
[i
], vt
, FALSE
);
2380 vt
= (char*)ALIGN_PTR_TO (vt
, MINT_VT_ALIGNMENT
);
2382 *(char**)vt_sp
= vt
;
2386 * These functions are the entry points into the interpreter from compiled code.
2387 * They are called by the interp_in wrappers. They have the following signature:
2388 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
2389 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
2390 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
2391 * more wrappers then these functions.
2392 * this/static * ret/void * 16 arguments -> 64 functions.
2395 #define MAX_INTERP_ENTRY_ARGS 8
2397 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
2398 InterpEntryData data; \
2399 (data).rmethod = (_method); \
2400 (data).res = (_res); \
2401 (data).this_arg = (_this_arg); \
2402 (data).many_args = NULL;
2404 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
2405 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2406 interp_entry (&data); \
2408 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
2409 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2410 (data).args [0] = arg1; \
2411 interp_entry (&data); \
2413 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
2414 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2415 (data).args [0] = arg1; \
2416 (data).args [1] = arg2; \
2417 interp_entry (&data); \
2419 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
2420 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2421 (data).args [0] = arg1; \
2422 (data).args [1] = arg2; \
2423 (data).args [2] = arg3; \
2424 interp_entry (&data); \
2426 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
2427 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2428 (data).args [0] = arg1; \
2429 (data).args [1] = arg2; \
2430 (data).args [2] = arg3; \
2431 (data).args [3] = arg4; \
2432 interp_entry (&data); \
2434 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
2435 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2436 (data).args [0] = arg1; \
2437 (data).args [1] = arg2; \
2438 (data).args [2] = arg3; \
2439 (data).args [3] = arg4; \
2440 (data).args [4] = arg5; \
2441 interp_entry (&data); \
2443 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
2444 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2445 (data).args [0] = arg1; \
2446 (data).args [1] = arg2; \
2447 (data).args [2] = arg3; \
2448 (data).args [3] = arg4; \
2449 (data).args [4] = arg5; \
2450 (data).args [5] = arg6; \
2451 interp_entry (&data); \
2453 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
2454 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2455 (data).args [0] = arg1; \
2456 (data).args [1] = arg2; \
2457 (data).args [2] = arg3; \
2458 (data).args [3] = arg4; \
2459 (data).args [4] = arg5; \
2460 (data).args [5] = arg6; \
2461 (data).args [6] = arg7; \
2462 interp_entry (&data); \
2464 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
2465 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2466 (data).args [0] = arg1; \
2467 (data).args [1] = arg2; \
2468 (data).args [2] = arg3; \
2469 (data).args [3] = arg4; \
2470 (data).args [4] = arg5; \
2471 (data).args [5] = arg6; \
2472 (data).args [6] = arg7; \
2473 (data).args [7] = arg8; \
2474 interp_entry (&data); \
2477 #define ARGLIST0 InterpMethod *rmethod
2478 #define ARGLIST1 gpointer arg1, InterpMethod *rmethod
2479 #define ARGLIST2 gpointer arg1, gpointer arg2, InterpMethod *rmethod
2480 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, InterpMethod *rmethod
2481 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, InterpMethod *rmethod
2482 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, InterpMethod *rmethod
2483 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, InterpMethod *rmethod
2484 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, InterpMethod *rmethod
2485 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, InterpMethod *rmethod
2487 static void interp_entry_static_0 (ARGLIST0
) INTERP_ENTRY0 (NULL
, NULL
, rmethod
)
2488 static void interp_entry_static_1 (ARGLIST1
) INTERP_ENTRY1 (NULL
, NULL
, rmethod
)
2489 static void interp_entry_static_2 (ARGLIST2
) INTERP_ENTRY2 (NULL
, NULL
, rmethod
)
2490 static void interp_entry_static_3 (ARGLIST3
) INTERP_ENTRY3 (NULL
, NULL
, rmethod
)
2491 static void interp_entry_static_4 (ARGLIST4
) INTERP_ENTRY4 (NULL
, NULL
, rmethod
)
2492 static void interp_entry_static_5 (ARGLIST5
) INTERP_ENTRY5 (NULL
, NULL
, rmethod
)
2493 static void interp_entry_static_6 (ARGLIST6
) INTERP_ENTRY6 (NULL
, NULL
, rmethod
)
2494 static void interp_entry_static_7 (ARGLIST7
) INTERP_ENTRY7 (NULL
, NULL
, rmethod
)
2495 static void interp_entry_static_8 (ARGLIST8
) INTERP_ENTRY8 (NULL
, NULL
, rmethod
)
2496 static void interp_entry_static_ret_0 (gpointer res
, ARGLIST0
) INTERP_ENTRY0 (NULL
, res
, rmethod
)
2497 static void interp_entry_static_ret_1 (gpointer res
, ARGLIST1
) INTERP_ENTRY1 (NULL
, res
, rmethod
)
2498 static void interp_entry_static_ret_2 (gpointer res
, ARGLIST2
) INTERP_ENTRY2 (NULL
, res
, rmethod
)
2499 static void interp_entry_static_ret_3 (gpointer res
, ARGLIST3
) INTERP_ENTRY3 (NULL
, res
, rmethod
)
2500 static void interp_entry_static_ret_4 (gpointer res
, ARGLIST4
) INTERP_ENTRY4 (NULL
, res
, rmethod
)
2501 static void interp_entry_static_ret_5 (gpointer res
, ARGLIST5
) INTERP_ENTRY5 (NULL
, res
, rmethod
)
2502 static void interp_entry_static_ret_6 (gpointer res
, ARGLIST6
) INTERP_ENTRY6 (NULL
, res
, rmethod
)
2503 static void interp_entry_static_ret_7 (gpointer res
, ARGLIST7
) INTERP_ENTRY7 (NULL
, res
, rmethod
)
2504 static void interp_entry_static_ret_8 (gpointer res
, ARGLIST8
) INTERP_ENTRY8 (NULL
, res
, rmethod
)
2505 static void interp_entry_instance_0 (gpointer this_arg
, ARGLIST0
) INTERP_ENTRY0 (this_arg
, NULL
, rmethod
)
2506 static void interp_entry_instance_1 (gpointer this_arg
, ARGLIST1
) INTERP_ENTRY1 (this_arg
, NULL
, rmethod
)
2507 static void interp_entry_instance_2 (gpointer this_arg
, ARGLIST2
) INTERP_ENTRY2 (this_arg
, NULL
, rmethod
)
2508 static void interp_entry_instance_3 (gpointer this_arg
, ARGLIST3
) INTERP_ENTRY3 (this_arg
, NULL
, rmethod
)
2509 static void interp_entry_instance_4 (gpointer this_arg
, ARGLIST4
) INTERP_ENTRY4 (this_arg
, NULL
, rmethod
)
2510 static void interp_entry_instance_5 (gpointer this_arg
, ARGLIST5
) INTERP_ENTRY5 (this_arg
, NULL
, rmethod
)
2511 static void interp_entry_instance_6 (gpointer this_arg
, ARGLIST6
) INTERP_ENTRY6 (this_arg
, NULL
, rmethod
)
2512 static void interp_entry_instance_7 (gpointer this_arg
, ARGLIST7
) INTERP_ENTRY7 (this_arg
, NULL
, rmethod
)
2513 static void interp_entry_instance_8 (gpointer this_arg
, ARGLIST8
) INTERP_ENTRY8 (this_arg
, NULL
, rmethod
)
2514 static void interp_entry_instance_ret_0 (gpointer this_arg
, gpointer res
, ARGLIST0
) INTERP_ENTRY0 (this_arg
, res
, rmethod
)
2515 static void interp_entry_instance_ret_1 (gpointer this_arg
, gpointer res
, ARGLIST1
) INTERP_ENTRY1 (this_arg
, res
, rmethod
)
2516 static void interp_entry_instance_ret_2 (gpointer this_arg
, gpointer res
, ARGLIST2
) INTERP_ENTRY2 (this_arg
, res
, rmethod
)
2517 static void interp_entry_instance_ret_3 (gpointer this_arg
, gpointer res
, ARGLIST3
) INTERP_ENTRY3 (this_arg
, res
, rmethod
)
2518 static void interp_entry_instance_ret_4 (gpointer this_arg
, gpointer res
, ARGLIST4
) INTERP_ENTRY4 (this_arg
, res
, rmethod
)
2519 static void interp_entry_instance_ret_5 (gpointer this_arg
, gpointer res
, ARGLIST5
) INTERP_ENTRY5 (this_arg
, res
, rmethod
)
2520 static void interp_entry_instance_ret_6 (gpointer this_arg
, gpointer res
, ARGLIST6
) INTERP_ENTRY6 (this_arg
, res
, rmethod
)
2521 static void interp_entry_instance_ret_7 (gpointer this_arg
, gpointer res
, ARGLIST7
) INTERP_ENTRY7 (this_arg
, res
, rmethod
)
2522 static void interp_entry_instance_ret_8 (gpointer this_arg
, gpointer res
, ARGLIST8
) INTERP_ENTRY8 (this_arg
, res
, rmethod
)
2524 #define INTERP_ENTRY_FUNCLIST(type) (gpointer)interp_entry_ ## type ## _0, (gpointer)interp_entry_ ## type ## _1, (gpointer)interp_entry_ ## type ## _2, (gpointer)interp_entry_ ## type ## _3, (gpointer)interp_entry_ ## type ## _4, (gpointer)interp_entry_ ## type ## _5, (gpointer)interp_entry_ ## type ## _6, (gpointer)interp_entry_ ## type ## _7, (gpointer)interp_entry_ ## type ## _8
2526 static gpointer entry_funcs_static
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (static) };
2527 static gpointer entry_funcs_static_ret
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (static_ret
) };
2528 static gpointer entry_funcs_instance
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (instance
) };
2529 static gpointer entry_funcs_instance_ret
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (instance_ret
) };
2531 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
2533 interp_entry_general (gpointer this_arg
, gpointer res
, gpointer
*args
, gpointer rmethod
)
2535 INTERP_ENTRY_BASE ((InterpMethod
*)rmethod
, this_arg
, res
);
2536 data
.many_args
= args
;
2537 interp_entry (&data
);
2540 #ifdef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
2542 // inline so we can alloc on stack
2543 #define alloc_storage_for_stackval(s, t, p) do { \
2544 if ((t)->type == MONO_TYPE_GENERICINST && !MONO_TYPE_IS_REFERENCE (t)) { \
2545 (s)->data.vt = alloca (mono_class_value_size (mono_class_from_mono_type_internal (t), NULL)); \
2546 } else if ((t)->type == MONO_TYPE_VALUETYPE) { \
2548 (s)->data.vt = alloca (mono_class_native_size ((t)->data.klass, NULL)); \
2550 (s)->data.vt = alloca (mono_class_value_size ((t)->data.klass, NULL)); \
2555 interp_entry_from_trampoline (gpointer ccontext_untyped
, gpointer rmethod_untyped
)
2558 ThreadContext
*context
;
2562 MonoMethodSignature
*sig
;
2563 CallContext
*ccontext
= (CallContext
*) ccontext_untyped
;
2564 InterpMethod
*rmethod
= (InterpMethod
*) rmethod_untyped
;
2565 gpointer orig_domain
= NULL
, attach_cookie
;
2568 if (rmethod
->needs_thread_attach
)
2569 orig_domain
= mono_threads_attach_coop (mono_domain_get (), &attach_cookie
);
2571 context
= get_context ();
2573 method
= rmethod
->method
;
2574 sig
= mono_method_signature_internal (method
);
2578 args
= (stackval
*)alloca (sizeof (stackval
) * (sig
->param_count
+ (sig
->hasthis
? 1 : 0)));
2580 init_frame (&frame
, NULL
, rmethod
, args
, &result
);
2582 /* Allocate storage for value types */
2583 for (i
= 0; i
< sig
->param_count
; i
++) {
2584 MonoType
*type
= sig
->params
[i
];
2585 alloc_storage_for_stackval (&frame
.stack_args
[i
+ sig
->hasthis
], type
, sig
->pinvoke
);
2588 if (sig
->ret
->type
!= MONO_TYPE_VOID
)
2589 alloc_storage_for_stackval (frame
.retval
, sig
->ret
, sig
->pinvoke
);
2591 /* Copy the args saved in the trampoline to the frame stack */
2592 mono_arch_get_native_call_context_args (ccontext
, &frame
, sig
);
2595 interp_exec_method (&frame
, context
, error
);
2597 if (rmethod
->needs_thread_attach
)
2598 mono_threads_detach_coop (orig_domain
, &attach_cookie
);
2601 g_assert (frame
.ex
== NULL
);
2603 /* Write back the return value */
2604 mono_arch_set_native_call_context_ret (ccontext
, &frame
, sig
);
2610 interp_entry_from_trampoline (gpointer ccontext_untyped
, gpointer rmethod_untyped
)
2612 g_assert_not_reached ();
2615 #endif /* MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE */
2617 static InterpMethod
*
2618 lookup_method_pointer (gpointer addr
)
2620 MonoDomain
*domain
= mono_domain_get ();
2621 MonoJitDomainInfo
*info
= domain_jit_info (domain
);
2622 InterpMethod
*res
= NULL
;
2624 mono_domain_lock (domain
);
2625 if (info
->interp_method_pointer_hash
)
2626 res
= (InterpMethod
*)g_hash_table_lookup (info
->interp_method_pointer_hash
, addr
);
2627 mono_domain_unlock (domain
);
2632 #ifndef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED
2634 interp_no_native_to_managed (void)
2636 g_error ("interpreter: native-to-managed transition not available on this platform");
2641 no_llvmonly_interp_method_pointer (void)
2643 g_assert_not_reached ();
2647 * interp_create_method_pointer_llvmonly:
2649 * Return an ftndesc for entering the interpreter and executing METHOD.
2652 interp_create_method_pointer_llvmonly (MonoMethod
*method
, gboolean unbox
, MonoError
*error
)
2654 MonoDomain
*domain
= mono_domain_get ();
2655 gpointer addr
, entry_func
, entry_wrapper
;
2656 MonoMethodSignature
*sig
;
2657 MonoMethod
*wrapper
;
2658 MonoJitDomainInfo
*info
;
2659 InterpMethod
*imethod
;
2661 imethod
= mono_interp_get_imethod (domain
, method
, error
);
2662 return_val_if_nok (error
, NULL
);
2665 if (imethod
->llvmonly_unbox_entry
)
2666 return (MonoFtnDesc
*)imethod
->llvmonly_unbox_entry
;
2668 if (imethod
->jit_entry
)
2669 return (MonoFtnDesc
*)imethod
->jit_entry
;
2672 sig
= mono_method_signature_internal (method
);
2675 * The entry functions need access to the method to call, so we have
2676 * to use a ftndesc. The caller uses a normal signature, while the
2677 * entry functions use a gsharedvt_in signature, so wrap the entry function in
2678 * a gsharedvt_in_sig wrapper.
2680 wrapper
= mini_get_gsharedvt_in_sig_wrapper (sig
);
2682 entry_wrapper
= mono_jit_compile_method_jit_only (wrapper
, error
);
2683 mono_error_assertf_ok (error
, "couldn't compile wrapper \"%s\" for \"%s\"",
2684 mono_method_get_name_full (wrapper
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
),
2685 mono_method_get_name_full (method
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
));
2687 if (sig
->param_count
> MAX_INTERP_ENTRY_ARGS
) {
2688 g_assert_not_reached ();
2689 //entry_func = (gpointer)interp_entry_general;
2690 } else if (sig
->hasthis
) {
2691 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2692 entry_func
= entry_funcs_instance
[sig
->param_count
];
2694 entry_func
= entry_funcs_instance_ret
[sig
->param_count
];
2696 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2697 entry_func
= entry_funcs_static
[sig
->param_count
];
2699 entry_func
= entry_funcs_static_ret
[sig
->param_count
];
2701 g_assert (entry_func
);
2703 /* Encode unbox in the lower bit of imethod */
2704 gpointer entry_arg
= imethod
;
2706 entry_arg
= (gpointer
)(((gsize
)entry_arg
) | 1);
2707 MonoFtnDesc
*entry_ftndesc
= mini_llvmonly_create_ftndesc (mono_domain_get (), entry_func
, entry_arg
);
2709 addr
= mini_llvmonly_create_ftndesc (mono_domain_get (), entry_wrapper
, entry_ftndesc
);
2711 info
= domain_jit_info (domain
);
2712 mono_domain_lock (domain
);
2713 if (!info
->interp_method_pointer_hash
)
2714 info
->interp_method_pointer_hash
= g_hash_table_new (NULL
, NULL
);
2715 g_hash_table_insert (info
->interp_method_pointer_hash
, addr
, imethod
);
2716 mono_domain_unlock (domain
);
2718 mono_memory_barrier ();
2720 imethod
->llvmonly_unbox_entry
= addr
;
2722 imethod
->jit_entry
= addr
;
2724 return (MonoFtnDesc
*)addr
;
2728 * interp_create_method_pointer:
2730 * Return a function pointer which can be used to call METHOD using the
2731 * interpreter. Return NULL for methods which are not supported.
2734 interp_create_method_pointer (MonoMethod
*method
, gboolean compile
, MonoError
*error
)
2736 #ifndef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED
2738 return (gpointer
)no_llvmonly_interp_method_pointer
;
2739 return (gpointer
)interp_no_native_to_managed
;
2741 gpointer addr
, entry_func
, entry_wrapper
= NULL
;
2742 MonoDomain
*domain
= mono_domain_get ();
2743 MonoJitDomainInfo
*info
;
2744 InterpMethod
*imethod
= mono_interp_get_imethod (domain
, method
, error
);
2747 return (gpointer
)no_llvmonly_interp_method_pointer
;
2749 if (imethod
->jit_entry
)
2750 return imethod
->jit_entry
;
2752 if (compile
&& !imethod
->transformed
) {
2753 /* Return any errors from method compilation */
2754 mono_interp_transform_method (imethod
, get_context (), error
);
2755 return_val_if_nok (error
, NULL
);
2758 MonoMethodSignature
*sig
= mono_method_signature_internal (method
);
2761 /* The caller should call interp_create_method_pointer_llvmonly */
2762 g_assert_not_reached ();
2764 if (method
->wrapper_type
&& method
->wrapper_type
== MONO_WRAPPER_MANAGED_TO_NATIVE
)
2767 #ifndef MONO_ARCH_HAVE_FTNPTR_ARG_TRAMPOLINE
2769 * Interp in wrappers get the argument in the rgctx register. If
2770 * MONO_ARCH_HAVE_FTNPTR_ARG_TRAMPOLINE is defined it means that
2771 * on that arch the rgctx register is not scratch, so we use a
2772 * separate temp register. We should update the wrappers for this
2773 * if we really care about those architectures (arm).
2775 MonoMethod
*wrapper
= mini_get_interp_in_wrapper (sig
);
2777 entry_wrapper
= mono_jit_compile_method_jit_only (wrapper
, error
);
2779 if (entry_wrapper
) {
2780 if (sig
->param_count
> MAX_INTERP_ENTRY_ARGS
) {
2781 entry_func
= (gpointer
)interp_entry_general
;
2782 } else if (sig
->hasthis
) {
2783 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2784 entry_func
= entry_funcs_instance
[sig
->param_count
];
2786 entry_func
= entry_funcs_instance_ret
[sig
->param_count
];
2788 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2789 entry_func
= entry_funcs_static
[sig
->param_count
];
2791 entry_func
= entry_funcs_static_ret
[sig
->param_count
];
2794 #ifndef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
2795 mono_error_assertf_ok (error
, "couldn't compile wrapper \"%s\" for \"%s\"",
2796 mono_method_get_name_full (wrapper
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
),
2797 mono_method_get_name_full (method
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
));
2799 mono_error_cleanup (error
);
2800 error_init_reuse (error
);
2801 if (!mono_native_to_interp_trampoline
) {
2802 if (mono_aot_only
) {
2803 mono_native_to_interp_trampoline
= (MonoFuncV
)mono_aot_get_trampoline ("native_to_interp_trampoline");
2805 MonoTrampInfo
*info
;
2806 mono_native_to_interp_trampoline
= (MonoFuncV
)mono_arch_get_native_to_interp_trampoline (&info
);
2807 mono_tramp_info_register (info
, NULL
);
2810 entry_wrapper
= (gpointer
)mono_native_to_interp_trampoline
;
2811 /* We need the lmf wrapper only when being called from mixed mode */
2813 entry_func
= (gpointer
)interp_entry_from_trampoline
;
2815 static gpointer cached_func
= NULL
;
2817 cached_func
= mono_jit_compile_method_jit_only (mini_get_interp_lmf_wrapper ("mono_interp_entry_from_trampoline", (gpointer
) mono_interp_entry_from_trampoline
), error
);
2818 mono_memory_barrier ();
2820 entry_func
= cached_func
;
2825 g_assert (entry_func
);
2826 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
2827 MonoFtnDesc
*ftndesc
= g_new0 (MonoFtnDesc
, 1);
2828 ftndesc
->addr
= entry_func
;
2829 ftndesc
->arg
= imethod
;
2830 mono_error_assert_ok (error
);
2833 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
2834 * rgctx register using a trampoline.
2837 addr
= mono_create_ftnptr_arg_trampoline (ftndesc
, entry_wrapper
);
2839 info
= domain_jit_info (domain
);
2840 mono_domain_lock (domain
);
2841 if (!info
->interp_method_pointer_hash
)
2842 info
->interp_method_pointer_hash
= g_hash_table_new (NULL
, NULL
);
2843 g_hash_table_insert (info
->interp_method_pointer_hash
, addr
, imethod
);
2844 mono_domain_unlock (domain
);
2846 mono_memory_barrier ();
2847 imethod
->jit_entry
= addr
;
2854 static int opcode_counts
[512];
2856 #define COUNT_OP(op) opcode_counts[op]++
2858 #define COUNT_OP(op)
2862 #define DUMP_INSTR() \
2863 if (tracing > 1) { \
2865 if (sp > frame->stack) { \
2866 ins = dump_stack (frame->stack, sp); \
2868 ins = g_strdup (""); \
2872 char *mn = mono_method_full_name (frame->imethod->method, FALSE); \
2873 char *disasm = mono_interp_dis_mintop(imethod->code, ip); \
2874 g_print ("(%p) %s -> %s\t%d:%s\n", mono_thread_internal_current (), mn, disasm, vt_sp - vtalloc, ins); \
2880 #define DUMP_INSTR()
2883 #define INIT_VTABLE(vtable) do { \
2884 if (G_UNLIKELY (!(vtable)->initialized)) { \
2885 mono_runtime_class_init_full ((vtable), error); \
2886 if (!is_ok (error)) \
2887 THROW_EX (mono_error_convert_to_exception (error), ip); \
2894 * The interpreter executes in gc unsafe (non-preempt) mode. On wasm, the C stack is
2895 * scannable but the wasm stack is not, so to make the code GC safe, the following rules
2896 * should be followed:
2897 * - every objref handled by the code needs to have a copy stored inside InterpFrame,
2898 * in stackval->data.o. For objrefs which are not yet on the IL stack, they can be stored
2899 * in frame->o. This will ensure the objects are pinned. The 'frame' local is assumed
2900 * to be allocated to the C stack and not to registers.
2901 * - minimalize the number of MonoObject* locals/arguments.
2905 #define frame_objref(frame) (frame)->o
2907 #define frame_objref(frame) o
2911 * If EXIT_AT_FINALLY is not -1, exit after exiting the finally clause with that index.
2912 * If BASE_FRAME is not NULL, copy arguments/locals from BASE_FRAME.
2913 * The ERROR argument is used to avoid declaring an error object for every interp frame, its not used
2914 * to return error information.
2917 interp_exec_method_full (InterpFrame
*frame
, ThreadContext
*context
, FrameClauseArgs
*clause_args
, MonoError
*error
)
2919 InterpFrame child_frame
;
2920 const unsigned short *ip
= NULL
;
2922 InterpMethod
*imethod
= NULL
;
2924 gint tracing
= global_tracing
;
2925 unsigned char *vtalloc
;
2928 unsigned char *vt_sp
;
2929 unsigned char *locals
= NULL
;
2930 // See the comment about GC safety above
2931 MonoObject
*o
= NULL
;
2933 #if USE_COMPUTED_GOTO
2934 static void *in_labels
[] = {
2935 #define OPDEF(a,b,c,d) \
2937 #include "mintops.def"
2941 MonoMethodPInvoke
* piinfo
= NULL
;
2944 frame
->finally_ips
= NULL
;
2945 frame
->endfinally_ip
= NULL
;
2948 debug_enter (frame
, &tracing
);
2951 imethod
= frame
->imethod
;
2952 if (!imethod
->transformed
) {
2954 char *mn
= mono_method_full_name (imethod
->method
, TRUE
);
2955 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn
);
2960 do_transform_method (frame
, context
);
2962 THROW_EX (frame
->ex
, NULL
);
2963 EXCEPTION_CHECKPOINT
;
2967 frame
->args
= g_newa (char, imethod
->alloca_size
);
2970 ip
= clause_args
->start_with_ip
;
2971 if (clause_args
->base_frame
) {
2972 frame
->args
= g_newa (char, imethod
->alloca_size
);
2973 memcpy (frame
->args
, clause_args
->base_frame
->args
, imethod
->alloca_size
);
2976 sp
= frame
->stack
= (stackval
*) (char *) frame
->args
;
2977 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
2981 locals
= (unsigned char *) vt_sp
+ imethod
->vt_stack_size
;
2982 frame
->locals
= locals
;
2983 child_frame
.parent
= frame
;
2985 if (clause_args
&& clause_args
->filter_exception
) {
2986 sp
->data
.p
= clause_args
->filter_exception
;
2990 //g_print ("(%p) Call %s\n", mono_thread_internal_current (), mono_method_get_full_name (frame->imethod->method));
2993 * using while (ip < end) may result in a 15% performance drop,
2994 * but it may be useful for debug
2997 #ifndef USE_COMPUTED_GOTO
3000 /* g_assert (sp >= frame->stack); */
3001 /* g_assert(vt_sp - vtalloc <= imethod->vt_stack_size); */
3003 MINT_IN_SWITCH (*ip
) {
3004 MINT_IN_CASE(MINT_INITLOCALS
)
3005 memset (locals
, 0, imethod
->locals_size
);
3008 MINT_IN_CASE(MINT_NOP
)
3011 MINT_IN_CASE(MINT_NIY
)
3012 g_error ("mint_niy: instruction not implemented yet. This shouldn't happen.");
3014 MINT_IN_CASE(MINT_BREAK
)
3016 do_debugger_tramp (mini_get_dbg_callbacks ()->user_break
, frame
);
3018 MINT_IN_CASE(MINT_BREAKPOINT
)
3022 MINT_IN_CASE(MINT_LDNULL
)
3027 MINT_IN_CASE(MINT_ARGLIST
)
3028 g_assert (frame
->varargs
);
3030 *(gpointer
*)sp
->data
.p
= frame
->varargs
;
3031 vt_sp
+= ALIGN_TO (sizeof (gpointer
), MINT_VT_ALIGNMENT
);
3035 MINT_IN_CASE(MINT_VTRESULT
) {
3036 int ret_size
= * (guint16
*)(ip
+ 1);
3037 unsigned char *ret_vt_sp
= vt_sp
;
3038 vt_sp
-= READ32(ip
+ 2);
3040 memmove (vt_sp
, ret_vt_sp
, ret_size
);
3041 sp
[-1].data
.p
= vt_sp
;
3042 vt_sp
+= ALIGN_TO (ret_size
, MINT_VT_ALIGNMENT
);
3047 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
3048 MINT_IN_CASE(MINT_LDC_I4_M1
)
3051 MINT_IN_CASE(MINT_LDC_I4_0
)
3054 MINT_IN_CASE(MINT_LDC_I4_1
)
3057 MINT_IN_CASE(MINT_LDC_I4_2
)
3060 MINT_IN_CASE(MINT_LDC_I4_3
)
3063 MINT_IN_CASE(MINT_LDC_I4_4
)
3066 MINT_IN_CASE(MINT_LDC_I4_5
)
3069 MINT_IN_CASE(MINT_LDC_I4_6
)
3072 MINT_IN_CASE(MINT_LDC_I4_7
)
3075 MINT_IN_CASE(MINT_LDC_I4_8
)
3078 MINT_IN_CASE(MINT_LDC_I4_S
)
3079 sp
->data
.i
= *(const short *)(ip
+ 1);
3083 MINT_IN_CASE(MINT_LDC_I4
)
3085 sp
->data
.i
= READ32 (ip
);
3089 MINT_IN_CASE(MINT_LDC_I8
)
3091 sp
->data
.l
= READ64 (ip
);
3095 MINT_IN_CASE(MINT_LDC_I8_S
)
3096 sp
->data
.l
= *(const short *)(ip
+ 1);
3100 MINT_IN_CASE(MINT_LDC_R4
) {
3104 sp
->data
.f_r4
= * (float *)&val
;
3109 MINT_IN_CASE(MINT_LDC_R8
)
3110 sp
->data
.l
= READ64 (ip
+ 1); /* note union usage */
3114 MINT_IN_CASE(MINT_DUP
)
3119 MINT_IN_CASE(MINT_DUP_VT
)
3120 i32
= READ32 (ip
+ 1);
3122 memcpy(sp
->data
.p
, sp
[-1].data
.p
, i32
);
3123 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
3127 MINT_IN_CASE(MINT_POP
) {
3128 guint16 u16
= (* (guint16
*)(ip
+ 1)) + 1;
3130 memmove (sp
- u16
, sp
- 1, (u16
- 1) * sizeof (stackval
));
3135 MINT_IN_CASE(MINT_JMP
) {
3136 InterpMethod
*new_method
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3137 gboolean realloc_frame
= new_method
->alloca_size
> imethod
->alloca_size
;
3139 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_TAIL_CALL
)
3140 MONO_PROFILER_RAISE (method_tail_call
, (imethod
->method
, new_method
->method
));
3142 if (!new_method
->transformed
) {
3143 MONO_API_ERROR_INIT (error
);
3146 mono_interp_transform_method (new_method
, context
, error
);
3147 frame
->ex
= mono_error_convert_to_exception (error
);
3152 imethod
= frame
->imethod
= new_method
;
3154 * We allocate the stack frame from scratch and store the arguments in the
3155 * locals again since it's possible for the caller stack frame to be smaller
3156 * than the callee stack frame (at the interp level)
3158 if (realloc_frame
) {
3159 frame
->args
= g_newa (char, imethod
->alloca_size
);
3160 memset (frame
->args
, 0, imethod
->alloca_size
);
3161 sp
= frame
->stack
= (stackval
*) frame
->args
;
3163 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
3167 locals
= vt_sp
+ imethod
->vt_stack_size
;
3168 frame
->locals
= locals
;
3172 MINT_IN_CASE(MINT_CALLI
) {
3173 MonoMethodSignature
*csignature
;
3174 stackval
*endsp
= sp
;
3178 csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3182 child_frame
.imethod
= (InterpMethod
*)sp
->data
.p
;
3185 child_frame
.retval
= sp
;
3186 /* decrement by the actual number of args */
3187 sp
-= csignature
->param_count
;
3188 if (csignature
->hasthis
)
3190 child_frame
.stack_args
= sp
;
3192 if (child_frame
.imethod
->method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
) {
3193 child_frame
.imethod
= mono_interp_get_imethod (imethod
->domain
, mono_marshal_get_native_wrapper (child_frame
.imethod
->method
, FALSE
, FALSE
), error
);
3194 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
3197 if (csignature
->hasthis
) {
3198 MonoObject
*this_arg
= (MonoObject
*)sp
->data
.p
;
3200 if (m_class_is_valuetype (this_arg
->vtable
->klass
)) {
3201 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3202 sp
[0].data
.p
= unboxed
;
3206 interp_exec_method (&child_frame
, context
, error
);
3208 CHECK_RESUME_STATE (context
);
3210 /* need to handle typedbyref ... */
3211 if (csignature
->ret
->type
!= MONO_TYPE_VOID
) {
3217 MINT_IN_CASE(MINT_CALLI_NAT_FAST
) {
3218 gpointer target_ip
= sp
[-1].data
.p
;
3219 MonoMethodSignature
*csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3220 int opcode
= *(guint16
*)(ip
+ 2);
3221 gboolean save_last_error
= *(guint16
*)(ip
+ 3);
3226 sp
= do_icall_wrapper (frame
, csignature
, opcode
, sp
, target_ip
, save_last_error
);
3227 EXCEPTION_CHECKPOINT
;
3228 CHECK_RESUME_STATE (context
);
3232 MINT_IN_CASE(MINT_CALLI_NAT
) {
3233 MonoMethodSignature
*csignature
;
3234 stackval
*endsp
= sp
;
3235 unsigned char *code
= NULL
;
3236 gboolean save_last_error
= FALSE
;
3240 csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3241 save_last_error
= *(guint16
*)(ip
+ 2);
3245 code
= (guchar
*)sp
->data
.p
;
3246 child_frame
.imethod
= NULL
;
3249 child_frame
.retval
= sp
;
3250 /* decrement by the actual number of args */
3251 sp
-= csignature
->param_count
;
3252 if (csignature
->hasthis
)
3254 child_frame
.stack_args
= sp
;
3255 if (imethod
->method
->dynamic
&& csignature
->pinvoke
) {
3256 MonoMarshalSpec
**mspecs
;
3259 /* Pinvoke call is missing the wrapper. See mono_get_native_calli_wrapper */
3260 mspecs
= g_new0 (MonoMarshalSpec
*, csignature
->param_count
+ 1);
3262 piinfo
= piinfo
? piinfo
: g_newa (MonoMethodPInvoke
, 1);
3263 memset (piinfo
, 0, sizeof (*piinfo
));
3265 m
= mono_marshal_get_native_func_wrapper (m_class_get_image (imethod
->method
->klass
), csignature
, piinfo
, mspecs
, code
);
3267 for (int i
= csignature
->param_count
; i
>= 0; i
--)
3269 mono_metadata_free_marshal_spec (mspecs
[i
]);
3272 child_frame
.imethod
= mono_interp_get_imethod (imethod
->domain
, m
, error
);
3273 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
3275 interp_exec_method (&child_frame
, context
, error
);
3277 ves_pinvoke_method (&child_frame
, csignature
, (MonoFuncV
) code
, FALSE
, context
, save_last_error
);
3280 CHECK_RESUME_STATE (context
);
3282 /* need to handle typedbyref ... */
3283 if (csignature
->ret
->type
!= MONO_TYPE_VOID
) {
3289 MINT_IN_CASE(MINT_CALLVIRT_FAST
)
3290 MINT_IN_CASE(MINT_VCALLVIRT_FAST
) {
3291 MonoObject
*this_arg
;
3292 MonoClass
*this_class
;
3293 gboolean is_void
= *ip
== MINT_VCALLVIRT_FAST
;
3294 InterpMethod
*target_imethod
;
3295 stackval
*endsp
= sp
;
3298 // FIXME Have it handle also remoting calls and use a single opcode for virtual calls
3302 target_imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3303 slot
= *(gint16
*)(ip
+ 2);
3306 child_frame
.retval
= sp
;
3308 /* decrement by the actual number of args */
3309 sp
-= target_imethod
->param_count
+ target_imethod
->hasthis
;
3310 child_frame
.stack_args
= sp
;
3312 this_arg
= (MonoObject
*)sp
->data
.p
;
3313 this_class
= this_arg
->vtable
->klass
;
3315 child_frame
.imethod
= get_virtual_method_fast (target_imethod
, this_arg
->vtable
, slot
);
3316 if (m_class_is_valuetype (this_class
) && m_class_is_valuetype (child_frame
.imethod
->method
->klass
)) {
3318 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3319 sp
[0].data
.p
= unboxed
;
3322 interp_exec_method (&child_frame
, context
, error
);
3324 CHECK_RESUME_STATE (context
);
3327 /* need to handle typedbyref ... */
3333 MINT_IN_CASE(MINT_CALL_VARARG
) {
3334 stackval
*endsp
= sp
;
3335 int num_varargs
= 0;
3336 MonoMethodSignature
*csig
;
3340 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3341 /* The real signature for vararg calls */
3342 csig
= (MonoMethodSignature
*) imethod
->data_items
[* (guint16
*) (ip
+ 2)];
3343 /* Push all vararg arguments from normal sp to vt_sp together with the signature */
3344 num_varargs
= csig
->param_count
- csig
->sentinelpos
;
3345 child_frame
.varargs
= (char*) vt_sp
;
3346 copy_varargs_vtstack (csig
, sp
, &vt_sp
);
3350 child_frame
.retval
= sp
;
3352 /* decrement by the actual number of args */
3353 sp
-= child_frame
.imethod
->param_count
+ child_frame
.imethod
->hasthis
+ num_varargs
;
3354 child_frame
.stack_args
= sp
;
3356 interp_exec_method (&child_frame
, context
, error
);
3358 CHECK_RESUME_STATE (context
);
3360 if (csig
->ret
->type
!= MONO_TYPE_VOID
) {
3366 MINT_IN_CASE(MINT_CALL
)
3367 MINT_IN_CASE(MINT_VCALL
)
3368 MINT_IN_CASE(MINT_CALLVIRT
)
3369 MINT_IN_CASE(MINT_VCALLVIRT
) {
3370 gboolean is_void
= *ip
== MINT_VCALL
|| *ip
== MINT_VCALLVIRT
;
3371 gboolean is_virtual
= *ip
== MINT_CALLVIRT
|| *ip
== MINT_VCALLVIRT
;
3372 stackval
*endsp
= sp
;
3376 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3379 child_frame
.retval
= sp
;
3381 /* decrement by the actual number of args */
3382 sp
-= child_frame
.imethod
->param_count
+ child_frame
.imethod
->hasthis
;
3383 child_frame
.stack_args
= sp
;
3386 MonoObject
*this_arg
= (MonoObject
*)sp
->data
.p
;
3387 MonoClass
*this_class
= this_arg
->vtable
->klass
;
3389 child_frame
.imethod
= get_virtual_method (child_frame
.imethod
, this_arg
->vtable
);
3390 if (m_class_is_valuetype (this_class
) && m_class_is_valuetype (child_frame
.imethod
->method
->klass
)) {
3392 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3393 sp
[0].data
.p
= unboxed
;
3397 interp_exec_method (&child_frame
, context
, error
);
3399 CHECK_RESUME_STATE (context
);
3402 /* need to handle typedbyref ... */
3408 MINT_IN_CASE(MINT_JIT_CALL
) {
3409 InterpMethod
*rmethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3410 MONO_API_ERROR_INIT (error
);
3412 sp
= do_jit_call (sp
, vt_sp
, context
, frame
, rmethod
, error
);
3413 if (!is_ok (error
)) {
3414 MonoException
*ex
= mono_error_convert_to_exception (error
);
3419 CHECK_RESUME_STATE (context
);
3421 if (rmethod
->rtype
->type
!= MONO_TYPE_VOID
)
3426 MINT_IN_CASE(MINT_CALLRUN
) {
3427 MonoMethod
*target_method
= (MonoMethod
*) imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3428 MonoMethodSignature
*sig
= (MonoMethodSignature
*) imethod
->data_items
[* (guint16
*)(ip
+ 2)];
3434 sp
-= sig
->param_count
;
3438 ves_imethod (frame
, target_method
, sig
, sp
, retval
);
3440 THROW_EX (frame
->ex
, ip
);
3442 if (sig
->ret
->type
!= MONO_TYPE_VOID
) {
3449 MINT_IN_CASE(MINT_RET
)
3451 *frame
->retval
= *sp
;
3452 if (sp
> frame
->stack
)
3453 g_warning ("ret: more values on stack: %d", sp
-frame
->stack
);
3455 MINT_IN_CASE(MINT_RET_VOID
)
3456 if (sp
> frame
->stack
)
3457 g_warning ("ret.void: more values on stack: %d %s", sp
-frame
->stack
, mono_method_full_name (imethod
->method
, TRUE
));
3459 MINT_IN_CASE(MINT_RET_VT
)
3460 i32
= READ32(ip
+ 1);
3462 memcpy(frame
->retval
->data
.p
, sp
->data
.p
, i32
);
3463 if (sp
> frame
->stack
)
3464 g_warning ("ret.vt: more values on stack: %d", sp
-frame
->stack
);
3466 MINT_IN_CASE(MINT_BR_S
)
3467 ip
+= (short) *(ip
+ 1);
3469 MINT_IN_CASE(MINT_BR
)
3470 ip
+= (gint32
) READ32(ip
+ 1);
3472 #define ZEROP_S(datamem, op) \
3474 if (sp->data.datamem op 0) \
3475 ip += * (gint16 *)(ip + 1); \
3479 #define ZEROP(datamem, op) \
3481 if (sp->data.datamem op 0) \
3482 ip += (gint32)READ32(ip + 1); \
3486 MINT_IN_CASE(MINT_BRFALSE_I4_S
)
3489 MINT_IN_CASE(MINT_BRFALSE_I8_S
)
3492 MINT_IN_CASE(MINT_BRFALSE_R4_S
)
3495 MINT_IN_CASE(MINT_BRFALSE_R8_S
)
3498 MINT_IN_CASE(MINT_BRFALSE_I4
)
3501 MINT_IN_CASE(MINT_BRFALSE_I8
)
3504 MINT_IN_CASE(MINT_BRFALSE_R4
)
3507 MINT_IN_CASE(MINT_BRFALSE_R8
)
3510 MINT_IN_CASE(MINT_BRTRUE_I4_S
)
3513 MINT_IN_CASE(MINT_BRTRUE_I8_S
)
3516 MINT_IN_CASE(MINT_BRTRUE_R4_S
)
3519 MINT_IN_CASE(MINT_BRTRUE_R8_S
)
3522 MINT_IN_CASE(MINT_BRTRUE_I4
)
3525 MINT_IN_CASE(MINT_BRTRUE_I8
)
3528 MINT_IN_CASE(MINT_BRTRUE_R4
)
3531 MINT_IN_CASE(MINT_BRTRUE_R8
)
3534 #define CONDBR_S(cond) \
3537 ip += * (gint16 *)(ip + 1); \
3540 #define BRELOP_S(datamem, op) \
3541 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
3543 #define CONDBR(cond) \
3546 ip += (gint32)READ32(ip + 1); \
3550 #define BRELOP(datamem, op) \
3551 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
3553 MINT_IN_CASE(MINT_BEQ_I4_S
)
3556 MINT_IN_CASE(MINT_BEQ_I8_S
)
3559 MINT_IN_CASE(MINT_BEQ_R4_S
)
3560 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
== sp
[1].data
.f_r4
)
3562 MINT_IN_CASE(MINT_BEQ_R8_S
)
3563 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
== sp
[1].data
.f
)
3565 MINT_IN_CASE(MINT_BEQ_I4
)
3568 MINT_IN_CASE(MINT_BEQ_I8
)
3571 MINT_IN_CASE(MINT_BEQ_R4
)
3572 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
== sp
[1].data
.f_r4
)
3574 MINT_IN_CASE(MINT_BEQ_R8
)
3575 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
== sp
[1].data
.f
)
3577 MINT_IN_CASE(MINT_BGE_I4_S
)
3580 MINT_IN_CASE(MINT_BGE_I8_S
)
3583 MINT_IN_CASE(MINT_BGE_R4_S
)
3584 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3586 MINT_IN_CASE(MINT_BGE_R8_S
)
3587 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
>= sp
[1].data
.f
)
3589 MINT_IN_CASE(MINT_BGE_I4
)
3592 MINT_IN_CASE(MINT_BGE_I8
)
3595 MINT_IN_CASE(MINT_BGE_R4
)
3596 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3598 MINT_IN_CASE(MINT_BGE_R8
)
3599 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
>= sp
[1].data
.f
)
3601 MINT_IN_CASE(MINT_BGT_I4_S
)
3604 MINT_IN_CASE(MINT_BGT_I8_S
)
3607 MINT_IN_CASE(MINT_BGT_R4_S
)
3608 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3610 MINT_IN_CASE(MINT_BGT_R8_S
)
3611 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
> sp
[1].data
.f
)
3613 MINT_IN_CASE(MINT_BGT_I4
)
3616 MINT_IN_CASE(MINT_BGT_I8
)
3619 MINT_IN_CASE(MINT_BGT_R4
)
3620 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3622 MINT_IN_CASE(MINT_BGT_R8
)
3623 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
> sp
[1].data
.f
)
3625 MINT_IN_CASE(MINT_BLT_I4_S
)
3628 MINT_IN_CASE(MINT_BLT_I8_S
)
3631 MINT_IN_CASE(MINT_BLT_R4_S
)
3632 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3634 MINT_IN_CASE(MINT_BLT_R8_S
)
3635 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
< sp
[1].data
.f
)
3637 MINT_IN_CASE(MINT_BLT_I4
)
3640 MINT_IN_CASE(MINT_BLT_I8
)
3643 MINT_IN_CASE(MINT_BLT_R4
)
3644 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3646 MINT_IN_CASE(MINT_BLT_R8
)
3647 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
< sp
[1].data
.f
)
3649 MINT_IN_CASE(MINT_BLE_I4_S
)
3652 MINT_IN_CASE(MINT_BLE_I8_S
)
3655 MINT_IN_CASE(MINT_BLE_R4_S
)
3656 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3658 MINT_IN_CASE(MINT_BLE_R8_S
)
3659 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
<= sp
[1].data
.f
)
3661 MINT_IN_CASE(MINT_BLE_I4
)
3664 MINT_IN_CASE(MINT_BLE_I8
)
3667 MINT_IN_CASE(MINT_BLE_R4
)
3668 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3670 MINT_IN_CASE(MINT_BLE_R8
)
3671 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
<= sp
[1].data
.f
)
3673 MINT_IN_CASE(MINT_BNE_UN_I4_S
)
3676 MINT_IN_CASE(MINT_BNE_UN_I8_S
)
3679 MINT_IN_CASE(MINT_BNE_UN_R4_S
)
3680 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
!= sp
[1].data
.f_r4
)
3682 MINT_IN_CASE(MINT_BNE_UN_R8_S
)
3683 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
!= sp
[1].data
.f
)
3685 MINT_IN_CASE(MINT_BNE_UN_I4
)
3688 MINT_IN_CASE(MINT_BNE_UN_I8
)
3691 MINT_IN_CASE(MINT_BNE_UN_R4
)
3692 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
!= sp
[1].data
.f_r4
)
3694 MINT_IN_CASE(MINT_BNE_UN_R8
)
3695 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
!= sp
[1].data
.f
)
3698 #define BRELOP_S_CAST(datamem, op, type) \
3700 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3701 ip += * (gint16 *)(ip + 1); \
3705 #define BRELOP_CAST(datamem, op, type) \
3707 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3708 ip += (gint32)READ32(ip + 1); \
3712 MINT_IN_CASE(MINT_BGE_UN_I4_S
)
3713 BRELOP_S_CAST(i
, >=, guint32
);
3715 MINT_IN_CASE(MINT_BGE_UN_I8_S
)
3716 BRELOP_S_CAST(l
, >=, guint64
);
3718 MINT_IN_CASE(MINT_BGE_UN_R4_S
)
3719 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3721 MINT_IN_CASE(MINT_BGE_UN_R8_S
)
3722 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
>= sp
[1].data
.f
)
3724 MINT_IN_CASE(MINT_BGE_UN_I4
)
3725 BRELOP_CAST(i
, >=, guint32
);
3727 MINT_IN_CASE(MINT_BGE_UN_I8
)
3728 BRELOP_CAST(l
, >=, guint64
);
3730 MINT_IN_CASE(MINT_BGE_UN_R4
)
3731 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3733 MINT_IN_CASE(MINT_BGE_UN_R8
)
3734 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
>= sp
[1].data
.f
)
3736 MINT_IN_CASE(MINT_BGT_UN_I4_S
)
3737 BRELOP_S_CAST(i
, >, guint32
);
3739 MINT_IN_CASE(MINT_BGT_UN_I8_S
)
3740 BRELOP_S_CAST(l
, >, guint64
);
3742 MINT_IN_CASE(MINT_BGT_UN_R4_S
)
3743 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3745 MINT_IN_CASE(MINT_BGT_UN_R8_S
)
3746 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
> sp
[1].data
.f
)
3748 MINT_IN_CASE(MINT_BGT_UN_I4
)
3749 BRELOP_CAST(i
, >, guint32
);
3751 MINT_IN_CASE(MINT_BGT_UN_I8
)
3752 BRELOP_CAST(l
, >, guint64
);
3754 MINT_IN_CASE(MINT_BGT_UN_R4
)
3755 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3757 MINT_IN_CASE(MINT_BGT_UN_R8
)
3758 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
> sp
[1].data
.f
)
3760 MINT_IN_CASE(MINT_BLE_UN_I4_S
)
3761 BRELOP_S_CAST(i
, <=, guint32
);
3763 MINT_IN_CASE(MINT_BLE_UN_I8_S
)
3764 BRELOP_S_CAST(l
, <=, guint64
);
3766 MINT_IN_CASE(MINT_BLE_UN_R4_S
)
3767 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3769 MINT_IN_CASE(MINT_BLE_UN_R8_S
)
3770 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
<= sp
[1].data
.f
)
3772 MINT_IN_CASE(MINT_BLE_UN_I4
)
3773 BRELOP_CAST(i
, <=, guint32
);
3775 MINT_IN_CASE(MINT_BLE_UN_I8
)
3776 BRELOP_CAST(l
, <=, guint64
);
3778 MINT_IN_CASE(MINT_BLE_UN_R4
)
3779 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3781 MINT_IN_CASE(MINT_BLE_UN_R8
)
3782 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
<= sp
[1].data
.f
)
3784 MINT_IN_CASE(MINT_BLT_UN_I4_S
)
3785 BRELOP_S_CAST(i
, <, guint32
);
3787 MINT_IN_CASE(MINT_BLT_UN_I8_S
)
3788 BRELOP_S_CAST(l
, <, guint64
);
3790 MINT_IN_CASE(MINT_BLT_UN_R4_S
)
3791 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3793 MINT_IN_CASE(MINT_BLT_UN_R8_S
)
3794 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
< sp
[1].data
.f
)
3796 MINT_IN_CASE(MINT_BLT_UN_I4
)
3797 BRELOP_CAST(i
, <, guint32
);
3799 MINT_IN_CASE(MINT_BLT_UN_I8
)
3800 BRELOP_CAST(l
, <, guint64
);
3802 MINT_IN_CASE(MINT_BLT_UN_R4
)
3803 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3805 MINT_IN_CASE(MINT_BLT_UN_R8
)
3806 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
< sp
[1].data
.f
)
3808 MINT_IN_CASE(MINT_SWITCH
) {
3810 const unsigned short *st
;
3816 if ((guint32
)sp
->data
.i
< n
) {
3818 ip
+= 2 * (guint32
)sp
->data
.i
;
3819 offset
= READ32 (ip
);
3826 MINT_IN_CASE(MINT_LDIND_I1_CHECK
)
3827 NULL_CHECK (sp
[-1].data
.p
);
3829 sp
[-1].data
.i
= *(gint8
*)sp
[-1].data
.p
;
3831 MINT_IN_CASE(MINT_LDIND_U1_CHECK
)
3832 NULL_CHECK (sp
[-1].data
.p
);
3834 sp
[-1].data
.i
= *(guint8
*)sp
[-1].data
.p
;
3836 MINT_IN_CASE(MINT_LDIND_I2_CHECK
)
3837 NULL_CHECK (sp
[-1].data
.p
);
3839 sp
[-1].data
.i
= *(gint16
*)sp
[-1].data
.p
;
3841 MINT_IN_CASE(MINT_LDIND_U2_CHECK
)
3842 NULL_CHECK (sp
[-1].data
.p
);
3844 sp
[-1].data
.i
= *(guint16
*)sp
[-1].data
.p
;
3846 MINT_IN_CASE(MINT_LDIND_I4_CHECK
) /* Fall through */
3847 MINT_IN_CASE(MINT_LDIND_U4_CHECK
)
3848 NULL_CHECK (sp
[-1].data
.p
);
3850 sp
[-1].data
.i
= *(gint32
*)sp
[-1].data
.p
;
3852 MINT_IN_CASE(MINT_LDIND_I8_CHECK
)
3853 NULL_CHECK (sp
[-1].data
.p
);
3855 #ifdef NO_UNALIGNED_ACCESS
3856 if ((gsize
)sp
[-1].data
.p
% SIZEOF_VOID_P
)
3857 memcpy (&sp
[-1].data
.l
, sp
[-1].data
.p
, sizeof (gint64
));
3860 sp
[-1].data
.l
= *(gint64
*)sp
[-1].data
.p
;
3862 MINT_IN_CASE(MINT_LDIND_I
) {
3863 guint16 offset
= * (guint16
*)(ip
+ 1);
3864 sp
[-1 - offset
].data
.p
= *(gpointer
*)sp
[-1 - offset
].data
.p
;
3868 MINT_IN_CASE(MINT_LDIND_I8
) {
3869 guint16 offset
= * (guint16
*)(ip
+ 1);
3870 #ifdef NO_UNALIGNED_ACCESS
3871 if ((gsize
)sp
[-1 - offset
].data
.p
% SIZEOF_VOID_P
)
3872 memcpy (&sp
[-1 - offset
].data
.l
, sp
[-1 - offset
].data
.p
, sizeof (gint64
));
3875 sp
[-1 - offset
].data
.l
= *(gint64
*)sp
[-1 - offset
].data
.p
;
3879 MINT_IN_CASE(MINT_LDIND_R4_CHECK
)
3880 NULL_CHECK (sp
[-1].data
.p
);
3882 sp
[-1].data
.f_r4
= *(gfloat
*)sp
[-1].data
.p
;
3884 MINT_IN_CASE(MINT_LDIND_R8_CHECK
)
3885 NULL_CHECK (sp
[-1].data
.p
);
3887 #ifdef NO_UNALIGNED_ACCESS
3888 if ((gsize
)sp
[-1].data
.p
% SIZEOF_VOID_P
)
3889 memcpy (&sp
[-1].data
.f
, sp
[-1].data
.p
, sizeof (gdouble
));
3892 sp
[-1].data
.f
= *(gdouble
*)sp
[-1].data
.p
;
3894 MINT_IN_CASE(MINT_LDIND_REF
)
3896 sp
[-1].data
.p
= *(gpointer
*)sp
[-1].data
.p
;
3898 MINT_IN_CASE(MINT_LDIND_REF_CHECK
) {
3899 NULL_CHECK (sp
[-1].data
.p
);
3901 sp
[-1].data
.p
= *(gpointer
*)sp
[-1].data
.p
;
3904 MINT_IN_CASE(MINT_STIND_REF
)
3907 mono_gc_wbarrier_generic_store_internal (sp
->data
.p
, sp
[1].data
.o
);
3909 MINT_IN_CASE(MINT_STIND_I1
)
3912 * (gint8
*) sp
->data
.p
= (gint8
)sp
[1].data
.i
;
3914 MINT_IN_CASE(MINT_STIND_I2
)
3917 * (gint16
*) sp
->data
.p
= (gint16
)sp
[1].data
.i
;
3919 MINT_IN_CASE(MINT_STIND_I4
)
3922 * (gint32
*) sp
->data
.p
= sp
[1].data
.i
;
3924 MINT_IN_CASE(MINT_STIND_I
)
3927 * (mono_i
*) sp
->data
.p
= (mono_i
)sp
[1].data
.p
;
3929 MINT_IN_CASE(MINT_STIND_I8
)
3932 #ifdef NO_UNALIGNED_ACCESS
3933 if ((gsize
)sp
->data
.p
% SIZEOF_VOID_P
)
3934 memcpy (sp
->data
.p
, &sp
[1].data
.l
, sizeof (gint64
));
3937 * (gint64
*) sp
->data
.p
= sp
[1].data
.l
;
3939 MINT_IN_CASE(MINT_STIND_R4
)
3942 * (float *) sp
->data
.p
= sp
[1].data
.f_r4
;
3944 MINT_IN_CASE(MINT_STIND_R8
)
3947 #ifdef NO_UNALIGNED_ACCESS
3948 if ((gsize
)sp
->data
.p
% SIZEOF_VOID_P
)
3949 memcpy (sp
->data
.p
, &sp
[1].data
.f
, sizeof (double));
3952 * (double *) sp
->data
.p
= sp
[1].data
.f
;
3954 MINT_IN_CASE(MINT_MONO_ATOMIC_STORE_I4
)
3957 mono_atomic_store_i32 ((gint32
*) sp
->data
.p
, sp
[1].data
.i
);
3959 #define BINOP(datamem, op) \
3961 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3963 MINT_IN_CASE(MINT_ADD_I4
)
3966 MINT_IN_CASE(MINT_ADD_I8
)
3969 MINT_IN_CASE(MINT_ADD_R4
)
3972 MINT_IN_CASE(MINT_ADD_R8
)
3975 MINT_IN_CASE(MINT_ADD1_I4
)
3979 MINT_IN_CASE(MINT_ADD1_I8
)
3983 MINT_IN_CASE(MINT_SUB_I4
)
3986 MINT_IN_CASE(MINT_SUB_I8
)
3989 MINT_IN_CASE(MINT_SUB_R4
)
3992 MINT_IN_CASE(MINT_SUB_R8
)
3995 MINT_IN_CASE(MINT_SUB1_I4
)
3999 MINT_IN_CASE(MINT_SUB1_I8
)
4003 MINT_IN_CASE(MINT_MUL_I4
)
4006 MINT_IN_CASE(MINT_MUL_I8
)
4009 MINT_IN_CASE(MINT_MUL_R4
)
4012 MINT_IN_CASE(MINT_MUL_R8
)
4015 MINT_IN_CASE(MINT_DIV_I4
)
4016 if (sp
[-1].data
.i
== 0)
4017 THROW_EX_DIV_ZERO (ip
);
4018 if (sp
[-1].data
.i
== (-1) && sp
[-2].data
.i
== G_MININT32
)
4022 MINT_IN_CASE(MINT_DIV_I8
)
4023 if (sp
[-1].data
.l
== 0)
4024 THROW_EX_DIV_ZERO (ip
);
4025 if (sp
[-1].data
.l
== (-1) && sp
[-2].data
.l
== G_MININT64
)
4029 MINT_IN_CASE(MINT_DIV_R4
)
4032 MINT_IN_CASE(MINT_DIV_R8
)
4036 #define BINOP_CAST(datamem, op, type) \
4038 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4040 MINT_IN_CASE(MINT_DIV_UN_I4
)
4041 if (sp
[-1].data
.i
== 0)
4042 THROW_EX_DIV_ZERO (ip
);
4043 BINOP_CAST(i
, /, guint32
);
4045 MINT_IN_CASE(MINT_DIV_UN_I8
)
4046 if (sp
[-1].data
.l
== 0)
4047 THROW_EX_DIV_ZERO (ip
);
4048 BINOP_CAST(l
, /, guint64
);
4050 MINT_IN_CASE(MINT_REM_I4
)
4051 if (sp
[-1].data
.i
== 0)
4052 THROW_EX_DIV_ZERO (ip
);
4053 if (sp
[-1].data
.i
== (-1) && sp
[-2].data
.i
== G_MININT32
)
4057 MINT_IN_CASE(MINT_REM_I8
)
4058 if (sp
[-1].data
.l
== 0)
4059 THROW_EX_DIV_ZERO (ip
);
4060 if (sp
[-1].data
.l
== (-1) && sp
[-2].data
.l
== G_MININT64
)
4064 MINT_IN_CASE(MINT_REM_R4
)
4065 /* FIXME: what do we actually do here? */
4067 sp
[-1].data
.f_r4
= fmodf (sp
[-1].data
.f_r4
, sp
[0].data
.f_r4
);
4070 MINT_IN_CASE(MINT_REM_R8
)
4071 /* FIXME: what do we actually do here? */
4073 sp
[-1].data
.f
= fmod (sp
[-1].data
.f
, sp
[0].data
.f
);
4076 MINT_IN_CASE(MINT_REM_UN_I4
)
4077 if (sp
[-1].data
.i
== 0)
4078 THROW_EX_DIV_ZERO (ip
);
4079 BINOP_CAST(i
, %, guint32
);
4081 MINT_IN_CASE(MINT_REM_UN_I8
)
4082 if (sp
[-1].data
.l
== 0)
4083 THROW_EX_DIV_ZERO (ip
);
4084 BINOP_CAST(l
, %, guint64
);
4086 MINT_IN_CASE(MINT_AND_I4
)
4089 MINT_IN_CASE(MINT_AND_I8
)
4092 MINT_IN_CASE(MINT_OR_I4
)
4095 MINT_IN_CASE(MINT_OR_I8
)
4098 MINT_IN_CASE(MINT_XOR_I4
)
4101 MINT_IN_CASE(MINT_XOR_I8
)
4105 #define SHIFTOP(datamem, op) \
4107 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
4110 MINT_IN_CASE(MINT_SHL_I4
)
4113 MINT_IN_CASE(MINT_SHL_I8
)
4116 MINT_IN_CASE(MINT_SHR_I4
)
4119 MINT_IN_CASE(MINT_SHR_I8
)
4122 MINT_IN_CASE(MINT_SHR_UN_I4
)
4124 sp
[-1].data
.i
= (guint32
)sp
[-1].data
.i
>> sp
[0].data
.i
;
4127 MINT_IN_CASE(MINT_SHR_UN_I8
)
4129 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.l
>> sp
[0].data
.i
;
4132 MINT_IN_CASE(MINT_NEG_I4
)
4133 sp
[-1].data
.i
= - sp
[-1].data
.i
;
4136 MINT_IN_CASE(MINT_NEG_I8
)
4137 sp
[-1].data
.l
= - sp
[-1].data
.l
;
4140 MINT_IN_CASE(MINT_NEG_R4
)
4141 sp
[-1].data
.f_r4
= - sp
[-1].data
.f_r4
;
4144 MINT_IN_CASE(MINT_NEG_R8
)
4145 sp
[-1].data
.f
= - sp
[-1].data
.f
;
4148 MINT_IN_CASE(MINT_NOT_I4
)
4149 sp
[-1].data
.i
= ~ sp
[-1].data
.i
;
4152 MINT_IN_CASE(MINT_NOT_I8
)
4153 sp
[-1].data
.l
= ~ sp
[-1].data
.l
;
4156 MINT_IN_CASE(MINT_CONV_I1_I4
)
4157 sp
[-1].data
.i
= (gint8
)sp
[-1].data
.i
;
4160 MINT_IN_CASE(MINT_CONV_I1_I8
)
4161 sp
[-1].data
.i
= (gint8
)sp
[-1].data
.l
;
4164 MINT_IN_CASE(MINT_CONV_I1_R4
)
4165 sp
[-1].data
.i
= (gint8
) (gint32
) sp
[-1].data
.f_r4
;
4168 MINT_IN_CASE(MINT_CONV_I1_R8
)
4169 /* without gint32 cast, C compiler is allowed to use undefined
4170 * behaviour if data.f is bigger than >255. See conv.fpint section
4172 * > The conversion truncates; that is, the fractional part
4173 * > is discarded. The behavior is undefined if the truncated
4174 * > value cannot be represented in the destination type.
4176 sp
[-1].data
.i
= (gint8
) (gint32
) sp
[-1].data
.f
;
4179 MINT_IN_CASE(MINT_CONV_U1_I4
)
4180 sp
[-1].data
.i
= (guint8
)sp
[-1].data
.i
;
4183 MINT_IN_CASE(MINT_CONV_U1_I8
)
4184 sp
[-1].data
.i
= (guint8
)sp
[-1].data
.l
;
4187 MINT_IN_CASE(MINT_CONV_U1_R4
)
4188 sp
[-1].data
.i
= (guint8
) (guint32
) sp
[-1].data
.f_r4
;
4191 MINT_IN_CASE(MINT_CONV_U1_R8
)
4192 sp
[-1].data
.i
= (guint8
) (guint32
) sp
[-1].data
.f
;
4195 MINT_IN_CASE(MINT_CONV_I2_I4
)
4196 sp
[-1].data
.i
= (gint16
)sp
[-1].data
.i
;
4199 MINT_IN_CASE(MINT_CONV_I2_I8
)
4200 sp
[-1].data
.i
= (gint16
)sp
[-1].data
.l
;
4203 MINT_IN_CASE(MINT_CONV_I2_R4
)
4204 sp
[-1].data
.i
= (gint16
) (gint32
) sp
[-1].data
.f_r4
;
4207 MINT_IN_CASE(MINT_CONV_I2_R8
)
4208 sp
[-1].data
.i
= (gint16
) (gint32
) sp
[-1].data
.f
;
4211 MINT_IN_CASE(MINT_CONV_U2_I4
)
4212 sp
[-1].data
.i
= (guint16
)sp
[-1].data
.i
;
4215 MINT_IN_CASE(MINT_CONV_U2_I8
)
4216 sp
[-1].data
.i
= (guint16
)sp
[-1].data
.l
;
4219 MINT_IN_CASE(MINT_CONV_U2_R4
)
4220 sp
[-1].data
.i
= (guint16
) (guint32
) sp
[-1].data
.f_r4
;
4223 MINT_IN_CASE(MINT_CONV_U2_R8
)
4224 sp
[-1].data
.i
= (guint16
) (guint32
) sp
[-1].data
.f
;
4227 MINT_IN_CASE(MINT_CONV_I4_R4
)
4228 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f_r4
;
4231 MINT_IN_CASE(MINT_CONV_I4_R8
)
4232 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.f
;
4235 MINT_IN_CASE(MINT_CONV_U4_I8
)
4236 MINT_IN_CASE(MINT_CONV_I4_I8
)
4237 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.l
;
4240 MINT_IN_CASE(MINT_CONV_I4_I8_SP
)
4241 sp
[-2].data
.i
= (gint32
)sp
[-2].data
.l
;
4244 MINT_IN_CASE(MINT_CONV_U4_R4
)
4245 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U4
4246 sp
[-1].data
.i
= mono_rconv_u4 (sp
[-1].data
.f_r4
);
4248 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f_r4
;
4252 MINT_IN_CASE(MINT_CONV_U4_R8
)
4253 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U4
4254 sp
[-1].data
.i
= mono_fconv_u4_2 (sp
[-1].data
.f
);
4256 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f
;
4260 MINT_IN_CASE(MINT_CONV_I8_I4
)
4261 sp
[-1].data
.l
= sp
[-1].data
.i
;
4264 MINT_IN_CASE(MINT_CONV_I8_I4_SP
)
4265 sp
[-2].data
.l
= sp
[-2].data
.i
;
4268 MINT_IN_CASE(MINT_CONV_I8_U4
)
4269 sp
[-1].data
.l
= (guint32
)sp
[-1].data
.i
;
4272 MINT_IN_CASE(MINT_CONV_I8_R4
)
4273 sp
[-1].data
.l
= (gint64
) sp
[-1].data
.f_r4
;
4276 MINT_IN_CASE(MINT_CONV_I8_R8
)
4277 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
4280 MINT_IN_CASE(MINT_CONV_R4_I4
)
4281 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.i
;
4284 MINT_IN_CASE(MINT_CONV_R4_I8
)
4285 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.l
;
4288 MINT_IN_CASE(MINT_CONV_R4_R8
)
4289 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.f
;
4292 MINT_IN_CASE(MINT_CONV_R8_I4
)
4293 sp
[-1].data
.f
= (double)sp
[-1].data
.i
;
4296 MINT_IN_CASE(MINT_CONV_R8_I8
)
4297 sp
[-1].data
.f
= (double)sp
[-1].data
.l
;
4300 MINT_IN_CASE(MINT_CONV_R8_R4
)
4301 sp
[-1].data
.f
= (double) sp
[-1].data
.f_r4
;
4304 MINT_IN_CASE(MINT_CONV_R8_R4_SP
)
4305 sp
[-2].data
.f
= (double) sp
[-2].data
.f_r4
;
4308 MINT_IN_CASE(MINT_CONV_U8_I4
)
4309 sp
[-1].data
.l
= sp
[-1].data
.i
& 0xffffffff;
4312 MINT_IN_CASE(MINT_CONV_U8_R4
)
4313 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U8
4314 sp
[-1].data
.l
= mono_rconv_u8 (sp
[-1].data
.f_r4
);
4316 sp
[-1].data
.l
= (guint64
) sp
[-1].data
.f_r4
;
4320 MINT_IN_CASE(MINT_CONV_U8_R8
)
4321 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U8
4322 sp
[-1].data
.l
= mono_fconv_u8_2 (sp
[-1].data
.f
);
4324 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f
;
4328 MINT_IN_CASE(MINT_CPOBJ
) {
4329 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4330 g_assert (m_class_is_valuetype (c
));
4331 /* if this assertion fails, we need to add a write barrier */
4332 g_assert (!MONO_TYPE_IS_REFERENCE (m_class_get_byval_arg (c
)));
4333 stackval_from_data (m_class_get_byval_arg (c
), (stackval
*)sp
[-2].data
.p
, sp
[-1].data
.p
, FALSE
);
4338 MINT_IN_CASE(MINT_CPOBJ_VT
) {
4339 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4340 mono_value_copy_internal (sp
[-2].data
.vt
, sp
[-1].data
.vt
, c
);
4345 MINT_IN_CASE(MINT_LDOBJ_VT
) {
4346 int size
= READ32(ip
+ 1);
4348 memcpy (vt_sp
, sp
[-1].data
.p
, size
);
4349 sp
[-1].data
.p
= vt_sp
;
4350 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
4353 MINT_IN_CASE(MINT_LDSTR
)
4354 sp
->data
.p
= imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4358 MINT_IN_CASE(MINT_LDSTR_TOKEN
) {
4359 MonoString
*s
= NULL
;
4360 guint32 strtoken
= (guint32
)(gsize
)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4362 MonoMethod
*method
= imethod
->method
;
4363 if (method
->wrapper_type
== MONO_WRAPPER_DYNAMIC_METHOD
) {
4364 s
= (MonoString
*)mono_method_get_wrapper_data (method
, strtoken
);
4365 } else if (method
->wrapper_type
!= MONO_WRAPPER_NONE
) {
4366 s
= mono_string_new_wrapper_internal ((const char*)mono_method_get_wrapper_data (method
, strtoken
));
4368 g_assert_not_reached ();
4375 MINT_IN_CASE(MINT_NEWOBJ_ARRAY
) {
4376 MonoClass
*newobj_class
;
4377 guint32 token
= * (guint16
*)(ip
+ 1);
4378 guint16 param_count
= * (guint16
*)(ip
+ 2);
4380 newobj_class
= (MonoClass
*) imethod
->data_items
[token
];
4383 sp
->data
.o
= ves_array_create (imethod
->domain
, newobj_class
, param_count
, sp
, error
);
4385 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4391 MINT_IN_CASE(MINT_NEWOBJ_FAST
) {
4392 guint16 param_count
;
4393 guint16 imethod_index
= *(guint16
*) (ip
+ 1);
4395 const gboolean is_inlined
= imethod_index
== 0xffff;
4397 param_count
= *(guint16
*)(ip
+ 2);
4401 memmove (sp
+ 1 + is_inlined
, sp
, param_count
* sizeof (stackval
));
4404 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 3)];
4405 INIT_VTABLE (vtable
);
4407 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
4408 if (G_UNLIKELY (!frame_objref (frame
))) {
4409 mono_error_set_out_of_memory (error
, "Could not allocate %i bytes", m_class_get_instance_size (vtable
->klass
));
4410 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4413 sp
[0].data
.o
= frame_objref (frame
);
4415 sp
[1].data
.o
= frame_objref (frame
);
4416 sp
+= param_count
+ 2;
4418 InterpMethod
*ctor_method
= (InterpMethod
*) imethod
->data_items
[imethod_index
];
4421 child_frame
.imethod
= ctor_method
;
4422 child_frame
.stack_args
= sp
;
4424 interp_exec_method (&child_frame
, context
, error
);
4425 CHECK_RESUME_STATE (context
);
4426 sp
[0].data
.o
= frame_objref (frame
);
4433 MINT_IN_CASE(MINT_NEWOBJ_VT_FAST
)
4434 MINT_IN_CASE(MINT_NEWOBJ_VTST_FAST
) {
4435 guint16 param_count
;
4436 stackval valuetype_this
;
4440 child_frame
.imethod
= (InterpMethod
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4441 param_count
= *(guint16
*)(ip
+ 2);
4445 memmove (sp
+ 1, sp
, param_count
* sizeof (stackval
));
4447 child_frame
.stack_args
= sp
;
4449 gboolean vtst
= *ip
== MINT_NEWOBJ_VTST_FAST
;
4451 memset (vt_sp
, 0, *(guint16
*)(ip
+ 3));
4453 valuetype_this
.data
.p
= vt_sp
;
4456 memset (&valuetype_this
, 0, sizeof (stackval
));
4457 sp
->data
.p
= &valuetype_this
;
4461 interp_exec_method (&child_frame
, context
, error
);
4463 CHECK_RESUME_STATE (context
);
4465 *sp
= valuetype_this
;
4469 MINT_IN_CASE(MINT_NEWOBJ
) {
4470 MonoClass
*newobj_class
;
4471 MonoMethodSignature
*csig
;
4472 stackval valuetype_this
;
4478 token
= * (guint16
*)(ip
+ 1);
4481 child_frame
.ip
= NULL
;
4482 child_frame
.ex
= NULL
;
4484 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[token
];
4485 csig
= mono_method_signature_internal (child_frame
.imethod
->method
);
4486 newobj_class
= child_frame
.imethod
->method
->klass
;
4487 /*if (profiling_classes) {
4488 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
4490 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
4493 g_assert (csig
->hasthis
);
4494 if (csig
->param_count
) {
4495 sp
-= csig
->param_count
;
4496 memmove (sp
+ 1, sp
, csig
->param_count
* sizeof (stackval
));
4498 child_frame
.stack_args
= sp
;
4501 * First arg is the object.
4503 if (m_class_is_valuetype (newobj_class
)) {
4504 MonoType
*t
= m_class_get_byval_arg (newobj_class
);
4505 memset (&valuetype_this
, 0, sizeof (stackval
));
4506 if (!m_class_is_enumtype (newobj_class
) && (t
->type
== MONO_TYPE_VALUETYPE
|| (t
->type
== MONO_TYPE_GENERICINST
&& mono_type_generic_inst_is_valuetype (t
)))) {
4508 valuetype_this
.data
.p
= vt_sp
;
4510 sp
->data
.p
= &valuetype_this
;
4513 if (newobj_class
!= mono_defaults
.string_class
) {
4514 MonoVTable
*vtable
= mono_class_vtable_checked (imethod
->domain
, newobj_class
, error
);
4515 if (!is_ok (error
) || !mono_runtime_class_init_full (vtable
, error
))
4516 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4517 frame_objref (frame
) = mono_object_new_checked (imethod
->domain
, newobj_class
, error
);
4518 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4519 EXCEPTION_CHECKPOINT
;
4520 sp
->data
.o
= frame_objref (frame
);
4521 #ifndef DISABLE_REMOTING
4522 if (mono_object_is_transparent_proxy (frame_objref (frame
))) {
4523 MonoMethod
*remoting_invoke_method
= mono_marshal_get_remoting_invoke_with_check (child_frame
.imethod
->method
, error
);
4524 mono_error_assert_ok (error
);
4525 child_frame
.imethod
= mono_interp_get_imethod (imethod
->domain
, remoting_invoke_method
, error
);
4526 mono_error_assert_ok (error
);
4531 child_frame
.retval
= &retval
;
4535 interp_exec_method (&child_frame
, context
, error
);
4537 CHECK_RESUME_STATE (context
);
4540 * a constructor returns void, but we need to return the object we created
4542 if (m_class_is_valuetype (newobj_class
) && !m_class_is_enumtype (newobj_class
)) {
4543 *sp
= valuetype_this
;
4544 } else if (newobj_class
== mono_defaults
.string_class
) {
4547 sp
->data
.o
= frame_objref (frame
);
4552 MINT_IN_CASE(MINT_NEWOBJ_MAGIC
) {
4558 MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_CTOR
) {
4559 MonoMethodSignature
*csig
;
4563 token
= * (guint16
*)(ip
+ 1);
4566 InterpMethod
*cmethod
= (InterpMethod
*)imethod
->data_items
[token
];
4567 csig
= mono_method_signature_internal (cmethod
->method
);
4569 g_assert (csig
->hasthis
);
4570 sp
-= csig
->param_count
;
4572 gpointer arg0
= sp
[0].data
.p
;
4574 gpointer
*byreference_this
= (gpointer
*)vt_sp
;
4575 *byreference_this
= arg0
;
4577 /* Followed by a VTRESULT opcode which will push the result on the stack */
4581 MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_GET_VALUE
) {
4582 gpointer
*byreference_this
= (gpointer
*)sp
[-1].data
.p
;
4583 sp
[-1].data
.p
= *byreference_this
;
4587 MINT_IN_CASE(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET
) {
4589 sp
[0].data
.p
= (guint8
*)sp
[0].data
.p
+ sp
[1].data
.nati
;
4594 MINT_IN_CASE(MINT_INTRINS_UNSAFE_BYTE_OFFSET
) {
4596 sp
[0].data
.nati
= (guint8
*)sp
[1].data
.p
- (guint8
*)sp
[0].data
.p
;
4601 MINT_IN_CASE(MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE
) {
4603 MonoObject
*obj
= sp
[0].data
.o
;
4604 sp
[0].data
.i
= (obj
->vtable
->flags
& MONO_VT_FLAG_ARRAY_OR_STRING
) != 0;
4609 MINT_IN_CASE(MINT_CASTCLASS_INTERFACE
)
4610 MINT_IN_CASE(MINT_ISINST_INTERFACE
) {
4611 gboolean isinst_instr
= *ip
== MINT_ISINST_INTERFACE
;
4612 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4613 if ((o
= sp
[-1].data
.o
)) {
4615 if (MONO_VTABLE_IMPLEMENTS_INTERFACE (o
->vtable
, m_class_get_interface_id (c
))) {
4617 } else if (m_class_is_array_special_interface (c
) || mono_object_is_transparent_proxy (o
)) {
4619 isinst
= mono_object_isinst_checked (o
, c
, error
) != NULL
;
4620 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4627 sp
[-1].data
.p
= NULL
;
4629 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4635 MINT_IN_CASE(MINT_CASTCLASS_COMMON
)
4636 MINT_IN_CASE(MINT_ISINST_COMMON
) {
4637 gboolean isinst_instr
= *ip
== MINT_ISINST_COMMON
;
4638 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4639 if ((o
= sp
[-1].data
.o
)) {
4640 gboolean isinst
= mono_class_has_parent_fast (o
->vtable
->klass
, c
);
4644 sp
[-1].data
.p
= NULL
;
4646 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4652 MINT_IN_CASE(MINT_CASTCLASS
)
4653 MINT_IN_CASE(MINT_ISINST
) {
4654 gboolean isinst_instr
= *ip
== MINT_ISINST
;
4655 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4656 if ((o
= sp
[-1].data
.o
)) {
4657 MonoObject
*isinst_obj
= mono_object_isinst_checked (o
, c
, error
);
4658 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4661 sp
[-1].data
.p
= NULL
;
4663 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4669 MINT_IN_CASE(MINT_CONV_R_UN_I4
)
4670 sp
[-1].data
.f
= (double)(guint32
)sp
[-1].data
.i
;
4673 MINT_IN_CASE(MINT_CONV_R_UN_I8
)
4674 sp
[-1].data
.f
= (double)(guint64
)sp
[-1].data
.l
;
4677 MINT_IN_CASE(MINT_UNBOX
)
4678 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4683 if (!(m_class_get_rank (o
->vtable
->klass
) == 0 && m_class_get_element_class (o
->vtable
->klass
) == m_class_get_element_class (c
)))
4684 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4686 sp
[-1].data
.p
= mono_object_unbox_internal (o
);
4689 MINT_IN_CASE(MINT_THROW
)
4692 sp
->data
.p
= mono_get_exception_null_reference ();
4694 THROW_EX ((MonoException
*)sp
->data
.p
, ip
);
4696 MINT_IN_CASE(MINT_CHECKPOINT
)
4697 /* Do synchronous checking of abort requests */
4698 EXCEPTION_CHECKPOINT
;
4701 MINT_IN_CASE(MINT_SAFEPOINT
)
4702 /* Do synchronous checking of abort requests */
4703 EXCEPTION_CHECKPOINT
;
4704 /* Poll safepoint */
4705 mono_threads_safepoint ();
4708 MINT_IN_CASE(MINT_LDFLDA_UNSAFE
)
4710 sp
[-1].data
.p
= (char *)o
+ * (guint16
*)(ip
+ 1);
4713 MINT_IN_CASE(MINT_LDFLDA
)
4716 sp
[-1].data
.p
= (char *)o
+ * (guint16
*)(ip
+ 1);
4719 MINT_IN_CASE(MINT_CKNULL_N
) {
4720 /* Same as CKNULL, but further down the stack */
4721 int n
= *(guint16
*)(ip
+ 1);
4728 #define LDFLD_UNALIGNED(datamem, fieldtype, unaligned) \
4729 o = sp [-1].data.o; \
4732 memcpy (&sp[-1].data.datamem, (char *)o + * (guint16 *)(ip + 1), sizeof (fieldtype)); \
4734 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
4737 #define LDFLD(datamem, fieldtype) LDFLD_UNALIGNED(datamem, fieldtype, FALSE)
4739 MINT_IN_CASE(MINT_LDFLD_I1
) LDFLD(i
, gint8
); MINT_IN_BREAK
;
4740 MINT_IN_CASE(MINT_LDFLD_U1
) LDFLD(i
, guint8
); MINT_IN_BREAK
;
4741 MINT_IN_CASE(MINT_LDFLD_I2
) LDFLD(i
, gint16
); MINT_IN_BREAK
;
4742 MINT_IN_CASE(MINT_LDFLD_U2
) LDFLD(i
, guint16
); MINT_IN_BREAK
;
4743 MINT_IN_CASE(MINT_LDFLD_I4
) LDFLD(i
, gint32
); MINT_IN_BREAK
;
4744 MINT_IN_CASE(MINT_LDFLD_I8
) LDFLD(l
, gint64
); MINT_IN_BREAK
;
4745 MINT_IN_CASE(MINT_LDFLD_R4
) LDFLD(f_r4
, float); MINT_IN_BREAK
;
4746 MINT_IN_CASE(MINT_LDFLD_R8
) LDFLD(f
, double); MINT_IN_BREAK
;
4747 MINT_IN_CASE(MINT_LDFLD_O
) LDFLD(p
, gpointer
); MINT_IN_BREAK
;
4748 MINT_IN_CASE(MINT_LDFLD_P
) LDFLD(p
, gpointer
); MINT_IN_BREAK
;
4749 MINT_IN_CASE(MINT_LDFLD_I8_UNALIGNED
) LDFLD_UNALIGNED(l
, gint64
, TRUE
); MINT_IN_BREAK
;
4750 MINT_IN_CASE(MINT_LDFLD_R8_UNALIGNED
) LDFLD_UNALIGNED(f
, double, TRUE
); MINT_IN_BREAK
;
4752 MINT_IN_CASE(MINT_LDFLD_VT
) {
4756 int size
= READ32(ip
+ 2);
4757 sp
[-1].data
.p
= vt_sp
;
4758 memcpy (sp
[-1].data
.p
, (char *)o
+ * (guint16
*)(ip
+ 1), size
);
4759 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
4764 MINT_IN_CASE(MINT_LDRMFLD
) {
4765 MonoClassField
*field
;
4770 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4772 #ifndef DISABLE_REMOTING
4774 if (mono_object_is_transparent_proxy (o
)) {
4775 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4777 addr
= (char*)mono_load_remote_field_checked (o
, klass
, field
, &tmp
, error
);
4778 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4781 addr
= (char*)o
+ field
->offset
;
4783 stackval_from_data (field
->type
, &sp
[-1], addr
, FALSE
);
4787 MINT_IN_CASE(MINT_LDRMFLD_VT
) {
4788 MonoClassField
*field
;
4794 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4795 MonoClass
*klass
= mono_class_from_mono_type_internal (field
->type
);
4796 i32
= mono_class_value_size (klass
, NULL
);
4799 #ifndef DISABLE_REMOTING
4801 if (mono_object_is_transparent_proxy (o
)) {
4802 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4803 addr
= (char*)mono_load_remote_field_checked (o
, klass
, field
, &tmp
, error
);
4804 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4807 addr
= (char*)o
+ field
->offset
;
4809 sp
[-1].data
.p
= vt_sp
;
4810 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4811 memcpy(sp
[-1].data
.p
, addr
, i32
);
4815 #define STFLD_UNALIGNED(datamem, fieldtype, unaligned) \
4816 o = sp [-2].data.o; \
4820 memcpy ((char *)o + * (guint16 *)(ip + 1), &sp[1].data.datamem, sizeof (fieldtype)); \
4822 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
4825 #define STFLD(datamem, fieldtype) STFLD_UNALIGNED(datamem, fieldtype, FALSE)
4827 MINT_IN_CASE(MINT_STFLD_I1
) STFLD(i
, gint8
); MINT_IN_BREAK
;
4828 MINT_IN_CASE(MINT_STFLD_U1
) STFLD(i
, guint8
); MINT_IN_BREAK
;
4829 MINT_IN_CASE(MINT_STFLD_I2
) STFLD(i
, gint16
); MINT_IN_BREAK
;
4830 MINT_IN_CASE(MINT_STFLD_U2
) STFLD(i
, guint16
); MINT_IN_BREAK
;
4831 MINT_IN_CASE(MINT_STFLD_I4
) STFLD(i
, gint32
); MINT_IN_BREAK
;
4832 MINT_IN_CASE(MINT_STFLD_I8
) STFLD(l
, gint64
); MINT_IN_BREAK
;
4833 MINT_IN_CASE(MINT_STFLD_R4
) STFLD(f_r4
, float); MINT_IN_BREAK
;
4834 MINT_IN_CASE(MINT_STFLD_R8
) STFLD(f
, double); MINT_IN_BREAK
;
4835 MINT_IN_CASE(MINT_STFLD_P
) STFLD(p
, gpointer
); MINT_IN_BREAK
;
4836 MINT_IN_CASE(MINT_STFLD_O
)
4840 mono_gc_wbarrier_set_field_internal (o
, (char *) o
+ * (guint16
*)(ip
+ 1), sp
[1].data
.o
);
4843 MINT_IN_CASE(MINT_STFLD_I8_UNALIGNED
) STFLD_UNALIGNED(l
, gint64
, TRUE
); MINT_IN_BREAK
;
4844 MINT_IN_CASE(MINT_STFLD_R8_UNALIGNED
) STFLD_UNALIGNED(f
, double, TRUE
); MINT_IN_BREAK
;
4846 MINT_IN_CASE(MINT_STFLD_VT
) {
4851 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 2)];
4852 i32
= mono_class_value_size (klass
, NULL
);
4854 guint16 offset
= * (guint16
*)(ip
+ 1);
4855 mono_value_copy_internal ((char *) o
+ offset
, sp
[1].data
.p
, klass
);
4857 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4861 MINT_IN_CASE(MINT_STRMFLD
) {
4862 MonoClassField
*field
;
4867 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4870 #ifndef DISABLE_REMOTING
4871 if (mono_object_is_transparent_proxy (o
)) {
4872 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4873 mono_store_remote_field_checked (o
, klass
, field
, &sp
[-1].data
, error
);
4874 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4877 stackval_to_data (field
->type
, &sp
[-1], (char*)o
+ field
->offset
, FALSE
);
4882 MINT_IN_CASE(MINT_STRMFLD_VT
) {
4883 MonoClassField
*field
;
4887 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4888 MonoClass
*klass
= mono_class_from_mono_type_internal (field
->type
);
4889 i32
= mono_class_value_size (klass
, NULL
);
4892 #ifndef DISABLE_REMOTING
4893 if (mono_object_is_transparent_proxy (o
)) {
4894 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4895 mono_store_remote_field_checked (o
, klass
, field
, sp
[-1].data
.p
, error
);
4896 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4899 mono_value_copy_internal ((char *) o
+ field
->offset
, sp
[-1].data
.p
, klass
);
4902 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4905 MINT_IN_CASE(MINT_LDSFLDA
) {
4906 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4907 INIT_VTABLE (vtable
);
4908 sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
4914 MINT_IN_CASE(MINT_LDSSFLDA
) {
4915 guint32 offset
= READ32(ip
+ 1);
4916 sp
->data
.p
= mono_get_special_static_data (offset
);
4922 /* We init class here to preserve cctor order */
4923 #define LDSFLD(datamem, fieldtype) { \
4924 MonoVTable *vtable = (MonoVTable*) imethod->data_items [*(guint16*)(ip + 1)]; \
4925 INIT_VTABLE (vtable); \
4926 sp[0].data.datamem = * (fieldtype *)(imethod->data_items [* (guint16 *)(ip + 2)]) ; \
4931 MINT_IN_CASE(MINT_LDSFLD_I1
) LDSFLD(i
, gint8
); MINT_IN_BREAK
;
4932 MINT_IN_CASE(MINT_LDSFLD_U1
) LDSFLD(i
, guint8
); MINT_IN_BREAK
;
4933 MINT_IN_CASE(MINT_LDSFLD_I2
) LDSFLD(i
, gint16
); MINT_IN_BREAK
;
4934 MINT_IN_CASE(MINT_LDSFLD_U2
) LDSFLD(i
, guint16
); MINT_IN_BREAK
;
4935 MINT_IN_CASE(MINT_LDSFLD_I4
) LDSFLD(i
, gint32
); MINT_IN_BREAK
;
4936 MINT_IN_CASE(MINT_LDSFLD_I8
) LDSFLD(l
, gint64
); MINT_IN_BREAK
;
4937 MINT_IN_CASE(MINT_LDSFLD_R4
) LDSFLD(f_r4
, float); MINT_IN_BREAK
;
4938 MINT_IN_CASE(MINT_LDSFLD_R8
) LDSFLD(f
, double); MINT_IN_BREAK
;
4939 MINT_IN_CASE(MINT_LDSFLD_O
) LDSFLD(p
, gpointer
); MINT_IN_BREAK
;
4940 MINT_IN_CASE(MINT_LDSFLD_P
) LDSFLD(p
, gpointer
); MINT_IN_BREAK
;
4942 MINT_IN_CASE(MINT_LDSFLD_VT
) {
4943 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4944 gpointer addr
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
4945 i32
= READ32(ip
+ 3);
4946 INIT_VTABLE (vtable
);
4949 memcpy (vt_sp
, addr
, i32
);
4950 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4956 #define LDTSFLD(datamem, fieldtype) { \
4957 guint32 offset = READ32(ip + 1); \
4958 MonoInternalThread *thread = mono_thread_internal_current (); \
4959 gpointer addr = ((char*)thread->static_data [offset & 0x3f]) + (offset >> 6); \
4960 sp[0].data.datamem = *(fieldtype*)addr; \
4964 MINT_IN_CASE(MINT_LDTSFLD_I1
) LDTSFLD(i
, gint8
); MINT_IN_BREAK
;
4965 MINT_IN_CASE(MINT_LDTSFLD_U1
) LDTSFLD(i
, guint8
); MINT_IN_BREAK
;
4966 MINT_IN_CASE(MINT_LDTSFLD_I2
) LDTSFLD(i
, gint16
); MINT_IN_BREAK
;
4967 MINT_IN_CASE(MINT_LDTSFLD_U2
) LDTSFLD(i
, guint16
); MINT_IN_BREAK
;
4968 MINT_IN_CASE(MINT_LDTSFLD_I4
) LDTSFLD(i
, gint32
); MINT_IN_BREAK
;
4969 MINT_IN_CASE(MINT_LDTSFLD_I8
) LDTSFLD(l
, gint64
); MINT_IN_BREAK
;
4970 MINT_IN_CASE(MINT_LDTSFLD_R4
) LDTSFLD(f_r4
, float); MINT_IN_BREAK
;
4971 MINT_IN_CASE(MINT_LDTSFLD_R8
) LDTSFLD(f
, double); MINT_IN_BREAK
;
4972 MINT_IN_CASE(MINT_LDTSFLD_O
) LDTSFLD(p
, gpointer
); MINT_IN_BREAK
;
4973 MINT_IN_CASE(MINT_LDTSFLD_P
) LDTSFLD(p
, gpointer
); MINT_IN_BREAK
;
4975 MINT_IN_CASE(MINT_LDSSFLD
) {
4976 MonoClassField
*field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4977 guint32 offset
= READ32(ip
+ 2);
4978 gpointer addr
= mono_get_special_static_data (offset
);
4979 stackval_from_data (field
->type
, sp
, addr
, FALSE
);
4984 MINT_IN_CASE(MINT_LDSSFLD_VT
) {
4985 guint32 offset
= READ32(ip
+ 1);
4986 gpointer addr
= mono_get_special_static_data (offset
);
4988 int size
= READ32 (ip
+ 3);
4989 memcpy (vt_sp
, addr
, size
);
4991 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
4996 #define STSFLD(datamem, fieldtype) { \
4997 MonoVTable *vtable = (MonoVTable*) imethod->data_items [*(guint16*)(ip + 1)]; \
4998 INIT_VTABLE (vtable); \
5000 * (fieldtype *)(imethod->data_items [* (guint16 *)(ip + 2)]) = sp[0].data.datamem; \
5004 MINT_IN_CASE(MINT_STSFLD_I1
) STSFLD(i
, gint8
); MINT_IN_BREAK
;
5005 MINT_IN_CASE(MINT_STSFLD_U1
) STSFLD(i
, guint8
); MINT_IN_BREAK
;
5006 MINT_IN_CASE(MINT_STSFLD_I2
) STSFLD(i
, gint16
); MINT_IN_BREAK
;
5007 MINT_IN_CASE(MINT_STSFLD_U2
) STSFLD(i
, guint16
); MINT_IN_BREAK
;
5008 MINT_IN_CASE(MINT_STSFLD_I4
) STSFLD(i
, gint32
); MINT_IN_BREAK
;
5009 MINT_IN_CASE(MINT_STSFLD_I8
) STSFLD(l
, gint64
); MINT_IN_BREAK
;
5010 MINT_IN_CASE(MINT_STSFLD_R4
) STSFLD(f_r4
, float); MINT_IN_BREAK
;
5011 MINT_IN_CASE(MINT_STSFLD_R8
) STSFLD(f
, double); MINT_IN_BREAK
;
5012 MINT_IN_CASE(MINT_STSFLD_P
) STSFLD(p
, gpointer
); MINT_IN_BREAK
;
5013 MINT_IN_CASE(MINT_STSFLD_O
) STSFLD(p
, gpointer
); MINT_IN_BREAK
;
5015 MINT_IN_CASE(MINT_STSFLD_VT
) {
5016 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5017 gpointer addr
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
5018 i32
= READ32(ip
+ 3);
5019 INIT_VTABLE (vtable
);
5021 memcpy (addr
, sp
[-1].data
.vt
, i32
);
5022 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5028 #define STTSFLD(datamem, fieldtype) { \
5029 guint32 offset = READ32(ip + 1); \
5030 MonoInternalThread *thread = mono_thread_internal_current (); \
5031 gpointer addr = ((char*)thread->static_data [offset & 0x3f]) + (offset >> 6); \
5033 *(fieldtype*)addr = sp[0].data.datamem; \
5037 MINT_IN_CASE(MINT_STTSFLD_I1
) STTSFLD(i
, gint8
); MINT_IN_BREAK
;
5038 MINT_IN_CASE(MINT_STTSFLD_U1
) STTSFLD(i
, guint8
); MINT_IN_BREAK
;
5039 MINT_IN_CASE(MINT_STTSFLD_I2
) STTSFLD(i
, gint16
); MINT_IN_BREAK
;
5040 MINT_IN_CASE(MINT_STTSFLD_U2
) STTSFLD(i
, guint16
); MINT_IN_BREAK
;
5041 MINT_IN_CASE(MINT_STTSFLD_I4
) STTSFLD(i
, gint32
); MINT_IN_BREAK
;
5042 MINT_IN_CASE(MINT_STTSFLD_I8
) STTSFLD(l
, gint64
); MINT_IN_BREAK
;
5043 MINT_IN_CASE(MINT_STTSFLD_R4
) STTSFLD(f_r4
, float); MINT_IN_BREAK
;
5044 MINT_IN_CASE(MINT_STTSFLD_R8
) STTSFLD(f
, double); MINT_IN_BREAK
;
5045 MINT_IN_CASE(MINT_STTSFLD_P
) STTSFLD(p
, gpointer
); MINT_IN_BREAK
;
5046 MINT_IN_CASE(MINT_STTSFLD_O
) STTSFLD(p
, gpointer
); MINT_IN_BREAK
;
5048 MINT_IN_CASE(MINT_STSSFLD
) {
5049 MonoClassField
*field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5050 guint32 offset
= READ32(ip
+ 2);
5051 gpointer addr
= mono_get_special_static_data (offset
);
5053 stackval_to_data (field
->type
, sp
, addr
, FALSE
);
5057 MINT_IN_CASE(MINT_STSSFLD_VT
) {
5058 guint32 offset
= READ32(ip
+ 1);
5059 gpointer addr
= mono_get_special_static_data (offset
);
5061 int size
= READ32 (ip
+ 3);
5062 memcpy (addr
, sp
->data
.vt
, size
);
5063 vt_sp
-= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5068 MINT_IN_CASE(MINT_STOBJ_VT
) {
5070 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5072 size
= mono_class_value_size (c
, NULL
);
5073 mono_value_copy_internal (sp
[-2].data
.p
, sp
[-1].data
.p
, c
);
5074 vt_sp
-= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5078 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8
)
5079 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT32
)
5081 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.f
;
5084 MINT_IN_CASE(MINT_CONV_OVF_U8_I4
)
5085 if (sp
[-1].data
.i
< 0)
5087 sp
[-1].data
.l
= sp
[-1].data
.i
;
5090 MINT_IN_CASE(MINT_CONV_OVF_U8_I8
)
5091 if (sp
[-1].data
.l
< 0)
5095 MINT_IN_CASE(MINT_CONV_OVF_I8_U8
)
5096 if ((guint64
) sp
[-1].data
.l
> G_MAXINT64
)
5100 MINT_IN_CASE(MINT_CONV_OVF_U8_R4
)
5101 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXUINT64
|| isnan (sp
[-1].data
.f_r4
))
5103 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f_r4
;
5106 MINT_IN_CASE(MINT_CONV_OVF_U8_R8
)
5107 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT64
|| isnan (sp
[-1].data
.f
))
5109 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f
;
5112 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8
)
5113 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT64
)
5115 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
5118 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R4
)
5119 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXINT64
)
5121 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f_r4
;
5124 MINT_IN_CASE(MINT_CONV_OVF_I8_R4
)
5125 if (sp
[-1].data
.f_r4
< G_MININT64
|| sp
[-1].data
.f_r4
> G_MAXINT64
|| isnan (sp
[-1].data
.f_r4
))
5127 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f_r4
;
5130 MINT_IN_CASE(MINT_CONV_OVF_I8_R8
)
5131 if (sp
[-1].data
.f
< G_MININT64
|| sp
[-1].data
.f
> G_MAXINT64
|| isnan (sp
[-1].data
.f
))
5133 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
5136 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8
)
5137 if ((guint64
)sp
[-1].data
.l
> G_MAXINT32
)
5139 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.l
;
5142 MINT_IN_CASE(MINT_BOX
) {
5143 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5144 guint16 offset
= * (guint16
*)(ip
+ 2);
5146 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
5147 stackval_to_data (m_class_get_byval_arg (vtable
->klass
), &sp
[-1 - offset
], mono_object_get_data (frame_objref (frame
)), FALSE
);
5149 sp
[-1 - offset
].data
.p
= frame_objref (frame
);
5154 MINT_IN_CASE(MINT_BOX_VT
) {
5155 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5157 guint16 offset
= * (guint16
*)(ip
+ 2);
5158 gboolean pop_vt_sp
= !(offset
& BOX_NOT_CLEAR_VT_SP
);
5159 offset
&= ~BOX_NOT_CLEAR_VT_SP
;
5161 int size
= mono_class_value_size (c
, NULL
);
5162 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
5163 mono_value_copy_internal (mono_object_get_data (frame_objref (frame
)), sp
[-1 - offset
].data
.p
, c
);
5165 sp
[-1 - offset
].data
.p
= frame_objref (frame
);
5166 size
= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5173 MINT_IN_CASE(MINT_BOX_NULLABLE
) {
5174 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5175 guint16 offset
= * (guint16
*)(ip
+ 2);
5176 gboolean pop_vt_sp
= !(offset
& BOX_NOT_CLEAR_VT_SP
);
5177 offset
&= ~BOX_NOT_CLEAR_VT_SP
;
5179 int size
= mono_class_value_size (c
, NULL
);
5181 sp
[-1 - offset
].data
.o
= mono_nullable_box (sp
[-1 - offset
].data
.p
, c
, error
);
5182 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5184 size
= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5191 MINT_IN_CASE(MINT_NEWARR
) {
5192 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5193 sp
[-1].data
.o
= (MonoObject
*) mono_array_new_specific_checked (vtable
, sp
[-1].data
.i
, error
);
5194 if (!is_ok (error
)) {
5195 THROW_EX (mono_error_convert_to_exception (error
), ip
);
5197 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5199 /*if (profiling_classes) {
5200 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
5202 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
5207 MINT_IN_CASE(MINT_LDLEN
)
5210 sp
[-1].data
.nati
= mono_array_length_internal ((MonoArray
*)o
);
5213 MINT_IN_CASE(MINT_LDLEN_SPAN
) {
5216 gsize offset_length
= (gsize
) *(gint16
*) (ip
+ 1);
5217 sp
[-1].data
.nati
= *(gint32
*) ((guint8
*) o
+ offset_length
);
5221 MINT_IN_CASE(MINT_GETCHR
) {
5223 s
= (MonoString
*)sp
[-2].data
.p
;
5225 i32
= sp
[-1].data
.i
;
5226 if (i32
< 0 || i32
>= mono_string_length_internal (s
))
5227 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5229 sp
[-1].data
.i
= mono_string_chars_internal (s
)[i32
];
5233 MINT_IN_CASE(MINT_GETITEM_SPAN
) {
5234 guint8
*span
= (guint8
*) sp
[-2].data
.p
;
5235 int index
= sp
[-1].data
.i
;
5236 gsize element_size
= (gsize
) *(gint16
*) (ip
+ 1);
5237 gsize offset_length
= (gsize
) *(gint16
*) (ip
+ 2);
5238 gsize offset_pointer
= (gsize
) *(gint16
*) (ip
+ 3);
5243 gint32 length
= *(gint32
*) (span
+ offset_length
);
5244 if (index
< 0 || index
>= length
)
5245 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5247 gpointer pointer
= *(gpointer
*)(span
+ offset_pointer
);
5248 sp
[-1].data
.p
= (guint8
*) pointer
+ index
* element_size
;
5253 MINT_IN_CASE(MINT_STRLEN
)
5257 sp
[-1].data
.i
= mono_string_length_internal ((MonoString
*) o
);
5259 MINT_IN_CASE(MINT_ARRAY_RANK
)
5262 sp
[-1].data
.i
= m_class_get_rank (mono_object_class (sp
[-1].data
.p
));
5265 MINT_IN_CASE(MINT_LDELEMA_FAST
) {
5266 /* No bounds, one direction */
5267 gint32 size
= READ32 (ip
+ 1);
5268 gint32 index
= sp
[-1].data
.i
;
5270 MonoArray
*ao
= (MonoArray
*)sp
[-2].data
.o
;
5272 if (index
>= ao
->max_length
)
5273 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5274 sp
[-2].data
.p
= mono_array_addr_with_size_fast (ao
, size
, index
);
5280 MINT_IN_CASE(MINT_LDELEMA
)
5281 MINT_IN_CASE(MINT_LDELEMA_TC
) {
5282 gboolean needs_typecheck
= *ip
== MINT_LDELEMA_TC
;
5284 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[*(guint16
*) (ip
+ 1)];
5285 guint16 numargs
= *(guint16
*) (ip
+ 2);
5291 sp
->data
.p
= ves_array_element_address (frame
, klass
, (MonoArray
*) o
, &sp
[1], needs_typecheck
);
5293 THROW_EX (frame
->ex
, ip
);
5298 MINT_IN_CASE(MINT_LDELEM_I1
) /* fall through */
5299 MINT_IN_CASE(MINT_LDELEM_U1
) /* fall through */
5300 MINT_IN_CASE(MINT_LDELEM_I2
) /* fall through */
5301 MINT_IN_CASE(MINT_LDELEM_U2
) /* fall through */
5302 MINT_IN_CASE(MINT_LDELEM_I4
) /* fall through */
5303 MINT_IN_CASE(MINT_LDELEM_U4
) /* fall through */
5304 MINT_IN_CASE(MINT_LDELEM_I8
) /* fall through */
5305 MINT_IN_CASE(MINT_LDELEM_I
) /* fall through */
5306 MINT_IN_CASE(MINT_LDELEM_R4
) /* fall through */
5307 MINT_IN_CASE(MINT_LDELEM_R8
) /* fall through */
5308 MINT_IN_CASE(MINT_LDELEM_REF
) /* fall through */
5309 MINT_IN_CASE(MINT_LDELEM_VT
) {
5315 o
= (MonoArray
*)sp
[0].data
.p
;
5318 aindex
= sp
[1].data
.i
;
5319 if (aindex
>= mono_array_length_internal (o
))
5320 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5323 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
5326 case MINT_LDELEM_I1
:
5327 sp
[0].data
.i
= mono_array_get_fast (o
, gint8
, aindex
);
5329 case MINT_LDELEM_U1
:
5330 sp
[0].data
.i
= mono_array_get_fast (o
, guint8
, aindex
);
5332 case MINT_LDELEM_I2
:
5333 sp
[0].data
.i
= mono_array_get_fast (o
, gint16
, aindex
);
5335 case MINT_LDELEM_U2
:
5336 sp
[0].data
.i
= mono_array_get_fast (o
, guint16
, aindex
);
5339 sp
[0].data
.nati
= mono_array_get_fast (o
, mono_i
, aindex
);
5341 case MINT_LDELEM_I4
:
5342 sp
[0].data
.i
= mono_array_get_fast (o
, gint32
, aindex
);
5344 case MINT_LDELEM_U4
:
5345 sp
[0].data
.i
= mono_array_get_fast (o
, guint32
, aindex
);
5347 case MINT_LDELEM_I8
:
5348 sp
[0].data
.l
= mono_array_get_fast (o
, guint64
, aindex
);
5350 case MINT_LDELEM_R4
:
5351 sp
[0].data
.f_r4
= mono_array_get_fast (o
, float, aindex
);
5353 case MINT_LDELEM_R8
:
5354 sp
[0].data
.f
= mono_array_get_fast (o
, double, aindex
);
5356 case MINT_LDELEM_REF
:
5357 sp
[0].data
.p
= mono_array_get_fast (o
, gpointer
, aindex
);
5359 case MINT_LDELEM_VT
: {
5360 i32
= READ32 (ip
+ 1);
5361 char *src_addr
= mono_array_addr_with_size_fast ((MonoArray
*) o
, i32
, aindex
);
5362 sp
[0].data
.vt
= vt_sp
;
5363 // Copying to vtstack. No wbarrier needed
5364 memcpy (sp
[0].data
.vt
, src_addr
, i32
);
5365 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5377 MINT_IN_CASE(MINT_STELEM_I
) /* fall through */
5378 MINT_IN_CASE(MINT_STELEM_I1
) /* fall through */
5379 MINT_IN_CASE(MINT_STELEM_U1
) /* fall through */
5380 MINT_IN_CASE(MINT_STELEM_I2
) /* fall through */
5381 MINT_IN_CASE(MINT_STELEM_U2
) /* fall through */
5382 MINT_IN_CASE(MINT_STELEM_I4
) /* fall through */
5383 MINT_IN_CASE(MINT_STELEM_I8
) /* fall through */
5384 MINT_IN_CASE(MINT_STELEM_R4
) /* fall through */
5385 MINT_IN_CASE(MINT_STELEM_R8
) /* fall through */
5386 MINT_IN_CASE(MINT_STELEM_REF
) /* fall through */
5387 MINT_IN_CASE(MINT_STELEM_VT
) {
5395 aindex
= sp
[1].data
.i
;
5396 if (aindex
>= mono_array_length_internal ((MonoArray
*)o
))
5397 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5401 mono_array_set_fast ((MonoArray
*)o
, mono_i
, aindex
, sp
[2].data
.nati
);
5403 case MINT_STELEM_I1
:
5404 mono_array_set_fast ((MonoArray
*)o
, gint8
, aindex
, sp
[2].data
.i
);
5406 case MINT_STELEM_U1
:
5407 mono_array_set_fast ((MonoArray
*) o
, guint8
, aindex
, sp
[2].data
.i
);
5409 case MINT_STELEM_I2
:
5410 mono_array_set_fast ((MonoArray
*)o
, gint16
, aindex
, sp
[2].data
.i
);
5412 case MINT_STELEM_U2
:
5413 mono_array_set_fast ((MonoArray
*)o
, guint16
, aindex
, sp
[2].data
.i
);
5415 case MINT_STELEM_I4
:
5416 mono_array_set_fast ((MonoArray
*)o
, gint32
, aindex
, sp
[2].data
.i
);
5418 case MINT_STELEM_I8
:
5419 mono_array_set_fast ((MonoArray
*)o
, gint64
, aindex
, sp
[2].data
.l
);
5421 case MINT_STELEM_R4
:
5422 mono_array_set_fast ((MonoArray
*)o
, float, aindex
, sp
[2].data
.f_r4
);
5424 case MINT_STELEM_R8
:
5425 mono_array_set_fast ((MonoArray
*)o
, double, aindex
, sp
[2].data
.f
);
5427 case MINT_STELEM_REF
: {
5428 MonoObject
*isinst_obj
= mono_object_isinst_checked (sp
[2].data
.o
, m_class_get_element_class (mono_object_class (o
)), error
);
5429 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5430 if (sp
[2].data
.p
&& !isinst_obj
)
5431 THROW_EX (mono_get_exception_array_type_mismatch (), ip
);
5432 mono_array_setref_fast ((MonoArray
*) o
, aindex
, sp
[2].data
.p
);
5435 case MINT_STELEM_VT
: {
5436 MonoClass
*klass_vt
= (MonoClass
*)imethod
->data_items
[*(guint16
*) (ip
+ 1)];
5437 i32
= READ32 (ip
+ 2);
5438 char *dst_addr
= mono_array_addr_with_size_fast ((MonoArray
*) o
, i32
, aindex
);
5440 mono_value_copy_internal (dst_addr
, sp
[2].data
.vt
, klass_vt
);
5441 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5452 MINT_IN_CASE(MINT_CONV_OVF_I4_U4
)
5453 if (sp
[-1].data
.i
< 0)
5457 MINT_IN_CASE(MINT_CONV_OVF_I4_I8
)
5458 if (sp
[-1].data
.l
< G_MININT32
|| sp
[-1].data
.l
> G_MAXINT32
)
5460 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.l
;
5463 MINT_IN_CASE(MINT_CONV_OVF_I4_U8
)
5464 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT32
)
5466 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.l
;
5469 MINT_IN_CASE(MINT_CONV_OVF_I4_R4
)
5470 if (sp
[-1].data
.f_r4
< G_MININT32
|| sp
[-1].data
.f_r4
> G_MAXINT32
)
5472 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f_r4
;
5475 MINT_IN_CASE(MINT_CONV_OVF_I4_R8
)
5476 if (sp
[-1].data
.f
< G_MININT32
|| sp
[-1].data
.f
> G_MAXINT32
)
5478 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f
;
5481 MINT_IN_CASE(MINT_CONV_OVF_U4_I4
)
5482 if (sp
[-1].data
.i
< 0)
5486 MINT_IN_CASE(MINT_CONV_OVF_U4_I8
)
5487 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT32
)
5489 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.l
;
5492 MINT_IN_CASE(MINT_CONV_OVF_U4_R4
)
5493 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXUINT32
)
5495 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f_r4
;
5498 MINT_IN_CASE(MINT_CONV_OVF_U4_R8
)
5499 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT32
)
5501 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f
;
5504 MINT_IN_CASE(MINT_CONV_OVF_I2_I4
)
5505 if (sp
[-1].data
.i
< G_MININT16
|| sp
[-1].data
.i
> G_MAXINT16
)
5509 MINT_IN_CASE(MINT_CONV_OVF_I2_U4
)
5510 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXINT16
)
5514 MINT_IN_CASE(MINT_CONV_OVF_I2_I8
)
5515 if (sp
[-1].data
.l
< G_MININT16
|| sp
[-1].data
.l
> G_MAXINT16
)
5517 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.l
;
5520 MINT_IN_CASE(MINT_CONV_OVF_I2_U8
)
5521 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT16
)
5523 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.l
;
5526 MINT_IN_CASE(MINT_CONV_OVF_I2_R8
)
5527 if (sp
[-1].data
.f
< G_MININT16
|| sp
[-1].data
.f
> G_MAXINT16
)
5529 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.f
;
5532 MINT_IN_CASE(MINT_CONV_OVF_I2_UN_R8
)
5533 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT16
)
5535 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.f
;
5538 MINT_IN_CASE(MINT_CONV_OVF_U2_I4
)
5539 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXUINT16
)
5543 MINT_IN_CASE(MINT_CONV_OVF_U2_I8
)
5544 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT16
)
5546 sp
[-1].data
.i
= (guint16
) sp
[-1].data
.l
;
5549 MINT_IN_CASE(MINT_CONV_OVF_U2_R8
)
5550 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT16
)
5552 sp
[-1].data
.i
= (guint16
) sp
[-1].data
.f
;
5555 MINT_IN_CASE(MINT_CONV_OVF_I1_I4
)
5556 if (sp
[-1].data
.i
< G_MININT8
|| sp
[-1].data
.i
> G_MAXINT8
)
5560 MINT_IN_CASE(MINT_CONV_OVF_I1_U4
)
5561 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXINT8
)
5565 MINT_IN_CASE(MINT_CONV_OVF_I1_I8
)
5566 if (sp
[-1].data
.l
< G_MININT8
|| sp
[-1].data
.l
> G_MAXINT8
)
5568 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.l
;
5571 MINT_IN_CASE(MINT_CONV_OVF_I1_U8
)
5572 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT8
)
5574 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.l
;
5577 MINT_IN_CASE(MINT_CONV_OVF_I1_R8
)
5578 if (sp
[-1].data
.f
< G_MININT8
|| sp
[-1].data
.f
> G_MAXINT8
)
5580 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.f
;
5583 MINT_IN_CASE(MINT_CONV_OVF_I1_UN_R8
)
5584 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT8
)
5586 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.f
;
5589 MINT_IN_CASE(MINT_CONV_OVF_U1_I4
)
5590 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXUINT8
)
5594 MINT_IN_CASE(MINT_CONV_OVF_U1_I8
)
5595 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT8
)
5597 sp
[-1].data
.i
= (guint8
) sp
[-1].data
.l
;
5600 MINT_IN_CASE(MINT_CONV_OVF_U1_R8
)
5601 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT8
)
5603 sp
[-1].data
.i
= (guint8
) sp
[-1].data
.f
;
5606 MINT_IN_CASE(MINT_CKFINITE
)
5607 if (!mono_isfinite (sp
[-1].data
.f
))
5608 THROW_EX (mono_get_exception_arithmetic (), ip
);
5611 MINT_IN_CASE(MINT_MKREFANY
) {
5612 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5614 /* The value address is on the stack */
5615 gpointer addr
= sp
[-1].data
.p
;
5616 /* Push the typedref value on the stack */
5617 sp
[-1].data
.p
= vt_sp
;
5618 vt_sp
+= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5620 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5622 tref
->type
= m_class_get_byval_arg (c
);
5628 MINT_IN_CASE(MINT_REFANYTYPE
) {
5629 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5630 MonoType
*type
= tref
->type
;
5632 vt_sp
-= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5633 sp
[-1].data
.p
= vt_sp
;
5635 *(gpointer
*)sp
[-1].data
.p
= type
;
5639 MINT_IN_CASE(MINT_REFANYVAL
) {
5640 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5641 gpointer addr
= tref
->value
;
5643 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5644 if (c
!= tref
->klass
)
5645 THROW_EX (mono_get_exception_invalid_cast (), ip
);
5647 vt_sp
-= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5649 sp
[-1].data
.p
= addr
;
5653 MINT_IN_CASE(MINT_LDTOKEN
)
5656 * (gpointer
*)sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5660 MINT_IN_CASE(MINT_ADD_OVF_I4
)
5661 if (CHECK_ADD_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5665 MINT_IN_CASE(MINT_ADD_OVF_I8
)
5666 if (CHECK_ADD_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5670 MINT_IN_CASE(MINT_ADD_OVF_UN_I4
)
5671 if (CHECK_ADD_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5673 BINOP_CAST(i
, +, guint32
);
5675 MINT_IN_CASE(MINT_ADD_OVF_UN_I8
)
5676 if (CHECK_ADD_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5678 BINOP_CAST(l
, +, guint64
);
5680 MINT_IN_CASE(MINT_MUL_OVF_I4
)
5681 if (CHECK_MUL_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5685 MINT_IN_CASE(MINT_MUL_OVF_I8
)
5686 if (CHECK_MUL_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5690 MINT_IN_CASE(MINT_MUL_OVF_UN_I4
)
5691 if (CHECK_MUL_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5693 BINOP_CAST(i
, *, guint32
);
5695 MINT_IN_CASE(MINT_MUL_OVF_UN_I8
)
5696 if (CHECK_MUL_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5698 BINOP_CAST(l
, *, guint64
);
5700 MINT_IN_CASE(MINT_SUB_OVF_I4
)
5701 if (CHECK_SUB_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5705 MINT_IN_CASE(MINT_SUB_OVF_I8
)
5706 if (CHECK_SUB_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5710 MINT_IN_CASE(MINT_SUB_OVF_UN_I4
)
5711 if (CHECK_SUB_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5713 BINOP_CAST(i
, -, guint32
);
5715 MINT_IN_CASE(MINT_SUB_OVF_UN_I8
)
5716 if (CHECK_SUB_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5718 BINOP_CAST(l
, -, guint64
);
5720 MINT_IN_CASE(MINT_START_ABORT_PROT
)
5721 mono_threads_begin_abort_protected_block ();
5724 MINT_IN_CASE(MINT_ENDFINALLY
) {
5726 int clause_index
= *ip
;
5727 gboolean pending_abort
= mono_threads_end_abort_protected_block ();
5729 if (clause_args
&& clause_index
== clause_args
->exit_clause
)
5731 g_assert (sp
>= frame
->stack
);
5734 if (frame
->finally_ips
) {
5735 ip
= (const guint16
*)frame
->finally_ips
->data
;
5736 frame
->finally_ips
= g_slist_remove (frame
->finally_ips
, ip
);
5737 /* Throw abort after the last finally block to avoid confusing EH */
5738 if (pending_abort
&& !frame
->finally_ips
)
5739 EXCEPTION_CHECKPOINT
;
5740 MINT_IN_DISPATCH(*ip
);
5746 MINT_IN_CASE(MINT_LEAVE
)
5747 MINT_IN_CASE(MINT_LEAVE_S
)
5748 MINT_IN_CASE(MINT_LEAVE_CHECK
)
5749 MINT_IN_CASE(MINT_LEAVE_S_CHECK
) {
5750 g_assert (sp
>= frame
->stack
);
5754 if (*ip
== MINT_LEAVE_S_CHECK
|| *ip
== MINT_LEAVE_CHECK
) {
5755 if (imethod
->method
->wrapper_type
!= MONO_WRAPPER_RUNTIME_INVOKE
) {
5758 child_frame
.parent
= frame
;
5759 child_frame
.imethod
= NULL
;
5761 * We need for mono_thread_get_undeniable_exception to be able to unwind
5762 * to check the abort threshold. For this to work we use child_frame as a
5763 * dummy frame that is stored in the lmf and serves as the transition frame
5765 do_icall_wrapper (&child_frame
, NULL
, MINT_ICALL_V_P
, &tmp_sp
, (gpointer
)mono_thread_get_undeniable_exception
, FALSE
);
5767 MonoException
*abort_exc
= (MonoException
*)tmp_sp
.data
.p
;
5769 THROW_EX (abort_exc
, frame
->ip
);
5773 if (*ip
== MINT_LEAVE_S
|| *ip
== MINT_LEAVE_S_CHECK
) {
5774 ip
+= (short) *(ip
+ 1);
5776 ip
+= (gint32
) READ32 (ip
+ 1);
5778 frame
->endfinally_ip
= ip
;
5781 MonoExceptionClause
*clause
;
5782 GSList
*old_list
= frame
->finally_ips
;
5783 MonoMethod
*method
= imethod
->method
;
5787 g_print ("* Handle finally IL_%04x\n", frame
->endfinally_ip
== NULL
? 0 : frame
->endfinally_ip
- imethod
->code
);
5789 if (imethod
== NULL
|| (method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
)
5790 || (method
->iflags
& (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
| METHOD_IMPL_ATTRIBUTE_RUNTIME
))) {
5793 ip_offset
= frame
->ip
- imethod
->code
;
5795 if (frame
->endfinally_ip
!= NULL
)
5796 frame
->finally_ips
= g_slist_prepend(frame
->finally_ips
, (void *)frame
->endfinally_ip
);
5798 for (int i
= imethod
->num_clauses
- 1; i
>= 0; i
--) {
5799 clause
= &imethod
->clauses
[i
];
5800 if (MONO_OFFSET_IN_CLAUSE (clause
, ip_offset
) && (frame
->endfinally_ip
== NULL
|| !(MONO_OFFSET_IN_CLAUSE (clause
, frame
->endfinally_ip
- imethod
->code
)))) {
5801 if (clause
->flags
== MONO_EXCEPTION_CLAUSE_FINALLY
) {
5802 ip
= imethod
->code
+ clause
->handler_offset
;
5803 frame
->finally_ips
= g_slist_prepend (frame
->finally_ips
, (gpointer
) ip
);
5806 g_print ("* Found finally at IL_%04x with exception: %s\n", clause
->handler_offset
, frame
->ex
? "yes": "no");
5812 frame
->endfinally_ip
= NULL
;
5814 if (old_list
!= frame
->finally_ips
&& frame
->finally_ips
) {
5815 ip
= (const guint16
*)frame
->finally_ips
->data
;
5816 frame
->finally_ips
= g_slist_remove (frame
->finally_ips
, ip
);
5817 sp
= frame
->stack
; /* spec says stack should be empty at endfinally so it should be at the start too */
5818 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
5819 MINT_IN_DISPATCH (*ip
);
5825 MINT_IN_CASE(MINT_ICALL_V_V
)
5826 MINT_IN_CASE(MINT_ICALL_V_P
)
5827 MINT_IN_CASE(MINT_ICALL_P_V
)
5828 MINT_IN_CASE(MINT_ICALL_P_P
)
5829 MINT_IN_CASE(MINT_ICALL_PP_V
)
5830 MINT_IN_CASE(MINT_ICALL_PP_P
)
5831 MINT_IN_CASE(MINT_ICALL_PPP_V
)
5832 MINT_IN_CASE(MINT_ICALL_PPP_P
)
5833 MINT_IN_CASE(MINT_ICALL_PPPP_V
)
5834 MINT_IN_CASE(MINT_ICALL_PPPP_P
)
5835 MINT_IN_CASE(MINT_ICALL_PPPPP_V
)
5836 MINT_IN_CASE(MINT_ICALL_PPPPP_P
)
5837 MINT_IN_CASE(MINT_ICALL_PPPPPP_V
)
5838 MINT_IN_CASE(MINT_ICALL_PPPPPP_P
)
5840 sp
= do_icall_wrapper (frame
, NULL
, *ip
, sp
, imethod
->data_items
[*(guint16
*)(ip
+ 1)], FALSE
);
5841 EXCEPTION_CHECKPOINT
;
5842 CHECK_RESUME_STATE (context
);
5845 MINT_IN_CASE(MINT_MONO_LDPTR
)
5846 sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5850 MINT_IN_CASE(MINT_MONO_NEWOBJ
)
5851 sp
->data
.p
= mono_object_new_checked (imethod
->domain
, (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)], error
);
5852 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5856 MINT_IN_CASE(MINT_MONO_FREE
)
5859 g_error ("that doesn't seem right");
5860 g_free (sp
->data
.p
);
5862 MINT_IN_CASE(MINT_MONO_RETOBJ
)
5865 stackval_from_data (mono_method_signature_internal (imethod
->method
)->ret
, frame
->retval
, sp
->data
.p
,
5866 mono_method_signature_internal (imethod
->method
)->pinvoke
);
5867 if (sp
> frame
->stack
)
5868 g_warning ("retobj: more values on stack: %d", sp
-frame
->stack
);
5870 MINT_IN_CASE(MINT_MONO_SGEN_THREAD_INFO
)
5871 sp
->data
.p
= mono_tls_get_sgen_thread_info ();
5875 MINT_IN_CASE(MINT_MONO_MEMORY_BARRIER
) {
5877 mono_memory_barrier ();
5880 MINT_IN_CASE(MINT_MONO_LDDOMAIN
)
5881 sp
->data
.p
= mono_domain_get ();
5885 MINT_IN_CASE(MINT_SDB_INTR_LOC
)
5886 if (G_UNLIKELY (ss_enabled
)) {
5887 typedef void (*T
) (void);
5891 void *tramp
= mini_get_single_step_trampoline ();
5892 mono_memory_barrier ();
5893 ss_tramp
= (T
)tramp
;
5897 * Make this point to the MINT_SDB_SEQ_POINT instruction which follows this since
5898 * the address of that instruction is stored as the seq point address.
5903 * Use the same trampoline as the JIT. This ensures that
5904 * the debugger has the context for the last interpreter
5907 do_debugger_tramp (ss_tramp
, frame
);
5909 CHECK_RESUME_STATE (context
);
5913 MINT_IN_CASE(MINT_SDB_SEQ_POINT
)
5914 /* Just a placeholder for a breakpoint */
5917 MINT_IN_CASE(MINT_SDB_BREAKPOINT
) {
5918 typedef void (*T
) (void);
5921 void *tramp
= mini_get_breakpoint_trampoline ();
5922 mono_memory_barrier ();
5923 bp_tramp
= (T
)tramp
;
5928 /* Use the same trampoline as the JIT */
5929 do_debugger_tramp (bp_tramp
, frame
);
5931 CHECK_RESUME_STATE (context
);
5937 #define RELOP(datamem, op) \
5939 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
5942 #define RELOP_FP(datamem, op, noorder) \
5944 if (mono_isunordered (sp [-1].data.datamem, sp [0].data.datamem)) \
5945 sp [-1].data.i = noorder; \
5947 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
5950 MINT_IN_CASE(MINT_CEQ_I4
)
5953 MINT_IN_CASE(MINT_CEQ0_I4
)
5954 sp
[-1].data
.i
= (sp
[-1].data
.i
== 0);
5957 MINT_IN_CASE(MINT_CEQ_I8
)
5960 MINT_IN_CASE(MINT_CEQ_R4
)
5961 RELOP_FP(f_r4
, ==, 0);
5963 MINT_IN_CASE(MINT_CEQ_R8
)
5966 MINT_IN_CASE(MINT_CNE_I4
)
5969 MINT_IN_CASE(MINT_CNE_I8
)
5972 MINT_IN_CASE(MINT_CNE_R4
)
5973 RELOP_FP(f_r4
, !=, 1);
5975 MINT_IN_CASE(MINT_CNE_R8
)
5978 MINT_IN_CASE(MINT_CGT_I4
)
5981 MINT_IN_CASE(MINT_CGT_I8
)
5984 MINT_IN_CASE(MINT_CGT_R4
)
5985 RELOP_FP(f_r4
, >, 0);
5987 MINT_IN_CASE(MINT_CGT_R8
)
5990 MINT_IN_CASE(MINT_CGE_I4
)
5993 MINT_IN_CASE(MINT_CGE_I8
)
5996 MINT_IN_CASE(MINT_CGE_R4
)
5997 RELOP_FP(f_r4
, >=, 0);
5999 MINT_IN_CASE(MINT_CGE_R8
)
6003 #define RELOP_CAST(datamem, op, type) \
6005 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
6008 MINT_IN_CASE(MINT_CGE_UN_I4
)
6009 RELOP_CAST(l
, >=, guint32
);
6011 MINT_IN_CASE(MINT_CGE_UN_I8
)
6012 RELOP_CAST(l
, >=, guint64
);
6015 MINT_IN_CASE(MINT_CGT_UN_I4
)
6016 RELOP_CAST(i
, >, guint32
);
6018 MINT_IN_CASE(MINT_CGT_UN_I8
)
6019 RELOP_CAST(l
, >, guint64
);
6021 MINT_IN_CASE(MINT_CGT_UN_R4
)
6022 RELOP_FP(f_r4
, >, 1);
6024 MINT_IN_CASE(MINT_CGT_UN_R8
)
6027 MINT_IN_CASE(MINT_CLT_I4
)
6030 MINT_IN_CASE(MINT_CLT_I8
)
6033 MINT_IN_CASE(MINT_CLT_R4
)
6034 RELOP_FP(f_r4
, <, 0);
6036 MINT_IN_CASE(MINT_CLT_R8
)
6039 MINT_IN_CASE(MINT_CLT_UN_I4
)
6040 RELOP_CAST(i
, <, guint32
);
6042 MINT_IN_CASE(MINT_CLT_UN_I8
)
6043 RELOP_CAST(l
, <, guint64
);
6045 MINT_IN_CASE(MINT_CLT_UN_R4
)
6046 RELOP_FP(f_r4
, <, 1);
6048 MINT_IN_CASE(MINT_CLT_UN_R8
)
6051 MINT_IN_CASE(MINT_CLE_I4
)
6054 MINT_IN_CASE(MINT_CLE_I8
)
6057 MINT_IN_CASE(MINT_CLE_UN_I4
)
6058 RELOP_CAST(l
, <=, guint32
);
6060 MINT_IN_CASE(MINT_CLE_UN_I8
)
6061 RELOP_CAST(l
, <=, guint64
);
6063 MINT_IN_CASE(MINT_CLE_R4
)
6064 RELOP_FP(f_r4
, <=, 0);
6066 MINT_IN_CASE(MINT_CLE_R8
)
6074 MINT_IN_CASE(MINT_LDFTN
) {
6075 sp
->data
.p
= imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6080 MINT_IN_CASE(MINT_LDVIRTFTN
) {
6081 InterpMethod
*m
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6083 NULL_CHECK (sp
->data
.p
);
6085 sp
->data
.p
= get_virtual_method (m
, sp
->data
.o
->vtable
);
6090 MINT_IN_CASE(MINT_LDFTN_DYNAMIC
) {
6091 MONO_API_ERROR_INIT (error
);
6092 InterpMethod
*m
= mono_interp_get_imethod (mono_domain_get (), (MonoMethod
*) sp
[-1].data
.p
, error
);
6093 mono_error_assert_ok (error
);
6099 #define LDARG(datamem, argtype) \
6100 sp->data.datamem = (argtype) frame->stack_args [*(guint16 *)(ip + 1)].data.datamem; \
6104 MINT_IN_CASE(MINT_LDARG_I1
) LDARG(i
, gint8
); MINT_IN_BREAK
;
6105 MINT_IN_CASE(MINT_LDARG_U1
) LDARG(i
, guint8
); MINT_IN_BREAK
;
6106 MINT_IN_CASE(MINT_LDARG_I2
) LDARG(i
, gint16
); MINT_IN_BREAK
;
6107 MINT_IN_CASE(MINT_LDARG_U2
) LDARG(i
, guint16
); MINT_IN_BREAK
;
6108 MINT_IN_CASE(MINT_LDARG_I4
) LDARG(i
, gint32
); MINT_IN_BREAK
;
6109 MINT_IN_CASE(MINT_LDARG_I8
) LDARG(l
, gint64
); MINT_IN_BREAK
;
6110 MINT_IN_CASE(MINT_LDARG_R4
) LDARG(f_r4
, float); MINT_IN_BREAK
;
6111 MINT_IN_CASE(MINT_LDARG_R8
) LDARG(f
, double); MINT_IN_BREAK
;
6112 MINT_IN_CASE(MINT_LDARG_O
) LDARG(p
, gpointer
); MINT_IN_BREAK
;
6113 MINT_IN_CASE(MINT_LDARG_P
) LDARG(p
, gpointer
); MINT_IN_BREAK
;
6115 MINT_IN_CASE(MINT_LDARG_VT
)
6117 i32
= READ32(ip
+ 2);
6118 memcpy(sp
->data
.p
, frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
, i32
);
6119 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6124 #define STARG(datamem, argtype) \
6126 frame->stack_args [*(guint16 *)(ip + 1)].data.datamem = (argtype) sp->data.datamem; \
6129 MINT_IN_CASE(MINT_STARG_I1
) STARG(i
, gint8
); MINT_IN_BREAK
;
6130 MINT_IN_CASE(MINT_STARG_U1
) STARG(i
, guint8
); MINT_IN_BREAK
;
6131 MINT_IN_CASE(MINT_STARG_I2
) STARG(i
, gint16
); MINT_IN_BREAK
;
6132 MINT_IN_CASE(MINT_STARG_U2
) STARG(i
, guint16
); MINT_IN_BREAK
;
6133 MINT_IN_CASE(MINT_STARG_I4
) STARG(i
, gint32
); MINT_IN_BREAK
;
6134 MINT_IN_CASE(MINT_STARG_I8
) STARG(l
, gint64
); MINT_IN_BREAK
;
6135 MINT_IN_CASE(MINT_STARG_R4
) STARG(f_r4
, float); MINT_IN_BREAK
;
6136 MINT_IN_CASE(MINT_STARG_R8
) STARG(f
, double); MINT_IN_BREAK
;
6137 MINT_IN_CASE(MINT_STARG_O
) STARG(p
, gpointer
); MINT_IN_BREAK
;
6138 MINT_IN_CASE(MINT_STARG_P
) STARG(p
, gpointer
); MINT_IN_BREAK
;
6140 MINT_IN_CASE(MINT_STARG_VT
)
6141 i32
= READ32(ip
+ 2);
6143 memcpy(frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
, sp
->data
.p
, i32
);
6144 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6148 MINT_IN_CASE(MINT_PROF_ENTER
) {
6151 if (MONO_PROFILER_ENABLED (method_enter
)) {
6152 MonoProfilerCallContext
*prof_ctx
= NULL
;
6154 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_ENTER_CONTEXT
) {
6155 prof_ctx
= g_new0 (MonoProfilerCallContext
, 1);
6156 prof_ctx
->interp_frame
= frame
;
6157 prof_ctx
->method
= imethod
->method
;
6160 MONO_PROFILER_RAISE (method_enter
, (imethod
->method
, prof_ctx
));
6168 MINT_IN_CASE(MINT_TRACE_ENTER
) {
6171 MonoProfilerCallContext
*prof_ctx
= g_alloca (sizeof (MonoProfilerCallContext
));
6172 prof_ctx
->interp_frame
= frame
;
6173 prof_ctx
->method
= imethod
->method
;
6175 mono_trace_enter_method (imethod
->method
, prof_ctx
);
6179 MINT_IN_CASE(MINT_TRACE_EXIT
) {
6181 i32
= READ32(ip
+ 1);
6186 memcpy(frame
->retval
->data
.p
, sp
->data
.p
, i32
);
6188 *frame
->retval
= *sp
;
6190 MonoProfilerCallContext
*prof_ctx
= g_alloca (sizeof (MonoProfilerCallContext
));
6191 prof_ctx
->interp_frame
= frame
;
6192 prof_ctx
->method
= imethod
->method
;
6194 mono_trace_leave_method (imethod
->method
, prof_ctx
);
6199 MINT_IN_CASE(MINT_LDARGA
)
6200 sp
->data
.p
= &frame
->stack_args
[* (guint16
*)(ip
+ 1)];
6205 MINT_IN_CASE(MINT_LDARGA_VT
)
6206 sp
->data
.p
= frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
;
6211 #define LDLOC(datamem, argtype) \
6212 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
6216 MINT_IN_CASE(MINT_LDLOC_I1
) LDLOC(i
, gint8
); MINT_IN_BREAK
;
6217 MINT_IN_CASE(MINT_LDLOC_U1
) LDLOC(i
, guint8
); MINT_IN_BREAK
;
6218 MINT_IN_CASE(MINT_LDLOC_I2
) LDLOC(i
, gint16
); MINT_IN_BREAK
;
6219 MINT_IN_CASE(MINT_LDLOC_U2
) LDLOC(i
, guint16
); MINT_IN_BREAK
;
6220 MINT_IN_CASE(MINT_LDLOC_I4
) LDLOC(i
, gint32
); MINT_IN_BREAK
;
6221 MINT_IN_CASE(MINT_LDLOC_I8
) LDLOC(l
, gint64
); MINT_IN_BREAK
;
6222 MINT_IN_CASE(MINT_LDLOC_R4
) LDLOC(f_r4
, float); MINT_IN_BREAK
;
6223 MINT_IN_CASE(MINT_LDLOC_R8
) LDLOC(f
, double); MINT_IN_BREAK
;
6224 MINT_IN_CASE(MINT_LDLOC_O
) LDLOC(p
, gpointer
); MINT_IN_BREAK
;
6225 MINT_IN_CASE(MINT_LDLOC_P
) LDLOC(p
, gpointer
); MINT_IN_BREAK
;
6227 MINT_IN_CASE(MINT_LDLOC_VT
)
6229 i32
= READ32(ip
+ 2);
6230 memcpy(sp
->data
.p
, locals
+ * (guint16
*)(ip
+ 1), i32
);
6231 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6236 MINT_IN_CASE(MINT_LDLOCA_S
)
6237 sp
->data
.p
= locals
+ * (guint16
*)(ip
+ 1);
6242 #define STLOC(datamem, argtype) \
6244 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
6247 MINT_IN_CASE(MINT_STLOC_I1
) STLOC(i
, gint8
); MINT_IN_BREAK
;
6248 MINT_IN_CASE(MINT_STLOC_U1
) STLOC(i
, guint8
); MINT_IN_BREAK
;
6249 MINT_IN_CASE(MINT_STLOC_I2
) STLOC(i
, gint16
); MINT_IN_BREAK
;
6250 MINT_IN_CASE(MINT_STLOC_U2
) STLOC(i
, guint16
); MINT_IN_BREAK
;
6251 MINT_IN_CASE(MINT_STLOC_I4
) STLOC(i
, gint32
); MINT_IN_BREAK
;
6252 MINT_IN_CASE(MINT_STLOC_I8
) STLOC(l
, gint64
); MINT_IN_BREAK
;
6253 MINT_IN_CASE(MINT_STLOC_R4
) STLOC(f_r4
, float); MINT_IN_BREAK
;
6254 MINT_IN_CASE(MINT_STLOC_R8
) STLOC(f
, double); MINT_IN_BREAK
;
6255 MINT_IN_CASE(MINT_STLOC_O
) STLOC(p
, gpointer
); MINT_IN_BREAK
;
6256 MINT_IN_CASE(MINT_STLOC_P
) STLOC(p
, gpointer
); MINT_IN_BREAK
;
6258 #define STLOC_NP(datamem, argtype) \
6259 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
6262 MINT_IN_CASE(MINT_STLOC_NP_I4
) STLOC_NP(i
, gint32
); MINT_IN_BREAK
;
6263 MINT_IN_CASE(MINT_STLOC_NP_O
) STLOC_NP(p
, gpointer
); MINT_IN_BREAK
;
6265 MINT_IN_CASE(MINT_STLOC_VT
)
6266 i32
= READ32(ip
+ 2);
6268 memcpy(locals
+ * (guint16
*)(ip
+ 1), sp
->data
.p
, i32
);
6269 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6273 MINT_IN_CASE(MINT_LOCALLOC
) {
6274 if (sp
!= frame
->stack
+ 1) /*FIX?*/
6275 THROW_EX (mono_get_exception_execution_engine (NULL
), ip
);
6277 int len
= sp
[-1].data
.i
;
6278 sp
[-1].data
.p
= alloca (len
);
6280 if (imethod
->init_locals
)
6281 memset (sp
[-1].data
.p
, 0, len
);
6285 MINT_IN_CASE(MINT_ENDFILTER
)
6286 /* top of stack is result of filter */
6287 frame
->retval
= &sp
[-1];
6289 MINT_IN_CASE(MINT_INITOBJ
)
6291 memset (sp
->data
.vt
, 0, READ32(ip
+ 1));
6294 MINT_IN_CASE(MINT_CPBLK
)
6296 if (!sp
[0].data
.p
|| !sp
[1].data
.p
)
6297 THROW_EX (mono_get_exception_null_reference(), ip
- 1);
6299 /* FIXME: value and size may be int64... */
6300 memcpy (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.i
);
6303 MINT_IN_CASE(MINT_CONSTRAINED_
) {
6305 /* FIXME: implement */
6307 token
= READ32 (ip
);
6312 MINT_IN_CASE(MINT_INITBLK
)
6314 NULL_CHECK (sp
[0].data
.p
);
6316 /* FIXME: value and size may be int64... */
6317 memset (sp
[0].data
.p
, sp
[1].data
.i
, sp
[2].data
.i
);
6320 MINT_IN_CASE(MINT_NO_
)
6321 /* FIXME: implement */
6325 MINT_IN_CASE(MINT_RETHROW
) {
6326 int exvar_offset
= *(guint16
*)(ip
+ 1);
6327 THROW_EX_GENERAL (*(MonoException
**)(frame
->locals
+ exvar_offset
), ip
, TRUE
);
6330 MINT_IN_CASE(MINT_MONO_RETHROW
) {
6332 * need to clarify what this should actually do:
6334 * Takes an exception from the stack and rethrows it.
6335 * This is useful for wrappers that don't want to have to
6336 * use CEE_THROW and lose the exception stacktrace.
6341 sp
->data
.p
= mono_get_exception_null_reference ();
6343 THROW_EX_GENERAL ((MonoException
*)sp
->data
.p
, ip
, TRUE
);
6346 MINT_IN_CASE(MINT_LD_DELEGATE_METHOD_PTR
) {
6350 del
= (MonoDelegate
*)sp
->data
.p
;
6351 if (!del
->interp_method
) {
6352 /* Not created from interpreted code */
6353 MONO_API_ERROR_INIT (error
);
6354 g_assert (del
->method
);
6355 del
->interp_method
= mono_interp_get_imethod (del
->object
.vtable
->domain
, del
->method
, error
);
6356 mono_error_assert_ok (error
);
6358 g_assert (del
->interp_method
);
6359 sp
->data
.p
= del
->interp_method
;
6364 MINT_IN_CASE(MINT_LD_DELEGATE_INVOKE_IMPL
) {
6366 int n
= *(guint16
*)(ip
+ 1);
6367 del
= (MonoDelegate
*)sp
[-n
].data
.p
;
6368 if (!del
->interp_invoke_impl
) {
6370 * First time we are called. Set up the invoke wrapper. We might be able to do this
6371 * in ctor but we would need to handle AllocDelegateLike_internal separately
6373 MONO_API_ERROR_INIT (error
);
6374 MonoMethod
*invoke
= mono_get_delegate_invoke_internal (del
->object
.vtable
->klass
);
6375 del
->interp_invoke_impl
= mono_interp_get_imethod (del
->object
.vtable
->domain
, mono_marshal_get_delegate_invoke (invoke
, del
), error
);
6376 mono_error_assert_ok (error
);
6379 sp
[-1].data
.p
= del
->interp_invoke_impl
;
6384 #define MATH_UNOP(mathfunc) \
6385 sp [-1].data.f = mathfunc (sp [-1].data.f); \
6388 MINT_IN_CASE(MINT_ABS
) MATH_UNOP(fabs
); MINT_IN_BREAK
;
6389 MINT_IN_CASE(MINT_ASIN
) MATH_UNOP(asin
); MINT_IN_BREAK
;
6390 MINT_IN_CASE(MINT_ASINH
) MATH_UNOP(asinh
); MINT_IN_BREAK
;
6391 MINT_IN_CASE(MINT_ACOS
) MATH_UNOP(acos
); MINT_IN_BREAK
;
6392 MINT_IN_CASE(MINT_ACOSH
) MATH_UNOP(acosh
); MINT_IN_BREAK
;
6393 MINT_IN_CASE(MINT_ATAN
) MATH_UNOP(atan
); MINT_IN_BREAK
;
6394 MINT_IN_CASE(MINT_ATANH
) MATH_UNOP(atanh
); MINT_IN_BREAK
;
6395 MINT_IN_CASE(MINT_COS
) MATH_UNOP(cos
); MINT_IN_BREAK
;
6396 MINT_IN_CASE(MINT_CBRT
) MATH_UNOP(cbrt
); MINT_IN_BREAK
;
6397 MINT_IN_CASE(MINT_COSH
) MATH_UNOP(cosh
); MINT_IN_BREAK
;
6398 MINT_IN_CASE(MINT_SIN
) MATH_UNOP(sin
); MINT_IN_BREAK
;
6399 MINT_IN_CASE(MINT_SQRT
) MATH_UNOP(sqrt
); MINT_IN_BREAK
;
6400 MINT_IN_CASE(MINT_SINH
) MATH_UNOP(sinh
); MINT_IN_BREAK
;
6401 MINT_IN_CASE(MINT_TAN
) MATH_UNOP(tan
); MINT_IN_BREAK
;
6402 MINT_IN_CASE(MINT_TANH
) MATH_UNOP(tanh
); MINT_IN_BREAK
;
6404 MINT_IN_CASE(MINT_INTRINS_ENUM_HASFLAG
) {
6405 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6406 guint64 a_val
= 0, b_val
= 0;
6408 stackval_to_data (m_class_get_byval_arg (klass
), &sp
[-2], &a_val
, FALSE
);
6409 stackval_to_data (m_class_get_byval_arg (klass
), &sp
[-1], &b_val
, FALSE
);
6411 sp
[-1].data
.i
= (a_val
& b_val
) == b_val
;
6415 MINT_IN_CASE(MINT_INTRINS_GET_HASHCODE
) {
6416 sp
[-1].data
.i
= mono_object_hash_internal (sp
[-1].data
.o
);
6420 MINT_IN_CASE(MINT_INTRINS_GET_TYPE
) {
6421 NULL_CHECK (sp
[-1].data
.p
);
6422 sp
[-1].data
.o
= (MonoObject
*) sp
[-1].data
.o
->vtable
->type
;
6428 g_error ("Unimplemented opcode: %04x %s at 0x%x\n", *ip
, mono_interp_opname
[*ip
], ip
-imethod
->code
);
6432 g_assert_not_reached ();
6435 error_init_reuse (error
);
6437 if (clause_args
&& clause_args
->base_frame
)
6438 memcpy (clause_args
->base_frame
->args
, frame
->args
, imethod
->alloca_size
);
6440 if (!frame
->ex
&& MONO_PROFILER_ENABLED (method_leave
) &&
6441 imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_LEAVE
) {
6442 MonoProfilerCallContext
*prof_ctx
= NULL
;
6444 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_LEAVE_CONTEXT
) {
6445 prof_ctx
= g_new0 (MonoProfilerCallContext
, 1);
6446 prof_ctx
->interp_frame
= frame
;
6447 prof_ctx
->method
= imethod
->method
;
6449 MonoType
*rtype
= mono_method_signature_internal (imethod
->method
)->ret
;
6451 switch (rtype
->type
) {
6452 case MONO_TYPE_VOID
:
6454 case MONO_TYPE_VALUETYPE
:
6455 prof_ctx
->return_value
= frame
->retval
->data
.p
;
6458 prof_ctx
->return_value
= frame
->retval
;
6463 MONO_PROFILER_RAISE (method_leave
, (imethod
->method
, prof_ctx
));
6466 } else if (frame
->ex
&& imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_EXCEPTION_LEAVE
)
6467 MONO_PROFILER_RAISE (method_exception_leave
, (imethod
->method
, &frame
->ex
->object
));
6473 interp_parse_options (const char *options
)
6480 args
= g_strsplit (options
, ",", -1);
6481 for (ptr
= args
; ptr
&& *ptr
; ptr
++) {
6484 if (strncmp (arg
, "jit=", 4) == 0)
6485 mono_interp_jit_classes
= g_slist_prepend (mono_interp_jit_classes
, arg
+ 4);
6486 if (strncmp (arg
, "interp-only=", 4) == 0)
6487 mono_interp_only_classes
= g_slist_prepend (mono_interp_only_classes
, arg
+ strlen ("interp-only="));
6488 if (strncmp (arg
, "-inline", 7) == 0)
6489 mono_interp_opt
&= ~INTERP_OPT_INLINE
;
6494 * interp_set_resume_state:
6496 * Set the state the interpeter will continue to execute from after execution returns to the interpreter.
6499 interp_set_resume_state (MonoJitTlsData
*jit_tls
, MonoException
*ex
, MonoJitExceptionInfo
*ei
, MonoInterpFrameHandle interp_frame
, gpointer handler_ip
)
6501 ThreadContext
*context
;
6504 context
= (ThreadContext
*)jit_tls
->interp_context
;
6507 context
->has_resume_state
= TRUE
;
6508 context
->handler_frame
= (InterpFrame
*)interp_frame
;
6509 context
->handler_ei
= ei
;
6510 /* This is on the stack, so it doesn't need a wbarrier */
6511 context
->handler_frame
->ex
= ex
;
6514 *(MonoException
**)(context
->handler_frame
->locals
+ ei
->exvar_offset
) = ex
;
6515 context
->handler_ip
= (guint16
*) handler_ip
;
6519 interp_get_resume_state (const MonoJitTlsData
*jit_tls
, gboolean
*has_resume_state
, MonoInterpFrameHandle
*interp_frame
, gpointer
*handler_ip
)
6522 ThreadContext
*context
= (ThreadContext
*)jit_tls
->interp_context
;
6524 *has_resume_state
= context
->has_resume_state
;
6525 if (context
->has_resume_state
) {
6526 *interp_frame
= context
->handler_frame
;
6527 *handler_ip
= context
->handler_ip
;
6532 * interp_run_finally:
6534 * Run the finally clause identified by CLAUSE_INDEX in the intepreter frame given by
6535 * frame->interp_frame.
6536 * Return TRUE if the finally clause threw an exception.
6539 interp_run_finally (StackFrameInfo
*frame
, int clause_index
, gpointer handler_ip
, gpointer handler_ip_end
)
6541 InterpFrame
*iframe
= (InterpFrame
*)frame
->interp_frame
;
6542 ThreadContext
*context
= get_context ();
6543 const unsigned short *old_ip
= iframe
->ip
;
6544 FrameClauseArgs clause_args
;
6546 memset (&clause_args
, 0, sizeof (FrameClauseArgs
));
6547 clause_args
.start_with_ip
= (guint16
*) handler_ip
;
6548 clause_args
.end_at_ip
= (guint16
*) handler_ip_end
;
6549 clause_args
.exit_clause
= clause_index
;
6552 interp_exec_method_full (iframe
, context
, &clause_args
, error
);
6553 if (context
->has_resume_state
) {
6556 iframe
->ip
= old_ip
;
6562 * interp_run_filter:
6564 * Run the filter clause identified by CLAUSE_INDEX in the intepreter frame given by
6565 * frame->interp_frame.
6568 interp_run_filter (StackFrameInfo
*frame
, MonoException
*ex
, int clause_index
, gpointer handler_ip
, gpointer handler_ip_end
)
6570 InterpFrame
*iframe
= (InterpFrame
*)frame
->interp_frame
;
6571 ThreadContext
*context
= get_context ();
6572 InterpFrame child_frame
;
6574 FrameClauseArgs clause_args
;
6577 * Have to run the clause in a new frame which is a copy of IFRAME, since
6578 * during debugging, there are two copies of the frame on the stack.
6580 memset (&child_frame
, 0, sizeof (InterpFrame
));
6581 child_frame
.imethod
= iframe
->imethod
;
6582 child_frame
.retval
= &retval
;
6583 child_frame
.parent
= iframe
;
6584 child_frame
.stack_args
= iframe
->stack_args
;
6586 memset (&clause_args
, 0, sizeof (FrameClauseArgs
));
6587 clause_args
.start_with_ip
= (guint16
*) handler_ip
;
6588 clause_args
.end_at_ip
= (guint16
*) handler_ip_end
;
6589 clause_args
.filter_exception
= ex
;
6590 clause_args
.base_frame
= iframe
;
6593 interp_exec_method_full (&child_frame
, context
, &clause_args
, error
);
6594 /* ENDFILTER stores the result into child_frame->retval */
6595 return child_frame
.retval
->data
.i
? TRUE
: FALSE
;
6599 InterpFrame
*current
;
6603 * interp_frame_iter_init:
6605 * Initialize an iterator for iterating through interpreted frames.
6608 interp_frame_iter_init (MonoInterpStackIter
*iter
, gpointer interp_exit_data
)
6610 StackIter
*stack_iter
= (StackIter
*)iter
;
6612 stack_iter
->current
= (InterpFrame
*)interp_exit_data
;
6616 * interp_frame_iter_next:
6618 * Fill out FRAME with date for the next interpreter frame.
6621 interp_frame_iter_next (MonoInterpStackIter
*iter
, StackFrameInfo
*frame
)
6623 StackIter
*stack_iter
= (StackIter
*)iter
;
6624 InterpFrame
*iframe
= stack_iter
->current
;
6626 memset (frame
, 0, sizeof (StackFrameInfo
));
6627 /* pinvoke frames doesn't have imethod set */
6628 while (iframe
&& !(iframe
->imethod
&& iframe
->imethod
->code
&& iframe
->imethod
->jinfo
))
6629 iframe
= iframe
->parent
;
6633 MonoMethod
*method
= iframe
->imethod
->method
;
6634 frame
->domain
= iframe
->imethod
->domain
;
6635 frame
->interp_frame
= iframe
;
6636 frame
->method
= method
;
6637 frame
->actual_method
= method
;
6638 if (method
&& ((method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
) || (method
->iflags
& (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
| METHOD_IMPL_ATTRIBUTE_RUNTIME
)))) {
6639 frame
->native_offset
= -1;
6640 frame
->type
= FRAME_TYPE_MANAGED_TO_NATIVE
;
6642 frame
->type
= FRAME_TYPE_INTERP
;
6643 /* This is the offset in the interpreter IR */
6644 frame
->native_offset
= (guint8
*)iframe
->ip
- (guint8
*)iframe
->imethod
->code
;
6645 if (!method
->wrapper_type
|| method
->wrapper_type
== MONO_WRAPPER_DYNAMIC_METHOD
)
6646 frame
->managed
= TRUE
;
6648 frame
->ji
= iframe
->imethod
->jinfo
;
6649 frame
->frame_addr
= iframe
;
6651 stack_iter
->current
= iframe
->parent
;
6657 interp_find_jit_info (MonoDomain
*domain
, MonoMethod
*method
)
6659 InterpMethod
* imethod
;
6661 imethod
= lookup_imethod (domain
, method
);
6663 return imethod
->jinfo
;
6669 interp_set_breakpoint (MonoJitInfo
*jinfo
, gpointer ip
)
6671 guint16
*code
= (guint16
*)ip
;
6672 g_assert (*code
== MINT_SDB_SEQ_POINT
);
6673 *code
= MINT_SDB_BREAKPOINT
;
6677 interp_clear_breakpoint (MonoJitInfo
*jinfo
, gpointer ip
)
6679 guint16
*code
= (guint16
*)ip
;
6680 g_assert (*code
== MINT_SDB_BREAKPOINT
);
6681 *code
= MINT_SDB_SEQ_POINT
;
6685 interp_frame_get_jit_info (MonoInterpFrameHandle frame
)
6687 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6689 g_assert (iframe
->imethod
);
6690 return iframe
->imethod
->jinfo
;
6694 interp_frame_get_ip (MonoInterpFrameHandle frame
)
6696 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6698 g_assert (iframe
->imethod
);
6699 return (gpointer
)iframe
->ip
;
6703 interp_frame_get_arg (MonoInterpFrameHandle frame
, int pos
)
6705 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6706 MonoMethodSignature
*sig
;
6708 g_assert (iframe
->imethod
);
6710 sig
= mono_method_signature_internal (iframe
->imethod
->method
);
6711 return stackval_to_data_addr (sig
->params
[pos
], &iframe
->stack_args
[pos
+ !!iframe
->imethod
->hasthis
]);
6715 interp_frame_get_local (MonoInterpFrameHandle frame
, int pos
)
6717 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6719 g_assert (iframe
->imethod
);
6721 return iframe
->locals
+ iframe
->imethod
->local_offsets
[pos
];
6725 interp_frame_get_this (MonoInterpFrameHandle frame
)
6727 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6729 g_assert (iframe
->imethod
);
6730 g_assert (iframe
->imethod
->hasthis
);
6731 return &iframe
->stack_args
[0].data
.p
;
6734 static MonoInterpFrameHandle
6735 interp_frame_get_parent (MonoInterpFrameHandle frame
)
6737 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6739 return iframe
->parent
;
6743 interp_frame_get_res (MonoInterpFrameHandle frame
)
6745 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6746 MonoMethodSignature
*sig
;
6748 g_assert (iframe
->imethod
);
6749 sig
= mono_method_signature_internal (iframe
->imethod
->method
);
6750 if (sig
->ret
->type
== MONO_TYPE_VOID
)
6753 return stackval_to_data_addr (sig
->ret
, iframe
->retval
);
6757 interp_start_single_stepping (void)
6763 interp_stop_single_stepping (void)
6769 register_interp_stats (void)
6771 mono_counters_init ();
6772 mono_counters_register ("Total transform time", MONO_COUNTER_INTERP
| MONO_COUNTER_LONG
| MONO_COUNTER_TIME
, &mono_interp_stats
.transform_time
);
6773 mono_counters_register ("Methods inlined", MONO_COUNTER_INTERP
| MONO_COUNTER_INT
, &mono_interp_stats
.inlined_methods
);
6774 mono_counters_register ("Inline failures", MONO_COUNTER_INTERP
| MONO_COUNTER_INT
, &mono_interp_stats
.inline_failures
);
6777 #undef MONO_EE_CALLBACK
6778 #define MONO_EE_CALLBACK(ret, name, sig) interp_ ## name,
6780 static const MonoEECallbacks mono_interp_callbacks
= {
6785 mono_ee_interp_init (const char *opts
)
6787 g_assert (mono_ee_api_version () == MONO_EE_API_VERSION
);
6788 g_assert (!interp_init_done
);
6789 interp_init_done
= TRUE
;
6791 mono_native_tls_alloc (&thread_context_id
, NULL
);
6794 interp_parse_options (opts
);
6795 if (mini_get_debug_options ()->mdb_optimizations
)
6796 mono_interp_opt
&= ~INTERP_OPT_INLINE
;
6797 mono_interp_transform_init ();
6799 mini_install_interp_callbacks (&mono_interp_callbacks
);
6801 register_interp_stats ();