summaryrefslogtreecommitdiff
path: root/compiler/utils/assembler.h
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2016-04-20 14:39:47 +0100
committer Vladimir Marko <vmarko@google.com> 2016-04-20 14:39:47 +0100
commit9152fed693f5d823ef29c373d658adc67fa92fe7 (patch)
treeef0ec2b7332db9e0361d61dcb588518103636a5e /compiler/utils/assembler.h
parentac6d660672c21a0ace14276e9c356906218b4412 (diff)
Thumb2: Fix EmitJumpTables() to extend buffer only if needed.
Bug: 28256882 Change-Id: I15227535c0fcb73c04b0b05160852c4b1bebee49
Diffstat (limited to 'compiler/utils/assembler.h')
-rw-r--r--compiler/utils/assembler.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h
index f70fe04ed1..5267dc3812 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -178,8 +178,8 @@ class AssemblerBuffer {
class EnsureCapacity {
public:
explicit EnsureCapacity(AssemblerBuffer* buffer) {
- if (buffer->cursor() >= buffer->limit()) {
- buffer->ExtendCapacity();
+ if (buffer->cursor() > buffer->limit()) {
+ buffer->ExtendCapacity(buffer->Size() + kMinimumGap);
}
// In debug mode, we save the assembler buffer along with the gap
// size before we start emitting to the buffer. This allows us to
@@ -219,7 +219,9 @@ class AssemblerBuffer {
class EnsureCapacity {
public:
explicit EnsureCapacity(AssemblerBuffer* buffer) {
- if (buffer->cursor() >= buffer->limit()) buffer->ExtendCapacity();
+ if (buffer->cursor() > buffer->limit()) {
+ buffer->ExtendCapacity(buffer->Size() + kMinimumGap);
+ }
}
};
@@ -233,7 +235,14 @@ class AssemblerBuffer {
// Returns the position in the instruction stream.
int GetPosition() { return cursor_ - contents_; }
- void ExtendCapacity(size_t min_capacity = 0u);
+ size_t Capacity() const {
+ CHECK_GE(limit_, contents_);
+ return (limit_ - contents_) + kMinimumGap;
+ }
+
+ // Unconditionally increase the capacity.
+ // The provided `min_capacity` must be higher than current `Capacity()`.
+ void ExtendCapacity(size_t min_capacity);
private:
// The limit is set to kMinimumGap bytes before the end of the data area.
@@ -255,10 +264,6 @@ class AssemblerBuffer {
uint8_t* cursor() const { return cursor_; }
uint8_t* limit() const { return limit_; }
- size_t Capacity() const {
- CHECK_GE(limit_, contents_);
- return (limit_ - contents_) + kMinimumGap;
- }
// Process the fixup chain starting at the given fixup. The offset is
// non-zero for fixups in the body if the preamble is non-empty.