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
;
587 static MONO_NEVER_INLINE InterpMethod
* // Inlining causes additional stack use in caller.
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 guchar
*
2358 copy_varargs_vtstack (MonoMethodSignature
*csig
, stackval
*sp
, guchar
*vt_sp
)
2360 stackval
*first_arg
= sp
- csig
->param_count
;
2363 * We need to have the varargs linearly on the stack so the ArgIterator
2364 * can iterate over them. We pass the signature first and then copy them
2365 * one by one on the vtstack.
2367 *(gpointer
*)vt_sp
= csig
;
2368 vt_sp
+= sizeof (gpointer
);
2370 for (int i
= csig
->sentinelpos
; i
< csig
->param_count
; i
++) {
2371 int align
, arg_size
;
2372 arg_size
= mono_type_stack_size (csig
->params
[i
], &align
);
2373 vt_sp
= (guchar
*)ALIGN_PTR_TO (vt_sp
, align
);
2375 stackval_to_data (csig
->params
[i
], &first_arg
[i
], vt_sp
, FALSE
);
2379 return (guchar
*)ALIGN_PTR_TO (vt_sp
, MINT_VT_ALIGNMENT
);
2383 * These functions are the entry points into the interpreter from compiled code.
2384 * They are called by the interp_in wrappers. They have the following signature:
2385 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
2386 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
2387 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
2388 * more wrappers then these functions.
2389 * this/static * ret/void * 16 arguments -> 64 functions.
2392 #define MAX_INTERP_ENTRY_ARGS 8
2394 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
2395 InterpEntryData data; \
2396 (data).rmethod = (_method); \
2397 (data).res = (_res); \
2398 (data).this_arg = (_this_arg); \
2399 (data).many_args = NULL;
2401 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
2402 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2403 interp_entry (&data); \
2405 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
2406 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2407 (data).args [0] = arg1; \
2408 interp_entry (&data); \
2410 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
2411 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2412 (data).args [0] = arg1; \
2413 (data).args [1] = arg2; \
2414 interp_entry (&data); \
2416 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
2417 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2418 (data).args [0] = arg1; \
2419 (data).args [1] = arg2; \
2420 (data).args [2] = arg3; \
2421 interp_entry (&data); \
2423 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
2424 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2425 (data).args [0] = arg1; \
2426 (data).args [1] = arg2; \
2427 (data).args [2] = arg3; \
2428 (data).args [3] = arg4; \
2429 interp_entry (&data); \
2431 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
2432 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2433 (data).args [0] = arg1; \
2434 (data).args [1] = arg2; \
2435 (data).args [2] = arg3; \
2436 (data).args [3] = arg4; \
2437 (data).args [4] = arg5; \
2438 interp_entry (&data); \
2440 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
2441 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2442 (data).args [0] = arg1; \
2443 (data).args [1] = arg2; \
2444 (data).args [2] = arg3; \
2445 (data).args [3] = arg4; \
2446 (data).args [4] = arg5; \
2447 (data).args [5] = arg6; \
2448 interp_entry (&data); \
2450 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
2451 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2452 (data).args [0] = arg1; \
2453 (data).args [1] = arg2; \
2454 (data).args [2] = arg3; \
2455 (data).args [3] = arg4; \
2456 (data).args [4] = arg5; \
2457 (data).args [5] = arg6; \
2458 (data).args [6] = arg7; \
2459 interp_entry (&data); \
2461 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
2462 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
2463 (data).args [0] = arg1; \
2464 (data).args [1] = arg2; \
2465 (data).args [2] = arg3; \
2466 (data).args [3] = arg4; \
2467 (data).args [4] = arg5; \
2468 (data).args [5] = arg6; \
2469 (data).args [6] = arg7; \
2470 (data).args [7] = arg8; \
2471 interp_entry (&data); \
2474 #define ARGLIST0 InterpMethod *rmethod
2475 #define ARGLIST1 gpointer arg1, InterpMethod *rmethod
2476 #define ARGLIST2 gpointer arg1, gpointer arg2, InterpMethod *rmethod
2477 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, InterpMethod *rmethod
2478 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, InterpMethod *rmethod
2479 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, InterpMethod *rmethod
2480 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, InterpMethod *rmethod
2481 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, InterpMethod *rmethod
2482 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, InterpMethod *rmethod
2484 static void interp_entry_static_0 (ARGLIST0
) INTERP_ENTRY0 (NULL
, NULL
, rmethod
)
2485 static void interp_entry_static_1 (ARGLIST1
) INTERP_ENTRY1 (NULL
, NULL
, rmethod
)
2486 static void interp_entry_static_2 (ARGLIST2
) INTERP_ENTRY2 (NULL
, NULL
, rmethod
)
2487 static void interp_entry_static_3 (ARGLIST3
) INTERP_ENTRY3 (NULL
, NULL
, rmethod
)
2488 static void interp_entry_static_4 (ARGLIST4
) INTERP_ENTRY4 (NULL
, NULL
, rmethod
)
2489 static void interp_entry_static_5 (ARGLIST5
) INTERP_ENTRY5 (NULL
, NULL
, rmethod
)
2490 static void interp_entry_static_6 (ARGLIST6
) INTERP_ENTRY6 (NULL
, NULL
, rmethod
)
2491 static void interp_entry_static_7 (ARGLIST7
) INTERP_ENTRY7 (NULL
, NULL
, rmethod
)
2492 static void interp_entry_static_8 (ARGLIST8
) INTERP_ENTRY8 (NULL
, NULL
, rmethod
)
2493 static void interp_entry_static_ret_0 (gpointer res
, ARGLIST0
) INTERP_ENTRY0 (NULL
, res
, rmethod
)
2494 static void interp_entry_static_ret_1 (gpointer res
, ARGLIST1
) INTERP_ENTRY1 (NULL
, res
, rmethod
)
2495 static void interp_entry_static_ret_2 (gpointer res
, ARGLIST2
) INTERP_ENTRY2 (NULL
, res
, rmethod
)
2496 static void interp_entry_static_ret_3 (gpointer res
, ARGLIST3
) INTERP_ENTRY3 (NULL
, res
, rmethod
)
2497 static void interp_entry_static_ret_4 (gpointer res
, ARGLIST4
) INTERP_ENTRY4 (NULL
, res
, rmethod
)
2498 static void interp_entry_static_ret_5 (gpointer res
, ARGLIST5
) INTERP_ENTRY5 (NULL
, res
, rmethod
)
2499 static void interp_entry_static_ret_6 (gpointer res
, ARGLIST6
) INTERP_ENTRY6 (NULL
, res
, rmethod
)
2500 static void interp_entry_static_ret_7 (gpointer res
, ARGLIST7
) INTERP_ENTRY7 (NULL
, res
, rmethod
)
2501 static void interp_entry_static_ret_8 (gpointer res
, ARGLIST8
) INTERP_ENTRY8 (NULL
, res
, rmethod
)
2502 static void interp_entry_instance_0 (gpointer this_arg
, ARGLIST0
) INTERP_ENTRY0 (this_arg
, NULL
, rmethod
)
2503 static void interp_entry_instance_1 (gpointer this_arg
, ARGLIST1
) INTERP_ENTRY1 (this_arg
, NULL
, rmethod
)
2504 static void interp_entry_instance_2 (gpointer this_arg
, ARGLIST2
) INTERP_ENTRY2 (this_arg
, NULL
, rmethod
)
2505 static void interp_entry_instance_3 (gpointer this_arg
, ARGLIST3
) INTERP_ENTRY3 (this_arg
, NULL
, rmethod
)
2506 static void interp_entry_instance_4 (gpointer this_arg
, ARGLIST4
) INTERP_ENTRY4 (this_arg
, NULL
, rmethod
)
2507 static void interp_entry_instance_5 (gpointer this_arg
, ARGLIST5
) INTERP_ENTRY5 (this_arg
, NULL
, rmethod
)
2508 static void interp_entry_instance_6 (gpointer this_arg
, ARGLIST6
) INTERP_ENTRY6 (this_arg
, NULL
, rmethod
)
2509 static void interp_entry_instance_7 (gpointer this_arg
, ARGLIST7
) INTERP_ENTRY7 (this_arg
, NULL
, rmethod
)
2510 static void interp_entry_instance_8 (gpointer this_arg
, ARGLIST8
) INTERP_ENTRY8 (this_arg
, NULL
, rmethod
)
2511 static void interp_entry_instance_ret_0 (gpointer this_arg
, gpointer res
, ARGLIST0
) INTERP_ENTRY0 (this_arg
, res
, rmethod
)
2512 static void interp_entry_instance_ret_1 (gpointer this_arg
, gpointer res
, ARGLIST1
) INTERP_ENTRY1 (this_arg
, res
, rmethod
)
2513 static void interp_entry_instance_ret_2 (gpointer this_arg
, gpointer res
, ARGLIST2
) INTERP_ENTRY2 (this_arg
, res
, rmethod
)
2514 static void interp_entry_instance_ret_3 (gpointer this_arg
, gpointer res
, ARGLIST3
) INTERP_ENTRY3 (this_arg
, res
, rmethod
)
2515 static void interp_entry_instance_ret_4 (gpointer this_arg
, gpointer res
, ARGLIST4
) INTERP_ENTRY4 (this_arg
, res
, rmethod
)
2516 static void interp_entry_instance_ret_5 (gpointer this_arg
, gpointer res
, ARGLIST5
) INTERP_ENTRY5 (this_arg
, res
, rmethod
)
2517 static void interp_entry_instance_ret_6 (gpointer this_arg
, gpointer res
, ARGLIST6
) INTERP_ENTRY6 (this_arg
, res
, rmethod
)
2518 static void interp_entry_instance_ret_7 (gpointer this_arg
, gpointer res
, ARGLIST7
) INTERP_ENTRY7 (this_arg
, res
, rmethod
)
2519 static void interp_entry_instance_ret_8 (gpointer this_arg
, gpointer res
, ARGLIST8
) INTERP_ENTRY8 (this_arg
, res
, rmethod
)
2521 #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
2523 static gpointer entry_funcs_static
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (static) };
2524 static gpointer entry_funcs_static_ret
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (static_ret
) };
2525 static gpointer entry_funcs_instance
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (instance
) };
2526 static gpointer entry_funcs_instance_ret
[MAX_INTERP_ENTRY_ARGS
+ 1] = { INTERP_ENTRY_FUNCLIST (instance_ret
) };
2528 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
2530 interp_entry_general (gpointer this_arg
, gpointer res
, gpointer
*args
, gpointer rmethod
)
2532 INTERP_ENTRY_BASE ((InterpMethod
*)rmethod
, this_arg
, res
);
2533 data
.many_args
= args
;
2534 interp_entry (&data
);
2537 #ifdef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
2539 // inline so we can alloc on stack
2540 #define alloc_storage_for_stackval(s, t, p) do { \
2541 if ((t)->type == MONO_TYPE_GENERICINST && !MONO_TYPE_IS_REFERENCE (t)) { \
2542 (s)->data.vt = alloca (mono_class_value_size (mono_class_from_mono_type_internal (t), NULL)); \
2543 } else if ((t)->type == MONO_TYPE_VALUETYPE) { \
2545 (s)->data.vt = alloca (mono_class_native_size ((t)->data.klass, NULL)); \
2547 (s)->data.vt = alloca (mono_class_value_size ((t)->data.klass, NULL)); \
2552 interp_entry_from_trampoline (gpointer ccontext_untyped
, gpointer rmethod_untyped
)
2555 ThreadContext
*context
;
2559 MonoMethodSignature
*sig
;
2560 CallContext
*ccontext
= (CallContext
*) ccontext_untyped
;
2561 InterpMethod
*rmethod
= (InterpMethod
*) rmethod_untyped
;
2562 gpointer orig_domain
= NULL
, attach_cookie
;
2565 if (rmethod
->needs_thread_attach
)
2566 orig_domain
= mono_threads_attach_coop (mono_domain_get (), &attach_cookie
);
2568 context
= get_context ();
2570 method
= rmethod
->method
;
2571 sig
= mono_method_signature_internal (method
);
2575 args
= (stackval
*)alloca (sizeof (stackval
) * (sig
->param_count
+ (sig
->hasthis
? 1 : 0)));
2577 init_frame (&frame
, NULL
, rmethod
, args
, &result
);
2579 /* Allocate storage for value types */
2580 for (i
= 0; i
< sig
->param_count
; i
++) {
2581 MonoType
*type
= sig
->params
[i
];
2582 alloc_storage_for_stackval (&frame
.stack_args
[i
+ sig
->hasthis
], type
, sig
->pinvoke
);
2585 if (sig
->ret
->type
!= MONO_TYPE_VOID
)
2586 alloc_storage_for_stackval (frame
.retval
, sig
->ret
, sig
->pinvoke
);
2588 /* Copy the args saved in the trampoline to the frame stack */
2589 mono_arch_get_native_call_context_args (ccontext
, &frame
, sig
);
2592 interp_exec_method (&frame
, context
, error
);
2594 if (rmethod
->needs_thread_attach
)
2595 mono_threads_detach_coop (orig_domain
, &attach_cookie
);
2598 g_assert (frame
.ex
== NULL
);
2600 /* Write back the return value */
2601 mono_arch_set_native_call_context_ret (ccontext
, &frame
, sig
);
2607 interp_entry_from_trampoline (gpointer ccontext_untyped
, gpointer rmethod_untyped
)
2609 g_assert_not_reached ();
2612 #endif /* MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE */
2614 static InterpMethod
*
2615 lookup_method_pointer (gpointer addr
)
2617 MonoDomain
*domain
= mono_domain_get ();
2618 MonoJitDomainInfo
*info
= domain_jit_info (domain
);
2619 InterpMethod
*res
= NULL
;
2621 mono_domain_lock (domain
);
2622 if (info
->interp_method_pointer_hash
)
2623 res
= (InterpMethod
*)g_hash_table_lookup (info
->interp_method_pointer_hash
, addr
);
2624 mono_domain_unlock (domain
);
2629 #ifndef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED
2631 interp_no_native_to_managed (void)
2633 g_error ("interpreter: native-to-managed transition not available on this platform");
2638 no_llvmonly_interp_method_pointer (void)
2640 g_assert_not_reached ();
2644 * interp_create_method_pointer_llvmonly:
2646 * Return an ftndesc for entering the interpreter and executing METHOD.
2649 interp_create_method_pointer_llvmonly (MonoMethod
*method
, gboolean unbox
, MonoError
*error
)
2651 MonoDomain
*domain
= mono_domain_get ();
2652 gpointer addr
, entry_func
, entry_wrapper
;
2653 MonoMethodSignature
*sig
;
2654 MonoMethod
*wrapper
;
2655 MonoJitDomainInfo
*info
;
2656 InterpMethod
*imethod
;
2658 imethod
= mono_interp_get_imethod (domain
, method
, error
);
2659 return_val_if_nok (error
, NULL
);
2662 if (imethod
->llvmonly_unbox_entry
)
2663 return (MonoFtnDesc
*)imethod
->llvmonly_unbox_entry
;
2665 if (imethod
->jit_entry
)
2666 return (MonoFtnDesc
*)imethod
->jit_entry
;
2669 sig
= mono_method_signature_internal (method
);
2672 * The entry functions need access to the method to call, so we have
2673 * to use a ftndesc. The caller uses a normal signature, while the
2674 * entry functions use a gsharedvt_in signature, so wrap the entry function in
2675 * a gsharedvt_in_sig wrapper.
2677 wrapper
= mini_get_gsharedvt_in_sig_wrapper (sig
);
2679 entry_wrapper
= mono_jit_compile_method_jit_only (wrapper
, error
);
2680 mono_error_assertf_ok (error
, "couldn't compile wrapper \"%s\" for \"%s\"",
2681 mono_method_get_name_full (wrapper
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
),
2682 mono_method_get_name_full (method
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
));
2684 if (sig
->param_count
> MAX_INTERP_ENTRY_ARGS
) {
2685 g_assert_not_reached ();
2686 //entry_func = (gpointer)interp_entry_general;
2687 } else if (sig
->hasthis
) {
2688 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2689 entry_func
= entry_funcs_instance
[sig
->param_count
];
2691 entry_func
= entry_funcs_instance_ret
[sig
->param_count
];
2693 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2694 entry_func
= entry_funcs_static
[sig
->param_count
];
2696 entry_func
= entry_funcs_static_ret
[sig
->param_count
];
2698 g_assert (entry_func
);
2700 /* Encode unbox in the lower bit of imethod */
2701 gpointer entry_arg
= imethod
;
2703 entry_arg
= (gpointer
)(((gsize
)entry_arg
) | 1);
2704 MonoFtnDesc
*entry_ftndesc
= mini_llvmonly_create_ftndesc (mono_domain_get (), entry_func
, entry_arg
);
2706 addr
= mini_llvmonly_create_ftndesc (mono_domain_get (), entry_wrapper
, entry_ftndesc
);
2708 info
= domain_jit_info (domain
);
2709 mono_domain_lock (domain
);
2710 if (!info
->interp_method_pointer_hash
)
2711 info
->interp_method_pointer_hash
= g_hash_table_new (NULL
, NULL
);
2712 g_hash_table_insert (info
->interp_method_pointer_hash
, addr
, imethod
);
2713 mono_domain_unlock (domain
);
2715 mono_memory_barrier ();
2717 imethod
->llvmonly_unbox_entry
= addr
;
2719 imethod
->jit_entry
= addr
;
2721 return (MonoFtnDesc
*)addr
;
2725 * interp_create_method_pointer:
2727 * Return a function pointer which can be used to call METHOD using the
2728 * interpreter. Return NULL for methods which are not supported.
2731 interp_create_method_pointer (MonoMethod
*method
, gboolean compile
, MonoError
*error
)
2733 #ifndef MONO_ARCH_HAVE_INTERP_NATIVE_TO_MANAGED
2735 return (gpointer
)no_llvmonly_interp_method_pointer
;
2736 return (gpointer
)interp_no_native_to_managed
;
2738 gpointer addr
, entry_func
, entry_wrapper
= NULL
;
2739 MonoDomain
*domain
= mono_domain_get ();
2740 MonoJitDomainInfo
*info
;
2741 InterpMethod
*imethod
= mono_interp_get_imethod (domain
, method
, error
);
2744 return (gpointer
)no_llvmonly_interp_method_pointer
;
2746 if (imethod
->jit_entry
)
2747 return imethod
->jit_entry
;
2749 if (compile
&& !imethod
->transformed
) {
2750 /* Return any errors from method compilation */
2751 mono_interp_transform_method (imethod
, get_context (), error
);
2752 return_val_if_nok (error
, NULL
);
2755 MonoMethodSignature
*sig
= mono_method_signature_internal (method
);
2758 /* The caller should call interp_create_method_pointer_llvmonly */
2759 g_assert_not_reached ();
2761 if (method
->wrapper_type
&& method
->wrapper_type
== MONO_WRAPPER_MANAGED_TO_NATIVE
)
2764 #ifndef MONO_ARCH_HAVE_FTNPTR_ARG_TRAMPOLINE
2766 * Interp in wrappers get the argument in the rgctx register. If
2767 * MONO_ARCH_HAVE_FTNPTR_ARG_TRAMPOLINE is defined it means that
2768 * on that arch the rgctx register is not scratch, so we use a
2769 * separate temp register. We should update the wrappers for this
2770 * if we really care about those architectures (arm).
2772 MonoMethod
*wrapper
= mini_get_interp_in_wrapper (sig
);
2774 entry_wrapper
= mono_jit_compile_method_jit_only (wrapper
, error
);
2776 if (entry_wrapper
) {
2777 if (sig
->param_count
> MAX_INTERP_ENTRY_ARGS
) {
2778 entry_func
= (gpointer
)interp_entry_general
;
2779 } else if (sig
->hasthis
) {
2780 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2781 entry_func
= entry_funcs_instance
[sig
->param_count
];
2783 entry_func
= entry_funcs_instance_ret
[sig
->param_count
];
2785 if (sig
->ret
->type
== MONO_TYPE_VOID
)
2786 entry_func
= entry_funcs_static
[sig
->param_count
];
2788 entry_func
= entry_funcs_static_ret
[sig
->param_count
];
2791 #ifndef MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE
2792 mono_error_assertf_ok (error
, "couldn't compile wrapper \"%s\" for \"%s\"",
2793 mono_method_get_name_full (wrapper
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
),
2794 mono_method_get_name_full (method
, TRUE
, TRUE
, MONO_TYPE_NAME_FORMAT_IL
));
2796 mono_error_cleanup (error
);
2797 error_init_reuse (error
);
2798 if (!mono_native_to_interp_trampoline
) {
2799 if (mono_aot_only
) {
2800 mono_native_to_interp_trampoline
= (MonoFuncV
)mono_aot_get_trampoline ("native_to_interp_trampoline");
2802 MonoTrampInfo
*info
;
2803 mono_native_to_interp_trampoline
= (MonoFuncV
)mono_arch_get_native_to_interp_trampoline (&info
);
2804 mono_tramp_info_register (info
, NULL
);
2807 entry_wrapper
= (gpointer
)mono_native_to_interp_trampoline
;
2808 /* We need the lmf wrapper only when being called from mixed mode */
2810 entry_func
= (gpointer
)interp_entry_from_trampoline
;
2812 static gpointer cached_func
= NULL
;
2814 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
);
2815 mono_memory_barrier ();
2817 entry_func
= cached_func
;
2822 g_assert (entry_func
);
2823 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
2824 MonoFtnDesc
*ftndesc
= g_new0 (MonoFtnDesc
, 1);
2825 ftndesc
->addr
= entry_func
;
2826 ftndesc
->arg
= imethod
;
2827 mono_error_assert_ok (error
);
2830 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
2831 * rgctx register using a trampoline.
2834 addr
= mono_create_ftnptr_arg_trampoline (ftndesc
, entry_wrapper
);
2836 info
= domain_jit_info (domain
);
2837 mono_domain_lock (domain
);
2838 if (!info
->interp_method_pointer_hash
)
2839 info
->interp_method_pointer_hash
= g_hash_table_new (NULL
, NULL
);
2840 g_hash_table_insert (info
->interp_method_pointer_hash
, addr
, imethod
);
2841 mono_domain_unlock (domain
);
2843 mono_memory_barrier ();
2844 imethod
->jit_entry
= addr
;
2851 static int opcode_counts
[512];
2853 #define COUNT_OP(op) opcode_counts[op]++
2855 #define COUNT_OP(op)
2859 #define DUMP_INSTR() \
2860 if (tracing > 1) { \
2862 if (sp > frame->stack) { \
2863 ins = dump_stack (frame->stack, sp); \
2865 ins = g_strdup (""); \
2869 char *mn = mono_method_full_name (frame->imethod->method, FALSE); \
2870 char *disasm = mono_interp_dis_mintop(imethod->code, ip); \
2871 g_print ("(%p) %s -> %s\t%d:%s\n", mono_thread_internal_current (), mn, disasm, vt_sp - vtalloc, ins); \
2877 #define DUMP_INSTR()
2880 #define INIT_VTABLE(vtable) do { \
2881 if (G_UNLIKELY (!(vtable)->initialized)) { \
2882 mono_runtime_class_init_full ((vtable), error); \
2883 if (!is_ok (error)) \
2884 THROW_EX (mono_error_convert_to_exception (error), ip); \
2891 * The interpreter executes in gc unsafe (non-preempt) mode. On wasm, the C stack is
2892 * scannable but the wasm stack is not, so to make the code GC safe, the following rules
2893 * should be followed:
2894 * - every objref handled by the code needs to have a copy stored inside InterpFrame,
2895 * in stackval->data.o. For objrefs which are not yet on the IL stack, they can be stored
2896 * in frame->o. This will ensure the objects are pinned. The 'frame' local is assumed
2897 * to be allocated to the C stack and not to registers.
2898 * - minimalize the number of MonoObject* locals/arguments.
2902 #define frame_objref(frame) (frame)->o
2904 #define frame_objref(frame) o
2907 // This function is outlined to help save stack in its caller, on the premise
2908 // that it is relatively rarely called. This also lets it use alloca.
2909 static MONO_NEVER_INLINE
void
2910 mono_interp_calli_nat_dynamic_pinvoke (
2911 // Parameters are sorted by name.
2912 InterpFrame
* child_frame
,
2914 ThreadContext
*context
,
2915 MonoMethodSignature
* csignature
,
2917 InterpMethod
* imethod
)
2919 g_assert (imethod
->method
->dynamic
&& csignature
->pinvoke
);
2921 /* Pinvoke call is missing the wrapper. See mono_get_native_calli_wrapper */
2922 MonoMarshalSpec
** mspecs
= g_newa (MonoMarshalSpec
*, csignature
->param_count
+ 1);
2923 memset (mspecs
, 0, sizeof (MonoMarshalSpec
*) * (csignature
->param_count
+ 1));
2925 MonoMethodPInvoke iinfo
;
2926 memset (&iinfo
, 0, sizeof (iinfo
));
2928 MonoMethod
* m
= mono_marshal_get_native_func_wrapper (m_class_get_image (imethod
->method
->klass
), csignature
, &iinfo
, mspecs
, code
);
2930 for (int i
= csignature
->param_count
; i
>= 0; i
--)
2932 mono_metadata_free_marshal_spec (mspecs
[i
]);
2934 child_frame
->imethod
= mono_interp_get_imethod (imethod
->domain
, m
, error
);
2935 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
2937 interp_exec_method (child_frame
, context
, error
);
2941 * If EXIT_AT_FINALLY is not -1, exit after exiting the finally clause with that index.
2942 * If BASE_FRAME is not NULL, copy arguments/locals from BASE_FRAME.
2943 * The ERROR argument is used to avoid declaring an error object for every interp frame, its not used
2944 * to return error information.
2947 interp_exec_method_full (InterpFrame
*frame
, ThreadContext
*context
, FrameClauseArgs
*clause_args
, MonoError
*error
)
2949 InterpFrame child_frame
;
2950 const unsigned short *ip
= NULL
;
2952 InterpMethod
*imethod
= NULL
;
2954 gint tracing
= global_tracing
;
2955 unsigned char *vtalloc
;
2958 unsigned char *vt_sp
;
2959 unsigned char *locals
= NULL
;
2960 // See the comment about GC safety above
2961 MonoObject
*o
= NULL
;
2963 #if USE_COMPUTED_GOTO
2964 static void *in_labels
[] = {
2965 #define OPDEF(a,b,c,d) \
2967 #include "mintops.def"
2972 frame
->finally_ips
= NULL
;
2973 frame
->endfinally_ip
= NULL
;
2976 debug_enter (frame
, &tracing
);
2979 imethod
= frame
->imethod
;
2980 if (!imethod
->transformed
) {
2982 char *mn
= mono_method_full_name (imethod
->method
, TRUE
);
2983 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn
);
2988 do_transform_method (frame
, context
);
2990 THROW_EX (frame
->ex
, NULL
);
2991 EXCEPTION_CHECKPOINT
;
2995 frame
->args
= g_newa (char, imethod
->alloca_size
);
2998 ip
= clause_args
->start_with_ip
;
2999 if (clause_args
->base_frame
) {
3000 frame
->args
= g_newa (char, imethod
->alloca_size
);
3001 memcpy (frame
->args
, clause_args
->base_frame
->args
, imethod
->alloca_size
);
3004 sp
= frame
->stack
= (stackval
*) (char *) frame
->args
;
3005 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
3009 locals
= (unsigned char *) vt_sp
+ imethod
->vt_stack_size
;
3010 frame
->locals
= locals
;
3011 child_frame
.parent
= frame
;
3013 if (clause_args
&& clause_args
->filter_exception
) {
3014 sp
->data
.p
= clause_args
->filter_exception
;
3018 //g_print ("(%p) Call %s\n", mono_thread_internal_current (), mono_method_get_full_name (frame->imethod->method));
3021 * using while (ip < end) may result in a 15% performance drop,
3022 * but it may be useful for debug
3025 #ifndef USE_COMPUTED_GOTO
3028 /* g_assert (sp >= frame->stack); */
3029 /* g_assert(vt_sp - vtalloc <= imethod->vt_stack_size); */
3031 MINT_IN_SWITCH (*ip
) {
3032 MINT_IN_CASE(MINT_INITLOCALS
)
3033 memset (locals
, 0, imethod
->locals_size
);
3036 MINT_IN_CASE(MINT_NOP
)
3039 MINT_IN_CASE(MINT_NIY
)
3040 g_error ("mint_niy: instruction not implemented yet. This shouldn't happen.");
3042 MINT_IN_CASE(MINT_BREAK
)
3044 do_debugger_tramp (mini_get_dbg_callbacks ()->user_break
, frame
);
3046 MINT_IN_CASE(MINT_BREAKPOINT
)
3050 MINT_IN_CASE(MINT_LDNULL
)
3055 MINT_IN_CASE(MINT_ARGLIST
)
3056 g_assert (frame
->varargs
);
3058 *(gpointer
*)sp
->data
.p
= frame
->varargs
;
3059 vt_sp
+= ALIGN_TO (sizeof (gpointer
), MINT_VT_ALIGNMENT
);
3063 MINT_IN_CASE(MINT_VTRESULT
) {
3064 int ret_size
= * (guint16
*)(ip
+ 1);
3065 unsigned char *ret_vt_sp
= vt_sp
;
3066 vt_sp
-= READ32(ip
+ 2);
3068 memmove (vt_sp
, ret_vt_sp
, ret_size
);
3069 sp
[-1].data
.p
= vt_sp
;
3070 vt_sp
+= ALIGN_TO (ret_size
, MINT_VT_ALIGNMENT
);
3075 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
3076 MINT_IN_CASE(MINT_LDC_I4_M1
)
3079 MINT_IN_CASE(MINT_LDC_I4_0
)
3082 MINT_IN_CASE(MINT_LDC_I4_1
)
3085 MINT_IN_CASE(MINT_LDC_I4_2
)
3088 MINT_IN_CASE(MINT_LDC_I4_3
)
3091 MINT_IN_CASE(MINT_LDC_I4_4
)
3094 MINT_IN_CASE(MINT_LDC_I4_5
)
3097 MINT_IN_CASE(MINT_LDC_I4_6
)
3100 MINT_IN_CASE(MINT_LDC_I4_7
)
3103 MINT_IN_CASE(MINT_LDC_I4_8
)
3106 MINT_IN_CASE(MINT_LDC_I4_S
)
3107 sp
->data
.i
= *(const short *)(ip
+ 1);
3111 MINT_IN_CASE(MINT_LDC_I4
)
3113 sp
->data
.i
= READ32 (ip
);
3117 MINT_IN_CASE(MINT_LDC_I8
)
3119 sp
->data
.l
= READ64 (ip
);
3123 MINT_IN_CASE(MINT_LDC_I8_S
)
3124 sp
->data
.l
= *(const short *)(ip
+ 1);
3128 MINT_IN_CASE(MINT_LDC_R4
) {
3132 sp
->data
.f_r4
= * (float *)&val
;
3137 MINT_IN_CASE(MINT_LDC_R8
)
3138 sp
->data
.l
= READ64 (ip
+ 1); /* note union usage */
3142 MINT_IN_CASE(MINT_DUP
)
3147 MINT_IN_CASE(MINT_DUP_VT
)
3148 i32
= READ32 (ip
+ 1);
3150 memcpy(sp
->data
.p
, sp
[-1].data
.p
, i32
);
3151 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
3155 MINT_IN_CASE(MINT_POP
) {
3156 guint16 u16
= (* (guint16
*)(ip
+ 1)) + 1;
3158 memmove (sp
- u16
, sp
- 1, (u16
- 1) * sizeof (stackval
));
3163 MINT_IN_CASE(MINT_JMP
) {
3164 InterpMethod
*new_method
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3165 gboolean realloc_frame
= new_method
->alloca_size
> imethod
->alloca_size
;
3167 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_TAIL_CALL
)
3168 MONO_PROFILER_RAISE (method_tail_call
, (imethod
->method
, new_method
->method
));
3170 if (!new_method
->transformed
) {
3171 MONO_API_ERROR_INIT (error
);
3174 mono_interp_transform_method (new_method
, context
, error
);
3175 frame
->ex
= mono_error_convert_to_exception (error
);
3180 imethod
= frame
->imethod
= new_method
;
3182 * We allocate the stack frame from scratch and store the arguments in the
3183 * locals again since it's possible for the caller stack frame to be smaller
3184 * than the callee stack frame (at the interp level)
3186 if (realloc_frame
) {
3187 frame
->args
= g_newa (char, imethod
->alloca_size
);
3188 memset (frame
->args
, 0, imethod
->alloca_size
);
3189 sp
= frame
->stack
= (stackval
*) frame
->args
;
3191 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
3195 locals
= vt_sp
+ imethod
->vt_stack_size
;
3196 frame
->locals
= locals
;
3200 MINT_IN_CASE(MINT_CALLI
) {
3201 MonoMethodSignature
*csignature
;
3202 stackval
*endsp
= sp
;
3206 csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3210 child_frame
.imethod
= (InterpMethod
*)sp
->data
.p
;
3213 child_frame
.retval
= sp
;
3214 /* decrement by the actual number of args */
3215 sp
-= csignature
->param_count
;
3216 if (csignature
->hasthis
)
3218 child_frame
.stack_args
= sp
;
3220 if (child_frame
.imethod
->method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
) {
3221 child_frame
.imethod
= mono_interp_get_imethod (imethod
->domain
, mono_marshal_get_native_wrapper (child_frame
.imethod
->method
, FALSE
, FALSE
), error
);
3222 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
3225 if (csignature
->hasthis
) {
3226 MonoObject
*this_arg
= (MonoObject
*)sp
->data
.p
;
3228 if (m_class_is_valuetype (this_arg
->vtable
->klass
)) {
3229 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3230 sp
[0].data
.p
= unboxed
;
3234 interp_exec_method (&child_frame
, context
, error
);
3236 CHECK_RESUME_STATE (context
);
3238 /* need to handle typedbyref ... */
3239 if (csignature
->ret
->type
!= MONO_TYPE_VOID
) {
3245 MINT_IN_CASE(MINT_CALLI_NAT_FAST
) {
3246 gpointer target_ip
= sp
[-1].data
.p
;
3247 MonoMethodSignature
*csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3248 int opcode
= *(guint16
*)(ip
+ 2);
3249 gboolean save_last_error
= *(guint16
*)(ip
+ 3);
3254 sp
= do_icall_wrapper (frame
, csignature
, opcode
, sp
, target_ip
, save_last_error
);
3255 EXCEPTION_CHECKPOINT
;
3256 CHECK_RESUME_STATE (context
);
3260 MINT_IN_CASE(MINT_CALLI_NAT
) {
3262 stackval
*endsp
= sp
;
3265 MonoMethodSignature
* csignature
= (MonoMethodSignature
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3270 guchar
* const code
= (guchar
*)sp
->data
.p
;
3271 child_frame
.imethod
= NULL
;
3274 child_frame
.retval
= sp
;
3275 /* decrement by the actual number of args */
3276 sp
-= csignature
->param_count
;
3277 if (csignature
->hasthis
)
3279 child_frame
.stack_args
= sp
;
3281 if (imethod
->method
->dynamic
&& csignature
->pinvoke
) {
3282 mono_interp_calli_nat_dynamic_pinvoke (&child_frame
, code
, context
, csignature
, error
, imethod
);
3284 const gboolean save_last_error
= *(guint16
*)(ip
- 3 + 2);
3285 ves_pinvoke_method (&child_frame
, csignature
, (MonoFuncV
) code
, FALSE
, context
, save_last_error
);
3288 CHECK_RESUME_STATE (context
);
3290 /* need to handle typedbyref ... */
3291 if (csignature
->ret
->type
!= MONO_TYPE_VOID
) {
3297 MINT_IN_CASE(MINT_CALLVIRT_FAST
)
3298 MINT_IN_CASE(MINT_VCALLVIRT_FAST
) {
3299 MonoObject
*this_arg
;
3300 MonoClass
*this_class
;
3301 gboolean is_void
= *ip
== MINT_VCALLVIRT_FAST
;
3302 InterpMethod
*target_imethod
;
3303 stackval
*endsp
= sp
;
3306 // FIXME Have it handle also remoting calls and use a single opcode for virtual calls
3310 target_imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3311 slot
= *(gint16
*)(ip
+ 2);
3314 child_frame
.retval
= sp
;
3316 /* decrement by the actual number of args */
3317 sp
-= target_imethod
->param_count
+ target_imethod
->hasthis
;
3318 child_frame
.stack_args
= sp
;
3320 this_arg
= (MonoObject
*)sp
->data
.p
;
3321 this_class
= this_arg
->vtable
->klass
;
3323 child_frame
.imethod
= get_virtual_method_fast (target_imethod
, this_arg
->vtable
, slot
);
3324 if (m_class_is_valuetype (this_class
) && m_class_is_valuetype (child_frame
.imethod
->method
->klass
)) {
3326 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3327 sp
[0].data
.p
= unboxed
;
3330 interp_exec_method (&child_frame
, context
, error
);
3332 CHECK_RESUME_STATE (context
);
3335 /* need to handle typedbyref ... */
3341 MINT_IN_CASE(MINT_CALL_VARARG
) {
3342 stackval
*endsp
= sp
;
3343 int num_varargs
= 0;
3344 MonoMethodSignature
*csig
;
3348 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3349 /* The real signature for vararg calls */
3350 csig
= (MonoMethodSignature
*) imethod
->data_items
[* (guint16
*) (ip
+ 2)];
3351 /* Push all vararg arguments from normal sp to vt_sp together with the signature */
3352 num_varargs
= csig
->param_count
- csig
->sentinelpos
;
3353 child_frame
.varargs
= (char*) vt_sp
;
3354 vt_sp
= copy_varargs_vtstack (csig
, sp
, vt_sp
);
3358 child_frame
.retval
= sp
;
3360 /* decrement by the actual number of args */
3361 sp
-= child_frame
.imethod
->param_count
+ child_frame
.imethod
->hasthis
+ num_varargs
;
3362 child_frame
.stack_args
= sp
;
3364 interp_exec_method (&child_frame
, context
, error
);
3366 CHECK_RESUME_STATE (context
);
3368 if (csig
->ret
->type
!= MONO_TYPE_VOID
) {
3374 MINT_IN_CASE(MINT_CALL
)
3375 MINT_IN_CASE(MINT_VCALL
)
3376 MINT_IN_CASE(MINT_CALLVIRT
)
3377 MINT_IN_CASE(MINT_VCALLVIRT
) {
3378 gboolean is_void
= *ip
== MINT_VCALL
|| *ip
== MINT_VCALLVIRT
;
3379 gboolean is_virtual
= *ip
== MINT_CALLVIRT
|| *ip
== MINT_VCALLVIRT
;
3380 stackval
*endsp
= sp
;
3384 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3387 child_frame
.retval
= sp
;
3389 /* decrement by the actual number of args */
3390 sp
-= child_frame
.imethod
->param_count
+ child_frame
.imethod
->hasthis
;
3391 child_frame
.stack_args
= sp
;
3394 MonoObject
*this_arg
= (MonoObject
*)sp
->data
.p
;
3395 MonoClass
*this_class
= this_arg
->vtable
->klass
;
3397 child_frame
.imethod
= get_virtual_method (child_frame
.imethod
, this_arg
->vtable
);
3398 if (m_class_is_valuetype (this_class
) && m_class_is_valuetype (child_frame
.imethod
->method
->klass
)) {
3400 gpointer unboxed
= mono_object_unbox_internal (this_arg
);
3401 sp
[0].data
.p
= unboxed
;
3405 interp_exec_method (&child_frame
, context
, error
);
3407 CHECK_RESUME_STATE (context
);
3410 /* need to handle typedbyref ... */
3416 MINT_IN_CASE(MINT_JIT_CALL
) {
3417 InterpMethod
*rmethod
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3418 MONO_API_ERROR_INIT (error
);
3420 sp
= do_jit_call (sp
, vt_sp
, context
, frame
, rmethod
, error
);
3421 if (!is_ok (error
)) {
3422 MonoException
*ex
= mono_error_convert_to_exception (error
);
3427 CHECK_RESUME_STATE (context
);
3429 if (rmethod
->rtype
->type
!= MONO_TYPE_VOID
)
3434 MINT_IN_CASE(MINT_CALLRUN
) {
3435 MonoMethod
*target_method
= (MonoMethod
*) imethod
->data_items
[* (guint16
*)(ip
+ 1)];
3436 MonoMethodSignature
*sig
= (MonoMethodSignature
*) imethod
->data_items
[* (guint16
*)(ip
+ 2)];
3442 sp
-= sig
->param_count
;
3446 ves_imethod (frame
, target_method
, sig
, sp
, retval
);
3448 THROW_EX (frame
->ex
, ip
);
3450 if (sig
->ret
->type
!= MONO_TYPE_VOID
) {
3457 MINT_IN_CASE(MINT_RET
)
3459 *frame
->retval
= *sp
;
3460 if (sp
> frame
->stack
)
3461 g_warning ("ret: more values on stack: %d", sp
-frame
->stack
);
3463 MINT_IN_CASE(MINT_RET_VOID
)
3464 if (sp
> frame
->stack
)
3465 g_warning ("ret.void: more values on stack: %d %s", sp
-frame
->stack
, mono_method_full_name (imethod
->method
, TRUE
));
3467 MINT_IN_CASE(MINT_RET_VT
)
3468 i32
= READ32(ip
+ 1);
3470 memcpy(frame
->retval
->data
.p
, sp
->data
.p
, i32
);
3471 if (sp
> frame
->stack
)
3472 g_warning ("ret.vt: more values on stack: %d", sp
-frame
->stack
);
3474 MINT_IN_CASE(MINT_BR_S
)
3475 ip
+= (short) *(ip
+ 1);
3477 MINT_IN_CASE(MINT_BR
)
3478 ip
+= (gint32
) READ32(ip
+ 1);
3480 #define ZEROP_S(datamem, op) \
3482 if (sp->data.datamem op 0) \
3483 ip += * (gint16 *)(ip + 1); \
3487 #define ZEROP(datamem, op) \
3489 if (sp->data.datamem op 0) \
3490 ip += (gint32)READ32(ip + 1); \
3494 MINT_IN_CASE(MINT_BRFALSE_I4_S
)
3497 MINT_IN_CASE(MINT_BRFALSE_I8_S
)
3500 MINT_IN_CASE(MINT_BRFALSE_R4_S
)
3503 MINT_IN_CASE(MINT_BRFALSE_R8_S
)
3506 MINT_IN_CASE(MINT_BRFALSE_I4
)
3509 MINT_IN_CASE(MINT_BRFALSE_I8
)
3512 MINT_IN_CASE(MINT_BRFALSE_R4
)
3515 MINT_IN_CASE(MINT_BRFALSE_R8
)
3518 MINT_IN_CASE(MINT_BRTRUE_I4_S
)
3521 MINT_IN_CASE(MINT_BRTRUE_I8_S
)
3524 MINT_IN_CASE(MINT_BRTRUE_R4_S
)
3527 MINT_IN_CASE(MINT_BRTRUE_R8_S
)
3530 MINT_IN_CASE(MINT_BRTRUE_I4
)
3533 MINT_IN_CASE(MINT_BRTRUE_I8
)
3536 MINT_IN_CASE(MINT_BRTRUE_R4
)
3539 MINT_IN_CASE(MINT_BRTRUE_R8
)
3542 #define CONDBR_S(cond) \
3545 ip += * (gint16 *)(ip + 1); \
3548 #define BRELOP_S(datamem, op) \
3549 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
3551 #define CONDBR(cond) \
3554 ip += (gint32)READ32(ip + 1); \
3558 #define BRELOP(datamem, op) \
3559 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
3561 MINT_IN_CASE(MINT_BEQ_I4_S
)
3564 MINT_IN_CASE(MINT_BEQ_I8_S
)
3567 MINT_IN_CASE(MINT_BEQ_R4_S
)
3568 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
== sp
[1].data
.f_r4
)
3570 MINT_IN_CASE(MINT_BEQ_R8_S
)
3571 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
== sp
[1].data
.f
)
3573 MINT_IN_CASE(MINT_BEQ_I4
)
3576 MINT_IN_CASE(MINT_BEQ_I8
)
3579 MINT_IN_CASE(MINT_BEQ_R4
)
3580 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
== sp
[1].data
.f_r4
)
3582 MINT_IN_CASE(MINT_BEQ_R8
)
3583 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
== sp
[1].data
.f
)
3585 MINT_IN_CASE(MINT_BGE_I4_S
)
3588 MINT_IN_CASE(MINT_BGE_I8_S
)
3591 MINT_IN_CASE(MINT_BGE_R4_S
)
3592 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3594 MINT_IN_CASE(MINT_BGE_R8_S
)
3595 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
>= sp
[1].data
.f
)
3597 MINT_IN_CASE(MINT_BGE_I4
)
3600 MINT_IN_CASE(MINT_BGE_I8
)
3603 MINT_IN_CASE(MINT_BGE_R4
)
3604 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3606 MINT_IN_CASE(MINT_BGE_R8
)
3607 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
>= sp
[1].data
.f
)
3609 MINT_IN_CASE(MINT_BGT_I4_S
)
3612 MINT_IN_CASE(MINT_BGT_I8_S
)
3615 MINT_IN_CASE(MINT_BGT_R4_S
)
3616 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3618 MINT_IN_CASE(MINT_BGT_R8_S
)
3619 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
> sp
[1].data
.f
)
3621 MINT_IN_CASE(MINT_BGT_I4
)
3624 MINT_IN_CASE(MINT_BGT_I8
)
3627 MINT_IN_CASE(MINT_BGT_R4
)
3628 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3630 MINT_IN_CASE(MINT_BGT_R8
)
3631 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
> sp
[1].data
.f
)
3633 MINT_IN_CASE(MINT_BLT_I4_S
)
3636 MINT_IN_CASE(MINT_BLT_I8_S
)
3639 MINT_IN_CASE(MINT_BLT_R4_S
)
3640 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3642 MINT_IN_CASE(MINT_BLT_R8_S
)
3643 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
< sp
[1].data
.f
)
3645 MINT_IN_CASE(MINT_BLT_I4
)
3648 MINT_IN_CASE(MINT_BLT_I8
)
3651 MINT_IN_CASE(MINT_BLT_R4
)
3652 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3654 MINT_IN_CASE(MINT_BLT_R8
)
3655 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
< sp
[1].data
.f
)
3657 MINT_IN_CASE(MINT_BLE_I4_S
)
3660 MINT_IN_CASE(MINT_BLE_I8_S
)
3663 MINT_IN_CASE(MINT_BLE_R4_S
)
3664 CONDBR_S(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3666 MINT_IN_CASE(MINT_BLE_R8_S
)
3667 CONDBR_S(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
<= sp
[1].data
.f
)
3669 MINT_IN_CASE(MINT_BLE_I4
)
3672 MINT_IN_CASE(MINT_BLE_I8
)
3675 MINT_IN_CASE(MINT_BLE_R4
)
3676 CONDBR(!isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) && sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3678 MINT_IN_CASE(MINT_BLE_R8
)
3679 CONDBR(!mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) && sp
[0].data
.f
<= sp
[1].data
.f
)
3681 MINT_IN_CASE(MINT_BNE_UN_I4_S
)
3684 MINT_IN_CASE(MINT_BNE_UN_I8_S
)
3687 MINT_IN_CASE(MINT_BNE_UN_R4_S
)
3688 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
!= sp
[1].data
.f_r4
)
3690 MINT_IN_CASE(MINT_BNE_UN_R8_S
)
3691 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
!= sp
[1].data
.f
)
3693 MINT_IN_CASE(MINT_BNE_UN_I4
)
3696 MINT_IN_CASE(MINT_BNE_UN_I8
)
3699 MINT_IN_CASE(MINT_BNE_UN_R4
)
3700 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
!= sp
[1].data
.f_r4
)
3702 MINT_IN_CASE(MINT_BNE_UN_R8
)
3703 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
!= sp
[1].data
.f
)
3706 #define BRELOP_S_CAST(datamem, op, type) \
3708 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3709 ip += * (gint16 *)(ip + 1); \
3713 #define BRELOP_CAST(datamem, op, type) \
3715 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
3716 ip += (gint32)READ32(ip + 1); \
3720 MINT_IN_CASE(MINT_BGE_UN_I4_S
)
3721 BRELOP_S_CAST(i
, >=, guint32
);
3723 MINT_IN_CASE(MINT_BGE_UN_I8_S
)
3724 BRELOP_S_CAST(l
, >=, guint64
);
3726 MINT_IN_CASE(MINT_BGE_UN_R4_S
)
3727 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3729 MINT_IN_CASE(MINT_BGE_UN_R8_S
)
3730 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
>= sp
[1].data
.f
)
3732 MINT_IN_CASE(MINT_BGE_UN_I4
)
3733 BRELOP_CAST(i
, >=, guint32
);
3735 MINT_IN_CASE(MINT_BGE_UN_I8
)
3736 BRELOP_CAST(l
, >=, guint64
);
3738 MINT_IN_CASE(MINT_BGE_UN_R4
)
3739 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
>= sp
[1].data
.f_r4
)
3741 MINT_IN_CASE(MINT_BGE_UN_R8
)
3742 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
>= sp
[1].data
.f
)
3744 MINT_IN_CASE(MINT_BGT_UN_I4_S
)
3745 BRELOP_S_CAST(i
, >, guint32
);
3747 MINT_IN_CASE(MINT_BGT_UN_I8_S
)
3748 BRELOP_S_CAST(l
, >, guint64
);
3750 MINT_IN_CASE(MINT_BGT_UN_R4_S
)
3751 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3753 MINT_IN_CASE(MINT_BGT_UN_R8_S
)
3754 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
> sp
[1].data
.f
)
3756 MINT_IN_CASE(MINT_BGT_UN_I4
)
3757 BRELOP_CAST(i
, >, guint32
);
3759 MINT_IN_CASE(MINT_BGT_UN_I8
)
3760 BRELOP_CAST(l
, >, guint64
);
3762 MINT_IN_CASE(MINT_BGT_UN_R4
)
3763 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
> sp
[1].data
.f_r4
)
3765 MINT_IN_CASE(MINT_BGT_UN_R8
)
3766 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
> sp
[1].data
.f
)
3768 MINT_IN_CASE(MINT_BLE_UN_I4_S
)
3769 BRELOP_S_CAST(i
, <=, guint32
);
3771 MINT_IN_CASE(MINT_BLE_UN_I8_S
)
3772 BRELOP_S_CAST(l
, <=, guint64
);
3774 MINT_IN_CASE(MINT_BLE_UN_R4_S
)
3775 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3777 MINT_IN_CASE(MINT_BLE_UN_R8_S
)
3778 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
<= sp
[1].data
.f
)
3780 MINT_IN_CASE(MINT_BLE_UN_I4
)
3781 BRELOP_CAST(i
, <=, guint32
);
3783 MINT_IN_CASE(MINT_BLE_UN_I8
)
3784 BRELOP_CAST(l
, <=, guint64
);
3786 MINT_IN_CASE(MINT_BLE_UN_R4
)
3787 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
<= sp
[1].data
.f_r4
)
3789 MINT_IN_CASE(MINT_BLE_UN_R8
)
3790 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
<= sp
[1].data
.f
)
3792 MINT_IN_CASE(MINT_BLT_UN_I4_S
)
3793 BRELOP_S_CAST(i
, <, guint32
);
3795 MINT_IN_CASE(MINT_BLT_UN_I8_S
)
3796 BRELOP_S_CAST(l
, <, guint64
);
3798 MINT_IN_CASE(MINT_BLT_UN_R4_S
)
3799 CONDBR_S(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3801 MINT_IN_CASE(MINT_BLT_UN_R8_S
)
3802 CONDBR_S(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
< sp
[1].data
.f
)
3804 MINT_IN_CASE(MINT_BLT_UN_I4
)
3805 BRELOP_CAST(i
, <, guint32
);
3807 MINT_IN_CASE(MINT_BLT_UN_I8
)
3808 BRELOP_CAST(l
, <, guint64
);
3810 MINT_IN_CASE(MINT_BLT_UN_R4
)
3811 CONDBR(isunordered (sp
[0].data
.f_r4
, sp
[1].data
.f_r4
) || sp
[0].data
.f_r4
< sp
[1].data
.f_r4
)
3813 MINT_IN_CASE(MINT_BLT_UN_R8
)
3814 CONDBR(mono_isunordered (sp
[0].data
.f
, sp
[1].data
.f
) || sp
[0].data
.f
< sp
[1].data
.f
)
3816 MINT_IN_CASE(MINT_SWITCH
) {
3818 const unsigned short *st
;
3824 if ((guint32
)sp
->data
.i
< n
) {
3826 ip
+= 2 * (guint32
)sp
->data
.i
;
3827 offset
= READ32 (ip
);
3834 MINT_IN_CASE(MINT_LDIND_I1_CHECK
)
3835 NULL_CHECK (sp
[-1].data
.p
);
3837 sp
[-1].data
.i
= *(gint8
*)sp
[-1].data
.p
;
3839 MINT_IN_CASE(MINT_LDIND_U1_CHECK
)
3840 NULL_CHECK (sp
[-1].data
.p
);
3842 sp
[-1].data
.i
= *(guint8
*)sp
[-1].data
.p
;
3844 MINT_IN_CASE(MINT_LDIND_I2_CHECK
)
3845 NULL_CHECK (sp
[-1].data
.p
);
3847 sp
[-1].data
.i
= *(gint16
*)sp
[-1].data
.p
;
3849 MINT_IN_CASE(MINT_LDIND_U2_CHECK
)
3850 NULL_CHECK (sp
[-1].data
.p
);
3852 sp
[-1].data
.i
= *(guint16
*)sp
[-1].data
.p
;
3854 MINT_IN_CASE(MINT_LDIND_I4_CHECK
) /* Fall through */
3855 MINT_IN_CASE(MINT_LDIND_U4_CHECK
)
3856 NULL_CHECK (sp
[-1].data
.p
);
3858 sp
[-1].data
.i
= *(gint32
*)sp
[-1].data
.p
;
3860 MINT_IN_CASE(MINT_LDIND_I8_CHECK
)
3861 NULL_CHECK (sp
[-1].data
.p
);
3863 #ifdef NO_UNALIGNED_ACCESS
3864 if ((gsize
)sp
[-1].data
.p
% SIZEOF_VOID_P
)
3865 memcpy (&sp
[-1].data
.l
, sp
[-1].data
.p
, sizeof (gint64
));
3868 sp
[-1].data
.l
= *(gint64
*)sp
[-1].data
.p
;
3870 MINT_IN_CASE(MINT_LDIND_I
) {
3871 guint16 offset
= * (guint16
*)(ip
+ 1);
3872 sp
[-1 - offset
].data
.p
= *(gpointer
*)sp
[-1 - offset
].data
.p
;
3876 MINT_IN_CASE(MINT_LDIND_I8
) {
3877 guint16 offset
= * (guint16
*)(ip
+ 1);
3878 #ifdef NO_UNALIGNED_ACCESS
3879 if ((gsize
)sp
[-1 - offset
].data
.p
% SIZEOF_VOID_P
)
3880 memcpy (&sp
[-1 - offset
].data
.l
, sp
[-1 - offset
].data
.p
, sizeof (gint64
));
3883 sp
[-1 - offset
].data
.l
= *(gint64
*)sp
[-1 - offset
].data
.p
;
3887 MINT_IN_CASE(MINT_LDIND_R4_CHECK
)
3888 NULL_CHECK (sp
[-1].data
.p
);
3890 sp
[-1].data
.f_r4
= *(gfloat
*)sp
[-1].data
.p
;
3892 MINT_IN_CASE(MINT_LDIND_R8_CHECK
)
3893 NULL_CHECK (sp
[-1].data
.p
);
3895 #ifdef NO_UNALIGNED_ACCESS
3896 if ((gsize
)sp
[-1].data
.p
% SIZEOF_VOID_P
)
3897 memcpy (&sp
[-1].data
.f
, sp
[-1].data
.p
, sizeof (gdouble
));
3900 sp
[-1].data
.f
= *(gdouble
*)sp
[-1].data
.p
;
3902 MINT_IN_CASE(MINT_LDIND_REF
)
3904 sp
[-1].data
.p
= *(gpointer
*)sp
[-1].data
.p
;
3906 MINT_IN_CASE(MINT_LDIND_REF_CHECK
) {
3907 NULL_CHECK (sp
[-1].data
.p
);
3909 sp
[-1].data
.p
= *(gpointer
*)sp
[-1].data
.p
;
3912 MINT_IN_CASE(MINT_STIND_REF
)
3915 mono_gc_wbarrier_generic_store_internal (sp
->data
.p
, sp
[1].data
.o
);
3917 MINT_IN_CASE(MINT_STIND_I1
)
3920 * (gint8
*) sp
->data
.p
= (gint8
)sp
[1].data
.i
;
3922 MINT_IN_CASE(MINT_STIND_I2
)
3925 * (gint16
*) sp
->data
.p
= (gint16
)sp
[1].data
.i
;
3927 MINT_IN_CASE(MINT_STIND_I4
)
3930 * (gint32
*) sp
->data
.p
= sp
[1].data
.i
;
3932 MINT_IN_CASE(MINT_STIND_I
)
3935 * (mono_i
*) sp
->data
.p
= (mono_i
)sp
[1].data
.p
;
3937 MINT_IN_CASE(MINT_STIND_I8
)
3940 #ifdef NO_UNALIGNED_ACCESS
3941 if ((gsize
)sp
->data
.p
% SIZEOF_VOID_P
)
3942 memcpy (sp
->data
.p
, &sp
[1].data
.l
, sizeof (gint64
));
3945 * (gint64
*) sp
->data
.p
= sp
[1].data
.l
;
3947 MINT_IN_CASE(MINT_STIND_R4
)
3950 * (float *) sp
->data
.p
= sp
[1].data
.f_r4
;
3952 MINT_IN_CASE(MINT_STIND_R8
)
3955 #ifdef NO_UNALIGNED_ACCESS
3956 if ((gsize
)sp
->data
.p
% SIZEOF_VOID_P
)
3957 memcpy (sp
->data
.p
, &sp
[1].data
.f
, sizeof (double));
3960 * (double *) sp
->data
.p
= sp
[1].data
.f
;
3962 MINT_IN_CASE(MINT_MONO_ATOMIC_STORE_I4
)
3965 mono_atomic_store_i32 ((gint32
*) sp
->data
.p
, sp
[1].data
.i
);
3967 #define BINOP(datamem, op) \
3969 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3971 MINT_IN_CASE(MINT_ADD_I4
)
3974 MINT_IN_CASE(MINT_ADD_I8
)
3977 MINT_IN_CASE(MINT_ADD_R4
)
3980 MINT_IN_CASE(MINT_ADD_R8
)
3983 MINT_IN_CASE(MINT_ADD1_I4
)
3987 MINT_IN_CASE(MINT_ADD1_I8
)
3991 MINT_IN_CASE(MINT_SUB_I4
)
3994 MINT_IN_CASE(MINT_SUB_I8
)
3997 MINT_IN_CASE(MINT_SUB_R4
)
4000 MINT_IN_CASE(MINT_SUB_R8
)
4003 MINT_IN_CASE(MINT_SUB1_I4
)
4007 MINT_IN_CASE(MINT_SUB1_I8
)
4011 MINT_IN_CASE(MINT_MUL_I4
)
4014 MINT_IN_CASE(MINT_MUL_I8
)
4017 MINT_IN_CASE(MINT_MUL_R4
)
4020 MINT_IN_CASE(MINT_MUL_R8
)
4023 MINT_IN_CASE(MINT_DIV_I4
)
4024 if (sp
[-1].data
.i
== 0)
4025 THROW_EX_DIV_ZERO (ip
);
4026 if (sp
[-1].data
.i
== (-1) && sp
[-2].data
.i
== G_MININT32
)
4030 MINT_IN_CASE(MINT_DIV_I8
)
4031 if (sp
[-1].data
.l
== 0)
4032 THROW_EX_DIV_ZERO (ip
);
4033 if (sp
[-1].data
.l
== (-1) && sp
[-2].data
.l
== G_MININT64
)
4037 MINT_IN_CASE(MINT_DIV_R4
)
4040 MINT_IN_CASE(MINT_DIV_R8
)
4044 #define BINOP_CAST(datamem, op, type) \
4046 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4048 MINT_IN_CASE(MINT_DIV_UN_I4
)
4049 if (sp
[-1].data
.i
== 0)
4050 THROW_EX_DIV_ZERO (ip
);
4051 BINOP_CAST(i
, /, guint32
);
4053 MINT_IN_CASE(MINT_DIV_UN_I8
)
4054 if (sp
[-1].data
.l
== 0)
4055 THROW_EX_DIV_ZERO (ip
);
4056 BINOP_CAST(l
, /, guint64
);
4058 MINT_IN_CASE(MINT_REM_I4
)
4059 if (sp
[-1].data
.i
== 0)
4060 THROW_EX_DIV_ZERO (ip
);
4061 if (sp
[-1].data
.i
== (-1) && sp
[-2].data
.i
== G_MININT32
)
4065 MINT_IN_CASE(MINT_REM_I8
)
4066 if (sp
[-1].data
.l
== 0)
4067 THROW_EX_DIV_ZERO (ip
);
4068 if (sp
[-1].data
.l
== (-1) && sp
[-2].data
.l
== G_MININT64
)
4072 MINT_IN_CASE(MINT_REM_R4
)
4073 /* FIXME: what do we actually do here? */
4075 sp
[-1].data
.f_r4
= fmodf (sp
[-1].data
.f_r4
, sp
[0].data
.f_r4
);
4078 MINT_IN_CASE(MINT_REM_R8
)
4079 /* FIXME: what do we actually do here? */
4081 sp
[-1].data
.f
= fmod (sp
[-1].data
.f
, sp
[0].data
.f
);
4084 MINT_IN_CASE(MINT_REM_UN_I4
)
4085 if (sp
[-1].data
.i
== 0)
4086 THROW_EX_DIV_ZERO (ip
);
4087 BINOP_CAST(i
, %, guint32
);
4089 MINT_IN_CASE(MINT_REM_UN_I8
)
4090 if (sp
[-1].data
.l
== 0)
4091 THROW_EX_DIV_ZERO (ip
);
4092 BINOP_CAST(l
, %, guint64
);
4094 MINT_IN_CASE(MINT_AND_I4
)
4097 MINT_IN_CASE(MINT_AND_I8
)
4100 MINT_IN_CASE(MINT_OR_I4
)
4103 MINT_IN_CASE(MINT_OR_I8
)
4106 MINT_IN_CASE(MINT_XOR_I4
)
4109 MINT_IN_CASE(MINT_XOR_I8
)
4113 #define SHIFTOP(datamem, op) \
4115 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
4118 MINT_IN_CASE(MINT_SHL_I4
)
4121 MINT_IN_CASE(MINT_SHL_I8
)
4124 MINT_IN_CASE(MINT_SHR_I4
)
4127 MINT_IN_CASE(MINT_SHR_I8
)
4130 MINT_IN_CASE(MINT_SHR_UN_I4
)
4132 sp
[-1].data
.i
= (guint32
)sp
[-1].data
.i
>> sp
[0].data
.i
;
4135 MINT_IN_CASE(MINT_SHR_UN_I8
)
4137 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.l
>> sp
[0].data
.i
;
4140 MINT_IN_CASE(MINT_NEG_I4
)
4141 sp
[-1].data
.i
= - sp
[-1].data
.i
;
4144 MINT_IN_CASE(MINT_NEG_I8
)
4145 sp
[-1].data
.l
= - sp
[-1].data
.l
;
4148 MINT_IN_CASE(MINT_NEG_R4
)
4149 sp
[-1].data
.f_r4
= - sp
[-1].data
.f_r4
;
4152 MINT_IN_CASE(MINT_NEG_R8
)
4153 sp
[-1].data
.f
= - sp
[-1].data
.f
;
4156 MINT_IN_CASE(MINT_NOT_I4
)
4157 sp
[-1].data
.i
= ~ sp
[-1].data
.i
;
4160 MINT_IN_CASE(MINT_NOT_I8
)
4161 sp
[-1].data
.l
= ~ sp
[-1].data
.l
;
4164 MINT_IN_CASE(MINT_CONV_I1_I4
)
4165 sp
[-1].data
.i
= (gint8
)sp
[-1].data
.i
;
4168 MINT_IN_CASE(MINT_CONV_I1_I8
)
4169 sp
[-1].data
.i
= (gint8
)sp
[-1].data
.l
;
4172 MINT_IN_CASE(MINT_CONV_I1_R4
)
4173 sp
[-1].data
.i
= (gint8
) (gint32
) sp
[-1].data
.f_r4
;
4176 MINT_IN_CASE(MINT_CONV_I1_R8
)
4177 /* without gint32 cast, C compiler is allowed to use undefined
4178 * behaviour if data.f is bigger than >255. See conv.fpint section
4180 * > The conversion truncates; that is, the fractional part
4181 * > is discarded. The behavior is undefined if the truncated
4182 * > value cannot be represented in the destination type.
4184 sp
[-1].data
.i
= (gint8
) (gint32
) sp
[-1].data
.f
;
4187 MINT_IN_CASE(MINT_CONV_U1_I4
)
4188 sp
[-1].data
.i
= (guint8
)sp
[-1].data
.i
;
4191 MINT_IN_CASE(MINT_CONV_U1_I8
)
4192 sp
[-1].data
.i
= (guint8
)sp
[-1].data
.l
;
4195 MINT_IN_CASE(MINT_CONV_U1_R4
)
4196 sp
[-1].data
.i
= (guint8
) (guint32
) sp
[-1].data
.f_r4
;
4199 MINT_IN_CASE(MINT_CONV_U1_R8
)
4200 sp
[-1].data
.i
= (guint8
) (guint32
) sp
[-1].data
.f
;
4203 MINT_IN_CASE(MINT_CONV_I2_I4
)
4204 sp
[-1].data
.i
= (gint16
)sp
[-1].data
.i
;
4207 MINT_IN_CASE(MINT_CONV_I2_I8
)
4208 sp
[-1].data
.i
= (gint16
)sp
[-1].data
.l
;
4211 MINT_IN_CASE(MINT_CONV_I2_R4
)
4212 sp
[-1].data
.i
= (gint16
) (gint32
) sp
[-1].data
.f_r4
;
4215 MINT_IN_CASE(MINT_CONV_I2_R8
)
4216 sp
[-1].data
.i
= (gint16
) (gint32
) sp
[-1].data
.f
;
4219 MINT_IN_CASE(MINT_CONV_U2_I4
)
4220 sp
[-1].data
.i
= (guint16
)sp
[-1].data
.i
;
4223 MINT_IN_CASE(MINT_CONV_U2_I8
)
4224 sp
[-1].data
.i
= (guint16
)sp
[-1].data
.l
;
4227 MINT_IN_CASE(MINT_CONV_U2_R4
)
4228 sp
[-1].data
.i
= (guint16
) (guint32
) sp
[-1].data
.f_r4
;
4231 MINT_IN_CASE(MINT_CONV_U2_R8
)
4232 sp
[-1].data
.i
= (guint16
) (guint32
) sp
[-1].data
.f
;
4235 MINT_IN_CASE(MINT_CONV_I4_R4
)
4236 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f_r4
;
4239 MINT_IN_CASE(MINT_CONV_I4_R8
)
4240 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.f
;
4243 MINT_IN_CASE(MINT_CONV_U4_I8
)
4244 MINT_IN_CASE(MINT_CONV_I4_I8
)
4245 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.l
;
4248 MINT_IN_CASE(MINT_CONV_I4_I8_SP
)
4249 sp
[-2].data
.i
= (gint32
)sp
[-2].data
.l
;
4252 MINT_IN_CASE(MINT_CONV_U4_R4
)
4253 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U4
4254 sp
[-1].data
.i
= mono_rconv_u4 (sp
[-1].data
.f_r4
);
4256 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f_r4
;
4260 MINT_IN_CASE(MINT_CONV_U4_R8
)
4261 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U4
4262 sp
[-1].data
.i
= mono_fconv_u4_2 (sp
[-1].data
.f
);
4264 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f
;
4268 MINT_IN_CASE(MINT_CONV_I8_I4
)
4269 sp
[-1].data
.l
= sp
[-1].data
.i
;
4272 MINT_IN_CASE(MINT_CONV_I8_I4_SP
)
4273 sp
[-2].data
.l
= sp
[-2].data
.i
;
4276 MINT_IN_CASE(MINT_CONV_I8_U4
)
4277 sp
[-1].data
.l
= (guint32
)sp
[-1].data
.i
;
4280 MINT_IN_CASE(MINT_CONV_I8_R4
)
4281 sp
[-1].data
.l
= (gint64
) sp
[-1].data
.f_r4
;
4284 MINT_IN_CASE(MINT_CONV_I8_R8
)
4285 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
4288 MINT_IN_CASE(MINT_CONV_R4_I4
)
4289 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.i
;
4292 MINT_IN_CASE(MINT_CONV_R4_I8
)
4293 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.l
;
4296 MINT_IN_CASE(MINT_CONV_R4_R8
)
4297 sp
[-1].data
.f_r4
= (float)sp
[-1].data
.f
;
4300 MINT_IN_CASE(MINT_CONV_R8_I4
)
4301 sp
[-1].data
.f
= (double)sp
[-1].data
.i
;
4304 MINT_IN_CASE(MINT_CONV_R8_I8
)
4305 sp
[-1].data
.f
= (double)sp
[-1].data
.l
;
4308 MINT_IN_CASE(MINT_CONV_R8_R4
)
4309 sp
[-1].data
.f
= (double) sp
[-1].data
.f_r4
;
4312 MINT_IN_CASE(MINT_CONV_R8_R4_SP
)
4313 sp
[-2].data
.f
= (double) sp
[-2].data
.f_r4
;
4316 MINT_IN_CASE(MINT_CONV_U8_I4
)
4317 sp
[-1].data
.l
= sp
[-1].data
.i
& 0xffffffff;
4320 MINT_IN_CASE(MINT_CONV_U8_R4
)
4321 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U8
4322 sp
[-1].data
.l
= mono_rconv_u8 (sp
[-1].data
.f_r4
);
4324 sp
[-1].data
.l
= (guint64
) sp
[-1].data
.f_r4
;
4328 MINT_IN_CASE(MINT_CONV_U8_R8
)
4329 #ifdef MONO_ARCH_EMULATE_FCONV_TO_U8
4330 sp
[-1].data
.l
= mono_fconv_u8_2 (sp
[-1].data
.f
);
4332 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f
;
4336 MINT_IN_CASE(MINT_CPOBJ
) {
4337 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4338 g_assert (m_class_is_valuetype (c
));
4339 /* if this assertion fails, we need to add a write barrier */
4340 g_assert (!MONO_TYPE_IS_REFERENCE (m_class_get_byval_arg (c
)));
4341 stackval_from_data (m_class_get_byval_arg (c
), (stackval
*)sp
[-2].data
.p
, sp
[-1].data
.p
, FALSE
);
4346 MINT_IN_CASE(MINT_CPOBJ_VT
) {
4347 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4348 mono_value_copy_internal (sp
[-2].data
.vt
, sp
[-1].data
.vt
, c
);
4353 MINT_IN_CASE(MINT_LDOBJ_VT
) {
4354 int size
= READ32(ip
+ 1);
4356 memcpy (vt_sp
, sp
[-1].data
.p
, size
);
4357 sp
[-1].data
.p
= vt_sp
;
4358 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
4361 MINT_IN_CASE(MINT_LDSTR
)
4362 sp
->data
.p
= imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4366 MINT_IN_CASE(MINT_LDSTR_TOKEN
) {
4367 MonoString
*s
= NULL
;
4368 guint32 strtoken
= (guint32
)(gsize
)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4370 MonoMethod
*method
= imethod
->method
;
4371 if (method
->wrapper_type
== MONO_WRAPPER_DYNAMIC_METHOD
) {
4372 s
= (MonoString
*)mono_method_get_wrapper_data (method
, strtoken
);
4373 } else if (method
->wrapper_type
!= MONO_WRAPPER_NONE
) {
4374 s
= mono_string_new_wrapper_internal ((const char*)mono_method_get_wrapper_data (method
, strtoken
));
4376 g_assert_not_reached ();
4383 MINT_IN_CASE(MINT_NEWOBJ_ARRAY
) {
4384 MonoClass
*newobj_class
;
4385 guint32 token
= * (guint16
*)(ip
+ 1);
4386 guint16 param_count
= * (guint16
*)(ip
+ 2);
4388 newobj_class
= (MonoClass
*) imethod
->data_items
[token
];
4391 sp
->data
.o
= ves_array_create (imethod
->domain
, newobj_class
, param_count
, sp
, error
);
4393 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4399 MINT_IN_CASE(MINT_NEWOBJ_FAST
) {
4400 guint16 param_count
;
4401 guint16 imethod_index
= *(guint16
*) (ip
+ 1);
4403 const gboolean is_inlined
= imethod_index
== 0xffff;
4405 param_count
= *(guint16
*)(ip
+ 2);
4409 memmove (sp
+ 1 + is_inlined
, sp
, param_count
* sizeof (stackval
));
4412 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 3)];
4413 INIT_VTABLE (vtable
);
4415 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
4416 if (G_UNLIKELY (!frame_objref (frame
))) {
4417 mono_error_set_out_of_memory (error
, "Could not allocate %i bytes", m_class_get_instance_size (vtable
->klass
));
4418 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4421 sp
[0].data
.o
= frame_objref (frame
);
4423 sp
[1].data
.o
= frame_objref (frame
);
4424 sp
+= param_count
+ 2;
4426 InterpMethod
*ctor_method
= (InterpMethod
*) imethod
->data_items
[imethod_index
];
4429 child_frame
.imethod
= ctor_method
;
4430 child_frame
.stack_args
= sp
;
4432 interp_exec_method (&child_frame
, context
, error
);
4433 CHECK_RESUME_STATE (context
);
4434 sp
[0].data
.o
= frame_objref (frame
);
4441 MINT_IN_CASE(MINT_NEWOBJ_VT_FAST
)
4442 MINT_IN_CASE(MINT_NEWOBJ_VTST_FAST
) {
4443 guint16 param_count
;
4444 stackval valuetype_this
;
4448 child_frame
.imethod
= (InterpMethod
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4449 param_count
= *(guint16
*)(ip
+ 2);
4453 memmove (sp
+ 1, sp
, param_count
* sizeof (stackval
));
4455 child_frame
.stack_args
= sp
;
4457 gboolean vtst
= *ip
== MINT_NEWOBJ_VTST_FAST
;
4459 memset (vt_sp
, 0, *(guint16
*)(ip
+ 3));
4461 valuetype_this
.data
.p
= vt_sp
;
4464 memset (&valuetype_this
, 0, sizeof (stackval
));
4465 sp
->data
.p
= &valuetype_this
;
4469 interp_exec_method (&child_frame
, context
, error
);
4471 CHECK_RESUME_STATE (context
);
4473 *sp
= valuetype_this
;
4477 MINT_IN_CASE(MINT_NEWOBJ
) {
4478 MonoClass
*newobj_class
;
4479 MonoMethodSignature
*csig
;
4480 stackval valuetype_this
;
4486 token
= * (guint16
*)(ip
+ 1);
4489 child_frame
.ip
= NULL
;
4490 child_frame
.ex
= NULL
;
4492 child_frame
.imethod
= (InterpMethod
*)imethod
->data_items
[token
];
4493 csig
= mono_method_signature_internal (child_frame
.imethod
->method
);
4494 newobj_class
= child_frame
.imethod
->method
->klass
;
4495 /*if (profiling_classes) {
4496 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
4498 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
4501 g_assert (csig
->hasthis
);
4502 if (csig
->param_count
) {
4503 sp
-= csig
->param_count
;
4504 memmove (sp
+ 1, sp
, csig
->param_count
* sizeof (stackval
));
4506 child_frame
.stack_args
= sp
;
4509 * First arg is the object.
4511 if (m_class_is_valuetype (newobj_class
)) {
4512 MonoType
*t
= m_class_get_byval_arg (newobj_class
);
4513 memset (&valuetype_this
, 0, sizeof (stackval
));
4514 if (!m_class_is_enumtype (newobj_class
) && (t
->type
== MONO_TYPE_VALUETYPE
|| (t
->type
== MONO_TYPE_GENERICINST
&& mono_type_generic_inst_is_valuetype (t
)))) {
4516 valuetype_this
.data
.p
= vt_sp
;
4518 sp
->data
.p
= &valuetype_this
;
4521 if (newobj_class
!= mono_defaults
.string_class
) {
4522 MonoVTable
*vtable
= mono_class_vtable_checked (imethod
->domain
, newobj_class
, error
);
4523 if (!is_ok (error
) || !mono_runtime_class_init_full (vtable
, error
))
4524 THROW_EX (mono_error_convert_to_exception (error
), ip
);
4525 frame_objref (frame
) = mono_object_new_checked (imethod
->domain
, newobj_class
, error
);
4526 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4527 EXCEPTION_CHECKPOINT
;
4528 sp
->data
.o
= frame_objref (frame
);
4529 #ifndef DISABLE_REMOTING
4530 if (mono_object_is_transparent_proxy (frame_objref (frame
))) {
4531 MonoMethod
*remoting_invoke_method
= mono_marshal_get_remoting_invoke_with_check (child_frame
.imethod
->method
, error
);
4532 mono_error_assert_ok (error
);
4533 child_frame
.imethod
= mono_interp_get_imethod (imethod
->domain
, remoting_invoke_method
, error
);
4534 mono_error_assert_ok (error
);
4539 child_frame
.retval
= &retval
;
4543 interp_exec_method (&child_frame
, context
, error
);
4545 CHECK_RESUME_STATE (context
);
4548 * a constructor returns void, but we need to return the object we created
4550 if (m_class_is_valuetype (newobj_class
) && !m_class_is_enumtype (newobj_class
)) {
4551 *sp
= valuetype_this
;
4552 } else if (newobj_class
== mono_defaults
.string_class
) {
4555 sp
->data
.o
= frame_objref (frame
);
4560 MINT_IN_CASE(MINT_NEWOBJ_MAGIC
) {
4566 MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_CTOR
) {
4567 MonoMethodSignature
*csig
;
4571 token
= * (guint16
*)(ip
+ 1);
4574 InterpMethod
*cmethod
= (InterpMethod
*)imethod
->data_items
[token
];
4575 csig
= mono_method_signature_internal (cmethod
->method
);
4577 g_assert (csig
->hasthis
);
4578 sp
-= csig
->param_count
;
4580 gpointer arg0
= sp
[0].data
.p
;
4582 gpointer
*byreference_this
= (gpointer
*)vt_sp
;
4583 *byreference_this
= arg0
;
4585 /* Followed by a VTRESULT opcode which will push the result on the stack */
4589 MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_GET_VALUE
) {
4590 gpointer
*byreference_this
= (gpointer
*)sp
[-1].data
.p
;
4591 sp
[-1].data
.p
= *byreference_this
;
4595 MINT_IN_CASE(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET
) {
4597 sp
[0].data
.p
= (guint8
*)sp
[0].data
.p
+ sp
[1].data
.nati
;
4602 MINT_IN_CASE(MINT_INTRINS_UNSAFE_BYTE_OFFSET
) {
4604 sp
[0].data
.nati
= (guint8
*)sp
[1].data
.p
- (guint8
*)sp
[0].data
.p
;
4609 MINT_IN_CASE(MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE
) {
4611 MonoObject
*obj
= sp
[0].data
.o
;
4612 sp
[0].data
.i
= (obj
->vtable
->flags
& MONO_VT_FLAG_ARRAY_OR_STRING
) != 0;
4617 MINT_IN_CASE(MINT_CASTCLASS_INTERFACE
)
4618 MINT_IN_CASE(MINT_ISINST_INTERFACE
) {
4619 gboolean isinst_instr
= *ip
== MINT_ISINST_INTERFACE
;
4620 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4621 if ((o
= sp
[-1].data
.o
)) {
4623 if (MONO_VTABLE_IMPLEMENTS_INTERFACE (o
->vtable
, m_class_get_interface_id (c
))) {
4625 } else if (m_class_is_array_special_interface (c
) || mono_object_is_transparent_proxy (o
)) {
4627 isinst
= mono_object_isinst_checked (o
, c
, error
) != NULL
;
4628 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4635 sp
[-1].data
.p
= NULL
;
4637 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4643 MINT_IN_CASE(MINT_CASTCLASS_COMMON
)
4644 MINT_IN_CASE(MINT_ISINST_COMMON
) {
4645 gboolean isinst_instr
= *ip
== MINT_ISINST_COMMON
;
4646 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4647 if ((o
= sp
[-1].data
.o
)) {
4648 gboolean isinst
= mono_class_has_parent_fast (o
->vtable
->klass
, c
);
4652 sp
[-1].data
.p
= NULL
;
4654 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4660 MINT_IN_CASE(MINT_CASTCLASS
)
4661 MINT_IN_CASE(MINT_ISINST
) {
4662 gboolean isinst_instr
= *ip
== MINT_ISINST
;
4663 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4664 if ((o
= sp
[-1].data
.o
)) {
4665 MonoObject
*isinst_obj
= mono_object_isinst_checked (o
, c
, error
);
4666 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4669 sp
[-1].data
.p
= NULL
;
4671 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4677 MINT_IN_CASE(MINT_CONV_R_UN_I4
)
4678 sp
[-1].data
.f
= (double)(guint32
)sp
[-1].data
.i
;
4681 MINT_IN_CASE(MINT_CONV_R_UN_I8
)
4682 sp
[-1].data
.f
= (double)(guint64
)sp
[-1].data
.l
;
4685 MINT_IN_CASE(MINT_UNBOX
)
4686 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4691 if (!(m_class_get_rank (o
->vtable
->klass
) == 0 && m_class_get_element_class (o
->vtable
->klass
) == m_class_get_element_class (c
)))
4692 THROW_EX (mono_get_exception_invalid_cast (), ip
);
4694 sp
[-1].data
.p
= mono_object_unbox_internal (o
);
4697 MINT_IN_CASE(MINT_THROW
)
4700 sp
->data
.p
= mono_get_exception_null_reference ();
4702 THROW_EX ((MonoException
*)sp
->data
.p
, ip
);
4704 MINT_IN_CASE(MINT_CHECKPOINT
)
4705 /* Do synchronous checking of abort requests */
4706 EXCEPTION_CHECKPOINT
;
4709 MINT_IN_CASE(MINT_SAFEPOINT
)
4710 /* Do synchronous checking of abort requests */
4711 EXCEPTION_CHECKPOINT
;
4712 /* Poll safepoint */
4713 mono_threads_safepoint ();
4716 MINT_IN_CASE(MINT_LDFLDA_UNSAFE
)
4718 sp
[-1].data
.p
= (char *)o
+ * (guint16
*)(ip
+ 1);
4721 MINT_IN_CASE(MINT_LDFLDA
)
4724 sp
[-1].data
.p
= (char *)o
+ * (guint16
*)(ip
+ 1);
4727 MINT_IN_CASE(MINT_CKNULL_N
) {
4728 /* Same as CKNULL, but further down the stack */
4729 int n
= *(guint16
*)(ip
+ 1);
4736 #define LDFLD_UNALIGNED(datamem, fieldtype, unaligned) \
4737 o = sp [-1].data.o; \
4740 memcpy (&sp[-1].data.datamem, (char *)o + * (guint16 *)(ip + 1), sizeof (fieldtype)); \
4742 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
4745 #define LDFLD(datamem, fieldtype) LDFLD_UNALIGNED(datamem, fieldtype, FALSE)
4747 MINT_IN_CASE(MINT_LDFLD_I1
) LDFLD(i
, gint8
); MINT_IN_BREAK
;
4748 MINT_IN_CASE(MINT_LDFLD_U1
) LDFLD(i
, guint8
); MINT_IN_BREAK
;
4749 MINT_IN_CASE(MINT_LDFLD_I2
) LDFLD(i
, gint16
); MINT_IN_BREAK
;
4750 MINT_IN_CASE(MINT_LDFLD_U2
) LDFLD(i
, guint16
); MINT_IN_BREAK
;
4751 MINT_IN_CASE(MINT_LDFLD_I4
) LDFLD(i
, gint32
); MINT_IN_BREAK
;
4752 MINT_IN_CASE(MINT_LDFLD_I8
) LDFLD(l
, gint64
); MINT_IN_BREAK
;
4753 MINT_IN_CASE(MINT_LDFLD_R4
) LDFLD(f_r4
, float); MINT_IN_BREAK
;
4754 MINT_IN_CASE(MINT_LDFLD_R8
) LDFLD(f
, double); MINT_IN_BREAK
;
4755 MINT_IN_CASE(MINT_LDFLD_O
) LDFLD(p
, gpointer
); MINT_IN_BREAK
;
4756 MINT_IN_CASE(MINT_LDFLD_P
) LDFLD(p
, gpointer
); MINT_IN_BREAK
;
4757 MINT_IN_CASE(MINT_LDFLD_I8_UNALIGNED
) LDFLD_UNALIGNED(l
, gint64
, TRUE
); MINT_IN_BREAK
;
4758 MINT_IN_CASE(MINT_LDFLD_R8_UNALIGNED
) LDFLD_UNALIGNED(f
, double, TRUE
); MINT_IN_BREAK
;
4760 MINT_IN_CASE(MINT_LDFLD_VT
) {
4764 int size
= READ32(ip
+ 2);
4765 sp
[-1].data
.p
= vt_sp
;
4766 memcpy (sp
[-1].data
.p
, (char *)o
+ * (guint16
*)(ip
+ 1), size
);
4767 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
4772 MINT_IN_CASE(MINT_LDRMFLD
) {
4773 MonoClassField
*field
;
4778 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4780 #ifndef DISABLE_REMOTING
4782 if (mono_object_is_transparent_proxy (o
)) {
4783 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4785 addr
= (char*)mono_load_remote_field_checked (o
, klass
, field
, &tmp
, error
);
4786 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4789 addr
= (char*)o
+ field
->offset
;
4791 stackval_from_data (field
->type
, &sp
[-1], addr
, FALSE
);
4795 MINT_IN_CASE(MINT_LDRMFLD_VT
) {
4796 MonoClassField
*field
;
4802 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4803 MonoClass
*klass
= mono_class_from_mono_type_internal (field
->type
);
4804 i32
= mono_class_value_size (klass
, NULL
);
4807 #ifndef DISABLE_REMOTING
4809 if (mono_object_is_transparent_proxy (o
)) {
4810 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4811 addr
= (char*)mono_load_remote_field_checked (o
, klass
, field
, &tmp
, error
);
4812 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4815 addr
= (char*)o
+ field
->offset
;
4817 sp
[-1].data
.p
= vt_sp
;
4818 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4819 memcpy(sp
[-1].data
.p
, addr
, i32
);
4823 #define STFLD_UNALIGNED(datamem, fieldtype, unaligned) \
4824 o = sp [-2].data.o; \
4828 memcpy ((char *)o + * (guint16 *)(ip + 1), &sp[1].data.datamem, sizeof (fieldtype)); \
4830 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
4833 #define STFLD(datamem, fieldtype) STFLD_UNALIGNED(datamem, fieldtype, FALSE)
4835 MINT_IN_CASE(MINT_STFLD_I1
) STFLD(i
, gint8
); MINT_IN_BREAK
;
4836 MINT_IN_CASE(MINT_STFLD_U1
) STFLD(i
, guint8
); MINT_IN_BREAK
;
4837 MINT_IN_CASE(MINT_STFLD_I2
) STFLD(i
, gint16
); MINT_IN_BREAK
;
4838 MINT_IN_CASE(MINT_STFLD_U2
) STFLD(i
, guint16
); MINT_IN_BREAK
;
4839 MINT_IN_CASE(MINT_STFLD_I4
) STFLD(i
, gint32
); MINT_IN_BREAK
;
4840 MINT_IN_CASE(MINT_STFLD_I8
) STFLD(l
, gint64
); MINT_IN_BREAK
;
4841 MINT_IN_CASE(MINT_STFLD_R4
) STFLD(f_r4
, float); MINT_IN_BREAK
;
4842 MINT_IN_CASE(MINT_STFLD_R8
) STFLD(f
, double); MINT_IN_BREAK
;
4843 MINT_IN_CASE(MINT_STFLD_P
) STFLD(p
, gpointer
); MINT_IN_BREAK
;
4844 MINT_IN_CASE(MINT_STFLD_O
)
4848 mono_gc_wbarrier_set_field_internal (o
, (char *) o
+ * (guint16
*)(ip
+ 1), sp
[1].data
.o
);
4851 MINT_IN_CASE(MINT_STFLD_I8_UNALIGNED
) STFLD_UNALIGNED(l
, gint64
, TRUE
); MINT_IN_BREAK
;
4852 MINT_IN_CASE(MINT_STFLD_R8_UNALIGNED
) STFLD_UNALIGNED(f
, double, TRUE
); MINT_IN_BREAK
;
4854 MINT_IN_CASE(MINT_STFLD_VT
) {
4859 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 2)];
4860 i32
= mono_class_value_size (klass
, NULL
);
4862 guint16 offset
= * (guint16
*)(ip
+ 1);
4863 mono_value_copy_internal ((char *) o
+ offset
, sp
[1].data
.p
, klass
);
4865 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4869 MINT_IN_CASE(MINT_STRMFLD
) {
4870 MonoClassField
*field
;
4875 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4878 #ifndef DISABLE_REMOTING
4879 if (mono_object_is_transparent_proxy (o
)) {
4880 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4881 mono_store_remote_field_checked (o
, klass
, field
, &sp
[-1].data
, error
);
4882 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4885 stackval_to_data (field
->type
, &sp
[-1], (char*)o
+ field
->offset
, FALSE
);
4890 MINT_IN_CASE(MINT_STRMFLD_VT
) {
4891 MonoClassField
*field
;
4895 field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4896 MonoClass
*klass
= mono_class_from_mono_type_internal (field
->type
);
4897 i32
= mono_class_value_size (klass
, NULL
);
4900 #ifndef DISABLE_REMOTING
4901 if (mono_object_is_transparent_proxy (o
)) {
4902 MonoClass
*klass
= ((MonoTransparentProxy
*)o
)->remote_class
->proxy_class
;
4903 mono_store_remote_field_checked (o
, klass
, field
, sp
[-1].data
.p
, error
);
4904 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
4907 mono_value_copy_internal ((char *) o
+ field
->offset
, sp
[-1].data
.p
, klass
);
4910 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4913 MINT_IN_CASE(MINT_LDSFLDA
) {
4914 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4915 INIT_VTABLE (vtable
);
4916 sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
4922 MINT_IN_CASE(MINT_LDSSFLDA
) {
4923 guint32 offset
= READ32(ip
+ 1);
4924 sp
->data
.p
= mono_get_special_static_data (offset
);
4930 /* We init class here to preserve cctor order */
4931 #define LDSFLD(datamem, fieldtype) { \
4932 MonoVTable *vtable = (MonoVTable*) imethod->data_items [*(guint16*)(ip + 1)]; \
4933 INIT_VTABLE (vtable); \
4934 sp[0].data.datamem = * (fieldtype *)(imethod->data_items [* (guint16 *)(ip + 2)]) ; \
4939 MINT_IN_CASE(MINT_LDSFLD_I1
) LDSFLD(i
, gint8
); MINT_IN_BREAK
;
4940 MINT_IN_CASE(MINT_LDSFLD_U1
) LDSFLD(i
, guint8
); MINT_IN_BREAK
;
4941 MINT_IN_CASE(MINT_LDSFLD_I2
) LDSFLD(i
, gint16
); MINT_IN_BREAK
;
4942 MINT_IN_CASE(MINT_LDSFLD_U2
) LDSFLD(i
, guint16
); MINT_IN_BREAK
;
4943 MINT_IN_CASE(MINT_LDSFLD_I4
) LDSFLD(i
, gint32
); MINT_IN_BREAK
;
4944 MINT_IN_CASE(MINT_LDSFLD_I8
) LDSFLD(l
, gint64
); MINT_IN_BREAK
;
4945 MINT_IN_CASE(MINT_LDSFLD_R4
) LDSFLD(f_r4
, float); MINT_IN_BREAK
;
4946 MINT_IN_CASE(MINT_LDSFLD_R8
) LDSFLD(f
, double); MINT_IN_BREAK
;
4947 MINT_IN_CASE(MINT_LDSFLD_O
) LDSFLD(p
, gpointer
); MINT_IN_BREAK
;
4948 MINT_IN_CASE(MINT_LDSFLD_P
) LDSFLD(p
, gpointer
); MINT_IN_BREAK
;
4950 MINT_IN_CASE(MINT_LDSFLD_VT
) {
4951 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
4952 gpointer addr
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
4953 i32
= READ32(ip
+ 3);
4954 INIT_VTABLE (vtable
);
4957 memcpy (vt_sp
, addr
, i32
);
4958 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
4964 #define LDTSFLD(datamem, fieldtype) { \
4965 guint32 offset = READ32(ip + 1); \
4966 MonoInternalThread *thread = mono_thread_internal_current (); \
4967 gpointer addr = ((char*)thread->static_data [offset & 0x3f]) + (offset >> 6); \
4968 sp[0].data.datamem = *(fieldtype*)addr; \
4972 MINT_IN_CASE(MINT_LDTSFLD_I1
) LDTSFLD(i
, gint8
); MINT_IN_BREAK
;
4973 MINT_IN_CASE(MINT_LDTSFLD_U1
) LDTSFLD(i
, guint8
); MINT_IN_BREAK
;
4974 MINT_IN_CASE(MINT_LDTSFLD_I2
) LDTSFLD(i
, gint16
); MINT_IN_BREAK
;
4975 MINT_IN_CASE(MINT_LDTSFLD_U2
) LDTSFLD(i
, guint16
); MINT_IN_BREAK
;
4976 MINT_IN_CASE(MINT_LDTSFLD_I4
) LDTSFLD(i
, gint32
); MINT_IN_BREAK
;
4977 MINT_IN_CASE(MINT_LDTSFLD_I8
) LDTSFLD(l
, gint64
); MINT_IN_BREAK
;
4978 MINT_IN_CASE(MINT_LDTSFLD_R4
) LDTSFLD(f_r4
, float); MINT_IN_BREAK
;
4979 MINT_IN_CASE(MINT_LDTSFLD_R8
) LDTSFLD(f
, double); MINT_IN_BREAK
;
4980 MINT_IN_CASE(MINT_LDTSFLD_O
) LDTSFLD(p
, gpointer
); MINT_IN_BREAK
;
4981 MINT_IN_CASE(MINT_LDTSFLD_P
) LDTSFLD(p
, gpointer
); MINT_IN_BREAK
;
4983 MINT_IN_CASE(MINT_LDSSFLD
) {
4984 MonoClassField
*field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
4985 guint32 offset
= READ32(ip
+ 2);
4986 gpointer addr
= mono_get_special_static_data (offset
);
4987 stackval_from_data (field
->type
, sp
, addr
, FALSE
);
4992 MINT_IN_CASE(MINT_LDSSFLD_VT
) {
4993 guint32 offset
= READ32(ip
+ 1);
4994 gpointer addr
= mono_get_special_static_data (offset
);
4996 int size
= READ32 (ip
+ 3);
4997 memcpy (vt_sp
, addr
, size
);
4999 vt_sp
+= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5004 #define STSFLD(datamem, fieldtype) { \
5005 MonoVTable *vtable = (MonoVTable*) imethod->data_items [*(guint16*)(ip + 1)]; \
5006 INIT_VTABLE (vtable); \
5008 * (fieldtype *)(imethod->data_items [* (guint16 *)(ip + 2)]) = sp[0].data.datamem; \
5012 MINT_IN_CASE(MINT_STSFLD_I1
) STSFLD(i
, gint8
); MINT_IN_BREAK
;
5013 MINT_IN_CASE(MINT_STSFLD_U1
) STSFLD(i
, guint8
); MINT_IN_BREAK
;
5014 MINT_IN_CASE(MINT_STSFLD_I2
) STSFLD(i
, gint16
); MINT_IN_BREAK
;
5015 MINT_IN_CASE(MINT_STSFLD_U2
) STSFLD(i
, guint16
); MINT_IN_BREAK
;
5016 MINT_IN_CASE(MINT_STSFLD_I4
) STSFLD(i
, gint32
); MINT_IN_BREAK
;
5017 MINT_IN_CASE(MINT_STSFLD_I8
) STSFLD(l
, gint64
); MINT_IN_BREAK
;
5018 MINT_IN_CASE(MINT_STSFLD_R4
) STSFLD(f_r4
, float); MINT_IN_BREAK
;
5019 MINT_IN_CASE(MINT_STSFLD_R8
) STSFLD(f
, double); MINT_IN_BREAK
;
5020 MINT_IN_CASE(MINT_STSFLD_P
) STSFLD(p
, gpointer
); MINT_IN_BREAK
;
5021 MINT_IN_CASE(MINT_STSFLD_O
) STSFLD(p
, gpointer
); MINT_IN_BREAK
;
5023 MINT_IN_CASE(MINT_STSFLD_VT
) {
5024 MonoVTable
*vtable
= (MonoVTable
*) imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5025 gpointer addr
= imethod
->data_items
[*(guint16
*)(ip
+ 2)];
5026 i32
= READ32(ip
+ 3);
5027 INIT_VTABLE (vtable
);
5029 memcpy (addr
, sp
[-1].data
.vt
, i32
);
5030 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5036 #define STTSFLD(datamem, fieldtype) { \
5037 guint32 offset = READ32(ip + 1); \
5038 MonoInternalThread *thread = mono_thread_internal_current (); \
5039 gpointer addr = ((char*)thread->static_data [offset & 0x3f]) + (offset >> 6); \
5041 *(fieldtype*)addr = sp[0].data.datamem; \
5045 MINT_IN_CASE(MINT_STTSFLD_I1
) STTSFLD(i
, gint8
); MINT_IN_BREAK
;
5046 MINT_IN_CASE(MINT_STTSFLD_U1
) STTSFLD(i
, guint8
); MINT_IN_BREAK
;
5047 MINT_IN_CASE(MINT_STTSFLD_I2
) STTSFLD(i
, gint16
); MINT_IN_BREAK
;
5048 MINT_IN_CASE(MINT_STTSFLD_U2
) STTSFLD(i
, guint16
); MINT_IN_BREAK
;
5049 MINT_IN_CASE(MINT_STTSFLD_I4
) STTSFLD(i
, gint32
); MINT_IN_BREAK
;
5050 MINT_IN_CASE(MINT_STTSFLD_I8
) STTSFLD(l
, gint64
); MINT_IN_BREAK
;
5051 MINT_IN_CASE(MINT_STTSFLD_R4
) STTSFLD(f_r4
, float); MINT_IN_BREAK
;
5052 MINT_IN_CASE(MINT_STTSFLD_R8
) STTSFLD(f
, double); MINT_IN_BREAK
;
5053 MINT_IN_CASE(MINT_STTSFLD_P
) STTSFLD(p
, gpointer
); MINT_IN_BREAK
;
5054 MINT_IN_CASE(MINT_STTSFLD_O
) STTSFLD(p
, gpointer
); MINT_IN_BREAK
;
5056 MINT_IN_CASE(MINT_STSSFLD
) {
5057 MonoClassField
*field
= (MonoClassField
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5058 guint32 offset
= READ32(ip
+ 2);
5059 gpointer addr
= mono_get_special_static_data (offset
);
5061 stackval_to_data (field
->type
, sp
, addr
, FALSE
);
5065 MINT_IN_CASE(MINT_STSSFLD_VT
) {
5066 guint32 offset
= READ32(ip
+ 1);
5067 gpointer addr
= mono_get_special_static_data (offset
);
5069 int size
= READ32 (ip
+ 3);
5070 memcpy (addr
, sp
->data
.vt
, size
);
5071 vt_sp
-= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5076 MINT_IN_CASE(MINT_STOBJ_VT
) {
5078 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5080 size
= mono_class_value_size (c
, NULL
);
5081 mono_value_copy_internal (sp
[-2].data
.p
, sp
[-1].data
.p
, c
);
5082 vt_sp
-= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5086 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8
)
5087 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT32
)
5089 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.f
;
5092 MINT_IN_CASE(MINT_CONV_OVF_U8_I4
)
5093 if (sp
[-1].data
.i
< 0)
5095 sp
[-1].data
.l
= sp
[-1].data
.i
;
5098 MINT_IN_CASE(MINT_CONV_OVF_U8_I8
)
5099 if (sp
[-1].data
.l
< 0)
5103 MINT_IN_CASE(MINT_CONV_OVF_I8_U8
)
5104 if ((guint64
) sp
[-1].data
.l
> G_MAXINT64
)
5108 MINT_IN_CASE(MINT_CONV_OVF_U8_R4
)
5109 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXUINT64
|| isnan (sp
[-1].data
.f_r4
))
5111 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f_r4
;
5114 MINT_IN_CASE(MINT_CONV_OVF_U8_R8
)
5115 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT64
|| isnan (sp
[-1].data
.f
))
5117 sp
[-1].data
.l
= (guint64
)sp
[-1].data
.f
;
5120 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8
)
5121 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT64
)
5123 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
5126 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R4
)
5127 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXINT64
)
5129 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f_r4
;
5132 MINT_IN_CASE(MINT_CONV_OVF_I8_R4
)
5133 if (sp
[-1].data
.f_r4
< G_MININT64
|| sp
[-1].data
.f_r4
> G_MAXINT64
|| isnan (sp
[-1].data
.f_r4
))
5135 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f_r4
;
5138 MINT_IN_CASE(MINT_CONV_OVF_I8_R8
)
5139 if (sp
[-1].data
.f
< G_MININT64
|| sp
[-1].data
.f
> G_MAXINT64
|| isnan (sp
[-1].data
.f
))
5141 sp
[-1].data
.l
= (gint64
)sp
[-1].data
.f
;
5144 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8
)
5145 if ((guint64
)sp
[-1].data
.l
> G_MAXINT32
)
5147 sp
[-1].data
.i
= (gint32
)sp
[-1].data
.l
;
5150 MINT_IN_CASE(MINT_BOX
) {
5151 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5152 guint16 offset
= * (guint16
*)(ip
+ 2);
5154 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
5155 stackval_to_data (m_class_get_byval_arg (vtable
->klass
), &sp
[-1 - offset
], mono_object_get_data (frame_objref (frame
)), FALSE
);
5157 sp
[-1 - offset
].data
.p
= frame_objref (frame
);
5162 MINT_IN_CASE(MINT_BOX_VT
) {
5163 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5165 guint16 offset
= * (guint16
*)(ip
+ 2);
5166 gboolean pop_vt_sp
= !(offset
& BOX_NOT_CLEAR_VT_SP
);
5167 offset
&= ~BOX_NOT_CLEAR_VT_SP
;
5169 int size
= mono_class_value_size (c
, NULL
);
5170 frame_objref (frame
) = mono_gc_alloc_obj (vtable
, m_class_get_instance_size (vtable
->klass
));
5171 mono_value_copy_internal (mono_object_get_data (frame_objref (frame
)), sp
[-1 - offset
].data
.p
, c
);
5173 sp
[-1 - offset
].data
.p
= frame_objref (frame
);
5174 size
= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5181 MINT_IN_CASE(MINT_BOX_NULLABLE
) {
5182 c
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
5183 guint16 offset
= * (guint16
*)(ip
+ 2);
5184 gboolean pop_vt_sp
= !(offset
& BOX_NOT_CLEAR_VT_SP
);
5185 offset
&= ~BOX_NOT_CLEAR_VT_SP
;
5187 int size
= mono_class_value_size (c
, NULL
);
5189 sp
[-1 - offset
].data
.o
= mono_nullable_box (sp
[-1 - offset
].data
.p
, c
, error
);
5190 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5192 size
= ALIGN_TO (size
, MINT_VT_ALIGNMENT
);
5199 MINT_IN_CASE(MINT_NEWARR
) {
5200 MonoVTable
*vtable
= (MonoVTable
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5201 sp
[-1].data
.o
= (MonoObject
*) mono_array_new_specific_checked (vtable
, sp
[-1].data
.i
, error
);
5202 if (!is_ok (error
)) {
5203 THROW_EX (mono_error_convert_to_exception (error
), ip
);
5205 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5207 /*if (profiling_classes) {
5208 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
5210 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
5215 MINT_IN_CASE(MINT_LDLEN
)
5218 sp
[-1].data
.nati
= mono_array_length_internal ((MonoArray
*)o
);
5221 MINT_IN_CASE(MINT_LDLEN_SPAN
) {
5224 gsize offset_length
= (gsize
) *(gint16
*) (ip
+ 1);
5225 sp
[-1].data
.nati
= *(gint32
*) ((guint8
*) o
+ offset_length
);
5229 MINT_IN_CASE(MINT_GETCHR
) {
5231 s
= (MonoString
*)sp
[-2].data
.p
;
5233 i32
= sp
[-1].data
.i
;
5234 if (i32
< 0 || i32
>= mono_string_length_internal (s
))
5235 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5237 sp
[-1].data
.i
= mono_string_chars_internal (s
)[i32
];
5241 MINT_IN_CASE(MINT_GETITEM_SPAN
) {
5242 guint8
*span
= (guint8
*) sp
[-2].data
.p
;
5243 int index
= sp
[-1].data
.i
;
5244 gsize element_size
= (gsize
) *(gint16
*) (ip
+ 1);
5245 gsize offset_length
= (gsize
) *(gint16
*) (ip
+ 2);
5246 gsize offset_pointer
= (gsize
) *(gint16
*) (ip
+ 3);
5251 gint32 length
= *(gint32
*) (span
+ offset_length
);
5252 if (index
< 0 || index
>= length
)
5253 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5255 gpointer pointer
= *(gpointer
*)(span
+ offset_pointer
);
5256 sp
[-1].data
.p
= (guint8
*) pointer
+ index
* element_size
;
5261 MINT_IN_CASE(MINT_STRLEN
)
5265 sp
[-1].data
.i
= mono_string_length_internal ((MonoString
*) o
);
5267 MINT_IN_CASE(MINT_ARRAY_RANK
)
5270 sp
[-1].data
.i
= m_class_get_rank (mono_object_class (sp
[-1].data
.p
));
5273 MINT_IN_CASE(MINT_LDELEMA_FAST
) {
5274 /* No bounds, one direction */
5275 gint32 size
= READ32 (ip
+ 1);
5276 gint32 index
= sp
[-1].data
.i
;
5278 MonoArray
*ao
= (MonoArray
*)sp
[-2].data
.o
;
5280 if (index
>= ao
->max_length
)
5281 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5282 sp
[-2].data
.p
= mono_array_addr_with_size_fast (ao
, size
, index
);
5288 MINT_IN_CASE(MINT_LDELEMA
)
5289 MINT_IN_CASE(MINT_LDELEMA_TC
) {
5290 gboolean needs_typecheck
= *ip
== MINT_LDELEMA_TC
;
5292 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[*(guint16
*) (ip
+ 1)];
5293 guint16 numargs
= *(guint16
*) (ip
+ 2);
5299 sp
->data
.p
= ves_array_element_address (frame
, klass
, (MonoArray
*) o
, &sp
[1], needs_typecheck
);
5301 THROW_EX (frame
->ex
, ip
);
5306 MINT_IN_CASE(MINT_LDELEM_I1
) /* fall through */
5307 MINT_IN_CASE(MINT_LDELEM_U1
) /* fall through */
5308 MINT_IN_CASE(MINT_LDELEM_I2
) /* fall through */
5309 MINT_IN_CASE(MINT_LDELEM_U2
) /* fall through */
5310 MINT_IN_CASE(MINT_LDELEM_I4
) /* fall through */
5311 MINT_IN_CASE(MINT_LDELEM_U4
) /* fall through */
5312 MINT_IN_CASE(MINT_LDELEM_I8
) /* fall through */
5313 MINT_IN_CASE(MINT_LDELEM_I
) /* fall through */
5314 MINT_IN_CASE(MINT_LDELEM_R4
) /* fall through */
5315 MINT_IN_CASE(MINT_LDELEM_R8
) /* fall through */
5316 MINT_IN_CASE(MINT_LDELEM_REF
) /* fall through */
5317 MINT_IN_CASE(MINT_LDELEM_VT
) {
5323 o
= (MonoArray
*)sp
[0].data
.p
;
5326 aindex
= sp
[1].data
.i
;
5327 if (aindex
>= mono_array_length_internal (o
))
5328 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5331 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
5334 case MINT_LDELEM_I1
:
5335 sp
[0].data
.i
= mono_array_get_fast (o
, gint8
, aindex
);
5337 case MINT_LDELEM_U1
:
5338 sp
[0].data
.i
= mono_array_get_fast (o
, guint8
, aindex
);
5340 case MINT_LDELEM_I2
:
5341 sp
[0].data
.i
= mono_array_get_fast (o
, gint16
, aindex
);
5343 case MINT_LDELEM_U2
:
5344 sp
[0].data
.i
= mono_array_get_fast (o
, guint16
, aindex
);
5347 sp
[0].data
.nati
= mono_array_get_fast (o
, mono_i
, aindex
);
5349 case MINT_LDELEM_I4
:
5350 sp
[0].data
.i
= mono_array_get_fast (o
, gint32
, aindex
);
5352 case MINT_LDELEM_U4
:
5353 sp
[0].data
.i
= mono_array_get_fast (o
, guint32
, aindex
);
5355 case MINT_LDELEM_I8
:
5356 sp
[0].data
.l
= mono_array_get_fast (o
, guint64
, aindex
);
5358 case MINT_LDELEM_R4
:
5359 sp
[0].data
.f_r4
= mono_array_get_fast (o
, float, aindex
);
5361 case MINT_LDELEM_R8
:
5362 sp
[0].data
.f
= mono_array_get_fast (o
, double, aindex
);
5364 case MINT_LDELEM_REF
:
5365 sp
[0].data
.p
= mono_array_get_fast (o
, gpointer
, aindex
);
5367 case MINT_LDELEM_VT
: {
5368 i32
= READ32 (ip
+ 1);
5369 char *src_addr
= mono_array_addr_with_size_fast ((MonoArray
*) o
, i32
, aindex
);
5370 sp
[0].data
.vt
= vt_sp
;
5371 // Copying to vtstack. No wbarrier needed
5372 memcpy (sp
[0].data
.vt
, src_addr
, i32
);
5373 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5385 MINT_IN_CASE(MINT_STELEM_I
) /* fall through */
5386 MINT_IN_CASE(MINT_STELEM_I1
) /* fall through */
5387 MINT_IN_CASE(MINT_STELEM_U1
) /* fall through */
5388 MINT_IN_CASE(MINT_STELEM_I2
) /* fall through */
5389 MINT_IN_CASE(MINT_STELEM_U2
) /* fall through */
5390 MINT_IN_CASE(MINT_STELEM_I4
) /* fall through */
5391 MINT_IN_CASE(MINT_STELEM_I8
) /* fall through */
5392 MINT_IN_CASE(MINT_STELEM_R4
) /* fall through */
5393 MINT_IN_CASE(MINT_STELEM_R8
) /* fall through */
5394 MINT_IN_CASE(MINT_STELEM_REF
) /* fall through */
5395 MINT_IN_CASE(MINT_STELEM_VT
) {
5403 aindex
= sp
[1].data
.i
;
5404 if (aindex
>= mono_array_length_internal ((MonoArray
*)o
))
5405 THROW_EX (mono_get_exception_index_out_of_range (), ip
);
5409 mono_array_set_fast ((MonoArray
*)o
, mono_i
, aindex
, sp
[2].data
.nati
);
5411 case MINT_STELEM_I1
:
5412 mono_array_set_fast ((MonoArray
*)o
, gint8
, aindex
, sp
[2].data
.i
);
5414 case MINT_STELEM_U1
:
5415 mono_array_set_fast ((MonoArray
*) o
, guint8
, aindex
, sp
[2].data
.i
);
5417 case MINT_STELEM_I2
:
5418 mono_array_set_fast ((MonoArray
*)o
, gint16
, aindex
, sp
[2].data
.i
);
5420 case MINT_STELEM_U2
:
5421 mono_array_set_fast ((MonoArray
*)o
, guint16
, aindex
, sp
[2].data
.i
);
5423 case MINT_STELEM_I4
:
5424 mono_array_set_fast ((MonoArray
*)o
, gint32
, aindex
, sp
[2].data
.i
);
5426 case MINT_STELEM_I8
:
5427 mono_array_set_fast ((MonoArray
*)o
, gint64
, aindex
, sp
[2].data
.l
);
5429 case MINT_STELEM_R4
:
5430 mono_array_set_fast ((MonoArray
*)o
, float, aindex
, sp
[2].data
.f_r4
);
5432 case MINT_STELEM_R8
:
5433 mono_array_set_fast ((MonoArray
*)o
, double, aindex
, sp
[2].data
.f
);
5435 case MINT_STELEM_REF
: {
5436 MonoObject
*isinst_obj
= mono_object_isinst_checked (sp
[2].data
.o
, m_class_get_element_class (mono_object_class (o
)), error
);
5437 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5438 if (sp
[2].data
.p
&& !isinst_obj
)
5439 THROW_EX (mono_get_exception_array_type_mismatch (), ip
);
5440 mono_array_setref_fast ((MonoArray
*) o
, aindex
, sp
[2].data
.p
);
5443 case MINT_STELEM_VT
: {
5444 MonoClass
*klass_vt
= (MonoClass
*)imethod
->data_items
[*(guint16
*) (ip
+ 1)];
5445 i32
= READ32 (ip
+ 2);
5446 char *dst_addr
= mono_array_addr_with_size_fast ((MonoArray
*) o
, i32
, aindex
);
5448 mono_value_copy_internal (dst_addr
, sp
[2].data
.vt
, klass_vt
);
5449 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
5460 MINT_IN_CASE(MINT_CONV_OVF_I4_U4
)
5461 if (sp
[-1].data
.i
< 0)
5465 MINT_IN_CASE(MINT_CONV_OVF_I4_I8
)
5466 if (sp
[-1].data
.l
< G_MININT32
|| sp
[-1].data
.l
> G_MAXINT32
)
5468 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.l
;
5471 MINT_IN_CASE(MINT_CONV_OVF_I4_U8
)
5472 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT32
)
5474 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.l
;
5477 MINT_IN_CASE(MINT_CONV_OVF_I4_R4
)
5478 if (sp
[-1].data
.f_r4
< G_MININT32
|| sp
[-1].data
.f_r4
> G_MAXINT32
)
5480 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f_r4
;
5483 MINT_IN_CASE(MINT_CONV_OVF_I4_R8
)
5484 if (sp
[-1].data
.f
< G_MININT32
|| sp
[-1].data
.f
> G_MAXINT32
)
5486 sp
[-1].data
.i
= (gint32
) sp
[-1].data
.f
;
5489 MINT_IN_CASE(MINT_CONV_OVF_U4_I4
)
5490 if (sp
[-1].data
.i
< 0)
5494 MINT_IN_CASE(MINT_CONV_OVF_U4_I8
)
5495 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT32
)
5497 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.l
;
5500 MINT_IN_CASE(MINT_CONV_OVF_U4_R4
)
5501 if (sp
[-1].data
.f_r4
< 0 || sp
[-1].data
.f_r4
> G_MAXUINT32
)
5503 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f_r4
;
5506 MINT_IN_CASE(MINT_CONV_OVF_U4_R8
)
5507 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT32
)
5509 sp
[-1].data
.i
= (guint32
) sp
[-1].data
.f
;
5512 MINT_IN_CASE(MINT_CONV_OVF_I2_I4
)
5513 if (sp
[-1].data
.i
< G_MININT16
|| sp
[-1].data
.i
> G_MAXINT16
)
5517 MINT_IN_CASE(MINT_CONV_OVF_I2_U4
)
5518 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXINT16
)
5522 MINT_IN_CASE(MINT_CONV_OVF_I2_I8
)
5523 if (sp
[-1].data
.l
< G_MININT16
|| sp
[-1].data
.l
> G_MAXINT16
)
5525 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.l
;
5528 MINT_IN_CASE(MINT_CONV_OVF_I2_U8
)
5529 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT16
)
5531 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.l
;
5534 MINT_IN_CASE(MINT_CONV_OVF_I2_R8
)
5535 if (sp
[-1].data
.f
< G_MININT16
|| sp
[-1].data
.f
> G_MAXINT16
)
5537 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.f
;
5540 MINT_IN_CASE(MINT_CONV_OVF_I2_UN_R8
)
5541 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT16
)
5543 sp
[-1].data
.i
= (gint16
) sp
[-1].data
.f
;
5546 MINT_IN_CASE(MINT_CONV_OVF_U2_I4
)
5547 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXUINT16
)
5551 MINT_IN_CASE(MINT_CONV_OVF_U2_I8
)
5552 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT16
)
5554 sp
[-1].data
.i
= (guint16
) sp
[-1].data
.l
;
5557 MINT_IN_CASE(MINT_CONV_OVF_U2_R8
)
5558 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT16
)
5560 sp
[-1].data
.i
= (guint16
) sp
[-1].data
.f
;
5563 MINT_IN_CASE(MINT_CONV_OVF_I1_I4
)
5564 if (sp
[-1].data
.i
< G_MININT8
|| sp
[-1].data
.i
> G_MAXINT8
)
5568 MINT_IN_CASE(MINT_CONV_OVF_I1_U4
)
5569 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXINT8
)
5573 MINT_IN_CASE(MINT_CONV_OVF_I1_I8
)
5574 if (sp
[-1].data
.l
< G_MININT8
|| sp
[-1].data
.l
> G_MAXINT8
)
5576 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.l
;
5579 MINT_IN_CASE(MINT_CONV_OVF_I1_U8
)
5580 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXINT8
)
5582 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.l
;
5585 MINT_IN_CASE(MINT_CONV_OVF_I1_R8
)
5586 if (sp
[-1].data
.f
< G_MININT8
|| sp
[-1].data
.f
> G_MAXINT8
)
5588 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.f
;
5591 MINT_IN_CASE(MINT_CONV_OVF_I1_UN_R8
)
5592 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXINT8
)
5594 sp
[-1].data
.i
= (gint8
) sp
[-1].data
.f
;
5597 MINT_IN_CASE(MINT_CONV_OVF_U1_I4
)
5598 if (sp
[-1].data
.i
< 0 || sp
[-1].data
.i
> G_MAXUINT8
)
5602 MINT_IN_CASE(MINT_CONV_OVF_U1_I8
)
5603 if (sp
[-1].data
.l
< 0 || sp
[-1].data
.l
> G_MAXUINT8
)
5605 sp
[-1].data
.i
= (guint8
) sp
[-1].data
.l
;
5608 MINT_IN_CASE(MINT_CONV_OVF_U1_R8
)
5609 if (sp
[-1].data
.f
< 0 || sp
[-1].data
.f
> G_MAXUINT8
)
5611 sp
[-1].data
.i
= (guint8
) sp
[-1].data
.f
;
5614 MINT_IN_CASE(MINT_CKFINITE
)
5615 if (!mono_isfinite (sp
[-1].data
.f
))
5616 THROW_EX (mono_get_exception_arithmetic (), ip
);
5619 MINT_IN_CASE(MINT_MKREFANY
) {
5620 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5622 /* The value address is on the stack */
5623 gpointer addr
= sp
[-1].data
.p
;
5624 /* Push the typedref value on the stack */
5625 sp
[-1].data
.p
= vt_sp
;
5626 vt_sp
+= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5628 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5630 tref
->type
= m_class_get_byval_arg (c
);
5636 MINT_IN_CASE(MINT_REFANYTYPE
) {
5637 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5638 MonoType
*type
= tref
->type
;
5640 vt_sp
-= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5641 sp
[-1].data
.p
= vt_sp
;
5643 *(gpointer
*)sp
[-1].data
.p
= type
;
5647 MINT_IN_CASE(MINT_REFANYVAL
) {
5648 MonoTypedRef
*tref
= (MonoTypedRef
*)sp
[-1].data
.p
;
5649 gpointer addr
= tref
->value
;
5651 c
= (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5652 if (c
!= tref
->klass
)
5653 THROW_EX (mono_get_exception_invalid_cast (), ip
);
5655 vt_sp
-= ALIGN_TO (sizeof (MonoTypedRef
), MINT_VT_ALIGNMENT
);
5657 sp
[-1].data
.p
= addr
;
5661 MINT_IN_CASE(MINT_LDTOKEN
)
5664 * (gpointer
*)sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5668 MINT_IN_CASE(MINT_ADD_OVF_I4
)
5669 if (CHECK_ADD_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5673 MINT_IN_CASE(MINT_ADD_OVF_I8
)
5674 if (CHECK_ADD_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5678 MINT_IN_CASE(MINT_ADD_OVF_UN_I4
)
5679 if (CHECK_ADD_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5681 BINOP_CAST(i
, +, guint32
);
5683 MINT_IN_CASE(MINT_ADD_OVF_UN_I8
)
5684 if (CHECK_ADD_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5686 BINOP_CAST(l
, +, guint64
);
5688 MINT_IN_CASE(MINT_MUL_OVF_I4
)
5689 if (CHECK_MUL_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5693 MINT_IN_CASE(MINT_MUL_OVF_I8
)
5694 if (CHECK_MUL_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5698 MINT_IN_CASE(MINT_MUL_OVF_UN_I4
)
5699 if (CHECK_MUL_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5701 BINOP_CAST(i
, *, guint32
);
5703 MINT_IN_CASE(MINT_MUL_OVF_UN_I8
)
5704 if (CHECK_MUL_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5706 BINOP_CAST(l
, *, guint64
);
5708 MINT_IN_CASE(MINT_SUB_OVF_I4
)
5709 if (CHECK_SUB_OVERFLOW (sp
[-2].data
.i
, sp
[-1].data
.i
))
5713 MINT_IN_CASE(MINT_SUB_OVF_I8
)
5714 if (CHECK_SUB_OVERFLOW64 (sp
[-2].data
.l
, sp
[-1].data
.l
))
5718 MINT_IN_CASE(MINT_SUB_OVF_UN_I4
)
5719 if (CHECK_SUB_OVERFLOW_UN (sp
[-2].data
.i
, sp
[-1].data
.i
))
5721 BINOP_CAST(i
, -, guint32
);
5723 MINT_IN_CASE(MINT_SUB_OVF_UN_I8
)
5724 if (CHECK_SUB_OVERFLOW64_UN (sp
[-2].data
.l
, sp
[-1].data
.l
))
5726 BINOP_CAST(l
, -, guint64
);
5728 MINT_IN_CASE(MINT_START_ABORT_PROT
)
5729 mono_threads_begin_abort_protected_block ();
5732 MINT_IN_CASE(MINT_ENDFINALLY
) {
5734 int clause_index
= *ip
;
5735 gboolean pending_abort
= mono_threads_end_abort_protected_block ();
5737 if (clause_args
&& clause_index
== clause_args
->exit_clause
)
5739 g_assert (sp
>= frame
->stack
);
5742 if (frame
->finally_ips
) {
5743 ip
= (const guint16
*)frame
->finally_ips
->data
;
5744 frame
->finally_ips
= g_slist_remove (frame
->finally_ips
, ip
);
5745 /* Throw abort after the last finally block to avoid confusing EH */
5746 if (pending_abort
&& !frame
->finally_ips
)
5747 EXCEPTION_CHECKPOINT
;
5748 MINT_IN_DISPATCH(*ip
);
5754 MINT_IN_CASE(MINT_LEAVE
)
5755 MINT_IN_CASE(MINT_LEAVE_S
)
5756 MINT_IN_CASE(MINT_LEAVE_CHECK
)
5757 MINT_IN_CASE(MINT_LEAVE_S_CHECK
) {
5758 g_assert (sp
>= frame
->stack
);
5762 if (*ip
== MINT_LEAVE_S_CHECK
|| *ip
== MINT_LEAVE_CHECK
) {
5763 if (imethod
->method
->wrapper_type
!= MONO_WRAPPER_RUNTIME_INVOKE
) {
5766 child_frame
.parent
= frame
;
5767 child_frame
.imethod
= NULL
;
5769 * We need for mono_thread_get_undeniable_exception to be able to unwind
5770 * to check the abort threshold. For this to work we use child_frame as a
5771 * dummy frame that is stored in the lmf and serves as the transition frame
5773 do_icall_wrapper (&child_frame
, NULL
, MINT_ICALL_V_P
, &tmp_sp
, (gpointer
)mono_thread_get_undeniable_exception
, FALSE
);
5775 MonoException
*abort_exc
= (MonoException
*)tmp_sp
.data
.p
;
5777 THROW_EX (abort_exc
, frame
->ip
);
5781 if (*ip
== MINT_LEAVE_S
|| *ip
== MINT_LEAVE_S_CHECK
) {
5782 ip
+= (short) *(ip
+ 1);
5784 ip
+= (gint32
) READ32 (ip
+ 1);
5786 frame
->endfinally_ip
= ip
;
5789 MonoExceptionClause
*clause
;
5790 GSList
*old_list
= frame
->finally_ips
;
5791 MonoMethod
*method
= imethod
->method
;
5795 g_print ("* Handle finally IL_%04x\n", frame
->endfinally_ip
== NULL
? 0 : frame
->endfinally_ip
- imethod
->code
);
5797 if (imethod
== NULL
|| (method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
)
5798 || (method
->iflags
& (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
| METHOD_IMPL_ATTRIBUTE_RUNTIME
))) {
5801 ip_offset
= frame
->ip
- imethod
->code
;
5803 if (frame
->endfinally_ip
!= NULL
)
5804 frame
->finally_ips
= g_slist_prepend(frame
->finally_ips
, (void *)frame
->endfinally_ip
);
5806 for (int i
= imethod
->num_clauses
- 1; i
>= 0; i
--) {
5807 clause
= &imethod
->clauses
[i
];
5808 if (MONO_OFFSET_IN_CLAUSE (clause
, ip_offset
) && (frame
->endfinally_ip
== NULL
|| !(MONO_OFFSET_IN_CLAUSE (clause
, frame
->endfinally_ip
- imethod
->code
)))) {
5809 if (clause
->flags
== MONO_EXCEPTION_CLAUSE_FINALLY
) {
5810 ip
= imethod
->code
+ clause
->handler_offset
;
5811 frame
->finally_ips
= g_slist_prepend (frame
->finally_ips
, (gpointer
) ip
);
5814 g_print ("* Found finally at IL_%04x with exception: %s\n", clause
->handler_offset
, frame
->ex
? "yes": "no");
5820 frame
->endfinally_ip
= NULL
;
5822 if (old_list
!= frame
->finally_ips
&& frame
->finally_ips
) {
5823 ip
= (const guint16
*)frame
->finally_ips
->data
;
5824 frame
->finally_ips
= g_slist_remove (frame
->finally_ips
, ip
);
5825 sp
= frame
->stack
; /* spec says stack should be empty at endfinally so it should be at the start too */
5826 vt_sp
= (unsigned char *) sp
+ imethod
->stack_size
;
5827 MINT_IN_DISPATCH (*ip
);
5833 MINT_IN_CASE(MINT_ICALL_V_V
)
5834 MINT_IN_CASE(MINT_ICALL_V_P
)
5835 MINT_IN_CASE(MINT_ICALL_P_V
)
5836 MINT_IN_CASE(MINT_ICALL_P_P
)
5837 MINT_IN_CASE(MINT_ICALL_PP_V
)
5838 MINT_IN_CASE(MINT_ICALL_PP_P
)
5839 MINT_IN_CASE(MINT_ICALL_PPP_V
)
5840 MINT_IN_CASE(MINT_ICALL_PPP_P
)
5841 MINT_IN_CASE(MINT_ICALL_PPPP_V
)
5842 MINT_IN_CASE(MINT_ICALL_PPPP_P
)
5843 MINT_IN_CASE(MINT_ICALL_PPPPP_V
)
5844 MINT_IN_CASE(MINT_ICALL_PPPPP_P
)
5845 MINT_IN_CASE(MINT_ICALL_PPPPPP_V
)
5846 MINT_IN_CASE(MINT_ICALL_PPPPPP_P
)
5848 sp
= do_icall_wrapper (frame
, NULL
, *ip
, sp
, imethod
->data_items
[*(guint16
*)(ip
+ 1)], FALSE
);
5849 EXCEPTION_CHECKPOINT
;
5850 CHECK_RESUME_STATE (context
);
5853 MINT_IN_CASE(MINT_MONO_LDPTR
)
5854 sp
->data
.p
= imethod
->data_items
[*(guint16
*)(ip
+ 1)];
5858 MINT_IN_CASE(MINT_MONO_NEWOBJ
)
5859 sp
->data
.p
= mono_object_new_checked (imethod
->domain
, (MonoClass
*)imethod
->data_items
[*(guint16
*)(ip
+ 1)], error
);
5860 mono_error_cleanup (error
); /* FIXME: don't swallow the error */
5864 MINT_IN_CASE(MINT_MONO_FREE
)
5867 g_error ("that doesn't seem right");
5868 g_free (sp
->data
.p
);
5870 MINT_IN_CASE(MINT_MONO_RETOBJ
)
5873 stackval_from_data (mono_method_signature_internal (imethod
->method
)->ret
, frame
->retval
, sp
->data
.p
,
5874 mono_method_signature_internal (imethod
->method
)->pinvoke
);
5875 if (sp
> frame
->stack
)
5876 g_warning ("retobj: more values on stack: %d", sp
-frame
->stack
);
5878 MINT_IN_CASE(MINT_MONO_SGEN_THREAD_INFO
)
5879 sp
->data
.p
= mono_tls_get_sgen_thread_info ();
5883 MINT_IN_CASE(MINT_MONO_MEMORY_BARRIER
) {
5885 mono_memory_barrier ();
5888 MINT_IN_CASE(MINT_MONO_LDDOMAIN
)
5889 sp
->data
.p
= mono_domain_get ();
5893 MINT_IN_CASE(MINT_SDB_INTR_LOC
)
5894 if (G_UNLIKELY (ss_enabled
)) {
5895 typedef void (*T
) (void);
5899 void *tramp
= mini_get_single_step_trampoline ();
5900 mono_memory_barrier ();
5901 ss_tramp
= (T
)tramp
;
5905 * Make this point to the MINT_SDB_SEQ_POINT instruction which follows this since
5906 * the address of that instruction is stored as the seq point address.
5911 * Use the same trampoline as the JIT. This ensures that
5912 * the debugger has the context for the last interpreter
5915 do_debugger_tramp (ss_tramp
, frame
);
5917 CHECK_RESUME_STATE (context
);
5921 MINT_IN_CASE(MINT_SDB_SEQ_POINT
)
5922 /* Just a placeholder for a breakpoint */
5925 MINT_IN_CASE(MINT_SDB_BREAKPOINT
) {
5926 typedef void (*T
) (void);
5929 void *tramp
= mini_get_breakpoint_trampoline ();
5930 mono_memory_barrier ();
5931 bp_tramp
= (T
)tramp
;
5936 /* Use the same trampoline as the JIT */
5937 do_debugger_tramp (bp_tramp
, frame
);
5939 CHECK_RESUME_STATE (context
);
5945 #define RELOP(datamem, op) \
5947 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
5950 #define RELOP_FP(datamem, op, noorder) \
5952 if (mono_isunordered (sp [-1].data.datamem, sp [0].data.datamem)) \
5953 sp [-1].data.i = noorder; \
5955 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
5958 MINT_IN_CASE(MINT_CEQ_I4
)
5961 MINT_IN_CASE(MINT_CEQ0_I4
)
5962 sp
[-1].data
.i
= (sp
[-1].data
.i
== 0);
5965 MINT_IN_CASE(MINT_CEQ_I8
)
5968 MINT_IN_CASE(MINT_CEQ_R4
)
5969 RELOP_FP(f_r4
, ==, 0);
5971 MINT_IN_CASE(MINT_CEQ_R8
)
5974 MINT_IN_CASE(MINT_CNE_I4
)
5977 MINT_IN_CASE(MINT_CNE_I8
)
5980 MINT_IN_CASE(MINT_CNE_R4
)
5981 RELOP_FP(f_r4
, !=, 1);
5983 MINT_IN_CASE(MINT_CNE_R8
)
5986 MINT_IN_CASE(MINT_CGT_I4
)
5989 MINT_IN_CASE(MINT_CGT_I8
)
5992 MINT_IN_CASE(MINT_CGT_R4
)
5993 RELOP_FP(f_r4
, >, 0);
5995 MINT_IN_CASE(MINT_CGT_R8
)
5998 MINT_IN_CASE(MINT_CGE_I4
)
6001 MINT_IN_CASE(MINT_CGE_I8
)
6004 MINT_IN_CASE(MINT_CGE_R4
)
6005 RELOP_FP(f_r4
, >=, 0);
6007 MINT_IN_CASE(MINT_CGE_R8
)
6011 #define RELOP_CAST(datamem, op, type) \
6013 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
6016 MINT_IN_CASE(MINT_CGE_UN_I4
)
6017 RELOP_CAST(l
, >=, guint32
);
6019 MINT_IN_CASE(MINT_CGE_UN_I8
)
6020 RELOP_CAST(l
, >=, guint64
);
6023 MINT_IN_CASE(MINT_CGT_UN_I4
)
6024 RELOP_CAST(i
, >, guint32
);
6026 MINT_IN_CASE(MINT_CGT_UN_I8
)
6027 RELOP_CAST(l
, >, guint64
);
6029 MINT_IN_CASE(MINT_CGT_UN_R4
)
6030 RELOP_FP(f_r4
, >, 1);
6032 MINT_IN_CASE(MINT_CGT_UN_R8
)
6035 MINT_IN_CASE(MINT_CLT_I4
)
6038 MINT_IN_CASE(MINT_CLT_I8
)
6041 MINT_IN_CASE(MINT_CLT_R4
)
6042 RELOP_FP(f_r4
, <, 0);
6044 MINT_IN_CASE(MINT_CLT_R8
)
6047 MINT_IN_CASE(MINT_CLT_UN_I4
)
6048 RELOP_CAST(i
, <, guint32
);
6050 MINT_IN_CASE(MINT_CLT_UN_I8
)
6051 RELOP_CAST(l
, <, guint64
);
6053 MINT_IN_CASE(MINT_CLT_UN_R4
)
6054 RELOP_FP(f_r4
, <, 1);
6056 MINT_IN_CASE(MINT_CLT_UN_R8
)
6059 MINT_IN_CASE(MINT_CLE_I4
)
6062 MINT_IN_CASE(MINT_CLE_I8
)
6065 MINT_IN_CASE(MINT_CLE_UN_I4
)
6066 RELOP_CAST(l
, <=, guint32
);
6068 MINT_IN_CASE(MINT_CLE_UN_I8
)
6069 RELOP_CAST(l
, <=, guint64
);
6071 MINT_IN_CASE(MINT_CLE_R4
)
6072 RELOP_FP(f_r4
, <=, 0);
6074 MINT_IN_CASE(MINT_CLE_R8
)
6082 MINT_IN_CASE(MINT_LDFTN
) {
6083 sp
->data
.p
= imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6088 MINT_IN_CASE(MINT_LDVIRTFTN
) {
6089 InterpMethod
*m
= (InterpMethod
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6091 NULL_CHECK (sp
->data
.p
);
6093 sp
->data
.p
= get_virtual_method (m
, sp
->data
.o
->vtable
);
6098 MINT_IN_CASE(MINT_LDFTN_DYNAMIC
) {
6099 MONO_API_ERROR_INIT (error
);
6100 InterpMethod
*m
= mono_interp_get_imethod (mono_domain_get (), (MonoMethod
*) sp
[-1].data
.p
, error
);
6101 mono_error_assert_ok (error
);
6107 #define LDARG(datamem, argtype) \
6108 sp->data.datamem = (argtype) frame->stack_args [*(guint16 *)(ip + 1)].data.datamem; \
6112 MINT_IN_CASE(MINT_LDARG_I1
) LDARG(i
, gint8
); MINT_IN_BREAK
;
6113 MINT_IN_CASE(MINT_LDARG_U1
) LDARG(i
, guint8
); MINT_IN_BREAK
;
6114 MINT_IN_CASE(MINT_LDARG_I2
) LDARG(i
, gint16
); MINT_IN_BREAK
;
6115 MINT_IN_CASE(MINT_LDARG_U2
) LDARG(i
, guint16
); MINT_IN_BREAK
;
6116 MINT_IN_CASE(MINT_LDARG_I4
) LDARG(i
, gint32
); MINT_IN_BREAK
;
6117 MINT_IN_CASE(MINT_LDARG_I8
) LDARG(l
, gint64
); MINT_IN_BREAK
;
6118 MINT_IN_CASE(MINT_LDARG_R4
) LDARG(f_r4
, float); MINT_IN_BREAK
;
6119 MINT_IN_CASE(MINT_LDARG_R8
) LDARG(f
, double); MINT_IN_BREAK
;
6120 MINT_IN_CASE(MINT_LDARG_O
) LDARG(p
, gpointer
); MINT_IN_BREAK
;
6121 MINT_IN_CASE(MINT_LDARG_P
) LDARG(p
, gpointer
); MINT_IN_BREAK
;
6123 MINT_IN_CASE(MINT_LDARG_VT
)
6125 i32
= READ32(ip
+ 2);
6126 memcpy(sp
->data
.p
, frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
, i32
);
6127 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6132 #define STARG(datamem, argtype) \
6134 frame->stack_args [*(guint16 *)(ip + 1)].data.datamem = (argtype) sp->data.datamem; \
6137 MINT_IN_CASE(MINT_STARG_I1
) STARG(i
, gint8
); MINT_IN_BREAK
;
6138 MINT_IN_CASE(MINT_STARG_U1
) STARG(i
, guint8
); MINT_IN_BREAK
;
6139 MINT_IN_CASE(MINT_STARG_I2
) STARG(i
, gint16
); MINT_IN_BREAK
;
6140 MINT_IN_CASE(MINT_STARG_U2
) STARG(i
, guint16
); MINT_IN_BREAK
;
6141 MINT_IN_CASE(MINT_STARG_I4
) STARG(i
, gint32
); MINT_IN_BREAK
;
6142 MINT_IN_CASE(MINT_STARG_I8
) STARG(l
, gint64
); MINT_IN_BREAK
;
6143 MINT_IN_CASE(MINT_STARG_R4
) STARG(f_r4
, float); MINT_IN_BREAK
;
6144 MINT_IN_CASE(MINT_STARG_R8
) STARG(f
, double); MINT_IN_BREAK
;
6145 MINT_IN_CASE(MINT_STARG_O
) STARG(p
, gpointer
); MINT_IN_BREAK
;
6146 MINT_IN_CASE(MINT_STARG_P
) STARG(p
, gpointer
); MINT_IN_BREAK
;
6148 MINT_IN_CASE(MINT_STARG_VT
)
6149 i32
= READ32(ip
+ 2);
6151 memcpy(frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
, sp
->data
.p
, i32
);
6152 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6156 MINT_IN_CASE(MINT_PROF_ENTER
) {
6159 if (MONO_PROFILER_ENABLED (method_enter
)) {
6160 MonoProfilerCallContext
*prof_ctx
= NULL
;
6162 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_ENTER_CONTEXT
) {
6163 prof_ctx
= g_new0 (MonoProfilerCallContext
, 1);
6164 prof_ctx
->interp_frame
= frame
;
6165 prof_ctx
->method
= imethod
->method
;
6168 MONO_PROFILER_RAISE (method_enter
, (imethod
->method
, prof_ctx
));
6176 MINT_IN_CASE(MINT_TRACE_ENTER
) {
6179 MonoProfilerCallContext
*prof_ctx
= g_alloca (sizeof (MonoProfilerCallContext
));
6180 prof_ctx
->interp_frame
= frame
;
6181 prof_ctx
->method
= imethod
->method
;
6183 mono_trace_enter_method (imethod
->method
, prof_ctx
);
6187 MINT_IN_CASE(MINT_TRACE_EXIT
) {
6189 i32
= READ32(ip
+ 1);
6194 memcpy(frame
->retval
->data
.p
, sp
->data
.p
, i32
);
6196 *frame
->retval
= *sp
;
6198 MonoProfilerCallContext
*prof_ctx
= g_alloca (sizeof (MonoProfilerCallContext
));
6199 prof_ctx
->interp_frame
= frame
;
6200 prof_ctx
->method
= imethod
->method
;
6202 mono_trace_leave_method (imethod
->method
, prof_ctx
);
6207 MINT_IN_CASE(MINT_LDARGA
)
6208 sp
->data
.p
= &frame
->stack_args
[* (guint16
*)(ip
+ 1)];
6213 MINT_IN_CASE(MINT_LDARGA_VT
)
6214 sp
->data
.p
= frame
->stack_args
[* (guint16
*)(ip
+ 1)].data
.p
;
6219 #define LDLOC(datamem, argtype) \
6220 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
6224 MINT_IN_CASE(MINT_LDLOC_I1
) LDLOC(i
, gint8
); MINT_IN_BREAK
;
6225 MINT_IN_CASE(MINT_LDLOC_U1
) LDLOC(i
, guint8
); MINT_IN_BREAK
;
6226 MINT_IN_CASE(MINT_LDLOC_I2
) LDLOC(i
, gint16
); MINT_IN_BREAK
;
6227 MINT_IN_CASE(MINT_LDLOC_U2
) LDLOC(i
, guint16
); MINT_IN_BREAK
;
6228 MINT_IN_CASE(MINT_LDLOC_I4
) LDLOC(i
, gint32
); MINT_IN_BREAK
;
6229 MINT_IN_CASE(MINT_LDLOC_I8
) LDLOC(l
, gint64
); MINT_IN_BREAK
;
6230 MINT_IN_CASE(MINT_LDLOC_R4
) LDLOC(f_r4
, float); MINT_IN_BREAK
;
6231 MINT_IN_CASE(MINT_LDLOC_R8
) LDLOC(f
, double); MINT_IN_BREAK
;
6232 MINT_IN_CASE(MINT_LDLOC_O
) LDLOC(p
, gpointer
); MINT_IN_BREAK
;
6233 MINT_IN_CASE(MINT_LDLOC_P
) LDLOC(p
, gpointer
); MINT_IN_BREAK
;
6235 MINT_IN_CASE(MINT_LDLOC_VT
)
6237 i32
= READ32(ip
+ 2);
6238 memcpy(sp
->data
.p
, locals
+ * (guint16
*)(ip
+ 1), i32
);
6239 vt_sp
+= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6244 MINT_IN_CASE(MINT_LDLOCA_S
)
6245 sp
->data
.p
= locals
+ * (guint16
*)(ip
+ 1);
6250 #define STLOC(datamem, argtype) \
6252 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
6255 MINT_IN_CASE(MINT_STLOC_I1
) STLOC(i
, gint8
); MINT_IN_BREAK
;
6256 MINT_IN_CASE(MINT_STLOC_U1
) STLOC(i
, guint8
); MINT_IN_BREAK
;
6257 MINT_IN_CASE(MINT_STLOC_I2
) STLOC(i
, gint16
); MINT_IN_BREAK
;
6258 MINT_IN_CASE(MINT_STLOC_U2
) STLOC(i
, guint16
); MINT_IN_BREAK
;
6259 MINT_IN_CASE(MINT_STLOC_I4
) STLOC(i
, gint32
); MINT_IN_BREAK
;
6260 MINT_IN_CASE(MINT_STLOC_I8
) STLOC(l
, gint64
); MINT_IN_BREAK
;
6261 MINT_IN_CASE(MINT_STLOC_R4
) STLOC(f_r4
, float); MINT_IN_BREAK
;
6262 MINT_IN_CASE(MINT_STLOC_R8
) STLOC(f
, double); MINT_IN_BREAK
;
6263 MINT_IN_CASE(MINT_STLOC_O
) STLOC(p
, gpointer
); MINT_IN_BREAK
;
6264 MINT_IN_CASE(MINT_STLOC_P
) STLOC(p
, gpointer
); MINT_IN_BREAK
;
6266 #define STLOC_NP(datamem, argtype) \
6267 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
6270 MINT_IN_CASE(MINT_STLOC_NP_I4
) STLOC_NP(i
, gint32
); MINT_IN_BREAK
;
6271 MINT_IN_CASE(MINT_STLOC_NP_O
) STLOC_NP(p
, gpointer
); MINT_IN_BREAK
;
6273 MINT_IN_CASE(MINT_STLOC_VT
)
6274 i32
= READ32(ip
+ 2);
6276 memcpy(locals
+ * (guint16
*)(ip
+ 1), sp
->data
.p
, i32
);
6277 vt_sp
-= ALIGN_TO (i32
, MINT_VT_ALIGNMENT
);
6281 MINT_IN_CASE(MINT_LOCALLOC
) {
6282 if (sp
!= frame
->stack
+ 1) /*FIX?*/
6283 THROW_EX (mono_get_exception_execution_engine (NULL
), ip
);
6285 int len
= sp
[-1].data
.i
;
6286 sp
[-1].data
.p
= alloca (len
);
6288 if (imethod
->init_locals
)
6289 memset (sp
[-1].data
.p
, 0, len
);
6293 MINT_IN_CASE(MINT_ENDFILTER
)
6294 /* top of stack is result of filter */
6295 frame
->retval
= &sp
[-1];
6297 MINT_IN_CASE(MINT_INITOBJ
)
6299 memset (sp
->data
.vt
, 0, READ32(ip
+ 1));
6302 MINT_IN_CASE(MINT_CPBLK
)
6304 if (!sp
[0].data
.p
|| !sp
[1].data
.p
)
6305 THROW_EX (mono_get_exception_null_reference(), ip
- 1);
6307 /* FIXME: value and size may be int64... */
6308 memcpy (sp
[0].data
.p
, sp
[1].data
.p
, sp
[2].data
.i
);
6311 MINT_IN_CASE(MINT_CONSTRAINED_
) {
6313 /* FIXME: implement */
6315 token
= READ32 (ip
);
6320 MINT_IN_CASE(MINT_INITBLK
)
6322 NULL_CHECK (sp
[0].data
.p
);
6324 /* FIXME: value and size may be int64... */
6325 memset (sp
[0].data
.p
, sp
[1].data
.i
, sp
[2].data
.i
);
6328 MINT_IN_CASE(MINT_NO_
)
6329 /* FIXME: implement */
6333 MINT_IN_CASE(MINT_RETHROW
) {
6334 int exvar_offset
= *(guint16
*)(ip
+ 1);
6335 THROW_EX_GENERAL (*(MonoException
**)(frame
->locals
+ exvar_offset
), ip
, TRUE
);
6338 MINT_IN_CASE(MINT_MONO_RETHROW
) {
6340 * need to clarify what this should actually do:
6342 * Takes an exception from the stack and rethrows it.
6343 * This is useful for wrappers that don't want to have to
6344 * use CEE_THROW and lose the exception stacktrace.
6349 sp
->data
.p
= mono_get_exception_null_reference ();
6351 THROW_EX_GENERAL ((MonoException
*)sp
->data
.p
, ip
, TRUE
);
6354 MINT_IN_CASE(MINT_LD_DELEGATE_METHOD_PTR
) {
6358 del
= (MonoDelegate
*)sp
->data
.p
;
6359 if (!del
->interp_method
) {
6360 /* Not created from interpreted code */
6361 MONO_API_ERROR_INIT (error
);
6362 g_assert (del
->method
);
6363 del
->interp_method
= mono_interp_get_imethod (del
->object
.vtable
->domain
, del
->method
, error
);
6364 mono_error_assert_ok (error
);
6366 g_assert (del
->interp_method
);
6367 sp
->data
.p
= del
->interp_method
;
6372 MINT_IN_CASE(MINT_LD_DELEGATE_INVOKE_IMPL
) {
6374 int n
= *(guint16
*)(ip
+ 1);
6375 del
= (MonoDelegate
*)sp
[-n
].data
.p
;
6376 if (!del
->interp_invoke_impl
) {
6378 * First time we are called. Set up the invoke wrapper. We might be able to do this
6379 * in ctor but we would need to handle AllocDelegateLike_internal separately
6381 MONO_API_ERROR_INIT (error
);
6382 MonoMethod
*invoke
= mono_get_delegate_invoke_internal (del
->object
.vtable
->klass
);
6383 del
->interp_invoke_impl
= mono_interp_get_imethod (del
->object
.vtable
->domain
, mono_marshal_get_delegate_invoke (invoke
, del
), error
);
6384 mono_error_assert_ok (error
);
6387 sp
[-1].data
.p
= del
->interp_invoke_impl
;
6392 #define MATH_UNOP(mathfunc) \
6393 sp [-1].data.f = mathfunc (sp [-1].data.f); \
6396 MINT_IN_CASE(MINT_ABS
) MATH_UNOP(fabs
); MINT_IN_BREAK
;
6397 MINT_IN_CASE(MINT_ASIN
) MATH_UNOP(asin
); MINT_IN_BREAK
;
6398 MINT_IN_CASE(MINT_ASINH
) MATH_UNOP(asinh
); MINT_IN_BREAK
;
6399 MINT_IN_CASE(MINT_ACOS
) MATH_UNOP(acos
); MINT_IN_BREAK
;
6400 MINT_IN_CASE(MINT_ACOSH
) MATH_UNOP(acosh
); MINT_IN_BREAK
;
6401 MINT_IN_CASE(MINT_ATAN
) MATH_UNOP(atan
); MINT_IN_BREAK
;
6402 MINT_IN_CASE(MINT_ATANH
) MATH_UNOP(atanh
); MINT_IN_BREAK
;
6403 MINT_IN_CASE(MINT_COS
) MATH_UNOP(cos
); MINT_IN_BREAK
;
6404 MINT_IN_CASE(MINT_CBRT
) MATH_UNOP(cbrt
); MINT_IN_BREAK
;
6405 MINT_IN_CASE(MINT_COSH
) MATH_UNOP(cosh
); MINT_IN_BREAK
;
6406 MINT_IN_CASE(MINT_SIN
) MATH_UNOP(sin
); MINT_IN_BREAK
;
6407 MINT_IN_CASE(MINT_SQRT
) MATH_UNOP(sqrt
); MINT_IN_BREAK
;
6408 MINT_IN_CASE(MINT_SINH
) MATH_UNOP(sinh
); MINT_IN_BREAK
;
6409 MINT_IN_CASE(MINT_TAN
) MATH_UNOP(tan
); MINT_IN_BREAK
;
6410 MINT_IN_CASE(MINT_TANH
) MATH_UNOP(tanh
); MINT_IN_BREAK
;
6412 MINT_IN_CASE(MINT_INTRINS_ENUM_HASFLAG
) {
6413 MonoClass
*klass
= (MonoClass
*)imethod
->data_items
[* (guint16
*)(ip
+ 1)];
6414 guint64 a_val
= 0, b_val
= 0;
6416 stackval_to_data (m_class_get_byval_arg (klass
), &sp
[-2], &a_val
, FALSE
);
6417 stackval_to_data (m_class_get_byval_arg (klass
), &sp
[-1], &b_val
, FALSE
);
6419 sp
[-1].data
.i
= (a_val
& b_val
) == b_val
;
6423 MINT_IN_CASE(MINT_INTRINS_GET_HASHCODE
) {
6424 sp
[-1].data
.i
= mono_object_hash_internal (sp
[-1].data
.o
);
6428 MINT_IN_CASE(MINT_INTRINS_GET_TYPE
) {
6429 NULL_CHECK (sp
[-1].data
.p
);
6430 sp
[-1].data
.o
= (MonoObject
*) sp
[-1].data
.o
->vtable
->type
;
6436 g_error ("Unimplemented opcode: %04x %s at 0x%x\n", *ip
, mono_interp_opname
[*ip
], ip
-imethod
->code
);
6440 g_assert_not_reached ();
6443 error_init_reuse (error
);
6445 if (clause_args
&& clause_args
->base_frame
)
6446 memcpy (clause_args
->base_frame
->args
, frame
->args
, imethod
->alloca_size
);
6448 if (!frame
->ex
&& MONO_PROFILER_ENABLED (method_leave
) &&
6449 imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_LEAVE
) {
6450 MonoProfilerCallContext
*prof_ctx
= NULL
;
6452 if (imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_LEAVE_CONTEXT
) {
6453 prof_ctx
= g_new0 (MonoProfilerCallContext
, 1);
6454 prof_ctx
->interp_frame
= frame
;
6455 prof_ctx
->method
= imethod
->method
;
6457 MonoType
*rtype
= mono_method_signature_internal (imethod
->method
)->ret
;
6459 switch (rtype
->type
) {
6460 case MONO_TYPE_VOID
:
6462 case MONO_TYPE_VALUETYPE
:
6463 prof_ctx
->return_value
= frame
->retval
->data
.p
;
6466 prof_ctx
->return_value
= frame
->retval
;
6471 MONO_PROFILER_RAISE (method_leave
, (imethod
->method
, prof_ctx
));
6474 } else if (frame
->ex
&& imethod
->prof_flags
& MONO_PROFILER_CALL_INSTRUMENTATION_EXCEPTION_LEAVE
)
6475 MONO_PROFILER_RAISE (method_exception_leave
, (imethod
->method
, &frame
->ex
->object
));
6481 interp_parse_options (const char *options
)
6488 args
= g_strsplit (options
, ",", -1);
6489 for (ptr
= args
; ptr
&& *ptr
; ptr
++) {
6492 if (strncmp (arg
, "jit=", 4) == 0)
6493 mono_interp_jit_classes
= g_slist_prepend (mono_interp_jit_classes
, arg
+ 4);
6494 if (strncmp (arg
, "interp-only=", 4) == 0)
6495 mono_interp_only_classes
= g_slist_prepend (mono_interp_only_classes
, arg
+ strlen ("interp-only="));
6496 if (strncmp (arg
, "-inline", 7) == 0)
6497 mono_interp_opt
&= ~INTERP_OPT_INLINE
;
6502 * interp_set_resume_state:
6504 * Set the state the interpeter will continue to execute from after execution returns to the interpreter.
6507 interp_set_resume_state (MonoJitTlsData
*jit_tls
, MonoException
*ex
, MonoJitExceptionInfo
*ei
, MonoInterpFrameHandle interp_frame
, gpointer handler_ip
)
6509 ThreadContext
*context
;
6512 context
= (ThreadContext
*)jit_tls
->interp_context
;
6515 context
->has_resume_state
= TRUE
;
6516 context
->handler_frame
= (InterpFrame
*)interp_frame
;
6517 context
->handler_ei
= ei
;
6518 /* This is on the stack, so it doesn't need a wbarrier */
6519 context
->handler_frame
->ex
= ex
;
6522 *(MonoException
**)(context
->handler_frame
->locals
+ ei
->exvar_offset
) = ex
;
6523 context
->handler_ip
= (guint16
*) handler_ip
;
6527 interp_get_resume_state (const MonoJitTlsData
*jit_tls
, gboolean
*has_resume_state
, MonoInterpFrameHandle
*interp_frame
, gpointer
*handler_ip
)
6530 ThreadContext
*context
= (ThreadContext
*)jit_tls
->interp_context
;
6532 *has_resume_state
= context
->has_resume_state
;
6533 if (context
->has_resume_state
) {
6534 *interp_frame
= context
->handler_frame
;
6535 *handler_ip
= context
->handler_ip
;
6540 * interp_run_finally:
6542 * Run the finally clause identified by CLAUSE_INDEX in the intepreter frame given by
6543 * frame->interp_frame.
6544 * Return TRUE if the finally clause threw an exception.
6547 interp_run_finally (StackFrameInfo
*frame
, int clause_index
, gpointer handler_ip
, gpointer handler_ip_end
)
6549 InterpFrame
*iframe
= (InterpFrame
*)frame
->interp_frame
;
6550 ThreadContext
*context
= get_context ();
6551 const unsigned short *old_ip
= iframe
->ip
;
6552 FrameClauseArgs clause_args
;
6554 memset (&clause_args
, 0, sizeof (FrameClauseArgs
));
6555 clause_args
.start_with_ip
= (guint16
*) handler_ip
;
6556 clause_args
.end_at_ip
= (guint16
*) handler_ip_end
;
6557 clause_args
.exit_clause
= clause_index
;
6560 interp_exec_method_full (iframe
, context
, &clause_args
, error
);
6561 if (context
->has_resume_state
) {
6564 iframe
->ip
= old_ip
;
6570 * interp_run_filter:
6572 * Run the filter clause identified by CLAUSE_INDEX in the intepreter frame given by
6573 * frame->interp_frame.
6576 interp_run_filter (StackFrameInfo
*frame
, MonoException
*ex
, int clause_index
, gpointer handler_ip
, gpointer handler_ip_end
)
6578 InterpFrame
*iframe
= (InterpFrame
*)frame
->interp_frame
;
6579 ThreadContext
*context
= get_context ();
6580 InterpFrame child_frame
;
6582 FrameClauseArgs clause_args
;
6585 * Have to run the clause in a new frame which is a copy of IFRAME, since
6586 * during debugging, there are two copies of the frame on the stack.
6588 memset (&child_frame
, 0, sizeof (InterpFrame
));
6589 child_frame
.imethod
= iframe
->imethod
;
6590 child_frame
.retval
= &retval
;
6591 child_frame
.parent
= iframe
;
6592 child_frame
.stack_args
= iframe
->stack_args
;
6594 memset (&clause_args
, 0, sizeof (FrameClauseArgs
));
6595 clause_args
.start_with_ip
= (guint16
*) handler_ip
;
6596 clause_args
.end_at_ip
= (guint16
*) handler_ip_end
;
6597 clause_args
.filter_exception
= ex
;
6598 clause_args
.base_frame
= iframe
;
6601 interp_exec_method_full (&child_frame
, context
, &clause_args
, error
);
6602 /* ENDFILTER stores the result into child_frame->retval */
6603 return child_frame
.retval
->data
.i
? TRUE
: FALSE
;
6607 InterpFrame
*current
;
6611 * interp_frame_iter_init:
6613 * Initialize an iterator for iterating through interpreted frames.
6616 interp_frame_iter_init (MonoInterpStackIter
*iter
, gpointer interp_exit_data
)
6618 StackIter
*stack_iter
= (StackIter
*)iter
;
6620 stack_iter
->current
= (InterpFrame
*)interp_exit_data
;
6624 * interp_frame_iter_next:
6626 * Fill out FRAME with date for the next interpreter frame.
6629 interp_frame_iter_next (MonoInterpStackIter
*iter
, StackFrameInfo
*frame
)
6631 StackIter
*stack_iter
= (StackIter
*)iter
;
6632 InterpFrame
*iframe
= stack_iter
->current
;
6634 memset (frame
, 0, sizeof (StackFrameInfo
));
6635 /* pinvoke frames doesn't have imethod set */
6636 while (iframe
&& !(iframe
->imethod
&& iframe
->imethod
->code
&& iframe
->imethod
->jinfo
))
6637 iframe
= iframe
->parent
;
6641 MonoMethod
*method
= iframe
->imethod
->method
;
6642 frame
->domain
= iframe
->imethod
->domain
;
6643 frame
->interp_frame
= iframe
;
6644 frame
->method
= method
;
6645 frame
->actual_method
= method
;
6646 if (method
&& ((method
->flags
& METHOD_ATTRIBUTE_PINVOKE_IMPL
) || (method
->iflags
& (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL
| METHOD_IMPL_ATTRIBUTE_RUNTIME
)))) {
6647 frame
->native_offset
= -1;
6648 frame
->type
= FRAME_TYPE_MANAGED_TO_NATIVE
;
6650 frame
->type
= FRAME_TYPE_INTERP
;
6651 /* This is the offset in the interpreter IR */
6652 frame
->native_offset
= (guint8
*)iframe
->ip
- (guint8
*)iframe
->imethod
->code
;
6653 if (!method
->wrapper_type
|| method
->wrapper_type
== MONO_WRAPPER_DYNAMIC_METHOD
)
6654 frame
->managed
= TRUE
;
6656 frame
->ji
= iframe
->imethod
->jinfo
;
6657 frame
->frame_addr
= iframe
;
6659 stack_iter
->current
= iframe
->parent
;
6665 interp_find_jit_info (MonoDomain
*domain
, MonoMethod
*method
)
6667 InterpMethod
* imethod
;
6669 imethod
= lookup_imethod (domain
, method
);
6671 return imethod
->jinfo
;
6677 interp_set_breakpoint (MonoJitInfo
*jinfo
, gpointer ip
)
6679 guint16
*code
= (guint16
*)ip
;
6680 g_assert (*code
== MINT_SDB_SEQ_POINT
);
6681 *code
= MINT_SDB_BREAKPOINT
;
6685 interp_clear_breakpoint (MonoJitInfo
*jinfo
, gpointer ip
)
6687 guint16
*code
= (guint16
*)ip
;
6688 g_assert (*code
== MINT_SDB_BREAKPOINT
);
6689 *code
= MINT_SDB_SEQ_POINT
;
6693 interp_frame_get_jit_info (MonoInterpFrameHandle frame
)
6695 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6697 g_assert (iframe
->imethod
);
6698 return iframe
->imethod
->jinfo
;
6702 interp_frame_get_ip (MonoInterpFrameHandle frame
)
6704 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6706 g_assert (iframe
->imethod
);
6707 return (gpointer
)iframe
->ip
;
6711 interp_frame_get_arg (MonoInterpFrameHandle frame
, int pos
)
6713 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6714 MonoMethodSignature
*sig
;
6716 g_assert (iframe
->imethod
);
6718 sig
= mono_method_signature_internal (iframe
->imethod
->method
);
6719 return stackval_to_data_addr (sig
->params
[pos
], &iframe
->stack_args
[pos
+ !!iframe
->imethod
->hasthis
]);
6723 interp_frame_get_local (MonoInterpFrameHandle frame
, int pos
)
6725 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6727 g_assert (iframe
->imethod
);
6729 return iframe
->locals
+ iframe
->imethod
->local_offsets
[pos
];
6733 interp_frame_get_this (MonoInterpFrameHandle frame
)
6735 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6737 g_assert (iframe
->imethod
);
6738 g_assert (iframe
->imethod
->hasthis
);
6739 return &iframe
->stack_args
[0].data
.p
;
6742 static MonoInterpFrameHandle
6743 interp_frame_get_parent (MonoInterpFrameHandle frame
)
6745 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6747 return iframe
->parent
;
6751 interp_frame_get_res (MonoInterpFrameHandle frame
)
6753 InterpFrame
*iframe
= (InterpFrame
*)frame
;
6754 MonoMethodSignature
*sig
;
6756 g_assert (iframe
->imethod
);
6757 sig
= mono_method_signature_internal (iframe
->imethod
->method
);
6758 if (sig
->ret
->type
== MONO_TYPE_VOID
)
6761 return stackval_to_data_addr (sig
->ret
, iframe
->retval
);
6765 interp_start_single_stepping (void)
6771 interp_stop_single_stepping (void)
6777 register_interp_stats (void)
6779 mono_counters_init ();
6780 mono_counters_register ("Total transform time", MONO_COUNTER_INTERP
| MONO_COUNTER_LONG
| MONO_COUNTER_TIME
, &mono_interp_stats
.transform_time
);
6781 mono_counters_register ("Methods inlined", MONO_COUNTER_INTERP
| MONO_COUNTER_INT
, &mono_interp_stats
.inlined_methods
);
6782 mono_counters_register ("Inline failures", MONO_COUNTER_INTERP
| MONO_COUNTER_INT
, &mono_interp_stats
.inline_failures
);
6785 #undef MONO_EE_CALLBACK
6786 #define MONO_EE_CALLBACK(ret, name, sig) interp_ ## name,
6788 static const MonoEECallbacks mono_interp_callbacks
= {
6793 mono_ee_interp_init (const char *opts
)
6795 g_assert (mono_ee_api_version () == MONO_EE_API_VERSION
);
6796 g_assert (!interp_init_done
);
6797 interp_init_done
= TRUE
;
6799 mono_native_tls_alloc (&thread_context_id
, NULL
);
6802 interp_parse_options (opts
);
6803 if (mini_get_debug_options ()->mdb_optimizations
)
6804 mono_interp_opt
&= ~INTERP_OPT_INLINE
;
6805 mono_interp_transform_init ();
6807 mini_install_interp_callbacks (&mono_interp_callbacks
);
6809 register_interp_stats ();