New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: reuse trampolines when possible #1218
Conversation
@dolphin-emu-bot rebuild |
@@ -11,6 +11,19 @@ | |||
// We need at least this many bytes for backpatching. | |||
const int BACKPATCH_SIZE = 5; | |||
|
|||
struct TrampolineCacheKey { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
347b1fa
to
265e608
Compare
Oops. I just noticed |
265e608
to
10d2cad
Compare
I fixed up those problems, and investigated the cause of the excessive back-patching: I think this PR is still a good idea (and should fix the trampoline cache full error). Other changes to the JIT should probably be made to address the underlying problem. edit: wrong link >_> |
Thanks for the investigation, @hthh. Since you have found out that it is not a leak would you please also double the trampoline cache size? This will account for the addition of fastmem-writes on top of fastmem-reads. We can merge this PR after that is done. I do find it a bit strange that the issue does not occur on Windows and that it took over a year for it to be reported, considering that SSBB is one of the most popular games on the Wii. |
@dolphin-emu-bot rebuild |
I can't read the document you linked; could you make it public? |
10d2cad
to
c720831
Compare
Could there be a nicer solution to that FIFO problem -- maybe tracking when an instruction fastmem-faults so that when the block is recompiled, we just disable fastmem for that particular load or store? |
@skidau You're absolutely right, it's a very strange problem, and I don't have any explanation for the Windows/Linux/OS X mysteries. The only thing I'm sure about is that the quadratic rate of trampoline generation is wrong. It's probably worth checking that other people find that this fixes it for them. It might be worth noting that trampolines have grown in size over time (the PC argument was added, which would make each trampoline a bit larger), which might explain why it only started getting noticed recently. Anyway, I've doubled the trampoline cache size and hopefully fixed the Windows build warnings. @FioraAeterna That sounds like a good approach, and would remove the back-patching overhead (in my tests, there are still 20000 redundant segfaults). I'm not sure that would be a complete fix: the bigger a block (of FIFO writes) is, the more times it will be recompiled, which could still cause problems (quadratic compilation time and quadratic code allocations come to mind). I'd like to keep this code because I think it will, generally speaking, prevent redundant trampoline generation. It's definitely not the most complete or most elegant fix. |
I'm going to write up a patch for this and see how well it works |
@hthh that's a very big problem you've discovered. |
JIT: reuse trampolines when possible
In tests, this showed hundreds of cache hits. A huge number of hits were, to my surprise, write trampolines with the same PC. I'm inferring from this that JIT code may be repeatedly invalidated and re-generated.
It seems this could easily lead to a trampoline-memory-leak causing the "Trampoline cache full" issue: https://code.google.com/p/dolphin-emu/issues/detail?id=7661
However, I was unable to reproduce that issue, so I'm not sure if this fixes it or not.