diff options
Diffstat (limited to 'src/3rdparty/v8/src/heap-inl.h')
-rw-r--r-- | src/3rdparty/v8/src/heap-inl.h | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/src/3rdparty/v8/src/heap-inl.h b/src/3rdparty/v8/src/heap-inl.h index aa933b6..cb274cb 100644 --- a/src/3rdparty/v8/src/heap-inl.h +++ b/src/3rdparty/v8/src/heap-inl.h @@ -85,13 +85,16 @@ void PromotionQueue::ActivateGuardIfOnTheSamePage() { MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str, PretenureFlag pretenure) { // Check for ASCII first since this is the common case. - if (String::IsAscii(str.start(), str.length())) { + const char* start = str.start(); + int length = str.length(); + int non_ascii_start = String::NonAsciiStart(start, length); + if (non_ascii_start >= length) { // If the string is ASCII, we do not need to convert the characters // since UTF8 is backwards compatible with ASCII. return AllocateStringFromAscii(str, pretenure); } // Non-ASCII and we need to decode. - return AllocateStringFromUtf8Slow(str, pretenure); + return AllocateStringFromUtf8Slow(str, non_ascii_start, pretenure); } @@ -283,13 +286,6 @@ MaybeObject* Heap::AllocateRawMap() { #endif MaybeObject* result = map_space_->AllocateRaw(Map::kSize); if (result->IsFailure()) old_gen_exhausted_ = true; -#ifdef DEBUG - if (!result->IsFailure()) { - // Maps have their own alignment. - CHECK((reinterpret_cast<intptr_t>(result) & kMapAlignmentMask) == - static_cast<intptr_t>(kHeapObjectTag)); - } -#endif return result; } @@ -484,10 +480,12 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( // Avoid overflow. if (amount > amount_of_external_allocated_memory_) { amount_of_external_allocated_memory_ = amount; + } else { + // Give up and reset the counters in case of an overflow. + amount_of_external_allocated_memory_ = 0; + amount_of_external_allocated_memory_at_last_global_gc_ = 0; } - intptr_t amount_since_last_global_gc = - amount_of_external_allocated_memory_ - - amount_of_external_allocated_memory_at_last_global_gc_; + intptr_t amount_since_last_global_gc = PromotedExternalMemorySize(); if (amount_since_last_global_gc > external_allocation_limit_) { CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached"); } @@ -495,8 +493,19 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( // Avoid underflow. if (amount >= 0) { amount_of_external_allocated_memory_ = amount; + } else { + // Give up and reset the counters in case of an overflow. + amount_of_external_allocated_memory_ = 0; + amount_of_external_allocated_memory_at_last_global_gc_ = 0; } } + if (FLAG_trace_external_memory) { + PrintPID("%8.0f ms: ", isolate()->time_millis_since_init()); + PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d KB, " + " amount=%6" V8_PTR_PREFIX "d KB, isolate=0x%08" V8PRIxPTR ".\n", + change_in_bytes / 1024, amount_of_external_allocated_memory_ / 1024, + reinterpret_cast<intptr_t>(isolate())); + } ASSERT(amount_of_external_allocated_memory_ >= 0); return amount_of_external_allocated_memory_; } @@ -621,12 +630,24 @@ void ExternalStringTable::Iterate(ObjectVisitor* v) { void ExternalStringTable::Verify() { #ifdef DEBUG for (int i = 0; i < new_space_strings_.length(); ++i) { - ASSERT(heap_->InNewSpace(new_space_strings_[i])); - ASSERT(new_space_strings_[i] != HEAP->raw_unchecked_the_hole_value()); + Object* obj = Object::cast(new_space_strings_[i]); + // TODO(yangguo): check that the object is indeed an external string. + ASSERT(heap_->InNewSpace(obj)); + ASSERT(obj != HEAP->the_hole_value()); + if (obj->IsExternalAsciiString()) { + ExternalAsciiString* string = ExternalAsciiString::cast(obj); + ASSERT(String::IsAscii(string->GetChars(), string->length())); + } } for (int i = 0; i < old_space_strings_.length(); ++i) { - ASSERT(!heap_->InNewSpace(old_space_strings_[i])); - ASSERT(old_space_strings_[i] != HEAP->raw_unchecked_the_hole_value()); + Object* obj = Object::cast(old_space_strings_[i]); + // TODO(yangguo): check that the object is indeed an external string. + ASSERT(!heap_->InNewSpace(obj)); + ASSERT(obj != HEAP->the_hole_value()); + if (obj->IsExternalAsciiString()) { + ExternalAsciiString* string = ExternalAsciiString::cast(obj); + ASSERT(String::IsAscii(string->GetChars(), string->length())); + } } #endif } @@ -641,9 +662,11 @@ void ExternalStringTable::AddOldObject(HeapObject* object) { void ExternalStringTable::ShrinkNewObjects(int position) { new_space_strings_.Rewind(position); +#ifdef VERIFY_HEAP if (FLAG_verify_heap) { Verify(); } +#endif } @@ -742,28 +765,15 @@ AlwaysAllocateScope::~AlwaysAllocateScope() { } -LinearAllocationScope::LinearAllocationScope() { - HEAP->linear_allocation_scope_depth_++; -} - - -LinearAllocationScope::~LinearAllocationScope() { - HEAP->linear_allocation_scope_depth_--; - ASSERT(HEAP->linear_allocation_scope_depth_ >= 0); -} - - -#ifdef DEBUG void VerifyPointersVisitor::VisitPointers(Object** start, Object** end) { for (Object** current = start; current < end; current++) { if ((*current)->IsHeapObject()) { HeapObject* object = HeapObject::cast(*current); - ASSERT(HEAP->Contains(object)); - ASSERT(object->map()->IsMap()); + CHECK(HEAP->Contains(object)); + CHECK(object->map()->IsMap()); } } } -#endif double GCTracer::SizeOfHeapObjects() { @@ -771,37 +781,47 @@ double GCTracer::SizeOfHeapObjects() { } -#ifdef DEBUG DisallowAllocationFailure::DisallowAllocationFailure() { +#ifdef DEBUG old_state_ = HEAP->disallow_allocation_failure_; HEAP->disallow_allocation_failure_ = true; +#endif } DisallowAllocationFailure::~DisallowAllocationFailure() { +#ifdef DEBUG HEAP->disallow_allocation_failure_ = old_state_; -} #endif +} #ifdef DEBUG AssertNoAllocation::AssertNoAllocation() { - old_state_ = HEAP->allow_allocation(false); + Isolate* isolate = ISOLATE; + active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread(); + if (active_) { + old_state_ = isolate->heap()->allow_allocation(false); + } } AssertNoAllocation::~AssertNoAllocation() { - HEAP->allow_allocation(old_state_); + if (active_) HEAP->allow_allocation(old_state_); } DisableAssertNoAllocation::DisableAssertNoAllocation() { - old_state_ = HEAP->allow_allocation(true); + Isolate* isolate = ISOLATE; + active_ = !isolate->optimizing_compiler_thread()->IsOptimizerThread(); + if (active_) { + old_state_ = isolate->heap()->allow_allocation(true); + } } DisableAssertNoAllocation::~DisableAssertNoAllocation() { - HEAP->allow_allocation(old_state_); + if (active_) HEAP->allow_allocation(old_state_); } #else |