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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 180113009: Pretenure large external typed data and strings. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
===================================================================
--- runtime/vm/dart_api_impl.cc (revision 33338)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -80,6 +80,18 @@
}
+Heap::Space SpaceForExternal(Isolate* isolate, intptr_t size) {
+ Heap* heap = isolate->heap();
+ // If 'size' would be a significant fraction of new space, then use old.
+ static const int kExtNewRatio = 16;
+ if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) {
+ return Heap::kOld;
+ } else {
+ return Heap::kNew;
+ }
+}
+
+
Dart_Handle Api::InitNewHandle(Isolate* isolate, RawObject* raw) {
LocalHandles* local_handles = Api::TopScope(isolate)->local_handles();
ASSERT(local_handles != NULL);
@@ -1799,7 +1811,11 @@
CHECK_LENGTH(length, String::kMaxElements);
CHECK_CALLBACK_STATE(isolate);
return Api::NewHandle(isolate,
- String::NewExternal(latin1_array, length, peer, cback));
+ String::NewExternal(latin1_array,
+ length,
+ peer,
+ cback,
+ SpaceForExternal(isolate, length)));
}
@@ -1814,8 +1830,13 @@
}
CHECK_LENGTH(length, String::kMaxElements);
CHECK_CALLBACK_STATE(isolate);
+ intptr_t bytes = length * sizeof(*utf16_array);
return Api::NewHandle(isolate,
- String::NewExternal(utf16_array, length, peer, cback));
+ String::NewExternal(utf16_array,
+ length,
+ peer,
+ cback,
+ SpaceForExternal(isolate, bytes)));
}
@@ -2661,9 +2682,13 @@
static Dart_Handle NewExternalTypedData(
Isolate* isolate, intptr_t cid, void* data, intptr_t length) {
CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid));
+ intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid);
const ExternalTypedData& result = ExternalTypedData::Handle(
isolate,
- ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), length));
+ ExternalTypedData::New(cid,
+ reinterpret_cast<uint8_t*>(data),
+ length,
+ SpaceForExternal(isolate, bytes)));
return Api::NewHandle(isolate, result.raw());
}
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698