Repository navigation
Description
Generic patching is something that was never supported officially; and if it works at all, it's mostly an "it happens to work situation". I think implementing proper support is viable (though there are some open questions). With this issue I want to share the overall basic ideas I've had and the missing pieces. What I share here does have a working proof of concept that sits at about 1.6k lines; but it's exactly that: a proof of concept.
Issues that either already have open issues or are mostly an implementation and not a design question
- Shared generic methods can't be detoured to on Mono; Mono Abi improvements #363
- Proper compilation of shared generic methods, probably Fix JIT compilation for methods on generic types #298
- Slightly related: Proper modeling of some open issues in x86 Mono Abi (return buffer ._.); Fix mono x86 struct returns #368
Open Issues
I think there are mostly 3 large open problems.
- Dispatch for shared generics
- Open Generics detours and its API
- Discovery of instantiations
Dispatch for shared generics
- For Fx and CoreCLR I think this is mostly just an implementation question. As far as I can tell all of this can happen directly in the managed domain; so we'd basically have a "hub" hook which handles dispatch.
- For Mono, we'll need a native/asm stub(s), since RGCTX.
I think using a dispatcher is the proper choice here and its only a question of how to implement it; but I might be missing something.
Open Generic Detours
- Allow only closed instantiation through the existing Hook APIs and introduce a new GenericHook, which does take open generics
- Insert explanation; maybe open issues/limits if they exist; short and pregnant
Discovery of instantiations (only an issue for unshared or partial shared ones)
- Instantiations after the fact:
- CoreCLR already has the JIT hook
- Fx needs a clrjit hook
- Mono needs profiler jit_done wiring
Those are what I think is the best way. At least I think that's the only way; though we might need to make sure there are no issues with e.g. using a mono profiler API?
- Instantiations before the fact:
- For a proof of concept (and maybe a first implementation), just telling people to manually hook the missed instantiations is good enough
- Dream would probably be to use CodeVersioning were possible to discover all existing instantiations at hook time
Runtime Async
I haven't looked at runtime async with regards to generic and I also think this should be adressed only after all other parts are done.
#187 is also an issue about generics; but it's more scoped and I wanted to open this one for possible design decissions.
Activity