Last active
March 22, 2023 13:30
-
-
Save lambdageek/e9659812a32a06b70704b358664d3fe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct _MonoDelegateCodeCache | |
{ | |
gpointer method_ptr; | |
gpointer invoke_impl; | |
} MonoDelegateCodeCache; | |
typedef struct _MonoDelegate { | |
... | |
MonoDelegateCodeCache *cache; // initially NULL | |
MonoDelegateCodeCache _priv_dont_access_cache; // inline struct | |
} MonoDelegate; | |
void | |
mono_delegate_trampoline (...) | |
{ | |
// start writing to del->_priv_dont_access cache | |
MonoDelegateCodeCache *cache = &del->_priv_dont_access_cache; | |
... | |
cache->method_ptr = ... | |
cache->invoke_impl = ... | |
mono_write_barrier(); | |
// publish by setting del->cache to a non-NULL value | |
del->cache = cache; | |
} | |
gpointer | |
get_delegate_invoke_impl (...) | |
{ | |
... | |
load_indirect(code, cache_reg, del, MONO_STRUCT_OFFSET (MonoDelegate, cache)); | |
// address dependency between del->cache and del->cache->code_ptr, no read barrier needed | |
load_indirect(code, code_reg, cache_reg, MONO_STRUCT_OFFSET (MonoDelegateCodeCache, code_ptr)); | |
branch_and_link(code, code_reg); | |
... | |
return code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment