50
50
import com .oracle .svm .core .annotate .Substitute ;
51
51
import com .oracle .svm .core .annotate .TargetClass ;
52
52
import com .oracle .svm .core .genscavenge .AlignedHeapChunk .AlignedHeader ;
53
- import com .oracle .svm .core .genscavenge .ThreadLocalAllocation .Descriptor ;
54
- import com .oracle .svm .core .genscavenge .UnalignedHeapChunk .UnalignedHeader ;
55
53
import com .oracle .svm .core .genscavenge .graal .nodes .FormatArrayNode ;
56
54
import com .oracle .svm .core .genscavenge .remset .RememberedSet ;
57
55
import com .oracle .svm .core .graal .snippets .SubstrateAllocationSnippets ;
@@ -196,7 +194,7 @@ public boolean isInPrimaryImageHeap(Pointer objPointer) {
196
194
@ Override
197
195
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
198
196
public void suspendAllocation () {
199
- ThreadLocalAllocation . suspendInCurrentThread ();
197
+ TlabSupport . suspendAllocationInCurrentThread ();
200
198
}
201
199
202
200
@ Override
@@ -415,13 +413,14 @@ public void endSafepoint() {
415
413
@ Uninterruptible (reason = "Called during startup." )
416
414
@ Override
417
415
public void attachThread (IsolateThread isolateThread ) {
418
- // nothing to do
416
+ TlabSupport .startupInitialization ();
417
+ TlabSupport .initialize (isolateThread );
419
418
}
420
419
421
420
@ Override
422
421
@ Uninterruptible (reason = "Thread is detaching and holds the THREAD_MUTEX." )
423
422
public void detachThread (IsolateThread isolateThread ) {
424
- ThreadLocalAllocation .disableAndFlushForThread (isolateThread );
423
+ TlabSupport .disableAndFlushForThread (isolateThread );
425
424
}
426
425
427
426
@ Fold
@@ -707,7 +706,7 @@ public void optionValueChanged(RuntimeOptionKey<?> key) {
707
706
@ Override
708
707
@ Uninterruptible (reason = "Called from uninterruptible code." , mayBeInlined = true )
709
708
public long getThreadAllocatedMemory (IsolateThread thread ) {
710
- UnsignedWord allocatedBytes = ThreadLocalAllocation .allocatedBytes . getVolatile (thread );
709
+ UnsignedWord allocatedBytes = ThreadLocalAllocation .getAllocatedBytes (thread );
711
710
712
711
/*
713
712
* The current aligned chunk in the TLAB is only partially filled and therefore not yet
@@ -717,9 +716,8 @@ public long getThreadAllocatedMemory(IsolateThread thread) {
717
716
* can cause that the memory in the current aligned TLAB chunk is counted twice.
718
717
*/
719
718
ThreadLocalAllocation .Descriptor tlab = ThreadLocalAllocation .getTlab (thread );
720
- AlignedHeader alignedTlab = tlab .getAlignedChunk ( );
719
+ Pointer start = tlab .getAlignedAllocationStart ( SubstrateAllocationSnippets . TLAB_START_IDENTITY );
721
720
Pointer top = tlab .getAllocationTop (SubstrateAllocationSnippets .TLAB_TOP_IDENTITY );
722
- Pointer start = AlignedHeapChunk .getObjectsStart (alignedTlab );
723
721
724
722
if (top .aboveThan (start )) {
725
723
UnsignedWord usedTlabSize = top .subtract (start );
@@ -787,7 +785,7 @@ private boolean printLocationInfo(Log log, Pointer ptr, boolean allowJavaHeapAcc
787
785
if (AuxiliaryImageHeap .isPresent () && AuxiliaryImageHeap .singleton ().containsObject (ptr )) {
788
786
log .string ("points into the auxiliary image heap" );
789
787
return true ;
790
- } else if (printTlabInfo (log , ptr , CurrentIsolate .getCurrentThread ())) {
788
+ } else if (TlabSupport . printTlabInfo (log , ptr , CurrentIsolate .getCurrentThread ())) {
791
789
return true ;
792
790
}
793
791
@@ -805,7 +803,7 @@ private boolean printLocationInfo(Log log, Pointer ptr, boolean allowJavaHeapAcc
805
803
* If we are not at a safepoint, then it is unsafe to access thread locals of another
806
804
* thread as the IsolateThread could be freed at any time.
807
805
*/
808
- if (printTlabInfo (log , ptr )) {
806
+ if (TlabSupport . printTlabInfo (log , ptr )) {
809
807
return true ;
810
808
}
811
809
}
@@ -824,53 +822,6 @@ boolean isInHeap(Pointer ptr) {
824
822
return isInImageHeap (ptr ) || youngGeneration .isInSpace (ptr ) || oldGeneration .isInSpace (ptr );
825
823
}
826
824
827
- private static boolean printTlabInfo (Log log , Pointer ptr ) {
828
- for (IsolateThread thread = VMThreads .firstThreadUnsafe (); thread .isNonNull (); thread = VMThreads .nextThread (thread )) {
829
- if (printTlabInfo (log , ptr , thread )) {
830
- return true ;
831
- }
832
- }
833
- return false ;
834
- }
835
-
836
- private static boolean printTlabInfo (Log log , Pointer ptr , IsolateThread thread ) {
837
- ThreadLocalAllocation .Descriptor tlab = getTlabUnsafe (thread );
838
- AlignedHeader aChunk = tlab .getAlignedChunk ();
839
- while (aChunk .isNonNull ()) {
840
- if (HeapChunk .asPointer (aChunk ).belowOrEqual (ptr ) && ptr .belowThan (HeapChunk .getEndPointer (aChunk ))) {
841
- /* top may be null for a thread's current aligned allocation chunk. */
842
- boolean unusablePart = HeapChunk .getTopPointer (aChunk ).isNonNull () && ptr .aboveOrEqual (HeapChunk .getTopPointer (aChunk ));
843
- printTlabChunkInfo (log , thread , aChunk , "aligned" , unusablePart );
844
- return true ;
845
- }
846
- aChunk = HeapChunk .getNext (aChunk );
847
- }
848
-
849
- UnalignedHeader uChunk = tlab .getUnalignedChunk ();
850
- while (uChunk .isNonNull ()) {
851
- if (HeapChunk .asPointer (uChunk ).belowOrEqual (ptr ) && ptr .belowThan (HeapChunk .getEndPointer (uChunk ))) {
852
- boolean unusablePart = ptr .aboveOrEqual (HeapChunk .getTopPointer (uChunk ));
853
- printTlabChunkInfo (log , thread , uChunk , "unaligned" , unusablePart );
854
- return true ;
855
- }
856
- uChunk = HeapChunk .getNext (uChunk );
857
- }
858
-
859
- return false ;
860
- }
861
-
862
- private static void printTlabChunkInfo (Log log , IsolateThread thread , HeapChunk .Header <?> chunk , String chunkType , boolean unusablePart ) {
863
- String unusable = unusablePart ? "unusable part of " : "" ;
864
- log .string ("points into " ).string (unusable ).string (chunkType ).string (" chunk " ).zhex (chunk ).spaces (1 );
865
- log .string ("(TLAB of thread " ).zhex (thread ).string (")" );
866
- }
867
-
868
- @ Uninterruptible (reason = "This whole method is unsafe, so it is only uninterruptible to satisfy the checks." )
869
- static Descriptor getTlabUnsafe (IsolateThread thread ) {
870
- assert SubstrateDiagnostics .isFatalErrorHandlingThread () : "can cause crashes, so it may only be used while printing diagnostics" ;
871
- return ThreadLocalAllocation .getTlab (thread );
872
- }
873
-
874
825
@ Override
875
826
@ Uninterruptible (reason = "Called during early startup." )
876
827
public boolean verifyImageHeapMapping () {
0 commit comments