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

Cleanups to new partest mode #100

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/scala/scala/tools/partest/nest/NestUI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class NestUI(val verbose: Boolean = false, val debug: Boolean = false, val terse
}

val color = new Colors(colorEnabled)
private val realSysErr = System.err
import color._

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

def verbose(msg: String): Unit =
if (verbose) System.err.println(msg)
if (verbose) realSysErr.println(msg)

def debug(msg: String): Unit =
if (debug) System.err.println(msg)
if (debug) realSysErr.println(msg)

def showAllJVMInfo(): Unit = {
vlog(vmArgString)
vlog(allPropertiesString)
}

def vlog(msg: => String) = if (verbose) System.err.println(msg)
def vlog(msg: => String) = if (verbose) realSysErr.println(msg)
}
3 changes: 3 additions & 0 deletions src/main/scala/scala/tools/partest/nest/StreamCapture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ object StreamCapture {
val modified = new java.util.Properties()
modified.putAll(saved)
extra.foreach { case (k, v) => modified.setProperty(k, v) }
// Trying to avoid other threads seeing the new properties object prior to the new entries
// https://github.com/scala/scala/pull/6391#issuecomment-371346171
UnsafeAccess.U.storeFence()
System.setProperties(modified)
try {
action
Expand Down
30 changes: 30 additions & 0 deletions src/main/scala/scala/tools/partest/nest/UnsafeAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package scala.tools.partest.nest;

import java.lang.reflect.Field;

@SuppressWarnings("unsafe")
public class UnsafeAccess {
public final static sun.misc.Unsafe U;

static {
U = lookupUnsafe();
}

private static sun.misc.Unsafe lookupUnsafe() {
try {
sun.misc.Unsafe found = null;
for (Field field : sun.misc.Unsafe.class.getDeclaredFields()) {
if (field.getType() == sun.misc.Unsafe.class) {
field.setAccessible(true);
found = (sun.misc.Unsafe) field.get(null);
break;
}
}
if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe");
else return found;
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}
}