Reduce race-related stack overflows, and handled invalid layouts in ClassSlotAccessNode #244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If multiple threads mutate objects from the same class, it can happen that the object layout gets invalidated by another thread while we try to access it.
In the worst case, this can lead to stack overflows, because our interpreter tries repeatedly to find a valid object layout while creating dispatch chains, or interacting with the object layout in other nodes, which use recursive fallbacks.
A bad case I saw during debugging was that class loading occurred while initializing a new object layout. This delayed the availability of a valid layout long enough to see stack overflows.
To reduce the chance of this happening, I added a busy loop to wait that our lookup getLayoutForInstancesToUpdateObject() actually returns a valid layout. It might still be invalidate before use again, but hopefully this happens now less often, and prevents stack overflows.
This is likely related to #85
@daumayr probably relevant for you, you might still have seen such races in your benchmarks
This change introduces a busy loop, for which we might want to add
Thread.onSpinWait()
once we can use JDK 9.