-
Notifications
You must be signed in to change notification settings - Fork 336
Reduce locking in HostClassLoader #13807
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
base: develop
Are you sure you want to change the base?
Conversation
Using a neat trick described in #13219 (comment) to avoid large synchronization blocks.
Akirathan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like something that could (should) be unit tested:
- Create an isolated
HostClassLoaderin the unit test - Point it to some arbitrary jar archives / directories with classes
- Scan from classpath system property, pass via sbt, ...
- Spawn multiple threads that will try to load same classes in parallel.
Or alternatively, move the scheduling/synchronization logic outside HostClassLoader and test it in isolation.
Let's try hard to ensure that we do not introduce hard-to-debug race conditions.
|
Hubert Plociniczak reports a new STANDUP for the provided date (2025-08-19): Progress: Addressing some comments #13781, improving locking in HostClassLoader in #13807. Added draft of caching of all arguments (#13813) which appears to have improved startup but will need more testing. It should be finished by 2025-08-19. Next Day: Next day I will be working on the #10525 task. Pick up work on reactive caches |
|
Well, that wasn't a clean merge. Looks like tests got stuck :/ |
If loading a classes would fail, then the result would not be properly reported to the underlying future. As a result `future.get()` would get stuck waiting infinitely. This has happenned surprisingly a lot with nested classes, as a retry mechanism is in place for replacing `.` with `$` in class name. Also tests would hang infinitely.
|
@JaroslavTulach checking if you are still OK with changes as I had to do a small modification and some time has passed. |
In theory, I agree. In practice this PR has been sitting delayed by that for a while as I didn't have an opportunity to do the refactoring. After a recent merge with develop our test suite has revealed some problems which are now fixed. I would argue we have sufficient enough coverage as-is for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think the spirit of the change is still OK even after 4b8d305
Let's try hard to ensure that we do not introduce hard-to-debug race conditions.
- all the hard synchronization is left on
ConcurrentHashMapandFuture- e.g. I am not afraid of race conditions, but deadlocks could appear...
- but there is one thing we should test:
- have two classes that depend on each other (referencing a static field of the other for example)
- block when one thread is about to load the first class and another thread is about to load the other class
- let the threads continue and see if they finish
- if the test passes then this change is likely correct
engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/HostClassLoader.java
Show resolved
Hide resolved
engine/runtime-language-epb/src/main/java/org/enso/interpreter/epb/HostClassLoader.java
Show resolved
Hide resolved
Added a test with mutual dependency between two classes. The test also uses two threads to evaluate two code examples. The setup should create sufficient race conditions. If the test fails at any point, then we know that our logic is at fault.
Fair enough. Added a test that should in theory create such a race condition. |
|
|
Anyway, I'm leaning towards reverting your changes, as discussed offline. |
|
Pull Request Description
Using a neat trick described in #13219 (comment) to avoid large synchronization blocks.
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.