Disable Graal language cache#5614
Conversation
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
|
Companion PR created: openhab/openhab-addons#20810 Neither of these will make much sense without the other. |
|
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
|
Looking at the addon PR, do I get it right that the test did not show a difference in behaviour? It kept working, but a reload was still necessary. |
That's my interpretation, but I'm not sure what causes the problem. It does solve one problem though, so it doesn't necessarily mean that this shouldn't be done: In Eclipse, this allows running both JS and Python at once - without it, that only occasionally works. I doubt that this only applies when running Eclipse, my interpretation is that this solves one problem, but that there are probably others involved as well. edit: From the little I peeked in the Graal code, they keep a map of "static caches". So, there are others in there than just the language cache. My guess is that, while this solves the language cache problem, there are others among the static caches that cause similar problems. |
Reading this again, I'm not sure that it's fully accurate. There is a difference in behavior, I can run both Graal engines on Windows with these two fixes, I can't without it. But, the exact test done with the KAR files still failed. I'm not sure exactly what is what in that situation. So, my stance is that unless this causes additional problems, it's a good thing to do. It will make the initialization less time sensitive. |
This change has been explained in greater detail in a forum post. The gist of it is that Graal has a static cache over installed languages that is frozen the first time it's retrieved. No changes after that point is registered, which is incompatible with OH's dynamic behavior of adding and removing add-ons, starting and stopping bundles etc. The fact that the cache is static also means that its lifetime is that of the JVM itself, nothing other than restarting the JVM will make it refresh. It also creates a race condition between Graal based add-ons where "the late one" might register too late to be cached, and thus "exist".
Unfortunately, just disabling the cache isn't enough, because what can be retrieved when the cache is off seems "unstable", not thread-safe and classloader dependent. I've therefor made some alterations to the JS and Python add-ons that must be considered in combination with this PR.
I also with for the combination to be tested. I use neither language myself, so I don't really know how to thoroughly test that there are no side effects from doing this. I will reference the add-ons PR when it has been created.