+#endif
+
+/*
+ * mini_get_shared_method:
+ *
+ * Return the method which is actually compiled/registered when doing generic sharing.
+ */
+MonoMethod*
+mini_get_shared_method (MonoMethod *method)
+{
+ MonoGenericContext shared_context;
+ MonoMethod *declaring_method, *res;
+ int i;
+ gboolean partial = FALSE;
+
+ if (method->is_generic || method->klass->generic_container)
+ declaring_method = method;
+ else
+ declaring_method = mono_method_get_declaring_generic_method (method);
+
+ if (declaring_method->is_generic)
+ shared_context = mono_method_get_generic_container (declaring_method)->context;
+ else
+ shared_context = declaring_method->klass->generic_container->context;
+
+ /* Handle partial sharing */
+ if (method != declaring_method && method->is_inflated && !mono_method_is_generic_sharable_impl_full (method, FALSE, FALSE)) {
+ MonoGenericContext *context = mono_method_get_context (method);
+ MonoGenericInst *inst;
+ MonoType **type_argv;
+
+ /*
+ * Create the shared context by replacing the ref type arguments with
+ * type parameters, and keeping the rest.
+ */
+ partial = TRUE;
+ inst = context->class_inst;
+ if (inst) {
+ type_argv = g_new0 (MonoType*, inst->type_argc);
+ for (i = 0; i < inst->type_argc; ++i) {
+ if (MONO_TYPE_IS_REFERENCE (inst->type_argv [i]) || inst->type_argv [i]->type == MONO_TYPE_VAR || inst->type_argv [i]->type == MONO_TYPE_MVAR)
+ type_argv [i] = shared_context.class_inst->type_argv [i];
+ else
+ type_argv [i] = inst->type_argv [i];
+ }
+
+ shared_context.class_inst = mono_metadata_get_generic_inst (inst->type_argc, type_argv);
+ g_free (type_argv);
+ }
+
+ inst = context->method_inst;
+ if (inst) {
+ type_argv = g_new0 (MonoType*, inst->type_argc);
+ for (i = 0; i < inst->type_argc; ++i) {
+ if (MONO_TYPE_IS_REFERENCE (inst->type_argv [i]) || inst->type_argv [i]->type == MONO_TYPE_VAR || inst->type_argv [i]->type == MONO_TYPE_MVAR)
+ type_argv [i] = shared_context.method_inst->type_argv [i];
+ else
+ type_argv [i] = inst->type_argv [i];
+ }
+
+ shared_context.method_inst = mono_metadata_get_generic_inst (inst->type_argc, type_argv);
+ g_free (type_argv);
+ }
+ }
+
+ res = mono_class_inflate_generic_method (declaring_method, &shared_context);
+ if (!partial) {
+ /* The result should be an inflated method whose parent is not inflated */
+ g_assert (!res->klass->is_inflated);
+ }
+ return res;
+}