Index: src/assembler.cc |
diff --git a/src/assembler.cc b/src/assembler.cc |
index 87b78048c65fb38ed83dc5324dee94da6d53906f..ec2deffd7ce0953430272008de277fadeb236382 100644 |
--- a/src/assembler.cc |
+++ b/src/assembler.cc |
@@ -106,7 +106,7 @@ const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
// ----------------------------------------------------------------------------- |
// Implementation of AssemblerBase |
-AssemblerBase::AssemblerBase(Isolate* isolate) |
+AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) |
: isolate_(isolate), |
jit_cookie_(0), |
emit_debug_code_(FLAG_debug_code), |
@@ -114,6 +114,40 @@ AssemblerBase::AssemblerBase(Isolate* isolate) |
if (FLAG_mask_constants_with_cookie && isolate != NULL) { |
jit_cookie_ = V8::RandomPrivate(isolate); |
} |
+ |
+ if (buffer == NULL) { |
+ // Do our own buffer management. |
+ if (buffer_size <= kMinimalBufferSize) { |
+ buffer_size = kMinimalBufferSize; |
+ if (isolate->assembler_spare_buffer() != NULL) { |
+ buffer = isolate->assembler_spare_buffer(); |
+ isolate->set_assembler_spare_buffer(NULL); |
+ } |
+ } |
+ if (buffer == NULL) buffer = NewArray<byte>(buffer_size); |
+ own_buffer_ = true; |
+ } else { |
+ // Use externally provided buffer instead. |
+ ASSERT(buffer_size > 0); |
+ own_buffer_ = false; |
+ } |
+ buffer_ = static_cast<byte*>(buffer); |
+ buffer_size_ = buffer_size; |
+ |
+ pc_ = buffer_; |
+} |
+ |
+ |
+AssemblerBase::~AssemblerBase() { |
+ if (own_buffer_) { |
+ if (isolate() != NULL && |
+ isolate()->assembler_spare_buffer() == NULL && |
+ buffer_size_ == kMinimalBufferSize) { |
+ isolate()->set_assembler_spare_buffer(buffer_); |
+ } else { |
+ DeleteArray(buffer_); |
+ } |
+ } |
} |