-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCoreRuntimeServices.html
More file actions
2613 lines (2522 loc) · 130 KB
/
Copy pathCoreRuntimeServices.html
File metadata and controls
2613 lines (2522 loc) · 130 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
layout: default
---
<?xml version="1.0" encoding="utf8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head><title>14 Core Runtime Services</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<meta name="generator" content="TeX4ht (https://tug.org/tex4ht/)" />
<meta name="originator" content="TeX4ht (https://tug.org/tex4ht/)" />
<!-- xhtml,charset=utf8,2,html -->
<meta name="src" content="index.tex" />
<link rel="stylesheet" type="text/css" href="index.css" />
</head><body
>
<!--l. 2--><div class="crosslinks"><p class="noindent"></p></div>
<h2 class="chapterHead"><span class="titlemark">Chapter 14</span><br /><a
id="x17-17100014"></a>Core Runtime Services</h2>
<!--l. 5--><p class="noindent" >The Jikes RVM runtime environment implements a variety of services which a Java
application relies upon for correct execution. The services include:
</p>
<ul class="itemize1">
<li class="itemize"><a
href="#x17-17200014.1">Object Model</a>: The way objects are represented in storage.
</li>
<li class="itemize"><a
href="#x17-17600014.2">Class and Code Management</a>: The mechanism for loading, and
representing classes from class files. The mechanism that triggers
compilation and linking of methods and subsequent storage of generated
code.
</li>
<li class="itemize"><a
href="#x17-18500014.3">Thread Management</a>: thread creation, scheduling and
synchronization/exclusion
</li>
<li class="itemize"><a
href="#x17-19000014.4">JNI</a>: Native interface for writing native methods and invoking the virtual
machine from native code.
</li>
<li class="itemize"><a
href="#x17-20300014.7">Calling Conventions</a>: calling conventions used for invoking methods in
Jikes RVM
</li>
<li class="itemize"><a
href="#x17-19700014.5">Exception Management</a>: hardware exception trapping and software
exception delivery.
</li>
<li class="itemize"><a
href="#x17-19800014.6">Bootstrap</a>: getting an initial Java application running in a fully functional
Java execution environment</li></ul>
<!--l. 17--><p class="noindent" >The requirement for many of these runtime services is clearly visible in language
primitives such as <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">new()</span></span></span>, <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">throw()</span></span></span> and in <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">java.lang</span></span></span> and <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">java.io</span></span></span> APIs such as
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">Thread.run()</span></span></span>, <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">System.println()</span></span></span>, <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">File.open()</span></span></span> etc. Unlike conventional Java APIs
which merely modify the state of Java objects created by the Java application,
implementation of these primitives requires interaction with and modification of the
platform (hardware and system software) on which the Java application is being
executed.
</p><!--l. 19--><p class="noindent" >In addition to the services described above, Jikes RVM also provides some services
that are specific to its purpose as a research tool: </p>
<ul class="itemize1">
<li class="itemize"><a
href="#x17-21000014.8">VM Callbacks</a>: Notfications about potentially interesting events in the
VM.</li></ul>
<h3 class="sectionHead"><span class="titlemark">14.1 </span> <a
id="x17-17200014.1"></a>Object Model</h3>
<!--l. 5--><p class="noindent" >An object model dictates how to represent objects in storage; the best object model
will maximize efficiency of frequent language operations while minimizing storage
overhead. Jikes RVM’s object model is defined by ObjectModel.
</p><!--l. 7--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.1.1 </span> <a
id="x17-17300014.1.1"></a>Overview</h4>
<!--l. 9--><p class="noindent" >Values in the Java<span
class="tcrm-1000">™ </span>programming language are either <span
class="cmti-10">primitive </span>(e.g. <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">int</span></span></span>, <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">double</span></span></span>,
etc.) or they are <span
class="cmti-10">references </span>(that is, pointers) to objects. Objects are either <span
class="cmti-10">arrays</span>
having elements or <span
class="cmti-10">scalar </span>objects having fields. Objects are logically composed of two
primary sections: an object header (described in more detail below) and the object’s
instance fields (or array elements).
</p><!--l. 11--><p class="noindent" >The following non-functional requirements govern the Jikes RVM object model:
</p>
<ul class="itemize1">
<li class="itemize">instance field and array accesses should be as fast as possible,
</li>
<li class="itemize">null-pointer checks should be performed by the hardware if possible,
</li>
<li class="itemize">method dispatch and other frequent runtime services should be fast,
</li>
<li class="itemize">other (less frequent) Java operations should not be prohibitively slow, and
</li>
<li class="itemize">per-object storage overhead (ie object header size) should be as small as
possible.</li></ul>
<!--l. 20--><p class="noindent" >Assuming the reference to an object resides in a register, compiled code can access
the object’s fields at a fixed displacement in a single instruction. To facilitate
array access, the reference to an array points to the first (zeroth) element
of an array and the remaining elements are laid out in ascending order.
The number of elements in an array, its <span
class="cmti-10">length</span>, resides just before its first
element. Thus, compiled code can access array elements via base + scaled index
addressing.
</p><!--l. 22--><p class="noindent" >The Java programming language requires that an attempt to access an object
through a null object reference generates a <span
class="cmtt-10">NullPointerException</span>. In Jikes RVM,
references are machine addresses, and <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">null</span></span></span> is represented by address 0. On Linux,
accesses to both very low and very high memory can be trapped by the hardware,
thus all null checks can be made implicit.
</p><!--l. 26--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.1.2 </span> <a
id="x17-17400014.1.2"></a>Object Header</h4>
<!--l. 28--><p class="noindent" >Logically, every object header contains the following components: </p>
<ul class="itemize1">
<li class="itemize">textbfTIB Pointer: The TIB (Type Information Block) holds information
that applies to all objects of a type. The structure of the TIB is defined by
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">TIBLayoutConstants</span></span></span>. A TIB includes the virtual method table, a pointer
to an object representing the type, and pointers to a few data structures
to facilitate efficient interface invocation and dynamic type checking.
</li>
<li class="itemize">textbfHash Code: Each Java object has an identity hash code. This
can be read by <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">Object.hashCode()</span></span></span> or in the case that this method
was overridden, by <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">System.identityHashCode</span></span></span>. The default hash code is
usually the location in memory of the object, however, with some garbage
collectors objects can move. So the hash code remains the same, space in
the object header may be used to hold the original hash code value.
</li>
<li class="itemize">textbfLock: Each Java object has an associated lock state. This could be
a pointer to a lock object or a direct representation of the lock.
</li>
<li class="itemize">textbfArray Length: Every array object provides a length field that
contains the length (number of elements) of the array.
</li>
<li class="itemize">textbfGarbage Collection Information: Each Java object has associated
information used by the memory management system. Usually this
consists of one or two mark bits, but this could also include some
combination of a reference count, forwarding pointer, etc.
</li>
<li class="itemize">textbfMisc Fields: In experimental configurations, the object header can
be expanded to add additional fields to every object, typically to support
profiling.</li></ul>
<!--l. 38--><p class="noindent" >An implementation of this abstract header is defined by two files: </p>
<ul class="itemize1">
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">JavaHeader</span></span></span>, which supports TIB access, default hash codes, and locking.
It also provides a few bits for use by the memory management subsystem.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">MiscHeader</span></span></span>, which supports adding additional fields to all objects.</li></ul>
<!--l. 44--><p class="noindent" >Information that is specific to garbage collection uses the available bits from the Java
header. Depending on the chosen garbage collector, the available bits can be accessed
via an appropriate class, e.g.: </p>
<ul class="itemize1">
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">HeaderByte</span></span></span> which provides access to methods for logging and unlogging
for various collectors
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RCHeader</span></span></span> for reference counting garbage collectors
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">ForwardingWord</span></span></span> which provides methods for object forwarding which is
used by some copying collectors</li></ul>
<!--l. 53--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.1.3 </span> <a
id="x17-17500014.1.3"></a>Field Layout</h4>
<!--l. 55--><p class="noindent" >Fields tend to be recorded in the Java class file in the order they are declared in the
Java source file. We lay out fields in the order they are declared with some exceptions
to improve alignment and pack the fields in the object.
</p><!--l. 57--><p class="noindent" >Fields of type <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">double</span></span></span> and <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">long</span></span></span> benefit from being 8 byte aligned. Every
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMClass</span></span></span> records the preferred alignment of the object as a whole. We lay out
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">double</span></span></span> and <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">long</span></span></span> fields first (and object references if these are 8 bytes long) so
that we can avoid making holes in the field layout for alignment. We don’t
do this for smaller fields as all objects need to be a multiple of 4 bytes in
size.
</p><!--l. 59--><p class="noindent" >When we lay out fields we may create holes to improve alignment. For example, an
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">int</span></span></span> following a <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">byte</span></span></span>, we’ll create a 3 byte hole following the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">byte</span></span></span> to keep the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">int</span></span></span> 4
byte aligned. Holes in the field layout can be 1, 2 or 4 bytes in size. As fields are laid
out, holes are used to avoid increasing the size of the object. Sub-classes inherit the
hole information of their parent, so holes in the parent object can be reused by their
children.
</p><!--l. 2--><p class="noindent" >
</p>
<h3 class="sectionHead"><span class="titlemark">14.2 </span> <a
id="x17-17600014.2"></a>Class and Code Management</h3>
<!--l. 5--><p class="noindent" >The runtime maintains a database of Java instances which identifies the currently
loaded class and method base. The classloader class base enables the runtime to
identify and dynamically load undefined classes as they required during execution.
All the classes, methods and compiled code arrays required to enable the runtime to
operate are pre-installed in the initial boot image. Other runtime classes and
application classes are loaded dynamically as they are needed during execution and
have their methods compiled lazily. The runtime can also identify the latest compiled
code array (and, on occasions, previously generated versions of compiled code) of any
given method via this classbase and recompile it dynamically should it wish to do
so.
</p><!--l. 7--><p class="noindent" >Lazy method compilation postpones compilation of a dynamically loaded class’
methods at load-time, enabling partial loading of the class base to occur. Immediate
compilation of all methods would require loading of all classes mentioned in the
bytecode in order to verify that they were being used correctly. Immediate
compilation of these class’ methods would require yet more loading and so on until
the whole classbase was installed. Lazy compilation delays this recursive
class loading process by postponing compilation of a method until it is first
called.
</p><!--l. 9--><p class="noindent" >Lazy compilation works by generating a stub for each of a class’ methods when the
class is loaded. If the method is an instance method this stub is installed in the
appropriate TIB slot. If the method is static it is placed in a linker table located in
the JTOC (linker table slots are allocated for each static method when a class is
dynamically loaded). When the stub is invoked it calls the compiler to compile the
method for real and then jumps into the relevant code to complete the call. The
compiler ensures that the relevant TIB slot/linker table slot is updated with
the new compiled code array. It also handles any race conditions caused by
concurrent calls to the dummy method code ensuring that only one caller
proceeds with the compilation and other callers wait for the resulting compiled
code.
</p><!--l. 11--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.2.1 </span> <a
id="x17-17700014.2.1"></a>Class Loading</h4>
<!--l. 13--><p class="noindent" >Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM implements the Java<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> programming language’s dynamic class
loading. While a class is being loaded it can be in one of seven states. These are:
</p>
<ul class="itemize1">
<li class="itemize"><span
class="cmbx-10">vacant</span>: The <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMClass</span></span></span> object for this class has been created and registered
and is in the process of being loaded.
</li>
<li class="itemize"><span
class="cmbx-10">loaded</span>: The class’s bytecode file has been read and parsed successfully.
The modifiers and attributes for the fields have been loaded and the
constant pool has been constructed. The class’s superclass (if any) and
superinterfaces have been loaded as well.
</li>
<li class="itemize"><span
class="cmbx-10">resolved</span>: The superclass and superinterfaces of this class has been
resolved. The offsets (whether in the object itself, the JTOC, or the class’s
TIB) of its fields and methods have been calculated.
</li>
<li class="itemize"><span
class="cmbx-10">instantiated</span>: The superclass has been instantiated and pointers to the
compiled methods or lazy compilation stubs have been inserted into the
JTOC (for static methods) and the TIB (for virtual methods).
</li>
<li class="itemize"><span
class="cmbx-10">initializing</span>: The superclass has been initialized and the class initializer
is being run.
</li>
<li class="itemize"><span
class="cmbx-10">initialized</span>: The superclass has been initialized and the class initializer
has been run.
</li>
<li class="itemize"><span
class="cmbx-10">class initializer has failed</span>: There was an exception during execution of
the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10"><clinit></span></span></span> method so the class cannot be initialized successfully.</li></ul>
<!--l. 26--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.2.2 </span> <a
id="x17-17800014.2.2"></a>Code Management</h4>
<!--l. 28--><p class="noindent" >A compiled method body is an array of machine instructions (stored as ints on
PowerPC<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> and bytes on x86-32). The Jikes RVM Table of Contents(JTOC), stores
pointers to static fields and methods. However, pointers for instance fields and
instance methods are stored in the receiver class’s <a
href="#x17-17200014.1">TIB</a>. Consequently, the dispatch
mechanism differs between static methods and instance methods.
</p><!--l. 30--><p class="noindent" >
</p>
<h5 class="subsubsectionHead"><a
id="x17-17900014.2.2"></a>The JTOC</h5>
<!--l. 32--><p class="noindent" >The JTOC holds pointers to each of Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM’s global data structures, as well
as literals, numeric constants and references to String constants. The JTOC
also contains references to the TIB for each class in the system. Since these
structures can have many types and the JTOC is declared to be an array
of ints, Jikes RVM uses a descriptor array, co-indexed with the JTOC, to
identify the entries containing references. The JTOC is depicted in the figure
below.
</p>
<hr class="figure" /><div class="figure"
>
<!--l. 36--><p class="noindent" ><img
src="/UserGuide/images/ClassAndCodeManagement-JTOC.png" alt="PIC"
width="345" height="345" />
</p>
</div><hr class="endfigure" />
<h5 class="subsubsectionHead"><a
id="x17-18000014.2.2"></a>Virtual Methods</h5>
<!--l. 43--><p class="noindent" >A TIB contains pointers to the compiled method bodies (executable code)
for the virtual methods and other instance methods of its class. Thus, the
TIB serves as Jikes RVM’s virtual method table. A virtual method dispatch
entails loading the TIB pointer from the object reference, loading the address
of the method body at a given offset off the TIB pointer, and making an
indirect branch and link to it. A virtual method is dispatched to with the
invokevirtual bytecode; other instance methods are invoked by the invokespecial
bytecode.
</p><!--l. 47--><p class="noindent" >
</p>
<h5 class="subsubsectionHead"><a
id="x17-18100014.2.2"></a>Static Fields and Methods</h5>
<!--l. 49--><p class="noindent" >Static fields and pointers to static method bodies are stored in the JTOC. Static
method dispatch is simpler than virtual dispatch, since a well-known JTOC entry
method holds the address of the compiled method body.
</p><!--l. 53--><p class="noindent" >
</p>
<h5 class="subsubsectionHead"><a
id="x17-18200014.2.2"></a>Instance Initialization Methods</h5>
<!--l. 55--><p class="noindent" >Pointers to the bodies of instance initialization methods, <span class="obeylines-h"><span class="verb"><span
class="cmtt-10"><init></span></span></span>, are stored in the
JTOC. (They are always dispatched to with the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">invokespecial</span></span></span> bytecode.)
</p><!--l. 59--><p class="noindent" >
</p>
<h5 class="subsubsectionHead"><a
id="x17-18300014.2.2"></a>Lazy Method Compilation</h5>
<!--l. 61--><p class="noindent" >Method slots in a TIB or the JTOC may hold either a pointer to the compiled code,
or a pointer to the compiled code of the <span
class="cmti-10">lazy method invocation stub</span>. When invoked,
the lazy method invocation stub compiles the method, installs a pointer to the
compiled code in the appropriate TIB or the JTOC slot, then jumps to the start of
the compiled code.
</p><!--l. 65--><p class="noindent" >
</p>
<h5 class="subsubsectionHead"><a
id="x17-18400014.2.2"></a>Interface Methods</h5>
<!--l. 67--><p class="noindent" >Regardless of whether or not a virtual method is overridden, virtual method dispatch
is still simple since the method will occupy the same TIB offset its defining class and
in every sub-class. However, a method invoked through an <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">invokeinterface</span></span></span> call
rather than an <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">invokevirtual</span></span></span> call, will not occupy the same TIB offset
in every class that implements its interface. This complicates dispatch for
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">invokeinterface</span></span></span>.
</p><!--l. 69--><p class="noindent" >The simplest, and least efficient way, of locating an interface method is to search all
the virtual method entries in the TIB finding a match. Instead, Jikes RVM uses an
<span
class="cmti-10">Interface Method Table (IMT) </span>which resembles a virtual method table for
interface methods. Any method that could be an interface method has a fixed
offset into the IMT just as with the TIB. However, unlike in the TIB, two
different methods may share the same offset into the IMT. In this case, a
<span
class="cmti-10">conflict resolution stub </span>is inserted in the IMT. Conflict resolution stubs are
custom-generated machine code sequences that test the value of a hidden
parameter to dispatch to the desired interface method. For more details, see
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">InterfaceInvocation</span></span></span>.
</p><!--l. 2--><p class="noindent" >
</p>
<h3 class="sectionHead"><span class="titlemark">14.3 </span> <a
id="x17-18500014.3"></a>Thread Management</h3>
<!--l. 5--><p class="noindent" >This section provides some explanation of how Java<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> threads are scheduled and
synchronized by Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM.
</p><!--l. 7--><p class="noindent" >All Java threads (application threads, garbage collector threads, etc.) derive from
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread</span></span></span>. Each <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread</span></span></span> maps directly to one native thread, which may be
implemented using whichever C/C++ threading library is in use (currently
pthreads). Unless <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">-X:availableProcessors</span></span></span> or <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">-X:gc:threads</span></span></span> is used, native
threads are allowed to be arbitrarily scheduled by the OS using whatever
processor resources are available; Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM does not attempt to control the
thread-processor mapping at all.
</p><!--l. 9--><p class="noindent" >Using native threading gives Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM better compatibility for existing JNI
code, as well as improved performance, and greater infrastructure simplicity.
Scheduling is offloaded entirely to the operating system; this is both what
native code would expect and what maximizes the OS scheduler’s ability to
optimally schedule Java<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> threads. As well, the resulting VM infrastructure
is both simpler and more robust, since instead of focusing on scheduling
decisions it can take a ”hands-off” approach except when Java threads have
to be preempted for sampling, on-stack-replacement, garbage collection,
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">Thread.suspend()</span></span></span>, or locking. The main task of <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread</span></span></span> and other code in
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">org.jikesrvm.scheduler</span></span></span> is thus to override OS scheduling decisions when the VM
demands it.
</p><!--l. 11--><p class="noindent" >The remainder of this section is organized as follows. The management of a thread’s
state is discussed in detail. Mechanisms for blocking and handshaking threads are
described. The VM’s internal locking mechanism, the Monitor, is described. Finally,
the locking implementation is discussed.
</p><!--l. 13--><p class="noindent" >
</p>
<h4 class="subsectionHead"><span class="titlemark">14.3.1 </span> <a
id="x17-18600014.3.1"></a>Tracking the Thread State</h4>
<!--l. 15--><p class="noindent" >The state of a thread is broken down into two elements: </p>
<ul class="itemize1">
<li class="itemize">Should the thread yield at a safe point?
</li>
<li class="itemize">Is the thread running Java code right now?</li></ul>
<!--l. 21--><p class="noindent" >The first mechanism is provided by the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread.takeYieldpoint</span></span></span> field, which is <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">0</span></span></span>
if the thread should not yield, or non-zero if it should yield at the next safe point.
Negative versus positive values indicate the type of safe point to yield at
(epilogue/prologue, or any, respectively).
</p><!--l. 23--><p class="noindent" >But this alone is insufficient to manage threads, as it relies on all threads
being able to reach a safe point in a timely fashion. New Java threads may
be started at any time, including at the exact moment that the garbage
collector is starting; a starting-but-not-yet-started thread may not reach a safe
point if the thread that was starting it is already blocked. Java threads may
terminate at any time; terminated threads will never again reach a safe point.
Any Java thread may call into arbitrary JNI code, which is outside of the
VM’s control, and may run for an arbitrary amount of time without reaching
a Java safe point. As well, other mechanisms of <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread</span></span></span> may cause a
thread to block, thereby making it incapable of reaching a safe point in a
timely fashion. However, in each of these cases, the Java thread is ”effectively
safe” - it is not running Java code that would interfere with the garbage
collector, on-stack-replacement, locking, or any other Java runtime mechanism.
Thus, a state management system is needed that would notify these runtime
services when a thread is ”effectively safe” and does not need to be waited
on.
</p><!--l. 25--><p class="noindent" >RVMThread provides for the following thread states, which describe to other runtime
services the state of a Java thread. These states are designed with extreme care to
support the following features: </p>
<ul class="itemize1">
<li class="itemize">Allow Java threads to either execute Java code, which periodically reaches
safe points, and native code which is ”effectively safe” by virtue of not
having access to VM services.
</li>
<li class="itemize">Allow other threads (either Java threads or VM threads) to
asynchronously request a Java thread to block. This overlaps with the
takeYieldpoint mechanism, but adds the following feature: a thread that
is ”effectively safe” does not have to block.
</li>
<li class="itemize">Prevent race conditions on state changes. In particular, if a thread running
native code transitions back to running Java code while some other thread
expects it to be either ”effectively safe” or blocked at a safe point, then
it should block. As well, if we are waiting on some Java thread to reach a
safe point but it instead escapes into running native code, then we would
like to be notified that even though it is not at a safe point, it is now
effectively safe, and thus, we do not have to wait for it anymore.</li></ul>
<!--l. 33--><p class="noindent" >The states used to put these features into effect are listed below. </p>
<ul class="itemize1">
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">NEW</span></span></span>. This means that the thread has been created but is not started, and
hence is not yet running. <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">NEW</span></span></span> threads are always effectively safe, provided
that they do not transition to any of the other states.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span>. The thread is running Java code. This almost always corresponds
to the OS ”runnable” state - i.e. the thread has no reason to be blocked, is
on the runnable queue, and if a processor becomes available it will execute,
if it is not already executing. <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span> thread will periodically reach safe
points at which the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">takeYieldpoint</span></span></span> field will be tested. Hence, setting
this field will ensure that the thread will yield in a timely fashion, unless
it transitions into one of the other states in the meantime.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span>. The thread is running either native C code, or internal VM
code (which, by virtue of Jikes<sup class="textsuperscript"><span
class="cmr-9">TM</span></sup> RVM’s metacircularity, may be written
in Java). <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> threads are ”effectively safe” in that they will not do
anything that interferes with runtime services, at least until they transition
into some other state. The <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> state is most often used to denote
threads that are blocked, for example on a lock.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span>. The thread has called into JNI code. This is identical to
the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> state in all ways except one: <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span> threads have
a JNIEnvironment that stores more information about the thread’s
execution state (stack information, etc), while <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> threads save
only the minimum set of information required for the GC to perform stack
scanning.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA_TO_BLOCK</span></span></span>. This represents a thread that is running Java code,
as in <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span>, but has been requested to yield. In most cases, when
you set <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">takeYieldpoint</span></span></span> to non-zero, you will also change the state of
the thread from <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span> to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA_TO_BLOCK</span></span></span>. If you don’t intend on
waiting for the thread (for example, in the case of sampling, where you’re
opportunistically requesting a yield), then this step may be omitted; but
in the cases of locking and garbage collection, when a thread is requested
to yield using <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">takeYieldpoint</span></span></span>, its state will also be changed.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_NATIVE</span></span></span>. <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_NATIVE</span></span></span> is to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> as <br
class="newline" /><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA_TO_BLOCK</span></span></span> is to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span>. When requesting a thread to yield, we
check its state; if it’s <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span>, we set it to be <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_NATIVE</span></span></span>.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_JNI</span></span></span>. Same as <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_NATIVE</span></span></span>, but for <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span>.
</li>
<li class="itemize"><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">TERMINATED</span></span></span>. The thread has died. It is ”effectively safe”, but will never
again reach a safe point.</li></ul>
<!--l. 45--><p class="noindent" >The states are stored in <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread.execStatus</span></span></span>, an integer field that may be rapidly
manipulated using compare-and-swap. This field uses a hybrid synchronization
protocol, which includes both compare-and-swap and conventional locking (using the
thread’s Monitor, accessible via the <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">RVMThread.monitor()</span></span></span> method). The rules are as
follows:
</p>
<ul class="itemize1">
<li class="itemize">All state changes except for <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span> to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> or <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span>, and <br
class="newline" /><span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> or <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span> back to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span>, must be done while holding the
lock.
</li>
<li class="itemize">Only the thread itself can change its own state without holding the lock.
</li>
<li class="itemize">The only asynchronous state changes (changes to the state not done by the
thread that owns it) that are allowed are <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA</span></span></span> to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JAVA_TO_BLOCK</span></span></span>,
<span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_NATIVE</span></span></span> to <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_NATIVE</span></span></span>, and <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">IN_JNI</span></span></span> TO <span class="obeylines-h"><span class="verb"><span
class="cmtt-10">BLOCKED_IN_JNI</span></span></span>.</li></ul>
<!--l. 53--><p class="noindent" >The typical algorithm for requesting a thread to block looks as follows:
</p>
<!--l. 55-->
<div class="lstlisting" id="listing-114"><span class="label"><a
id="x17-186001r1"></a></span><span
class="cmtt-10">thread</span><span
class="cmtt-10">.</span><span
class="cmtt-10">monitor</span><span
class="cmtt-10">()</span><span
class="cmtt-10">.</span><span
class="cmtt-10">lockNoHandshake</span><span
class="cmtt-10">()</span><span
class="cmtt-10">;</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186002r2"></a></span><span
class="cmtt-10">if</span><span
class="cmtt-10"> </span><span
class="cmtt-10">(</span><span
class="cmtt-10">thread</span><span
class="cmtt-10"> </span><span
class="cmtt-10">is</span><span
class="cmtt-10"> </span><span
class="cmtt-10">running</span><span
class="cmtt-10">)</span><span
class="cmtt-10"> </span><span
class="cmtt-10">{</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186003r3"></a></span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10">thread</span><span
class="cmtt-10">.</span><span
class="cmtt-10">takeYieldpoint</span><span
class="cmtt-10">=1;</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186004r4"></a></span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186005r5"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">transitions</span><span
class="cmitt-10"> </span><span
class="cmitt-10">IN_JAVA</span><span
class="cmitt-10"> </span><span
class="cmitt-10">-></span><span
class="cmitt-10"> </span><span
class="cmitt-10">IN_JAVA_TO_BLOCK</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">IN_NATIVE</span><span
class="cmitt-10">-></span><span
class="cmitt-10">BLOCKED_IN_NATIVE</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">etc</span><span
class="cmitt-10">.</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186006r6"></a></span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10">thread</span><span
class="cmtt-10">.</span><span
class="cmtt-10">setBlockedExecStatus</span><span
class="cmtt-10">()</span><span
class="cmtt-10">;</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186007r7"></a></span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186008r8"></a></span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10">if</span><span
class="cmtt-10"> </span><span
class="cmtt-10">(</span><span
class="cmtt-10">thread</span><span
class="cmtt-10">.</span><span
class="cmtt-10">isInJava</span><span
class="cmtt-10">()</span><span
class="cmtt-10">)</span><span
class="cmtt-10"> </span><span
class="cmtt-10">{</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186009r9"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">Thread</span><span
class="cmitt-10"> </span><span
class="cmitt-10">will</span><span
class="cmitt-10"> </span><span
class="cmitt-10">reach</span><span
class="cmitt-10"> </span><span
class="cmitt-10">safe</span><span
class="cmitt-10"> </span><span
class="cmitt-10">point</span><span
class="cmitt-10"> </span><span
class="cmitt-10">soon</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">or</span><span
class="cmitt-10"> </span><span
class="cmitt-10">else</span><span
class="cmitt-10"> </span><span
class="cmitt-10">notify</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186010r10"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">us</span><span
class="cmitt-10"> </span><span
class="cmitt-10">that</span><span
class="cmitt-10"> </span><span
class="cmitt-10">it</span><span
class="cmitt-10"> </span><span
class="cmitt-10">left</span><span
class="cmitt-10"> </span><span
class="cmitt-10">to</span><span
class="cmitt-10"> </span><span
class="cmitt-10">native</span><span
class="cmitt-10"> </span><span
class="cmitt-10">code</span><span
class="cmitt-10">.</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186011r11"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">In</span><span
class="cmitt-10"> </span><span
class="cmitt-10">either</span><span
class="cmitt-10"> </span><span
class="cmitt-10">case</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">since</span><span
class="cmitt-10"> </span><span
class="cmitt-10">we</span><span
class="cmitt-10"> </span><span
class="cmitt-10">are</span><span
class="cmitt-10"> </span><span
class="cmitt-10">holding</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">lock</span><span
class="cmitt-10">,</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186012r12"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">thread</span><span
class="cmitt-10"> </span><span
class="cmitt-10">will</span><span
class="cmitt-10"> </span><span
class="cmitt-10">effectively</span><span
class="cmitt-10"> </span><span
class="cmitt-10">block</span><span
class="cmitt-10"> </span><span
class="cmitt-10">on</span><span
class="cmitt-10"> </span><span
class="cmitt-10">either</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">safe</span><span
class="cmitt-10"> </span><span
class="cmitt-10">point</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186013r13"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">or</span><span
class="cmitt-10"> </span><span
class="cmitt-10">on</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">attempt</span><span
class="cmitt-10"> </span><span
class="cmitt-10">to</span><span
class="cmitt-10"> </span><span
class="cmitt-10">go</span><span
class="cmitt-10"> </span><span
class="cmitt-10">to</span><span
class="cmitt-10"> </span><span
class="cmitt-10">native</span><span
class="cmitt-10"> </span><span
class="cmitt-10">code</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">since</span><span
class="cmitt-10"> </span><span
class="cmitt-10">performing</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186014r14"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">either</span><span
class="cmitt-10"> </span><span
class="cmitt-10">state</span><span
class="cmitt-10"> </span><span
class="cmitt-10">transition</span><span
class="cmitt-10"> </span><span
class="cmitt-10">requires</span><span
class="cmitt-10"> </span><span
class="cmitt-10">acquiring</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">lock</span><span
class="cmitt-10">,</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186015r15"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">which</span><span
class="cmitt-10"> </span><span
class="cmitt-10">we</span><span
class="cmitt-10"> </span><span
class="cmitt-10">are</span><span
class="cmitt-10"> </span><span
class="cmitt-10">now</span><span
class="cmitt-10"> </span><span
class="cmitt-10">holding</span><span
class="cmitt-10">.</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186016r16"></a></span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10">}</span><span
class="cmtt-10"> </span><span
class="cmtt-10">else</span><span
class="cmtt-10"> </span><span
class="cmtt-10">{</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186017r17"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">Thread</span><span
class="cmitt-10"> </span><span
class="cmitt-10">is</span><span
class="cmitt-10"> </span><span
class="cmitt-10">in</span><span
class="cmitt-10"> </span><span
class="cmitt-10">native</span><span
class="cmitt-10"> </span><span
class="cmitt-10">code</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">and</span><span
class="cmitt-10"> </span><span
class="cmitt-10">thus</span><span
class="cmitt-10"> </span><span
class="cmitt-10">is</span><span
class="cmitt-10"> </span><span
class="cmitt-10">"</span><span
class="cmitt-10">effectively</span><span
class="cmitt-10"> </span><span
class="cmitt-10">safe</span><span
class="cmitt-10">",</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186018r18"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">and</span><span
class="cmitt-10"> </span><span
class="cmitt-10">cannot</span><span
class="cmitt-10"> </span><span
class="cmitt-10">go</span><span
class="cmitt-10"> </span><span
class="cmitt-10">back</span><span
class="cmitt-10"> </span><span
class="cmitt-10">to</span><span
class="cmitt-10"> </span><span
class="cmitt-10">running</span><span
class="cmitt-10"> </span><span
class="cmitt-10">Java</span><span
class="cmitt-10"> </span><span
class="cmitt-10">code</span><span
class="cmitt-10"> </span><span
class="cmitt-10">so</span><span
class="cmitt-10"> </span><span
class="cmitt-10">long</span><span
class="cmitt-10"> </span><span
class="cmitt-10">as</span><span
class="cmitt-10"> </span><span
class="cmitt-10">we</span><span
class="cmitt-10"> </span><span
class="cmitt-10">hold</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186019r19"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">lock</span><span
class="cmitt-10">,</span><span
class="cmitt-10"> </span><span
class="cmitt-10">since</span><span
class="cmitt-10"> </span><span
class="cmitt-10">that</span><span
class="cmitt-10"> </span><span
class="cmitt-10">state</span><span
class="cmitt-10"> </span><span
class="cmitt-10">transition</span><span
class="cmitt-10"> </span><span
class="cmitt-10">requires</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186020r20"></a></span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10"> </span><span
class="cmitt-10">//</span><span
class="cmitt-10"> </span><span
class="cmitt-10">acquiring</span><span
class="cmitt-10"> </span><span
class="cmitt-10">the</span><span
class="cmitt-10"> </span><span
class="cmitt-10">lock</span><span
class="cmitt-10">.</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186021r21"></a></span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10"> </span><span
class="cmtt-10">}</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186022r22"></a></span><span
class="cmtt-10">}</span><span
class="cmtt-10"> </span><br /><span class="label"><a
id="x17-186023r23"></a></span><span
class="cmtt-10">thread</span><span