Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit b44ccb0

Browse files
authored
Merge pull request #100 from retronym/ticket/75-cleanup
Cleanups to new partest mode
2 parents fbeb205 + bb3aeee commit b44ccb0

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/main/scala/scala/tools/partest/nest/NestUI.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class NestUI(val verbose: Boolean = false, val debug: Boolean = false, val terse
3636
}
3737

3838
val color = new Colors(colorEnabled)
39+
private val realSysErr = System.err
3940
import color._
4041

4142
private[this] val (_outline, _success, _failure, _warning, _default) =
@@ -137,15 +138,15 @@ class NestUI(val verbose: Boolean = false, val debug: Boolean = false, val terse
137138
}
138139

139140
def verbose(msg: String): Unit =
140-
if (verbose) System.err.println(msg)
141+
if (verbose) realSysErr.println(msg)
141142

142143
def debug(msg: String): Unit =
143-
if (debug) System.err.println(msg)
144+
if (debug) realSysErr.println(msg)
144145

145146
def showAllJVMInfo(): Unit = {
146147
vlog(vmArgString)
147148
vlog(allPropertiesString)
148149
}
149150

150-
def vlog(msg: => String) = if (verbose) System.err.println(msg)
151+
def vlog(msg: => String) = if (verbose) realSysErr.println(msg)
151152
}

src/main/scala/scala/tools/partest/nest/StreamCapture.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ object StreamCapture {
4343
val modified = new java.util.Properties()
4444
modified.putAll(saved)
4545
extra.foreach { case (k, v) => modified.setProperty(k, v) }
46+
// Trying to avoid other threads seeing the new properties object prior to the new entries
47+
// https://github.com/scala/scala/pull/6391#issuecomment-371346171
48+
UnsafeAccess.U.storeFence()
4649
System.setProperties(modified)
4750
try {
4851
action
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package scala.tools.partest.nest;
2+
3+
import java.lang.reflect.Field;
4+
5+
@SuppressWarnings("unsafe")
6+
public class UnsafeAccess {
7+
public final static sun.misc.Unsafe U;
8+
9+
static {
10+
U = lookupUnsafe();
11+
}
12+
13+
private static sun.misc.Unsafe lookupUnsafe() {
14+
try {
15+
sun.misc.Unsafe found = null;
16+
for (Field field : sun.misc.Unsafe.class.getDeclaredFields()) {
17+
if (field.getType() == sun.misc.Unsafe.class) {
18+
field.setAccessible(true);
19+
found = (sun.misc.Unsafe) field.get(null);
20+
break;
21+
}
22+
}
23+
if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe");
24+
else return found;
25+
} catch (Throwable t) {
26+
throw new ExceptionInInitializerError(t);
27+
}
28+
}
29+
}
30+

0 commit comments

Comments
 (0)