41
41
42
42
public class RubyThread extends RubyDynamicObject implements ObjectGraphNode {
43
43
44
- // All fields are explicitly initialized in the constructor to make the ordering clear
45
- public final ThreadLocalGlobals threadLocalGlobals ;
46
- public volatile InterruptMode interruptMode ;
47
- public volatile ThreadStatus status ;
48
- public final List <Lock > ownedLocks ;
44
+ // Fields initialized here are initialized just after the super() call, and before the rest of the constructor
45
+ public final ThreadLocalGlobals threadLocalGlobals = new ThreadLocalGlobals () ;
46
+ public volatile InterruptMode interruptMode = InterruptMode . IMMEDIATE ;
47
+ public volatile ThreadStatus status = ThreadStatus . RUN ;
48
+ public final List <Lock > ownedLocks = new ArrayList <>() ;
49
49
public final FiberManager fiberManager ;
50
- CountDownLatch finishedLatch ;
50
+ CountDownLatch finishedLatch = new CountDownLatch ( 1 ) ;
51
51
final RubyHash threadLocalVariables ;
52
52
final RubyHash recursiveObjects ;
53
53
final RubyHash recursiveObjectsSingle ;
54
54
final RubyRandomizer randomizer ;
55
- public final TracePointState tracePointState ;
55
+ public final TracePointState tracePointState = new TracePointState () ;
56
56
boolean reportOnException ;
57
57
boolean abortOnException ;
58
- public volatile Thread thread ;
59
- volatile RubyException exception ;
60
- volatile Object value ;
61
- public final AtomicBoolean wakeUp ;
62
- volatile int priority ;
63
- public ThreadLocalBuffer ioBuffer ;
64
- public final Queue <SafepointAction > pendingSafepointActions ;
58
+ public volatile Thread thread = null ;
59
+ volatile RubyException exception = null ;
60
+ volatile Object value = null ;
61
+ public final AtomicBoolean wakeUp = new AtomicBoolean (false );
62
+ volatile int priority = Thread .NORM_PRIORITY ;
63
+ public ThreadLocalBuffer ioBuffer = ThreadLocalBuffer .NULL_BUFFER ;
64
+ // Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
65
+ public final Queue <SafepointAction > pendingSafepointActions = newLinkedBlockingQueue ();
65
66
Object threadGroup ;
66
67
String sourceLocation ;
67
- Object name ;
68
+ Object name = Nil . INSTANCE ;
68
69
69
70
public RubyThread (
70
71
RubyClass rubyClass ,
@@ -76,33 +77,16 @@ public RubyThread(
76
77
Object threadGroup ,
77
78
String sourceLocation ) {
78
79
super (rubyClass , shape );
79
- this .threadLocalGlobals = new ThreadLocalGlobals ();
80
- this .interruptMode = InterruptMode .IMMEDIATE ;
81
- this .status = ThreadStatus .RUN ;
82
- this .ownedLocks = new ArrayList <>();
83
- this .finishedLatch = new CountDownLatch (1 );
84
80
this .threadLocalVariables = HashOperations .newEmptyHash (context , language );
85
81
this .recursiveObjects = HashOperations .newEmptyHash (context , language );
86
82
this .recursiveObjectsSingle = HashOperations .newEmptyHash (context , language );
87
83
this .recursiveObjectsSingle .compareByIdentity = true ;
88
- this .randomizer = RandomizerNodes .newRandomizer (
89
- context ,
90
- language ,
91
- false ); // This random instance is only for this thread and thus does not need to be thread-safe
92
- this .tracePointState = new TracePointState ();
84
+ // This random instance is only for this thread and thus does not need to be thread-safe
85
+ this .randomizer = RandomizerNodes .newRandomizer (context , language , false );
93
86
this .reportOnException = reportOnException ;
94
87
this .abortOnException = abortOnException ;
95
- this .thread = null ;
96
- this .exception = null ;
97
- this .value = null ;
98
- this .wakeUp = new AtomicBoolean (false );
99
- this .priority = Thread .NORM_PRIORITY ;
100
- this .ioBuffer = ThreadLocalBuffer .NULL_BUFFER ;
101
- // Needs to be a thread-safe queue because multiple Fibers of the same Thread might enqueue concurrently
102
- this .pendingSafepointActions = newLinkedBlockingQueue ();
103
88
this .threadGroup = threadGroup ;
104
89
this .sourceLocation = sourceLocation ;
105
- this .name = Nil .INSTANCE ;
106
90
// Initialized last as it captures `this`
107
91
this .fiberManager = new FiberManager (language , context , this );
108
92
}
0 commit comments