Skip to content

Conversation

@hubertp
Copy link
Collaborator

@hubertp hubertp commented Aug 19, 2025

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:

  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

Using a neat trick described in #13219 (comment)
to avoid large synchronization blocks.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Aug 19, 2025
Copy link
Contributor

@Akirathan Akirathan left a 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 HostClassLoader in 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.

@enso-bot
Copy link

enso-bot bot commented Aug 25, 2025

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

@hubertp
Copy link
Collaborator Author

hubertp commented Jan 20, 2026

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.
@hubertp
Copy link
Collaborator Author

hubertp commented Jan 21, 2026

@JaroslavTulach checking if you are still OK with changes as I had to do a small modification and some time has passed.

@hubertp
Copy link
Collaborator Author

hubertp commented Jan 21, 2026

Let's try hard to ensure that we do not introduce hard-to-debug race conditions.

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 HostClassLoader.

Copy link
Member

@JaroslavTulach JaroslavTulach left a 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 ConcurrentHashMap and Future
    • 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

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.
@hubertp
Copy link
Collaborator Author

hubertp commented Jan 22, 2026

  • but there is one thing we should test:

Fair enough. Added a test that should in theory create such a race condition.

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jan 22, 2026

Added a test that should in theory create such a race condition.

@hubertp
Copy link
Collaborator Author

hubertp commented Jan 23, 2026

I'm not sure the two examples are comparable.
The first fails because context never gets initialized - the usual TruffleSafepoint limitation we've encountered countless number of times:
Ignore that. This appears to only show up when executing an individual test from test class.

   java.lang.Thread.State: WAITING (parking)
        at jdk.internal.misc.Unsafe.park([email protected]/Native Method)
        - parking to wait for  <0x000000028bbbe228> (a com.oracle.truffle.api.impl.ThreadLocalHandshake$Barrier)
        at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:223)
...

Anyway, I'm leaning towards reverting your changes, as discussed offline.
The regular classloader test deadlock is, it seems, working according to the spec. Here is a good thread from SO.

@JaroslavTulach
Copy link
Member

Anyway, I'm leaning towards reverting your changes, as discussed offline.

  • OK, revert is reasonable
  • Simpler way to revert is:
enso$ git checkout -f wip/hubert/hostclassloader-improvements
enso$ git revert 90b880a3ddfa6736602edd36d5d78235b58a6b51
enso$ git push -f
  • but these individual commits will be gone when this PR is squashed, so it doesn't matter

@hubertp hubertp added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants