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}
This commit is contained in:
jochen 2015-04-28 02:40:35 -07:00 committed by Commit bot
parent 4b95b9bb32
commit 1630253f93
5 changed files with 35 additions and 28 deletions

View File

@ -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() {

View File

@ -2439,9 +2439,9 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
Add<HLoadNamedField>(checked_object, nullptr,
HObjectAccess::ForJSArrayBufferViewBuffer());
HInstruction* flags = Add<HLoadNamedField>(
buffer, nullptr, HObjectAccess::ForJSArrayBufferFlag());
buffer, nullptr, HObjectAccess::ForJSArrayBufferBitField());
HValue* was_neutered_mask =
Add<HConstant>(1 << JSArrayBuffer::kWasNeuteredBit);
Add<HConstant>(1 << JSArrayBuffer::WasNeutered::kShift);
HValue* was_neutered_test =
AddUncasted<HBitwise>(Token::BIT_AND, flags, was_neutered_mask);
@ -3195,9 +3195,9 @@ HValue* HGraphBuilder::BuildArrayBufferViewFieldAccessor(HValue* object,
if_has_buffer.Then();
{
HInstruction* flags = Add<HLoadNamedField>(
buffer, has_buffer, HObjectAccess::ForJSArrayBufferFlag());
buffer, has_buffer, HObjectAccess::ForJSArrayBufferBitField());
HValue* was_neutered_mask =
Add<HConstant>(1 << JSArrayBuffer::kWasNeuteredBit);
Add<HConstant>(1 << JSArrayBuffer::WasNeutered::kShift);
HValue* was_neutered_test =
AddUncasted<HBitwise>(Token::BIT_AND, flags, was_neutered_mask);

View File

@ -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));
}

View File

@ -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<bool, 1, 1> {};
class ShouldBeFreed : public BitField<bool, 2, 1> {};
class IsNeuterable : public BitField<bool, 3, 1> {};
class WasNeutered : public BitField<bool, 4, 1> {};
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer);

View File

@ -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);