Skip to content

Commit

Permalink
[jit] Implement the delegate ctor optimization in AOT mode too.
Browse files Browse the repository at this point in the history
  • Loading branch information
vargaz committed Dec 10, 2013
1 parent a07c846 commit c1908d7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4863,6 +4863,7 @@ encode_patch (MonoAotCompile *acfg, MonoJumpInfo *patch_info, guint8 *buf, guint
case MONO_PATCH_INFO_METHOD_JUMP:
case MONO_PATCH_INFO_ICALL_ADDR:
case MONO_PATCH_INFO_METHOD_RGCTX:
case MONO_PATCH_INFO_METHOD_CODE_SLOT:
encode_method_ref (acfg, patch_info->data.method, p, &p);
break;
case MONO_PATCH_INFO_INTERNAL_METHOD:
Expand Down Expand Up @@ -6357,7 +6358,8 @@ can_encode_patch (MonoAotCompile *acfg, MonoJumpInfo *patch_info)
{
switch (patch_info->type) {
case MONO_PATCH_INFO_METHOD:
case MONO_PATCH_INFO_METHODCONST: {
case MONO_PATCH_INFO_METHODCONST:
case MONO_PATCH_INFO_METHOD_CODE_SLOT: {
MonoMethod *method = patch_info->data.method;

return can_encode_method (acfg, method);
Expand Down
3 changes: 2 additions & 1 deletion mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2948,7 +2948,8 @@ decode_patch (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji, guin
case MONO_PATCH_INFO_METHOD:
case MONO_PATCH_INFO_METHOD_JUMP:
case MONO_PATCH_INFO_ICALL_ADDR:
case MONO_PATCH_INFO_METHOD_RGCTX: {
case MONO_PATCH_INFO_METHOD_RGCTX:
case MONO_PATCH_INFO_METHOD_CODE_SLOT: {
MethodRef ref;
gboolean res;

Expand Down
7 changes: 5 additions & 2 deletions mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4411,7 +4411,7 @@ handle_delegate_ctor (MonoCompile *cfg, MonoClass *klass, MonoInst *target, Mono
* in mono_delegate_trampoline (), we allocate a per-domain memory slot to
* store it, and we fill it after the method has been compiled.
*/
if (!cfg->compile_aot && !method->dynamic && !(cfg->opt & MONO_OPT_SHARED)) {
if (!method->dynamic && !(cfg->opt & MONO_OPT_SHARED)) {
MonoInst *code_slot_ins;

if (context_used) {
Expand All @@ -4428,7 +4428,10 @@ handle_delegate_ctor (MonoCompile *cfg, MonoClass *klass, MonoInst *target, Mono
}
mono_domain_unlock (domain);

EMIT_NEW_PCONST (cfg, code_slot_ins, code_slot);
if (cfg->compile_aot)
EMIT_NEW_AOTCONST (cfg, code_slot_ins, MONO_PATCH_INFO_METHOD_CODE_SLOT, method);
else
EMIT_NEW_PCONST (cfg, code_slot_ins, code_slot);
}
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, obj->dreg, G_STRUCT_OFFSET (MonoDelegate, method_code), code_slot_ins->dreg);
}
Expand Down
16 changes: 16 additions & 0 deletions mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,7 @@ mono_patch_info_hash (gconstpointer data)
case MONO_PATCH_INFO_DELEGATE_TRAMPOLINE:
case MONO_PATCH_INFO_SIGNATURE:
case MONO_PATCH_INFO_TLS_OFFSET:
case MONO_PATCH_INFO_METHOD_CODE_SLOT:
return (ji->type << 8) | (gssize)ji->data.target;
case MONO_PATCH_INFO_GSHAREDVT_CALL:
return (ji->type << 8) | (gssize)ji->data.gsharedvt->method;
Expand Down Expand Up @@ -3317,6 +3318,21 @@ mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code,
}
#endif
break;
case MONO_PATCH_INFO_METHOD_CODE_SLOT: {
gpointer code_slot;

mono_domain_lock (domain);
if (!domain_jit_info (domain)->method_code_hash)
domain_jit_info (domain)->method_code_hash = g_hash_table_new (NULL, NULL);
code_slot = g_hash_table_lookup (domain_jit_info (domain)->method_code_hash, patch_info->data.method);
if (!code_slot) {
code_slot = mono_domain_alloc0 (domain, sizeof (gpointer));
g_hash_table_insert (domain_jit_info (domain)->method_code_hash, patch_info->data.method, code_slot);
}
mono_domain_unlock (domain);
target = code_slot;
break;
}
case MONO_PATCH_INFO_SWITCH: {
gpointer *jump_table;
int i;
Expand Down
4 changes: 1 addition & 3 deletions mono/mini/patch-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ PATCH_INFO(GSHAREDVT_METHOD, "gsharedvt_method")
PATCH_INFO(JIT_TLS_ID, "jit_tls_id")
PATCH_INFO(TLS_OFFSET, "tls_offset")
PATCH_INFO(OBJC_SELECTOR_REF, "objc_selector_ref")
PATCH_INFO(METHOD_CODE_SLOT, "method_code_slot")
PATCH_INFO(NONE, "none")



0 comments on commit c1908d7

Please sign in to comment.