From 1630253f937f200bd67c05d39d503ba1144440cb Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 28 Apr 2015 02:40:35 -0700 Subject: [PATCH] Turn JSArrayBuffer::flags into a bit field That way, we can access it more easily without all the smi magic BUG=none R=dcarney@chromium.org LOG=n Review URL: https://codereview.chromium.org/1112503002 Cr-Commit-Position: refs/heads/master@{#28098} --- src/hydrogen-instructions.h | 4 ++-- src/hydrogen.cc | 8 ++++---- src/objects-inl.h | 32 ++++++++++++++++++++------------ src/objects.h | 17 ++++++++--------- src/runtime/runtime-typedarray.cc | 2 +- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index e60ec52..71fc0f9 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -6097,9 +6097,9 @@ class HObjectAccess final { JSArrayBuffer::kByteLengthOffset, Representation::Tagged()); } - static HObjectAccess ForJSArrayBufferFlag() { + static HObjectAccess ForJSArrayBufferBitField() { return HObjectAccess::ForObservableJSObjectOffset( - JSArrayBuffer::kFlagOffset, Representation::Smi()); + JSArrayBuffer::kBitFieldOffset, Representation::Integer32()); } static HObjectAccess ForExternalArrayExternalPointer() { diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 57e6396..adc4aa4 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -2439,9 +2439,9 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( Add(checked_object, nullptr, HObjectAccess::ForJSArrayBufferViewBuffer()); HInstruction* flags = Add( - buffer, nullptr, HObjectAccess::ForJSArrayBufferFlag()); + buffer, nullptr, HObjectAccess::ForJSArrayBufferBitField()); HValue* was_neutered_mask = - Add(1 << JSArrayBuffer::kWasNeuteredBit); + Add(1 << JSArrayBuffer::WasNeutered::kShift); HValue* was_neutered_test = AddUncasted(Token::BIT_AND, flags, was_neutered_mask); @@ -3195,9 +3195,9 @@ HValue* HGraphBuilder::BuildArrayBufferViewFieldAccessor(HValue* object, if_has_buffer.Then(); { HInstruction* flags = Add( - buffer, has_buffer, HObjectAccess::ForJSArrayBufferFlag()); + buffer, has_buffer, HObjectAccess::ForJSArrayBufferBitField()); HValue* was_neutered_mask = - Add(1 << JSArrayBuffer::kWasNeuteredBit); + Add(1 << JSArrayBuffer::WasNeutered::kShift); HValue* was_neutered_test = AddUncasted(Token::BIT_AND, flags, was_neutered_mask); diff --git a/src/objects-inl.h b/src/objects-inl.h index b505baa..647b123 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6424,46 +6424,54 @@ void JSArrayBuffer::set_backing_store(void* value, WriteBarrierMode mode) { ACCESSORS(JSArrayBuffer, byte_length, Object, kByteLengthOffset) -ACCESSORS_TO_SMI(JSArrayBuffer, flag, kFlagOffset) -bool JSArrayBuffer::is_external() { - return BooleanBit::get(flag(), kIsExternalBit); +void JSArrayBuffer::set_bit_field(uint32_t bits) { + if (kInt32Size != kPointerSize) { + WRITE_UINT32_FIELD(this, kBitFieldOffset + kInt32Size, 0); + } + WRITE_UINT32_FIELD(this, kBitFieldOffset, bits); +} + + +uint32_t JSArrayBuffer::bit_field() const { + return READ_UINT32_FIELD(this, kBitFieldOffset); } +bool JSArrayBuffer::is_external() { return IsExternal::decode(bit_field()); } + + void JSArrayBuffer::set_is_external(bool value) { - set_flag(BooleanBit::set(flag(), kIsExternalBit, value)); + set_bit_field(IsExternal::update(bit_field(), value)); } bool JSArrayBuffer::should_be_freed() { - return BooleanBit::get(flag(), kShouldBeFreed); + return ShouldBeFreed::decode(bit_field()); } void JSArrayBuffer::set_should_be_freed(bool value) { - set_flag(BooleanBit::set(flag(), kShouldBeFreed, value)); + set_bit_field(ShouldBeFreed::update(bit_field(), value)); } bool JSArrayBuffer::is_neuterable() { - return BooleanBit::get(flag(), kIsNeuterableBit); + return IsNeuterable::decode(bit_field()); } void JSArrayBuffer::set_is_neuterable(bool value) { - set_flag(BooleanBit::set(flag(), kIsNeuterableBit, value)); + set_bit_field(IsNeuterable::update(bit_field(), value)); } -bool JSArrayBuffer::was_neutered() { - return BooleanBit::get(flag(), kWasNeuteredBit); -} +bool JSArrayBuffer::was_neutered() { return WasNeutered::decode(bit_field()); } void JSArrayBuffer::set_was_neutered(bool value) { - set_flag(BooleanBit::set(flag(), kWasNeuteredBit, value)); + set_bit_field(WasNeutered::update(bit_field(), value)); } diff --git a/src/objects.h b/src/objects.h index c5b235d..1a6c179 100644 --- a/src/objects.h +++ b/src/objects.h @@ -10242,8 +10242,8 @@ class JSArrayBuffer: public JSObject { // [byte_length]: length in bytes DECL_ACCESSORS(byte_length, Object) - // [flags] - DECL_ACCESSORS(flag, Smi) + inline uint32_t bit_field() const; + inline void set_bit_field(uint32_t bits); inline bool is_external(); inline void set_is_external(bool value); @@ -10270,18 +10270,17 @@ class JSArrayBuffer: public JSObject { static const int kBackingStoreOffset = JSObject::kHeaderSize; static const int kByteLengthOffset = kBackingStoreOffset + kPointerSize; - static const int kFlagOffset = kByteLengthOffset + kPointerSize; - static const int kWeakNextOffset = kFlagOffset + kPointerSize; + static const int kBitFieldOffset = kByteLengthOffset + kPointerSize; + static const int kWeakNextOffset = kBitFieldOffset + kPointerSize; static const int kSize = kWeakNextOffset + kPointerSize; static const int kSizeWithInternalFields = kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize; - // Bit position in a flag - static const int kIsExternalBit = 0; - static const int kShouldBeFreed = 1; - static const int kIsNeuterableBit = 2; - static const int kWasNeuteredBit = 3; + class IsExternal : public BitField {}; + class ShouldBeFreed : public BitField {}; + class IsNeuterable : public BitField {}; + class WasNeutered : public BitField {}; private: DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer); diff --git a/src/runtime/runtime-typedarray.cc b/src/runtime/runtime-typedarray.cc index 02b5579..c3f69f5 100644 --- a/src/runtime/runtime-typedarray.cc +++ b/src/runtime/runtime-typedarray.cc @@ -42,7 +42,7 @@ void Runtime::SetupArrayBuffer(Isolate* isolate, array_buffer->SetInternalField(i, Smi::FromInt(0)); } array_buffer->set_backing_store(data); - array_buffer->set_flag(Smi::FromInt(0)); + array_buffer->set_bit_field(0); array_buffer->set_is_external(is_external); array_buffer->set_is_neuterable(true); -- 2.7.4