From 52f46a3e9037d1a2b5e8d636ebbe54f0eb9c6e68 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Wed, 11 Nov 2020 11:35:17 +0100 Subject: [PATCH] Enforce assertions in the native image so that we can remove volatile from some TerminalOutput fields --- client/pom.xml | 1 + .../mvnd/common/logging/TerminalOutput.java | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/client/pom.xml b/client/pom.xml index 49217609..a2cb285f 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -125,6 +125,7 @@ --allow-incomplete-classpath -H:IncludeResources=org/jboss/fuse/mvnd/.* -H:-ParseRuntimeOptions + -ea diff --git a/common/src/main/java/org/jboss/fuse/mvnd/common/logging/TerminalOutput.java b/common/src/main/java/org/jboss/fuse/mvnd/common/logging/TerminalOutput.java index 981d54c0..bfeabf53 100644 --- a/common/src/main/java/org/jboss/fuse/mvnd/common/logging/TerminalOutput.java +++ b/common/src/main/java/org/jboss/fuse/mvnd/common/logging/TerminalOutput.java @@ -71,18 +71,25 @@ public class TerminalOutput implements ClientOutput { /** A sink for sending messages back to the daemon */ private volatile Consumer daemonDispatch; - private volatile String name; - private volatile int totalProjects; - /** String format for formatting the number of projects done with padding based on {@link #totalProjects} */ - private volatile String projectsDoneFomat; - private volatile int maxThreads; - /** String format for formatting the actual/hidden/max thread counts */ - private volatile String threadsFormat; - private int linesPerProject = 0; // read/written only by the displayLoop - private int doneProjects = 0; // read/written only by the displayLoop - private String buildStatus; // read/written only by the displayLoop - private boolean displayDone = false; // read/written only by the displayLoop + /* + * The following non-final fields are read/written from the main thread only. + * This is guaranteed as follows: + * * The read/write ops are only reachable from accept(Message) and accept(List) + * * Both of these methods are guarded with "main".equals(Thread.currentThread().getName()) assertion + * Therefore, these fields do not need to be volatile + */ + private String name; + private int totalProjects; + /** String format for formatting the number of projects done with padding based on {@link #totalProjects} */ + private String projectsDoneFomat; + private int maxThreads; + /** String format for formatting the actual/hidden/max thread counts */ + private String threadsFormat; + private int linesPerProject = 0; + private int doneProjects = 0; + private String buildStatus; + private boolean displayDone = false; /** * {@link Project} is owned by the display loop thread and is accessed only from there. Therefore it does not need