| 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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 643 |
| 644 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) { | 644 RUNTIME_FUNCTION(MaybeObject*, Runtime_Fix) { |
| 645 SealHandleScope shs(isolate); | 645 SealHandleScope shs(isolate); |
| 646 ASSERT(args.length() == 1); | 646 ASSERT(args.length() == 1); |
| 647 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); | 647 CONVERT_ARG_CHECKED(JSProxy, proxy, 0); |
| 648 proxy->Fix(); | 648 proxy->Fix(); |
| 649 return isolate->heap()->undefined_value(); | 649 return isolate->heap()->undefined_value(); |
| 650 } | 650 } |
| 651 | 651 |
| 652 | 652 |
| 653 static void ArrayBufferWeakCallback(v8::Isolate* external_isolate, | 653 void Runtime::FreeArrayBuffer(Isolate* isolate, |
| 654 Persistent<Value>* object, | 654 JSArrayBuffer* phantom_array_buffer) { |
| 655 void* data) { | 655 if (phantom_array_buffer->is_external()) return; |
| 656 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); | |
| 657 HandleScope scope(isolate); | |
| 658 Handle<Object> internal_object = Utils::OpenPersistent(object); | |
| 659 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object)); | |
| 660 | 656 |
| 661 if (!array_buffer->is_external()) { | 657 size_t allocated_length = NumberToSize( |
| 662 size_t allocated_length = NumberToSize( | 658 isolate, phantom_array_buffer->byte_length()); |
| 663 isolate, array_buffer->byte_length()); | 659 |
| 664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( | 660 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( |
| 665 -static_cast<intptr_t>(allocated_length)); | 661 -static_cast<intptr_t>(allocated_length)); |
| 666 CHECK(V8::ArrayBufferAllocator() != NULL); | 662 CHECK(V8::ArrayBufferAllocator() != NULL); |
| 667 V8::ArrayBufferAllocator()->Free(data); | 663 V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store()); |
| 668 } | |
| 669 object->Dispose(external_isolate); | |
| 670 } | 664 } |
| 671 | 665 |
| 672 | 666 |
| 673 void Runtime::SetupArrayBuffer(Isolate* isolate, | 667 void Runtime::SetupArrayBuffer(Isolate* isolate, |
| 674 Handle<JSArrayBuffer> array_buffer, | 668 Handle<JSArrayBuffer> array_buffer, |
| 675 bool is_external, | 669 bool is_external, |
| 676 void* data, | 670 void* data, |
| 677 size_t allocated_length) { | 671 size_t allocated_length) { |
| 678 ASSERT(array_buffer->GetInternalFieldCount() == | 672 ASSERT(array_buffer->GetInternalFieldCount() == |
| 679 v8::ArrayBuffer::kInternalFieldCount); | 673 v8::ArrayBuffer::kInternalFieldCount); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 704 if (allocated_length != 0) { | 698 if (allocated_length != 0) { |
| 705 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); | 699 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); |
| 706 if (data == NULL) return false; | 700 if (data == NULL) return false; |
| 707 memset(data, 0, allocated_length); | 701 memset(data, 0, allocated_length); |
| 708 } else { | 702 } else { |
| 709 data = NULL; | 703 data = NULL; |
| 710 } | 704 } |
| 711 | 705 |
| 712 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); | 706 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); |
| 713 | 707 |
| 714 Handle<Object> persistent = isolate->global_handles()->Create(*array_buffer); | |
| 715 GlobalHandles::MakeWeak(persistent.location(), data, ArrayBufferWeakCallback); | |
| 716 GlobalHandles::MarkIndependent(persistent.location()); | |
| 717 | |
| 718 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); | 708 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); |
| 719 | 709 |
| 720 return true; | 710 return true; |
| 721 } | 711 } |
| 722 | 712 |
| 723 | 713 |
| 724 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { | 714 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { |
| 725 HandleScope scope(isolate); | 715 HandleScope scope(isolate); |
| 726 ASSERT(args.length() == 2); | 716 ASSERT(args.length() == 2); |
| 727 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); | 717 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); |
| (...skipping 12906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13634 // Handle last resort GC and make sure to allow future allocations | 13624 // Handle last resort GC and make sure to allow future allocations |
| 13635 // to grow the heap without causing GCs (if possible). | 13625 // to grow the heap without causing GCs (if possible). |
| 13636 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13626 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13637 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13627 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13638 "Runtime::PerformGC"); | 13628 "Runtime::PerformGC"); |
| 13639 } | 13629 } |
| 13640 } | 13630 } |
| 13641 | 13631 |
| 13642 | 13632 |
| 13643 } } // namespace v8::internal | 13633 } } // namespace v8::internal |
| OLD | NEW |