Skip to content

Commit

Permalink
Ensure compilation is run with a compilation lock
Browse files Browse the repository at this point in the history
Evaluating visualization expression may trigger a full compilation.
A change in #7042 went a bit too far and led to a situation when there
could be compilations running at the same time leading to a rather
obscure `RedefinedMethodException` when the compilation on one thread
already finished. This will make the logic correct again at the price of
potentially slowing the processing of visualization.
  • Loading branch information
hubertp committed Nov 27, 2023
1 parent ec5c60b commit 9352be8
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class UpsertVisualizationJob(
implicit val logger: TruffleLogger = ctx.executionService.getLogger
val lockTimestamp =
ctx.locking.acquireContextLock(config.executionContextId)
val writeLockTimestamp = ctx.locking.acquireWriteCompilationLock()
try {
val maybeCallable =
UpsertVisualizationJob.evaluateVisualizationExpression(
Expand Down Expand Up @@ -118,6 +119,11 @@ class UpsertVisualizationJob(
}
}
} finally {
ctx.locking.releaseWriteCompilationLock()
logger.log(
Level.FINEST,
s"Kept write compilation lock [UpsertVisualizationJob] for ${System.currentTimeMillis() - writeLockTimestamp} milliseconds"
)
ctx.locking.releaseContextLock(config.executionContextId)
logger.log(
Level.FINEST,
Expand Down Expand Up @@ -319,6 +325,7 @@ object UpsertVisualizationJob {
)

case error =>
error.printStackTrace()
ctx.executionService.getLogger.log(
Level.SEVERE,
"Evaluation of visualization argument [{0}] failed in module [{1}] with [{2}]: {3}",
Expand Down Expand Up @@ -507,16 +514,7 @@ object UpsertVisualizationJob {
callback,
arguments
)
val writeLockTimestamp = ctx.locking.acquireWriteCompilationLock()
try {
invalidateCaches(visualization)
} finally {
ctx.locking.releaseWriteCompilationLock()
logger.log(
Level.FINEST,
s"Kept write compilation lock [UpsertVisualizationJob] for ${System.currentTimeMillis() - writeLockTimestamp} milliseconds"
)
}
invalidateCaches(visualization)
ctx.contextManager.upsertVisualization(
visualizationConfig.executionContextId,
visualization
Expand Down

0 comments on commit 9352be8

Please sign in to comment.