This repository was archived by the owner on Sep 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
src/main/scala/scala/tools/partest/nest Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments