forked from eclipse-openj9/openj9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectAccessBarrier.cpp
2257 lines (2049 loc) · 86.6 KB
/
ObjectAccessBarrier.cpp
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
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
/**
* @file
* @ingroup GC_Base
*/
#include "ObjectAccessBarrier.hpp"
#include "j9protos.h"
#include "ModronAssertions.h"
#include "rommeth.h"
#include "ArrayletObjectModel.hpp"
#include "AtomicOperations.hpp"
#include "EnvironmentBase.hpp"
#include "HeapRegionManager.hpp"
#include "MemorySpace.hpp"
#include "ObjectAccessBarrierAPI.hpp"
#include "ObjectMonitor.hpp"
#include "VMHelpers.hpp"
#include "VMThreadListIterator.hpp"
bool
MM_ObjectAccessBarrier::initialize(MM_EnvironmentBase *env)
{
_extensions = MM_GCExtensions::getExtensions(env);
_heap = _extensions->heap;
J9JavaVM *vm = (J9JavaVM*)env->getOmrVM()->_language_vm;
OMR_VM *omrVM = env->getOmrVM();
#if defined(OMR_GC_COMPRESSED_POINTERS)
if (env->compressObjectReferences()) {
#if defined(J9VM_GC_REALTIME)
/*
* Do not allow 4-bit shift for Metronome
* Cell Sizes Table for Segregated heap should be modified to have aligned to 16 values
*/
if (_extensions->isMetronomeGC()) {
if (DEFAULT_LOW_MEMORY_HEAP_CEILING_SHIFT < omrVM->_compressedPointersShift) {
/* Non-standard NLS message required */
_extensions->heapInitializationFailureReason = MM_GCExtensionsBase::HEAP_INITIALIZATION_FAILURE_REASON_METRONOME_DOES_NOT_SUPPORT_4BIT_SHIFT;
return false;
}
}
#endif /* J9VM_GC_REALTIME */
#if defined(OMR_GC_FULL_POINTERS)
_compressObjectReferences = true;
#endif /* defined(OMR_GC_FULL_POINTERS) */
_compressedPointersShift = omrVM->_compressedPointersShift;
vm->compressedPointersShift = omrVM->_compressedPointersShift;
Trc_MM_CompressedAccessBarrierInitialized(env->getLanguageVMThread(), 0, _compressedPointersShift);
}
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) */
vm->objectAlignmentInBytes = omrVM->_objectAlignmentInBytes;
vm->objectAlignmentShift = omrVM->_objectAlignmentShift;
/* request an extra slot in java/lang/ref/Reference which we will use to maintain linked lists of reference objects */
if (0 != vm->internalVMFunctions->addHiddenInstanceField(vm, "java/lang/ref/Reference", "gcLink", "Ljava/lang/ref/Reference;", &_referenceLinkOffset)) {
return false;
}
/* request an extra slot in java/util/concurrent/locks/AbstractOwnableSynchronizer which we will use to maintain linked lists of ownable synchronizer objects */
if (0 != vm->internalVMFunctions->addHiddenInstanceField(vm, "java/util/concurrent/locks/AbstractOwnableSynchronizer", "ownableSynchronizerLink", "Ljava/util/concurrent/locks/AbstractOwnableSynchronizer;", &_ownableSynchronizerLinkOffset)) {
return false;
}
return true;
}
void
MM_ObjectAccessBarrier::kill(MM_EnvironmentBase *env)
{
tearDown(env);
env->getForge()->free(this);
}
void
MM_ObjectAccessBarrier::tearDown(MM_EnvironmentBase *env)
{
}
/**
* Read an object pointer from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readObject() for higher-level actions.
* By default, forwards to readU32Impl() on 32-bit platforms, and readU64Impl() on 64-bit.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
mm_j9object_t
MM_ObjectAccessBarrier::readObjectImpl(J9VMThread *vmThread, mm_j9object_t srcObject, fj9object_t *srcAddress, bool isVolatile)
{
mm_j9object_t result = NULL;
if (compressObjectReferences()) {
result = convertPointerFromToken(*(uint32_t*)srcAddress);
} else {
result = (mm_j9object_t)*(uintptr_t*)srcAddress;
}
return result;
}
/**
* Read a static object field.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See staticReadObject() for higher-level actions.
* By default, forwards to readU32Impl() on 32-bit platforms, and readU64Impl() on 64-bit.
* @param clazz the class which contains the static field
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
mm_j9object_t
MM_ObjectAccessBarrier::staticReadObjectImpl(J9VMThread *vmThread, J9Class *clazz, j9object_t *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Read an object from an internal VM slot (J9VMThread, J9JavaVM, named field of J9Class).
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readObjectFromInternalVMSlot() for higher-level actions.
* By default, forwards to readU32Impl() on 32-bit platforms, and readU64Impl() on 64-bit.
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
mm_j9object_t
MM_ObjectAccessBarrier::readObjectFromInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store an object pointer into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeObject() for higher-level actions.
* By default, forwards to storeU32Impl() on 32-bit platforms, and storeU64Impl() on 64-bit.
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeObjectImpl(J9VMThread *vmThread, mm_j9object_t destObject, fj9object_t *destAddress, mm_j9object_t value, bool isVolatile)
{
if (compressObjectReferences()) {
*(uint32_t*)destAddress = (uint32_t)convertTokenFromPointer(value);
} else {
*(uintptr_t*)destAddress = (uintptr_t)value;
}
}
/**
* Store a static field.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeObject() for higher-level actions.
* By default, forwards to storeU32Impl() on 32-bit platforms, and storeU64Impl() on 64-bit.
* @param clazz the class the field belongs to
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::staticStoreObjectImpl(J9VMThread *vmThread, J9Class* clazz, j9object_t *destAddress, mm_j9object_t value, bool isVolatile)
{
*destAddress = value;
}
/**
* Write an object to an internal VM slot (J9VMThread, J9JavaVM, named field of J9Class).
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeObject() for higher-level actions.
* By default, forwards to storeU32Impl() on 32-bit platforms, and storeU64Impl() on 64-bit.
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeObjectToInternalVMSlotImpl(J9VMThread *vmThread, j9object_t *destAddress, mm_j9object_t value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a U_8 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
U_8
MM_ObjectAccessBarrier::readU8Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_8 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a U_8 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeU8Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_8 *destAddress, U_8 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a I_8 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
I_8
MM_ObjectAccessBarrier::readI8Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_8 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a I_8 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeI8Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_8 *destAddress, I_8 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a U_16 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
U_16
MM_ObjectAccessBarrier::readU16Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_16 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a U_16 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeU16Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_16 *destAddress, U_16 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a I_16 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
I_16
MM_ObjectAccessBarrier::readI16Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_16 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a I_16 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
*
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeI16Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_16 *destAddress, I_16 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a U_32 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readU32() for higher-level actions.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
U_32
MM_ObjectAccessBarrier::readU32Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_32 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a U_32 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeU32() for higher-level actions.
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeU32Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_32 *destAddress, U_32 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a I_32 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readI32() for higher-level actions.
* By default, forwards to readU32Impl, and casts the return value.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
I_32
MM_ObjectAccessBarrier::readI32Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_32 *srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a U_32 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeI32() for higher-level actions.
* By default, casts the value to unsigned and forwards to storeU32().
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeI32Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_32 *destAddress, I_32 value, bool isVolatile)
{
*destAddress = value;
}
/**
* Read a U_64 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readU64() for higher-level actions.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
U_64
MM_ObjectAccessBarrier::readU64Impl(J9VMThread *vmThread, mm_j9object_t srcObject, U_64 *srcAddress, bool isVolatile)
{
#if !defined(J9VM_ENV_DATA64)
if (isVolatile) {
return longVolatileRead(vmThread, srcAddress);
}
#endif /* J9VM_ENV_DATA64 */
return *srcAddress;
}
/**
* Store a U_64 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeU64() for higher-level actions.
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeU64Impl(J9VMThread *vmThread, mm_j9object_t destObject, U_64 *destAddress, U_64 value, bool isVolatile)
{
#if !defined(J9VM_ENV_DATA64)
if (isVolatile) {
longVolatileWrite(vmThread, destAddress, &value);
return;
}
#endif /* J9VM_ENV_DATA64 */
*destAddress = value;
}
/**
* Read a I_64 from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readI64() for higher-level actions.
* By default, forwards to readU64Impl, and casts the return value.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
I_64
MM_ObjectAccessBarrier::readI64Impl(J9VMThread *vmThread, mm_j9object_t srcObject, I_64 *srcAddress, bool isVolatile)
{
#if !defined(J9VM_ENV_DATA64)
if (isVolatile) {
return longVolatileRead(vmThread, (U_64 *)srcAddress);
}
#endif /* J9VM_ENV_DATA64 */
return *srcAddress;
}
/**
* Store an I_64 into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeI64() for higher-level actions.
* By default, casts the value to unsigned and forwards to storeU64Impl().
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeI64Impl(J9VMThread *vmThread, mm_j9object_t destObject, I_64 *destAddress, I_64 value, bool isVolatile)
{
#if !defined(J9VM_ENV_DATA64)
if (isVolatile) {
longVolatileWrite(vmThread, (U_64 *)destAddress, (U_64 *)&value);
return;
}
#endif /* J9VM_ENV_DATA64 */
*destAddress = value;
}
/**
* Read a non-object address (pointer to internal VM data) from an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See readAddress() for higher-level actions.
* By default, forwards to readU32Impl() on 32-bit platforms, and readU64Impl() on 64-bit.
* @param srcObject the object being read from
* @param srcAddress the address of the field to be read
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void *
MM_ObjectAccessBarrier::readAddressImpl(J9VMThread *vmThread, mm_j9object_t srcObject, void **srcAddress, bool isVolatile)
{
return *srcAddress;
}
/**
* Store a non-object address into an object.
* This function is only concerned with moving the actual data. Do not re-implement
* unless the value is stored in a non-native format (e.g. compressed object pointers).
* See storeAddress() for higher-level actions.
* By default, forwards to storeU32Impl on 32-bit platforms and storeU64Impl on 64-bit.
* @param destObject the object to read from
* @param destAddress the address of the field to be read
* @param value the value to be stored
* @param isVolatile non-zero if the field is volatile, zero otherwise
*/
void
MM_ObjectAccessBarrier::storeAddressImpl(J9VMThread *vmThread, mm_j9object_t destObject, void **destAddress, void *value, bool isVolatile)
{
*destAddress = value;
}
/**
* Call before a read or write of a possibly volatile field.
* @note This must be used in tandem with protectIfVolatileAfter()
* @param isVolatile true if the field is volatile, false otherwise
* @param isRead true if the field is being read, false if it is being written
* @param isWide true if the field is wide (64-bit), false otherwise
*/
void
MM_ObjectAccessBarrier::protectIfVolatileBefore(J9VMThread *vmThread, bool isVolatile, bool isRead, bool isWide)
{
if (isVolatile) {
/* need to insert a sync instruction
* As this is inline, compiler should optimize this away when not necessary.
*/
if (!isRead) {
/* atomic writeBarrier */
MM_AtomicOperations::storeSync();
}
}
}
/**
* Call after a read or write of a possibly volatile field.
* @note This must be used in tandem with protectIfVolatileBefore()
* @param isVolatile true if the field is volatile, false otherwise
* @param isRead true if the field is being read, false if it is being written
* @param isWide true if the field is wide (64-bit), false otherwise
*/
void
MM_ObjectAccessBarrier::protectIfVolatileAfter(J9VMThread *vmThread, bool isVolatile, bool isRead, bool isWide)
{
if (isVolatile) {
/* need to insert a sync instruction
* As this is inline, compiler should optimize this away when not necessary.
*/
if (isRead) {
/* atomic readBarrier */
MM_AtomicOperations::loadSync();
} else {
/* atomic readWriteBarrier */
MM_AtomicOperations::sync();
}
}
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
J9Object *
MM_ObjectAccessBarrier::mixedObjectReadObject(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
fj9object_t *actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset, fj9object_t);
J9Object *result = NULL;
if (preObjectRead(vmThread, srcObject, actualAddress)) {
protectIfVolatileBefore(vmThread, isVolatile, true, false);
result = readObjectImpl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
if (!postObjectRead(vmThread, srcObject, actualAddress)) {
result = NULL;
}
}
/* This must always be called to massage the return value */
return result;
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
void *
MM_ObjectAccessBarrier::mixedObjectReadAddress(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
void **actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset,void *);
protectIfVolatileBefore(vmThread, isVolatile, true, false);
void *result = readAddressImpl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
U_32
MM_ObjectAccessBarrier::mixedObjectReadU32(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
U_32 *actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset, U_32);
protectIfVolatileBefore(vmThread, isVolatile, true, false);
U_32 result = readU32Impl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
I_32
MM_ObjectAccessBarrier::mixedObjectReadI32(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
I_32 *actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset, I_32);
protectIfVolatileBefore(vmThread, isVolatile, true, false);
I_32 result = readI32Impl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
U_64
MM_ObjectAccessBarrier::mixedObjectReadU64(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
U_64 *actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset, U_64);
protectIfVolatileBefore(vmThread, isVolatile, true, true);
U_64 result = readU64Impl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, true);
return result;
}
/**
* Read an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The object being used.
* @param srcOffset The offset of the field.
* @param isVolatile non-zero if the field is volatile.
*/
I_64
MM_ObjectAccessBarrier::mixedObjectReadI64(J9VMThread *vmThread, J9Object *srcObject, UDATA srcOffset, bool isVolatile)
{
I_64 *actualAddress = J9OAB_MIXEDOBJECT_EA(srcObject, srcOffset, I_64);
protectIfVolatileBefore(vmThread, isVolatile, true, true);
I_64 result = readI64Impl(vmThread, srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, true);
return result;
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreObject(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, J9Object *value, bool isVolatile)
{
fj9object_t *actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset, fj9object_t);
if (preObjectStore(vmThread, destObject, actualAddress, value, isVolatile)) {
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeObjectImpl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
postObjectStore(vmThread, destObject, actualAddress, value, isVolatile);
}
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreAddress(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset,void *value, bool isVolatile)
{
void **actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset,void *);
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeAddressImpl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreU32(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, U_32 value, bool isVolatile)
{
U_32 *actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset, U_32);
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeU32Impl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreI32(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, I_32 value, bool isVolatile)
{
I_32 *actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset, I_32);
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeI32Impl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreU64(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, U_64 value, bool isVolatile)
{
U_64 *actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset, U_64);
protectIfVolatileBefore(vmThread, isVolatile, false, true);
storeU64Impl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, true);
}
/**
* Store an object field: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The object being used.
* @param destOffset The offset of the field.
* @param value The value to be stored
* @param isVolatile non-zero if the field is volatile.
*/
void
MM_ObjectAccessBarrier::mixedObjectStoreI64(J9VMThread *vmThread, J9Object *destObject, UDATA destOffset, I_64 value, bool isVolatile)
{
I_64 *actualAddress = J9OAB_MIXEDOBJECT_EA(destObject, destOffset, I_64);
protectIfVolatileBefore(vmThread, isVolatile, false, true);
storeI64Impl(vmThread, destObject, actualAddress, value, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, false, true);
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
J9Object *
MM_ObjectAccessBarrier::indexableReadObject(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
UDATA const referenceSize = J9VMTHREAD_REFERENCE_SIZE(vmThread);
fj9object_t *actualAddress = (fj9object_t *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, referenceSize);
J9Object *result = NULL;
/* No preObjectRead yet because no barrier require it */
if (preObjectRead(vmThread, (J9Object *)srcObject, actualAddress)) {
protectIfVolatileBefore(vmThread, isVolatile, true, false);
result = readObjectImpl(vmThread, (J9Object*)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
if (!postObjectRead(vmThread, (J9Object *)srcObject, actualAddress)) {
result = NULL;
}
}
/* This must always be called to massage the return value */
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
void *
MM_ObjectAccessBarrier::indexableReadAddress(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
void **actualAddress = (void **)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(void *));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
void *result = readAddressImpl(vmThread, (J9Object*)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
U_8
MM_ObjectAccessBarrier::indexableReadU8(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
U_8 *actualAddress = (U_8 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(U_8));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
U_8 result = readU8Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
I_8
MM_ObjectAccessBarrier::indexableReadI8(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
I_8 *actualAddress = (I_8 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(I_8));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
I_8 result = readI8Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
U_16
MM_ObjectAccessBarrier::indexableReadU16(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
U_16 *actualAddress = (U_16 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex,sizeof(U_16));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
U_16 result = readU16Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
I_16
MM_ObjectAccessBarrier::indexableReadI16(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
I_16 *actualAddress = (I_16 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(I_16));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
I_16 result = readI16Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
U_32
MM_ObjectAccessBarrier::indexableReadU32(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
U_32 *actualAddress = (U_32 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(U_32));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
U_32 result = readU32Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
I_32
MM_ObjectAccessBarrier::indexableReadI32(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
I_32 *actualAddress = (I_32 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(I_32));
protectIfVolatileBefore(vmThread, isVolatile, true, false);
I_32 result = readI32Impl(vmThread, (mm_j9object_t)srcObject, actualAddress);
protectIfVolatileAfter(vmThread, isVolatile, true, false);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
U_64
MM_ObjectAccessBarrier::indexableReadU64(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
U_64 *actualAddress = (U_64 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(U_64));
protectIfVolatileBefore(vmThread, isVolatile, true, true);
U_64 result = readU64Impl(vmThread, (mm_j9object_t)srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, true);
return result;
}
/**
* Read an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param srcObject The array being used.
* @param srcIndex The element index
*/
I_64
MM_ObjectAccessBarrier::indexableReadI64(J9VMThread *vmThread, J9IndexableObject *srcObject, I_32 srcIndex, bool isVolatile)
{
I_64 *actualAddress = (I_64 *)indexableEffectiveAddress(vmThread, srcObject, srcIndex, sizeof(I_64));
protectIfVolatileBefore(vmThread, isVolatile, true, true);
I_64 result = readI64Impl(vmThread, (mm_j9object_t)srcObject, actualAddress, isVolatile);
protectIfVolatileAfter(vmThread, isVolatile, true, true);
return result;
}
/**
* Store an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The array being used.
* @param destIndex The element index
* @param value The value to store.
*/
void
MM_ObjectAccessBarrier::indexableStoreObject(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex, J9Object *value, bool isVolatile)
{
UDATA const referenceSize = J9VMTHREAD_REFERENCE_SIZE(vmThread);
fj9object_t *actualAddress = (fj9object_t *)indexableEffectiveAddress(vmThread, destObject, destIndex, referenceSize);
if (preObjectStore(vmThread, (J9Object *)destObject, actualAddress, value)) {
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeObjectImpl(vmThread, (J9Object*)destObject, actualAddress, value);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
postObjectStore(vmThread, (J9Object *)destObject, actualAddress, value);
}
}
/**
* Store an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The array being used.
* @param destIndex The element index
* @param value The value to store.
*/
void
MM_ObjectAccessBarrier::indexableStoreAddress(J9VMThread *vmThread, J9IndexableObject *destObject, I_32 destIndex,void *value, bool isVolatile)
{
void **actualAddress = (void **)indexableEffectiveAddress(vmThread, destObject, destIndex, sizeof(void *));
protectIfVolatileBefore(vmThread, isVolatile, false, false);
storeAddressImpl(vmThread, (mm_j9object_t)destObject, actualAddress, value);
protectIfVolatileAfter(vmThread, isVolatile, false, false);
}
/**
* Store an array element: perform any pre-use barriers, calculate an effective address
* and perform the work.
* @param destObject The array being used.
* @param destIndex The element index
* @param value The value to store.
*/