summaryrefslogtreecommitdiff
path: root/deps/v8/src/codegen/signature.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/codegen/signature.h')
-rw-r--r--deps/v8/src/codegen/signature.h37
1 files changed, 31 insertions, 6 deletions
diff --git a/deps/v8/src/codegen/signature.h b/deps/v8/src/codegen/signature.h
index 38f79d4629..5a17688a54 100644
--- a/deps/v8/src/codegen/signature.h
+++ b/deps/v8/src/codegen/signature.h
@@ -66,11 +66,22 @@ class Signature : public ZoneObject {
Builder(Zone* zone, size_t return_count, size_t parameter_count)
: return_count_(return_count),
parameter_count_(parameter_count),
- zone_(zone),
rcursor_(0),
- pcursor_(0),
- buffer_(zone->NewArray<T>(
- static_cast<int>(return_count + parameter_count))) {}
+ pcursor_(0) {
+ // Allocate memory for the signature plus the array backing the
+ // signature.
+ constexpr size_t padding = sizeof(Signature<T>) % alignof(T);
+ using AllocationTypeTag = Signature<T>::Builder;
+ const size_t allocated_bytes =
+ sizeof(Signature<T>) + padding +
+ sizeof(T) * (return_count + parameter_count);
+ void* memory = zone->Allocate<AllocationTypeTag>(allocated_bytes);
+ uint8_t* rep_buffer =
+ reinterpret_cast<uint8_t*>(memory) + sizeof(Signature<T>) + padding;
+ DCHECK(IsAligned(reinterpret_cast<uintptr_t>(rep_buffer), alignof(T)));
+ buffer_ = reinterpret_cast<T*>(rep_buffer);
+ sig_ = new (memory) Signature<T>{return_count, parameter_count, buffer_};
+ }
const size_t return_count_;
const size_t parameter_count_;
@@ -91,16 +102,30 @@ class Signature : public ZoneObject {
pcursor_ = std::max(pcursor_, index + 1);
}
+ Signature<T>* Get() const {
+ DCHECK_EQ(rcursor_, return_count_);
+ DCHECK_EQ(pcursor_, parameter_count_);
+ DCHECK_NOT_NULL(sig_);
+ return sig_;
+ }
+
+ // TODO(clemensb): Remove {Build()}, replace all callers by {Get()}.
Signature<T>* Build() {
+ // {Build} is the old API, and should be replaced by {Get}.
+ // {Build} did previously return a freshly allocated pointer, so make sure
+ // that we do not call it twice by clearing the {sig_} field.
+ DCHECK_NOT_NULL(sig_);
DCHECK_EQ(rcursor_, return_count_);
DCHECK_EQ(pcursor_, parameter_count_);
- return zone_->New<Signature<T>>(return_count_, parameter_count_, buffer_);
+ Signature<T>* sig = sig_;
+ sig_ = nullptr;
+ return sig;
}
private:
- Zone* zone_;
size_t rcursor_;
size_t pcursor_;
+ Signature<T>* sig_;
T* buffer_;
};