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

Unified Diff: runtime/vm/object.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, 5 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
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 10080)
+++ runtime/vm/object.cc (working copy)
@@ -2196,8 +2196,7 @@
const char* library_name = lib.IsNull() ? "" : lib.ToCString();
const char* class_name = String::Handle(Name()).ToCString();
intptr_t len = OS::SNPrint(NULL, 0, format, library_name, class_name) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, library_name, class_name);
return chars;
}
@@ -2926,8 +2925,7 @@
const char* class_name =
String::Handle(Class::Handle(type_class()).Name()).ToCString();
intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, class_name);
return chars;
} else {
@@ -2937,8 +2935,7 @@
const char* args_cstr =
AbstractTypeArguments::Handle(arguments()).ToCString();
intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, class_name, args_cstr);
return chars;
}
@@ -3084,8 +3081,7 @@
const char* format = "TypeParameter: name %s; index: %d";
const char* name_cstr = String::Handle(Name()).ToCString();
intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, index()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, name_cstr, index());
return chars;
}
@@ -3540,8 +3536,7 @@
const AbstractType& type_at = AbstractType::Handle(TypeAt(i));
const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString();
intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, prev_cstr, type_cstr);
prev_cstr = chars;
}
@@ -3620,8 +3615,7 @@
AbstractTypeArguments::Handle(instantiator_type_arguments()).ToCString();
intptr_t len =
OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr);
return chars;
}
@@ -3928,8 +3922,7 @@
reserve_len +=
OS::SNPrint(NULL, 0, lib_class_format, library_name, class_name);
ASSERT(chars != NULL);
- *chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(reserve_len + 1));
+ *chars = Isolate::Current()->current_zone()->Alloc<char>(reserve_len + 1);
written = OS::SNPrint(
*chars, reserve_len, lib_class_format, library_name, class_name);
} else {
@@ -4389,8 +4382,7 @@
const char* kFormat = "Function '%s':%s%s%s.";
const char* function_name = String::Handle(name()).ToCString();
intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, f0, f1, f2) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, function_name, f0, f1, f2);
return chars;
}
@@ -4515,8 +4507,7 @@
const char* cls_name = String::Handle(cls.Name()).ToCString();
intptr_t len =
OS::SNPrint(NULL, 0, kFormat, cls_name, field_name, kF0, kF1, kF2) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, cls_name, field_name, kF0, kF1, kF2);
return chars;
}
@@ -6267,8 +6258,7 @@
const char* kFormat = "Library:'%s'";
const String& name = String::Handle(url());
intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, name.ToCString());
return chars;
}
@@ -6362,8 +6352,7 @@
const char* kFormat = "LibraryPrefix:'%s'";
const String& prefix = String::Handle(name());
intptr_t len = OS::SNPrint(NULL, 0, kFormat, prefix.ToCString()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, prefix.ToCString());
return chars;
}
@@ -6593,8 +6582,7 @@
PC(i), KindAsStr(i), NodeId(i), TryIndex(i), TokenIndex(i));
}
// Allocate the buffer.
- char* buffer = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
// Layout the fields in the buffer.
intptr_t index = 0;
for (intptr_t i = 0; i < Length(); i++) {
@@ -6711,12 +6699,16 @@
if (IsNull()) {
return "{null}";
} else {
+ // Guard against integer overflow, though it is highly unlikely.
+ if (MaximumBitIndex() > kIntptrMax / 4) {
+ FATAL1("MaximumBitIndex() is unexpectedly large (%ld)",
+ MaximumBitIndex());
+ }
intptr_t index = OS::SNPrint(NULL, 0, "0x%lx { ", PC());
intptr_t alloc_size =
index + ((MaximumBitIndex() + 1) * 2) + 2; // "{ 1 0 .... }".
Isolate* isolate = Isolate::Current();
- char* chars = reinterpret_cast<char*>(
- isolate->current_zone()->Allocate(alloc_size));
+ char* chars = isolate->current_zone()->Alloc<char>(alloc_size);
index = OS::SNPrint(chars, alloc_size, "0x%lx { ", PC());
for (intptr_t i = 0; i <= MaximumBitIndex(); i++) {
index += OS::SNPrint((chars + index),
@@ -6846,8 +6838,7 @@
TryIndex(i), HandlerPC(i));
}
// Allocate the buffer.
- char* buffer = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
// Layout the fields in the buffer.
intptr_t index = 0;
for (intptr_t i = 0; i < Length(); i++) {
@@ -6958,8 +6949,7 @@
uword addr = instrs.EntryPoint();
uword size = instrs.size();
intptr_t len = OS::SNPrint(NULL, 0, format, addr, size, name);
- char* buffer = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
OS::SNPrint(buffer, len + 1, format, addr, size, name);
(*perf_events_writer)(buffer, len);
}
@@ -6982,8 +6972,7 @@
// <name> for rest of the code (first instruction is prolog sequence).
const char* kFormat = "%s_%s";
intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry");
- char* pname = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* pname = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
DebugInfo::RegisterSection(pname, instrs.EntryPoint(), prolog_offset);
DebugInfo::RegisterSection(name,
@@ -7079,8 +7068,7 @@
const char* Code::ToCString() const {
const char* kFormat = "Code entry:0x%d";
intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint());
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, EntryPoint());
return chars;
}
@@ -7270,8 +7258,7 @@
const char* kFormat = "ICData target:%s";
const String& name = String::Handle(target_name());
intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, name.ToCString());
return chars;
}
@@ -7691,7 +7678,7 @@
int len = (strlen(exc_str) + strlen(stack_str) + strlen(format)
- 4 // Two '%s'
+ 1); // '\0'
- char* chars = reinterpret_cast<char*>(isolate->current_zone()->Allocate(len));
+ char* chars = isolate->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, exc_str, stack_str);
return chars;
}
@@ -7975,8 +7962,7 @@
const String& type_name = String::Handle(type.Name());
// Calculate the size of the string.
intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, type_name.ToCString());
return chars;
}
@@ -8100,8 +8086,7 @@
const char* kFormat = "%ld";
// Calculate the size of the string.
intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, Value());
return chars;
}
@@ -8215,8 +8200,7 @@
const char* kFormat = "%lld";
// Calculate the size of the string.
intptr_t len = OS::SNPrint(NULL, 0, kFormat, value()) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, kFormat, value());
return chars;
}
@@ -8336,8 +8320,7 @@
return value() < 0 ? "-Infinity" : "Infinity";
}
const int kBufferSize = 128;
- char* buffer = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(kBufferSize));
+ char* buffer = Isolate::Current()->current_zone()->Alloc<char>(kBufferSize);
buffer[kBufferSize - 1] = '\0';
DoubleToCString(value(), buffer, kBufferSize);
return buffer;
@@ -8424,14 +8407,14 @@
}
-static uword ZoneAllocator(intptr_t size) {
+static uword BigintAllocator(intptr_t size) {
Zone* zone = Isolate::Current()->current_zone();
- return zone->Allocate(size);
+ return zone->AllocUnsafe(size);
}
const char* Bigint::ToCString() const {
- return BigintOperations::ToDecimalCString(*this, &ZoneAllocator);
+ return BigintOperations::ToDecimalCString(*this, &BigintAllocator);
}
@@ -8928,7 +8911,7 @@
va_end(args);
Zone* zone = Isolate::Current()->current_zone();
- 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);
@@ -9033,7 +9016,7 @@
const char* String::ToCString() const {
intptr_t len = Utf8::Length(*this);
Zone* zone = Isolate::Current()->current_zone();
- char* result = reinterpret_cast<char*>(zone->Allocate(len + 1));
+ char* result = zone->Alloc<char>(len + 1);
Utf8::Encode(*this, result, len);
result[len] = 0;
return result;
@@ -10597,8 +10580,7 @@
const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
const char* format = "Closure: %s%s%s";
intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
OS::SNPrint(chars, len, format, fun_sig, from, fun_desc);
return chars;
}
@@ -10751,8 +10733,7 @@
line, column,
code.EntryPoint());
total_len += len;
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
OS::SNPrint(chars, (len + 1), kFormat,
i,
class_name.ToCString(),
@@ -10765,8 +10746,7 @@
}
// Now concatentate the frame descriptions into a single C string.
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(total_len + 1));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(total_len + 1);
intptr_t index = 0;
for (intptr_t i = 0; i < frame_strings.length(); i++) {
index += OS::SNPrint((chars + index),
@@ -10871,8 +10851,7 @@
const String& str = String::Handle(pattern());
const char* format = "JSRegExp: pattern=%s flags=%s";
intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
- char* chars = reinterpret_cast<char*>(
- Isolate::Current()->current_zone()->Allocate(len + 1));
+ char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
return chars;
}

Powered by Google App Engine
This is Rietveld 408576698