API: Change AdjustAmountOfExternalAllocatedMemory calls to use int64_t instead

of intptr_t

This prevents an overflow in FreeArrayBuffer, which in turn caused needless GCs
as well as crashes on isolate teardown.

LOG=Y
R=ulan@chromium.org

Review URL: https://codereview.chromium.org/70233010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17944 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 617c2dd7
...@@ -4102,7 +4102,7 @@ class V8_EXPORT Isolate { ...@@ -4102,7 +4102,7 @@ class V8_EXPORT Isolate {
* kept alive by JavaScript objects. * kept alive by JavaScript objects.
* \returns the adjusted value. * \returns the adjusted value.
*/ */
intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes); int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
/** /**
* Returns heap profiler for this isolate. Will return NULL until the isolate * Returns heap profiler for this isolate. Will return NULL until the isolate
...@@ -4685,8 +4685,8 @@ class V8_EXPORT V8 { ...@@ -4685,8 +4685,8 @@ class V8_EXPORT V8 {
V8_DEPRECATED( V8_DEPRECATED(
"Use Isolate::AdjustAmountOfExternalAllocatedMemory instead", "Use Isolate::AdjustAmountOfExternalAllocatedMemory instead",
static intptr_t AdjustAmountOfExternalAllocatedMemory( static int64_t AdjustAmountOfExternalAllocatedMemory(
intptr_t change_in_bytes)); int64_t change_in_bytes));
/** /**
* Forcefully terminate the current thread of JavaScript execution * Forcefully terminate the current thread of JavaScript execution
......
...@@ -6389,14 +6389,14 @@ void V8::SetFailedAccessCheckCallbackFunction( ...@@ -6389,14 +6389,14 @@ void V8::SetFailedAccessCheckCallbackFunction(
} }
intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory( int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
intptr_t change_in_bytes) { int64_t change_in_bytes) {
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap(); i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
} }
intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) { int64_t V8::AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes) {
i::Isolate* isolate = i::Isolate::UncheckedCurrent(); i::Isolate* isolate = i::Isolate::UncheckedCurrent();
if (isolate == NULL || !isolate->IsInitialized()) { if (isolate == NULL || !isolate->IsInitialized()) {
return 0; return 0;
......
...@@ -541,10 +541,10 @@ MaybeObject* Heap::PrepareForCompare(String* str) { ...@@ -541,10 +541,10 @@ MaybeObject* Heap::PrepareForCompare(String* str) {
} }
intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( int64_t Heap::AdjustAmountOfExternalAllocatedMemory(
intptr_t change_in_bytes) { int64_t change_in_bytes) {
ASSERT(HasBeenSetUp()); ASSERT(HasBeenSetUp());
intptr_t amount = amount_of_external_allocated_memory_ + change_in_bytes; int64_t amount = amount_of_external_allocated_memory_ + change_in_bytes;
if (change_in_bytes > 0) { if (change_in_bytes > 0) {
// Avoid overflow. // Avoid overflow.
if (amount > amount_of_external_allocated_memory_) { if (amount > amount_of_external_allocated_memory_) {
...@@ -554,7 +554,7 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( ...@@ -554,7 +554,7 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
amount_of_external_allocated_memory_ = 0; amount_of_external_allocated_memory_ = 0;
amount_of_external_allocated_memory_at_last_global_gc_ = 0; amount_of_external_allocated_memory_at_last_global_gc_ = 0;
} }
intptr_t amount_since_last_global_gc = PromotedExternalMemorySize(); int64_t amount_since_last_global_gc = PromotedExternalMemorySize();
if (amount_since_last_global_gc > external_allocation_limit_) { if (amount_since_last_global_gc > external_allocation_limit_) {
CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached"); CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached");
} }
...@@ -573,9 +573,9 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory( ...@@ -573,9 +573,9 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d KB, " PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d KB, "
"amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d KB, " "amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d KB, "
"isolate=0x%08" V8PRIxPTR ".\n", "isolate=0x%08" V8PRIxPTR ".\n",
change_in_bytes / KB, static_cast<intptr_t>(change_in_bytes / KB),
amount_of_external_allocated_memory_ / KB, static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB),
PromotedExternalMemorySize() / KB, static_cast<intptr_t>(PromotedExternalMemorySize() / KB),
reinterpret_cast<intptr_t>(isolate())); reinterpret_cast<intptr_t>(isolate()));
} }
ASSERT(amount_of_external_allocated_memory_ >= 0); ASSERT(amount_of_external_allocated_memory_ >= 0);
......
...@@ -412,7 +412,7 @@ void Heap::PrintShortHeapStatistics() { ...@@ -412,7 +412,7 @@ void Heap::PrintShortHeapStatistics() {
this->Available() / KB, this->Available() / KB,
this->CommittedMemory() / KB); this->CommittedMemory() / KB);
PrintPID("External memory reported: %6" V8_PTR_PREFIX "d KB\n", PrintPID("External memory reported: %6" V8_PTR_PREFIX "d KB\n",
amount_of_external_allocated_memory_ / KB); static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB));
PrintPID("Total time spent in GC : %.1f ms\n", total_gc_time_ms_); PrintPID("Total time spent in GC : %.1f ms\n", total_gc_time_ms_);
} }
...@@ -6591,7 +6591,7 @@ bool Heap::AdvanceSweepers(int step_size) { ...@@ -6591,7 +6591,7 @@ bool Heap::AdvanceSweepers(int step_size) {
} }
intptr_t Heap::PromotedExternalMemorySize() { int64_t Heap::PromotedExternalMemorySize() {
if (amount_of_external_allocated_memory_ if (amount_of_external_allocated_memory_
<= amount_of_external_allocated_memory_at_last_global_gc_) return 0; <= amount_of_external_allocated_memory_at_last_global_gc_) return 0;
return amount_of_external_allocated_memory_ return amount_of_external_allocated_memory_
......
...@@ -1475,8 +1475,8 @@ class Heap { ...@@ -1475,8 +1475,8 @@ class Heap {
// Adjusts the amount of registered external memory. // Adjusts the amount of registered external memory.
// Returns the adjusted value. // Returns the adjusted value.
inline intptr_t AdjustAmountOfExternalAllocatedMemory( inline int64_t AdjustAmountOfExternalAllocatedMemory(
intptr_t change_in_bytes); int64_t change_in_bytes);
// This is only needed for testing high promotion mode. // This is only needed for testing high promotion mode.
void SetNewSpaceHighPromotionModeActive(bool mode) { void SetNewSpaceHighPromotionModeActive(bool mode) {
...@@ -1495,7 +1495,10 @@ class Heap { ...@@ -1495,7 +1495,10 @@ class Heap {
} }
inline intptr_t PromotedTotalSize() { inline intptr_t PromotedTotalSize() {
return PromotedSpaceSizeOfObjects() + PromotedExternalMemorySize(); int64_t total = PromotedSpaceSizeOfObjects() + PromotedExternalMemorySize();
if (total > kMaxInt) return static_cast<intptr_t>(kMaxInt);
if (total < 0) return 0;
return static_cast<intptr_t>(total);
} }
inline intptr_t OldGenerationSpaceAvailable() { inline intptr_t OldGenerationSpaceAvailable() {
...@@ -1906,7 +1909,7 @@ class Heap { ...@@ -1906,7 +1909,7 @@ class Heap {
int gc_post_processing_depth_; int gc_post_processing_depth_;
// Returns the amount of external memory registered since last global gc. // Returns the amount of external memory registered since last global gc.
intptr_t PromotedExternalMemorySize(); int64_t PromotedExternalMemorySize();
unsigned int ms_count_; // how many mark-sweep collections happened unsigned int ms_count_; // how many mark-sweep collections happened
unsigned int gc_count_; // how many gc happened unsigned int gc_count_; // how many gc happened
...@@ -1960,10 +1963,10 @@ class Heap { ...@@ -1960,10 +1963,10 @@ class Heap {
// The amount of external memory registered through the API kept alive // The amount of external memory registered through the API kept alive
// by global handles // by global handles
intptr_t amount_of_external_allocated_memory_; int64_t amount_of_external_allocated_memory_;
// Caches the amount of external memory registered at the last global gc. // Caches the amount of external memory registered at the last global gc.
intptr_t amount_of_external_allocated_memory_at_last_global_gc_; int64_t amount_of_external_allocated_memory_at_last_global_gc_;
// Indicates that an allocation has failed in the old generation since the // Indicates that an allocation has failed in the old generation since the
// last GC. // last GC.
......
...@@ -700,7 +700,7 @@ void Runtime::FreeArrayBuffer(Isolate* isolate, ...@@ -700,7 +700,7 @@ void Runtime::FreeArrayBuffer(Isolate* isolate,
isolate, phantom_array_buffer->byte_length()); isolate, phantom_array_buffer->byte_length());
isolate->heap()->AdjustAmountOfExternalAllocatedMemory( isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
-static_cast<intptr_t>(allocated_length)); -static_cast<int64_t>(allocated_length));
CHECK(V8::ArrayBufferAllocator() != NULL); CHECK(V8::ArrayBufferAllocator() != NULL);
V8::ArrayBufferAllocator()->Free( V8::ArrayBufferAllocator()->Free(
phantom_array_buffer->backing_store(), phantom_array_buffer->backing_store(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment