Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/runtime.cc

Issue 15855012: Change ArrayBuffer API and implementation to use embedder-provided allocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/d8.cc ('k') | src/v8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate); 656 Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate);
657 HandleScope scope(isolate); 657 HandleScope scope(isolate);
658 Handle<Object> internal_object = Utils::OpenHandle(**object); 658 Handle<Object> internal_object = Utils::OpenHandle(**object);
659 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object)); 659 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(*internal_object));
660 660
661 if (!array_buffer->is_external()) { 661 if (!array_buffer->is_external()) {
662 size_t allocated_length = NumberToSize( 662 size_t allocated_length = NumberToSize(
663 isolate, array_buffer->byte_length()); 663 isolate, array_buffer->byte_length());
664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory( 664 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
665 -static_cast<intptr_t>(allocated_length)); 665 -static_cast<intptr_t>(allocated_length));
666 free(data); 666 CHECK(V8::ArrayBufferAllocator() != NULL);
667 V8::ArrayBufferAllocator()->Free(data);
667 } 668 }
668 object->Dispose(external_isolate); 669 object->Dispose(external_isolate);
669 } 670 }
670 671
671 672
672 void Runtime::SetupArrayBuffer(Isolate* isolate, 673 void Runtime::SetupArrayBuffer(Isolate* isolate,
673 Handle<JSArrayBuffer> array_buffer, 674 Handle<JSArrayBuffer> array_buffer,
674 bool is_external, 675 bool is_external,
675 void* data, 676 void* data,
676 size_t allocated_length) { 677 size_t allocated_length) {
(...skipping 15 matching lines...) Expand all
692 isolate->heap()->set_array_buffers_list(*array_buffer); 693 isolate->heap()->set_array_buffers_list(*array_buffer);
693 array_buffer->set_weak_first_array(Smi::FromInt(0)); 694 array_buffer->set_weak_first_array(Smi::FromInt(0));
694 } 695 }
695 696
696 697
697 bool Runtime::SetupArrayBufferAllocatingData( 698 bool Runtime::SetupArrayBufferAllocatingData(
698 Isolate* isolate, 699 Isolate* isolate,
699 Handle<JSArrayBuffer> array_buffer, 700 Handle<JSArrayBuffer> array_buffer,
700 size_t allocated_length) { 701 size_t allocated_length) {
701 void* data; 702 void* data;
703 CHECK(V8::ArrayBufferAllocator() != NULL);
702 if (allocated_length != 0) { 704 if (allocated_length != 0) {
703 data = malloc(allocated_length); 705 data = V8::ArrayBufferAllocator()->Allocate(allocated_length);
704 if (data == NULL) return false; 706 if (data == NULL) return false;
705 memset(data, 0, allocated_length); 707 memset(data, 0, allocated_length);
706 } else { 708 } else {
707 data = NULL; 709 data = NULL;
708 } 710 }
709 711
710 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 712 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
711 713
712 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate); 714 v8::Isolate* external_isolate = reinterpret_cast<v8::Isolate*>(isolate);
713 v8::Persistent<v8::Value> weak_handle( 715 v8::Persistent<v8::Value> weak_handle(
(...skipping 12919 matching lines...) Expand 10 before | Expand all | Expand 10 after
13633 // Handle last resort GC and make sure to allow future allocations 13635 // Handle last resort GC and make sure to allow future allocations
13634 // to grow the heap without causing GCs (if possible). 13636 // to grow the heap without causing GCs (if possible).
13635 isolate->counters()->gc_last_resort_from_js()->Increment(); 13637 isolate->counters()->gc_last_resort_from_js()->Increment();
13636 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13638 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13637 "Runtime::PerformGC"); 13639 "Runtime::PerformGC");
13638 } 13640 }
13639 } 13641 }
13640 13642
13641 13643
13642 } } // namespace v8::internal 13644 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | src/v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698