Skip to content

Commit 001343c

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm, gc] Disable reads and writes to from-space after a scavenge.
Change-Id: Id44de869e9c6823baf63a80caa10ceff9758dc31 Reviewed-on: https://dart-review.googlesource.com/c/79148 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
1 parent 97ffcd9 commit 001343c

6 files changed

Lines changed: 43 additions & 26 deletions

File tree

runtime/vm/heap/scavenger.cc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,7 @@ SemiSpace::SemiSpace(VirtualMemory* reserved)
277277
}
278278

279279
SemiSpace::~SemiSpace() {
280-
if (reserved_ != NULL) {
281-
#if defined(DEBUG)
282-
memset(reserved_->address(), Heap::kZapByte,
283-
size_in_words() << kWordSizeLog2);
284-
#endif // defined(DEBUG)
285-
delete reserved_;
286-
}
280+
delete reserved_;
287281
}
288282

289283
Mutex* SemiSpace::mutex_ = NULL;
@@ -303,25 +297,32 @@ void SemiSpace::Cleanup() {
303297
}
304298

305299
SemiSpace* SemiSpace::New(intptr_t size_in_words, const char* name) {
300+
SemiSpace* result = nullptr;
306301
{
307302
MutexLocker locker(mutex_);
308303
// TODO(koda): Cache one entry per size.
309-
if (cache_ != NULL && cache_->size_in_words() == size_in_words) {
310-
SemiSpace* result = cache_;
311-
cache_ = NULL;
312-
return result;
304+
if (cache_ != nullptr && cache_->size_in_words() == size_in_words) {
305+
result = cache_;
306+
cache_ = nullptr;
313307
}
314308
}
309+
if (result != nullptr) {
310+
#ifdef DEBUG
311+
result->reserved_->Protect(VirtualMemory::kReadWrite);
312+
#endif
313+
return result;
314+
}
315+
315316
if (size_in_words == 0) {
316-
return new SemiSpace(NULL);
317+
return new SemiSpace(nullptr);
317318
} else {
318319
intptr_t size_in_bytes = size_in_words << kWordSizeLog2;
319320
const bool kExecutable = false;
320321
VirtualMemory* memory =
321322
VirtualMemory::Allocate(size_in_bytes, kExecutable, name);
322-
if (memory == NULL) {
323+
if (memory == nullptr) {
323324
// TODO(koda): If cache_ is not empty, we could try to delete it.
324-
return NULL;
325+
return nullptr;
325326
}
326327
#if defined(DEBUG)
327328
memset(memory->address(), Heap::kZapByte, size_in_bytes);
@@ -332,12 +333,13 @@ SemiSpace* SemiSpace::New(intptr_t size_in_words, const char* name) {
332333

333334
void SemiSpace::Delete() {
334335
#ifdef DEBUG
335-
if (reserved_ != NULL) {
336+
if (reserved_ != nullptr) {
336337
const intptr_t size_in_bytes = size_in_words() << kWordSizeLog2;
337338
memset(reserved_->address(), Heap::kZapByte, size_in_bytes);
339+
reserved_->Protect(VirtualMemory::kNoAccess);
338340
}
339341
#endif
340-
SemiSpace* old_cache = NULL;
342+
SemiSpace* old_cache = nullptr;
341343
{
342344
MutexLocker locker(mutex_);
343345
old_cache = cache_;

runtime/vm/virtual_memory_android.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ bool VirtualMemory::FreeSubSegment(void* address,
102102
}
103103

104104
void VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
105-
ASSERT(Thread::Current()->IsMutatorThread() ||
106-
Isolate::Current()->mutator_thread()->IsAtSafepoint());
105+
#if defined(DEBUG)
106+
Thread* thread = Thread::Current();
107+
ASSERT((thread == nullptr) || thread->IsMutatorThread() ||
108+
thread->isolate()->mutator_thread()->IsAtSafepoint());
109+
#endif
107110
uword start_address = reinterpret_cast<uword>(address);
108111
uword end_address = start_address + size;
109112
uword page_address = Utils::RoundDown(start_address, PageSize());

runtime/vm/virtual_memory_fuchsia.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ bool VirtualMemory::FreeSubSegment(void* address, intptr_t size) {
178178
}
179179

180180
void VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
181-
ASSERT(Thread::Current()->IsMutatorThread() ||
182-
Isolate::Current()->mutator_thread()->IsAtSafepoint());
181+
#if defined(DEBUG)
182+
Thread* thread = Thread::Current();
183+
ASSERT((thread == nullptr) || thread->IsMutatorThread() ||
184+
thread->isolate()->mutator_thread()->IsAtSafepoint());
185+
#endif
183186
const uword start_address = reinterpret_cast<uword>(address);
184187
const uword end_address = start_address + size;
185188
const uword page_address = Utils::RoundDown(start_address, PageSize());

runtime/vm/virtual_memory_linux.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ bool VirtualMemory::FreeSubSegment(void* address,
102102
}
103103

104104
void VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
105-
ASSERT(Thread::Current()->IsMutatorThread() ||
106-
Isolate::Current()->mutator_thread()->IsAtSafepoint());
105+
#if defined(DEBUG)
106+
Thread* thread = Thread::Current();
107+
ASSERT((thread == nullptr) || thread->IsMutatorThread() ||
108+
thread->isolate()->mutator_thread()->IsAtSafepoint());
109+
#endif
107110
uword start_address = reinterpret_cast<uword>(address);
108111
uword end_address = start_address + size;
109112
uword page_address = Utils::RoundDown(start_address, PageSize());

runtime/vm/virtual_memory_macos.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ bool VirtualMemory::FreeSubSegment(void* address,
102102
}
103103

104104
void VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
105-
ASSERT(Thread::Current()->IsMutatorThread() ||
106-
Isolate::Current()->mutator_thread()->IsAtSafepoint());
105+
#if defined(DEBUG)
106+
Thread* thread = Thread::Current();
107+
ASSERT((thread == nullptr) || thread->IsMutatorThread() ||
108+
thread->isolate()->mutator_thread()->IsAtSafepoint());
109+
#endif
107110
uword start_address = reinterpret_cast<uword>(address);
108111
uword end_address = start_address + size;
109112
uword page_address = Utils::RoundDown(start_address, PageSize());

runtime/vm/virtual_memory_win.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ bool VirtualMemory::FreeSubSegment(void* address,
8383
}
8484

8585
void VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
86-
ASSERT(Thread::Current()->IsMutatorThread() ||
87-
Isolate::Current()->mutator_thread()->IsAtSafepoint());
86+
#if defined(DEBUG)
87+
Thread* thread = Thread::Current();
88+
ASSERT((thread == nullptr) || thread->IsMutatorThread() ||
89+
thread->isolate()->mutator_thread()->IsAtSafepoint());
90+
#endif
8891
uword start_address = reinterpret_cast<uword>(address);
8992
uword end_address = start_address + size;
9093
uword page_address = Utils::RoundDown(start_address, PageSize());

0 commit comments

Comments
 (0)