mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Make fatal out of memory messages uniform.
Add checks in a few more places with large allocations. R=fschneider@google.com Review URL: https://codereview.chromium.org/2418323002 .
This commit is contained in:
parent
c9c33d9db3
commit
61bf8abd75
|
@ -254,6 +254,9 @@ T DynamicAssertionHelper::NotNull(const T p) {
|
|||
#define UNREACHABLE() \
|
||||
FATAL("unreachable code")
|
||||
|
||||
#define OUT_OF_MEMORY() \
|
||||
FATAL("Out of memory.")
|
||||
|
||||
|
||||
#if defined(DEBUG)
|
||||
// DEBUG binaries use assertions in the code.
|
||||
|
|
|
@ -166,9 +166,7 @@ void HashMap::Initialize(uint32_t capacity) {
|
|||
ASSERT(dart::Utils::IsPowerOfTwo(capacity));
|
||||
map_ = new Entry[capacity];
|
||||
if (map_ == NULL) {
|
||||
// TODO(sgjesse): Handle out of memory.
|
||||
FATAL("Cannot allocate memory for hashmap");
|
||||
return;
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
capacity_ = capacity;
|
||||
occupancy_ = 0;
|
||||
|
|
|
@ -15,6 +15,9 @@ namespace dart {
|
|||
TextBuffer::TextBuffer(intptr_t buf_size) {
|
||||
ASSERT(buf_size > 0);
|
||||
buf_ = reinterpret_cast<char*>(malloc(buf_size));
|
||||
if (buf_ == NULL) {
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
buf_size_ = buf_size;
|
||||
Clear();
|
||||
}
|
||||
|
@ -152,7 +155,9 @@ void TextBuffer::EnsureCapacity(intptr_t len) {
|
|||
// the debugger front-end.
|
||||
intptr_t new_size = buf_size_ + len + kBufferSpareCapacity;
|
||||
char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
|
||||
ASSERT(new_buf != NULL);
|
||||
if (new_buf == NULL) {
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
buf_ = new_buf;
|
||||
buf_size_ = new_size;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ static RawObject* AllocateUninitialized(PageSpace* old_space, intptr_t size) {
|
|||
uword address = old_space->TryAllocateDataBumpLocked(size,
|
||||
PageSpace::kForceGrowth);
|
||||
if (address == 0) {
|
||||
FATAL("Out of memory");
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
return reinterpret_cast<RawObject*>(address + kHeapObjectTag);
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ Scavenger::Scavenger(Heap* heap,
|
|||
(FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor);
|
||||
to_ = SemiSpace::New(initial_semi_capacity_in_words);
|
||||
if (to_ == NULL) {
|
||||
FATAL("Out of memory.\n");
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
// Setup local fields.
|
||||
top_ = FirstObjectStart();
|
||||
|
@ -393,7 +393,7 @@ SemiSpace* Scavenger::Prologue(Isolate* isolate, bool invoke_api_callbacks) {
|
|||
if (to_ == NULL) {
|
||||
// TODO(koda): We could try to recover (collect old space, wait for another
|
||||
// isolate to finish scavenge, etc.).
|
||||
FATAL("Out of memory.\n");
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
UpdateMaxHeapCapacity();
|
||||
top_ = FirstObjectStart();
|
||||
|
|
|
@ -222,6 +222,9 @@ RawObject* Service::RequestAssets() {
|
|||
|
||||
static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
|
||||
void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
|
||||
if (new_ptr == NULL) {
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
return reinterpret_cast<uint8_t*>(new_ptr);
|
||||
}
|
||||
|
||||
|
@ -1038,6 +1041,9 @@ void Service::SendEventWithData(const char* stream_id,
|
|||
const intptr_t total_bytes = sizeof(uint64_t) + metadata_size + data_size;
|
||||
|
||||
uint8_t* message = static_cast<uint8_t*>(malloc(total_bytes));
|
||||
if (message == NULL) {
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
intptr_t offset = 0;
|
||||
|
||||
// Metadata size.
|
||||
|
|
|
@ -59,7 +59,7 @@ Zone::Segment* Zone::Segment::New(intptr_t size, Zone::Segment* next) {
|
|||
ASSERT(size >= 0);
|
||||
Segment* result = reinterpret_cast<Segment*>(malloc(size));
|
||||
if (result == NULL) {
|
||||
FATAL("Out of memory.\n");
|
||||
OUT_OF_MEMORY();
|
||||
}
|
||||
ASSERT(Utils::IsAligned(result->start(), Zone::kAlignment));
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Reference in a new issue