Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 return isolate->heap()->undefined_value(); | 651 return isolate->heap()->undefined_value(); |
| 652 } | 652 } |
| 653 | 653 |
| 654 | 654 |
| 655 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, | 655 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, |
| 656 Persistent<Value>* object, | 656 Persistent<Value>* object, |
| 657 void* data) { | 657 void* data) { |
| 658 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); | 658 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); |
| 659 HandleScope scope(isolate); | 659 HandleScope scope(isolate); |
| 660 Handle<Object> internal_object = Utils::OpenHandle(**object); | 660 Handle<Object> internal_object = Utils::OpenHandle(**object); |
| 661 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object)); | |
| 661 | 662 |
| 662 size_t allocated_length = NumberToSize( | 663 if (!array_buffer->is_external()) { |
| 663 isolate, JSArrayBuffer::cast(*internal_object)->byte_length()); | 664 size_t allocated_length = NumberToSize( |
| 664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( | 665 isolate, array_buffer->byte_length()); |
| 665 -static_cast<intptr_t>(allocated_length)); | 666 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 666 if (data != NULL) | 667 -static_cast<intptr_t>(allocated_length)); |
| 667 free(data); | 668 if (data != NULL) |
|
Sven Panne
2013/05/23 07:57:01
No need for this guard here, either.
Dmitry Lomov (no reviews)
2013/05/23 08:42:15
Done.
| |
| 669 free(data); | |
| 670 } | |
| 668 object->Dispose(external_isolate); | 671 object->Dispose(external_isolate); |
| 669 } | 672 } |
| 670 | 673 |
| 671 | 674 |
| 672 bool Runtime::SetupArrayBuffer(Isolate* isolate, | 675 void Runtime::SetupArrayBuffer(Isolate* isolate, |
| 673 Handle<JSArrayBuffer> array_buffer, | 676 Handle<JSArrayBuffer> array_buffer, |
| 677 bool is_external, | |
| 674 void* data, | 678 void* data, |
| 675 size_t allocated_length) { | 679 size_t allocated_length) { |
| 680 ASSERT(array_buffer->GetInternalFieldCount() == | |
| 681 v8::ArrayBuffer::kInternalFieldCount); | |
| 682 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { | |
| 683 array_buffer->SetInternalField(i, Smi::FromInt(0)); | |
| 684 } | |
| 676 array_buffer->set_backing_store(data); | 685 array_buffer->set_backing_store(data); |
| 686 array_buffer->set_flag(Smi::FromInt(0)); | |
| 687 array_buffer->set_is_external(is_external); | |
| 677 | 688 |
| 678 Handle<Object> byte_length = | 689 Handle<Object> byte_length = |
| 679 isolate->factory()->NewNumberFromSize(allocated_length); | 690 isolate->factory()->NewNumberFromSize(allocated_length); |
| 680 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); | 691 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); |
| 681 array_buffer->set_byte_length(*byte_length); | 692 array_buffer->set_byte_length(*byte_length); |
| 682 return true; | |
| 683 } | 693 } |
| 684 | 694 |
| 685 | 695 |
| 686 bool Runtime::SetupArrayBufferAllocatingData( | 696 bool Runtime::SetupArrayBufferAllocatingData( |
| 687 Isolate* isolate, | 697 Isolate* isolate, |
| 688 Handle<JSArrayBuffer> array_buffer, | 698 Handle<JSArrayBuffer> array_buffer, |
| 689 size_t allocated_length) { | 699 size_t allocated_length) { |
| 690 void* data; | 700 void* data; |
| 691 if (allocated_length != 0) { | 701 if (allocated_length != 0) { |
| 692 data = malloc(allocated_length); | 702 data = malloc(allocated_length); |
| 693 if (data == NULL) return false; | 703 if (data == NULL) return false; |
| 694 memset(data, 0, allocated_length); | 704 memset(data, 0, allocated_length); |
| 695 } else { | 705 } else { |
| 696 data = NULL; | 706 data = NULL; |
| 697 } | 707 } |
| 698 | 708 |
| 699 if (!SetupArrayBuffer(isolate, array_buffer, data, allocated_length)) | 709 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
| 700 return false; | |
| 701 | 710 |
| 702 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 711 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 703 v8::Persistent<v8::Value> weak_handle = v8::Persistent<v8::Value>::New( | 712 v8::Persistent<v8::Value> weak_handle = v8::Persistent<v8::Value>::New( |
| 704 external_isolate, v8::Utils::ToLocal(Handle<Object>::cast(array_buffer))); | 713 external_isolate, v8::Utils::ToLocal(Handle<Object>::cast(array_buffer))); |
| 705 weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); | 714 weak_handle.MakeWeak(external_isolate, data, ArrayBufferWeakCallback); |
| 706 weak_handle.MarkIndependent(external_isolate); | 715 weak_handle.MarkIndependent(external_isolate); |
| 707 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 716 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
| 708 | 717 |
| 709 return true; | 718 return true; |
| 710 } | 719 } |
| (...skipping 12784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13495 // Handle last resort GC and make sure to allow future allocations | 13504 // Handle last resort GC and make sure to allow future allocations |
| 13496 // to grow the heap without causing GCs (if possible). | 13505 // to grow the heap without causing GCs (if possible). |
| 13497 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13506 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13498 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13507 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13499 "Runtime::PerformGC"); | 13508 "Runtime::PerformGC"); |
| 13500 } | 13509 } |
| 13501 } | 13510 } |
| 13502 | 13511 |
| 13503 | 13512 |
| 13504 } } // namespace v8::internal | 13513 } } // namespace v8::internal |
| OLD | NEW |