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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10836061: Change the zone allocation api. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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/vm/dart_api_impl.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 10253)
+++ runtime/vm/dart_api_impl.cc (working copy)
@@ -176,7 +176,7 @@
const Error& err = Error::Handle(isolate->object_store()->sticky_error());
const char* errmsg = err.ToErrorCString();
intptr_t errlen = strlen(errmsg) + 1;
- char* msg = reinterpret_cast<char*>(Api::Allocate(isolate, errlen));
+ char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen);
OS::SNPrint(msg, errlen, "%s", errmsg);
return msg;
}
@@ -189,12 +189,7 @@
Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) {
- ASSERT(isolate != NULL);
- ApiState* state = isolate->api_state();
- ASSERT(state != NULL);
- ApiLocalScope* scope = state->top_scope();
- ASSERT(scope != NULL);
- LocalHandles* local_handles = scope->local_handles();
+ LocalHandles* local_handles = Api::TopScope(isolate)->local_handles();
ASSERT(local_handles != NULL);
LocalHandle* ref = local_handles->AllocateHandle();
ref->set_raw(raw);
@@ -284,7 +279,7 @@
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
+ char* buffer = zone.Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -322,29 +317,16 @@
}
-uword Api::Allocate(Isolate* isolate, intptr_t size) {
+ApiLocalScope* Api::TopScope(Isolate* isolate) {
ASSERT(isolate != NULL);
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
ApiLocalScope* scope = state->top_scope();
ASSERT(scope != NULL);
- return scope->zone()->Allocate(size);
+ return scope;
}
-uword Api::Reallocate(Isolate* isolate,
- uword ptr,
- intptr_t old_size,
- intptr_t new_size) {
- ASSERT(isolate != NULL);
- ApiState* state = isolate->api_state();
- ASSERT(state != NULL);
- ApiLocalScope* scope = state->top_scope();
- ASSERT(scope != NULL);
- return scope->zone()->Reallocate(ptr, old_size, new_size);
-}
-
-
void Api::InitOnce() {
ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey);
api_native_key_ = Thread::CreateThreadLocal();
@@ -388,7 +370,7 @@
const Error& error = Error::Cast(obj);
const char* str = error.ToErrorCString();
intptr_t len = strlen(str) + 1;
- char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len));
+ char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len);
strncpy(str_copy, str, len);
// Strip a possible trailing '\n'.
if ((len > 1) && (str_copy[len - 2] == '\n')) {
@@ -450,7 +432,7 @@
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
+ char* buffer = zone.Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -472,7 +454,7 @@
intptr_t len = OS::VSNPrint(NULL, 0, format, args);
va_end(args);
- char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
+ char* buffer = zone.Alloc<char>(len + 1);
va_list args2;
va_start(args2, format);
OS::VSNPrint(buffer, (len + 1), format, args2);
@@ -891,11 +873,8 @@
static uint8_t* ApiReallocate(uint8_t* ptr,
intptr_t old_size,
intptr_t new_size) {
- uword new_ptr = Api::Reallocate(Isolate::Current(),
- reinterpret_cast<uword>(ptr),
- old_size,
- new_size);
- return reinterpret_cast<uint8_t*>(new_ptr);
+ return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>(
+ ptr, old_size, new_size);
}
@@ -1195,7 +1174,7 @@
if (scope == NULL) return NULL;
zone = scope->zone();
}
- return reinterpret_cast<uint8_t*>(zone->Allocate(size));
+ return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size));
}
@@ -1448,8 +1427,8 @@
}
-static uword ApiAllocate(intptr_t size) {
- return Api::Allocate(Isolate::Current(), size);
+static uword BigintAllocate(intptr_t size) {
+ return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size);
}
@@ -1464,9 +1443,10 @@
if (int_obj.IsSmi() || int_obj.IsMint()) {
const Bigint& bigint = Bigint::Handle(isolate,
BigintOperations::NewFromInt64(int_obj.AsInt64Value()));
- *value = BigintOperations::ToHexCString(bigint, ApiAllocate);
+ *value = BigintOperations::ToHexCString(bigint, BigintAllocate);
} else {
- *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), ApiAllocate);
+ *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj),
+ BigintAllocate);
}
return Api::Success(isolate);
}
@@ -1762,8 +1742,7 @@
RETURN_TYPE_ERROR(isolate, object, String);
}
intptr_t string_length = Utf8::Length(str_obj);
- char* res =
- reinterpret_cast<char*>(Api::Allocate(isolate, string_length + 1));
+ char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1);
if (res == NULL) {
return Api::NewError("Unable to allocate memory");
}
@@ -1792,7 +1771,7 @@
}
const char* cstring = str.ToCString();
*length = Utf8::Length(str);
- uint8_t* result = reinterpret_cast<uint8_t*>(Api::Allocate(isolate, *length));
+ uint8_t* result = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(*length);
if (result == NULL) {
return Api::NewError("Unable to allocate memory");
}
@@ -4185,7 +4164,8 @@
pprof_symbol_generator->WriteToMemory(debug_region);
*buffer_size = debug_region->size();
if (*buffer_size != 0) {
- *buffer = reinterpret_cast<void*>(Api::Allocate(isolate, *buffer_size));
+ ApiZone* zone = Api::TopScope(isolate)->zone();
+ *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size));
memmove(*buffer, debug_region->data(), *buffer_size);
} else {
*buffer = NULL;
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698