diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 17:42:45 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 17:42:45 +0000 |
commit | 43a9e24a52fa867db98fc2195b8db85b4729e7a1 (patch) | |
tree | cad7a14c415542083ac3d1ecc2df1fd86f789557 /courgette/assembly_program.h | |
parent | 6768ac0b06ae36ec7b2d27adfb9b64fc17f57cee (diff) | |
download | chromium_src-43a9e24a52fa867db98fc2195b8db85b4729e7a1.zip chromium_src-43a9e24a52fa867db98fc2195b8db85b4729e7a1.tar.gz chromium_src-43a9e24a52fa867db98fc2195b8db85b4729e7a1.tar.bz2 |
Switch out use of std::string and std::vector for large allocations for a buffer class that doesn't throw exceptions.
The new buffer class is pretty simple and relies on the MemoryAllocator class that I previously to back large
allocations with mapped files when memory is scarce. That reduced the number of crashes quite a bit but we
still crash on machines that are simply out of diskspace as well. So, the right thing to do is to expect and
handle failures which is what this cl is all about. What we should see once this has landed is that crash
dumps due to courgette running out of disk space should disappear from crash/ and instead we should see the
number of users that run into this particular problem in dashboards.
TEST=Courgette out-of-memory/out-of-diskspace errors should disappear from crash/
BUG=74777
Review URL: http://codereview.chromium.org/6677141
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80648 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/assembly_program.h')
-rw-r--r-- | courgette/assembly_program.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/courgette/assembly_program.h b/courgette/assembly_program.h index f7429201..0d865f5 100644 --- a/courgette/assembly_program.h +++ b/courgette/assembly_program.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" #include "courgette/image_info.h" #include "courgette/memory_allocator.h" @@ -19,8 +20,7 @@ namespace courgette { class EncodedProgram; class Instruction; -typedef std::vector<Instruction*, MemoryAllocator<Instruction*> > - InstructionVector; +typedef NoThrowBuffer<Instruction*> InstructionVector; // A Label is a symbolic reference to an address. Unlike a conventional // assembly language, we always know the address. The address will later be @@ -34,7 +34,7 @@ class Label { Label() : rva_(0), index_(kNoIndex) {} explicit Label(RVA rva) : rva_(rva), index_(kNoIndex) {} - RVA rva_; // Address refered to by the label. + RVA rva_; // Address referred to by the label. int index_; // Index of address in address table, kNoIndex until assigned. }; @@ -69,21 +69,24 @@ class AssemblyProgram { // Instructions will be assembled in the order they are emitted. // Generates an entire base relocation table. - void EmitMakeRelocsInstruction(); + CheckBool EmitMakeRelocsInstruction() WARN_UNUSED_RESULT; // Following instruction will be assembled at address 'rva'. - void EmitOriginInstruction(RVA rva); + CheckBool EmitOriginInstruction(RVA rva) WARN_UNUSED_RESULT; // Generates a single byte of data or machine instruction. - void EmitByteInstruction(uint8 byte); + CheckBool EmitByteInstruction(uint8 byte) WARN_UNUSED_RESULT; // Generates 4-byte relative reference to address of 'label'. - void EmitRel32(Label* label); + CheckBool EmitRel32(Label* label) WARN_UNUSED_RESULT; // Generates 4-byte absolute reference to address of 'label'. - void EmitAbs32(Label* label); + CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT; + // Looks up a label or creates a new one. Might return NULL. Label* FindOrMakeAbs32Label(RVA rva); + + // Looks up a label or creates a new one. Might return NULL. Label* FindOrMakeRel32Label(RVA rva); void DefaultAssignIndexes(); @@ -106,8 +109,9 @@ class AssemblyProgram { Label* InstructionRel32Label(const Instruction* instruction) const; private: - void Emit(Instruction* instruction) { instructions_.push_back(instruction); } + CheckBool Emit(Instruction* instruction) WARN_UNUSED_RESULT; + // Looks up a label or creates a new one. Might return NULL. Label* FindLabel(RVA rva, RVAToLabel* labels); // Helper methods for the public versions. @@ -117,7 +121,7 @@ class AssemblyProgram { // Sharing instructions that emit a single byte saves a lot of space. Instruction* GetByteInstruction(uint8 byte); - Instruction** byte_instruction_cache_; + scoped_array<Instruction*> byte_instruction_cache_; uint64 image_base_; // Desired or mandated base address of image. |