@@ -277,13 +277,7 @@ SemiSpace::SemiSpace(VirtualMemory* reserved)
277277}
278278
279279SemiSpace::~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
289283Mutex* SemiSpace::mutex_ = NULL ;
@@ -303,25 +297,32 @@ void SemiSpace::Cleanup() {
303297}
304298
305299SemiSpace* 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
333334void 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_;
0 commit comments