File tree 3 files changed +17
-5
lines changed 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ uword Heap::AllocateNew(intptr_t size) {
91
91
return addr;
92
92
}
93
93
94
- intptr_t tlab_size = CalculateTLABSize ();
94
+ intptr_t tlab_size = GetTLABSize ();
95
95
if ((tlab_size > 0 ) && (size > tlab_size)) {
96
96
return AllocateOld (size, HeapPage::kData );
97
97
}
@@ -101,8 +101,11 @@ uword Heap::AllocateNew(intptr_t size) {
101
101
uword tlab_top = new_space_.TryAllocateNewTLAB (thread, tlab_size);
102
102
if (tlab_top != 0 ) {
103
103
addr = new_space_.TryAllocateInTLAB (thread, size);
104
- ASSERT (addr != 0 );
105
- return addr;
104
+ if (addr != 0 ) { // but "leftover" TLAB could end smaller than tlab_size
105
+ return addr;
106
+ }
107
+ // Abandon "leftover" TLAB as well so we can start from scratch.
108
+ AbandonRemainingTLAB (thread);
106
109
}
107
110
}
108
111
@@ -112,7 +115,7 @@ uword Heap::AllocateNew(intptr_t size) {
112
115
// from a different thread and will be racing to allocate the requested
113
116
// memory with other threads being released after the collection.
114
117
CollectGarbage (kNew );
115
- tlab_size = CalculateTLABSize ();
118
+
116
119
uword tlab_top = new_space_.TryAllocateNewTLAB (thread, tlab_size);
117
120
if (tlab_top != 0 ) {
118
121
addr = new_space_.TryAllocateInTLAB (thread, size);
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ class Heap {
285
285
286
286
static const intptr_t kNewAllocatableSize = 256 * KB;
287
287
288
- intptr_t CalculateTLABSize () {
288
+ intptr_t GetTLABSize () {
289
289
// Inspired by V8 tlab size. More than threshold for old space allocation,
290
290
// less then minimal(initial) new semi-space.
291
291
const intptr_t size = 512 * KB;
Original file line number Diff line number Diff line change @@ -926,6 +926,15 @@ uword Scavenger::TryAllocateNewTLAB(Thread* thread, intptr_t size) {
926
926
uword result = top_;
927
927
intptr_t remaining = end_ - top_;
928
928
if (remaining < size) {
929
+ // Grab whatever is remaining
930
+ size = remaining;
931
+ } else {
932
+ // Reduce TLAB size so we land at even TLAB size for future TLABs.
933
+ intptr_t survived_size = UsedInWords () * kWordSize ;
934
+ size -= survived_size % size;
935
+ }
936
+ size = Utils::RoundDown (size, kObjectAlignment );
937
+ if (size == 0 ) {
929
938
return 0 ;
930
939
}
931
940
ASSERT (to_->Contains (result));
You can’t perform that action at this time.
0 commit comments