Commit 722f7139 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[csa] re-enable release build FixedArray bounds checks

To address previously observed regressions, this CL also introduces
unchecked FixedArray accessors and uses them to access collections.

Bug: v8:8029
Change-Id: I6bcd8db2b89b29b7acb3b8431ec5405b737bcef2
Reviewed-on: https://chromium-review.googlesource.com/c/1473033
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59631}
parent 2f8a5f59
......@@ -1955,10 +1955,14 @@ void CodeStubAssembler::FixedArrayBoundsCheck(TNode<FixedArrayBase> array,
TNode<Object> CodeStubAssembler::LoadFixedArrayElement(
TNode<FixedArray> object, Node* index_node, int additional_offset,
ParameterMode parameter_mode, LoadSensitivity needs_poisoning) {
ParameterMode parameter_mode, LoadSensitivity needs_poisoning,
CheckBounds check_bounds) {
CSA_ASSERT(this, IsFixedArraySubclass(object));
CSA_ASSERT(this, IsNotWeakFixedArraySubclass(object));
FixedArrayBoundsCheck(object, index_node, additional_offset, parameter_mode);
if (NeedsBoundsCheck(check_bounds)) {
FixedArrayBoundsCheck(object, index_node, additional_offset,
parameter_mode);
}
TNode<MaybeObject> element =
LoadArrayElement(object, FixedArray::kHeaderSize, index_node,
additional_offset, parameter_mode, needs_poisoning);
......@@ -2804,10 +2808,12 @@ void CodeStubAssembler::StoreFixedArrayOrPropertyArrayElement(
void CodeStubAssembler::StoreFixedDoubleArrayElement(
TNode<FixedDoubleArray> object, Node* index_node, TNode<Float64T> value,
ParameterMode parameter_mode) {
ParameterMode parameter_mode, CheckBounds check_bounds) {
CSA_ASSERT(this, IsFixedDoubleArray(object));
CSA_SLOW_ASSERT(this, MatchesParameterMode(index_node, parameter_mode));
FixedArrayBoundsCheck(object, index_node, 0, parameter_mode);
if (NeedsBoundsCheck(check_bounds)) {
FixedArrayBoundsCheck(object, index_node, 0, parameter_mode);
}
Node* offset =
ElementOffsetFromIndex(index_node, PACKED_DOUBLE_ELEMENTS, parameter_mode,
FixedArray::kHeaderSize - kHeapObjectTag);
......@@ -3615,7 +3621,7 @@ void CodeStubAssembler::FindOrderedHashTableEntry(
CAST(table), CollectionType::NumberOfBucketsIndex())));
Node* const bucket =
WordAnd(hash, IntPtrSub(number_of_buckets, IntPtrConstant(1)));
Node* const first_entry = SmiUntag(CAST(LoadFixedArrayElement(
Node* const first_entry = SmiUntag(CAST(UnsafeLoadFixedArrayElement(
CAST(table), bucket,
CollectionType::HashTableStartIndex() * kTaggedSize)));
......@@ -3640,9 +3646,9 @@ void CodeStubAssembler::FindOrderedHashTableEntry(
UintPtrLessThan(
var_entry.value(),
SmiUntag(SmiAdd(
CAST(LoadFixedArrayElement(
CAST(UnsafeLoadFixedArrayElement(
CAST(table), CollectionType::NumberOfElementsIndex())),
CAST(LoadFixedArrayElement(
CAST(UnsafeLoadFixedArrayElement(
CAST(table),
CollectionType::NumberOfDeletedElementsIndex()))))));
......@@ -3661,7 +3667,7 @@ void CodeStubAssembler::FindOrderedHashTableEntry(
BIND(&continue_next_entry);
// Load the index of the next entry in the bucket chain.
var_entry.Bind(SmiUntag(CAST(LoadFixedArrayElement(
var_entry.Bind(SmiUntag(CAST(UnsafeLoadFixedArrayElement(
CAST(table), entry_start,
(CollectionType::HashTableStartIndex() + CollectionType::kChainOffset) *
kTaggedSize))));
......
......@@ -1013,7 +1013,17 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<Object> LoadFixedArrayElement(
TNode<FixedArray> object, Node* index, int additional_offset = 0,
ParameterMode parameter_mode = INTPTR_PARAMETERS,
LoadSensitivity needs_poisoning = LoadSensitivity::kSafe);
LoadSensitivity needs_poisoning = LoadSensitivity::kSafe,
CheckBounds check_bounds = CheckBounds::kAlways);
TNode<Object> UnsafeLoadFixedArrayElement(
TNode<FixedArray> object, Node* index, int additional_offset = 0,
ParameterMode parameter_mode = INTPTR_PARAMETERS,
LoadSensitivity needs_poisoning = LoadSensitivity::kSafe) {
return LoadFixedArrayElement(object, index, additional_offset,
parameter_mode, needs_poisoning,
CheckBounds::kDebugOnly);
}
TNode<Object> LoadFixedArrayElement(TNode<FixedArray> object,
TNode<IntPtrT> index,
......@@ -1036,6 +1046,13 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
additional_offset, INTPTR_PARAMETERS,
needs_poisoning);
}
TNode<Object> UnsafeLoadFixedArrayElement(
TNode<FixedArray> object, int index, int additional_offset = 0,
LoadSensitivity needs_poisoning = LoadSensitivity::kSafe) {
return LoadFixedArrayElement(object, IntPtrConstant(index),
additional_offset, INTPTR_PARAMETERS,
needs_poisoning, CheckBounds::kDebugOnly);
}
TNode<Object> LoadFixedArrayElement(TNode<FixedArray> object,
TNode<Smi> index) {
return LoadFixedArrayElement(object, index, 0, SMI_PARAMETERS);
......@@ -1233,14 +1250,29 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// Store an array element to a FixedArray.
void StoreFixedArrayElement(
TNode<FixedArray> object, int index, SloppyTNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER) {
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
CheckBounds check_bounds = CheckBounds::kAlways) {
return StoreFixedArrayElement(object, IntPtrConstant(index), value,
barrier_mode);
barrier_mode, 0, INTPTR_PARAMETERS,
check_bounds);
}
void UnsafeStoreFixedArrayElement(
TNode<FixedArray> object, int index, SloppyTNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER) {
return StoreFixedArrayElement(object, index, value, barrier_mode,
CheckBounds::kDebugOnly);
}
void StoreFixedArrayElement(TNode<FixedArray> object, int index,
TNode<Smi> value) {
TNode<Smi> value,
CheckBounds check_bounds = CheckBounds::kAlways) {
return StoreFixedArrayElement(object, IntPtrConstant(index), value,
SKIP_WRITE_BARRIER);
SKIP_WRITE_BARRIER, 0, INTPTR_PARAMETERS,
check_bounds);
}
void UnsafeStoreFixedArrayElement(TNode<FixedArray> object, int index,
TNode<Smi> value) {
return StoreFixedArrayElement(object, index, value,
CheckBounds::kDebugOnly);
}
void StoreJSArrayLength(TNode<JSArray> array, TNode<Smi> length);
......@@ -1256,12 +1288,25 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<FixedArray> array, Node* index, SloppyTNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
int additional_offset = 0,
ParameterMode parameter_mode = INTPTR_PARAMETERS) {
FixedArrayBoundsCheck(array, index, additional_offset, parameter_mode);
ParameterMode parameter_mode = INTPTR_PARAMETERS,
CheckBounds check_bounds = CheckBounds::kAlways) {
if (NeedsBoundsCheck(check_bounds)) {
FixedArrayBoundsCheck(array, index, additional_offset, parameter_mode);
}
StoreFixedArrayOrPropertyArrayElement(array, index, value, barrier_mode,
additional_offset, parameter_mode);
}
void UnsafeStoreFixedArrayElement(
TNode<FixedArray> array, Node* index, SloppyTNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
int additional_offset = 0,
ParameterMode parameter_mode = INTPTR_PARAMETERS) {
return StoreFixedArrayElement(array, index, value, barrier_mode,
additional_offset, parameter_mode,
CheckBounds::kDebugOnly);
}
void StorePropertyArrayElement(
TNode<PropertyArray> array, Node* index, SloppyTNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
......@@ -1289,7 +1334,14 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
void StoreFixedDoubleArrayElement(
TNode<FixedDoubleArray> object, Node* index, TNode<Float64T> value,
ParameterMode parameter_mode = INTPTR_PARAMETERS);
ParameterMode parameter_mode = INTPTR_PARAMETERS,
CheckBounds check_bounds = CheckBounds::kAlways);
void UnsafeStoreFixedDoubleArrayElement(
TNode<FixedDoubleArray> object, Node* index, TNode<Float64T> value,
ParameterMode parameter_mode = INTPTR_PARAMETERS) {
return StoreFixedDoubleArrayElement(object, index, value, parameter_mode,
CheckBounds::kDebugOnly);
}
void StoreFixedDoubleArrayElementSmi(TNode<FixedDoubleArray> object,
TNode<Smi> index,
......
......@@ -272,6 +272,16 @@ enum class ObjectType {
#undef ENUM_ELEMENT
#undef ENUM_STRUCT_ELEMENT
enum class CheckBounds { kAlways, kDebugOnly };
inline bool NeedsBoundsCheck(CheckBounds check_bounds) {
switch (check_bounds) {
case CheckBounds::kAlways:
return true;
case CheckBounds::kDebugOnly:
return DEBUG_BOOL;
}
}
class AccessCheckNeeded;
class BigIntWrapper;
class ClassBoilerplate;
......
......@@ -449,7 +449,7 @@ DEFINE_BOOL(trace_verify_csa, false, "trace code stubs verification")
DEFINE_STRING(csa_trap_on_node, nullptr,
"trigger break point when a node with given id is created in "
"given stub. The format is: StubName,NodeId")
DEFINE_BOOL_READONLY(fixed_array_bounds_checks, DEBUG_BOOL,
DEFINE_BOOL_READONLY(fixed_array_bounds_checks, true,
"enable FixedArray bounds checks")
DEFINE_BOOL(turbo_stats, false, "print TurboFan statistics")
DEFINE_BOOL(turbo_stats_nvp, false,
......
......@@ -705,8 +705,8 @@ void CSAGenerator::EmitInstruction(
out_ << field.name_and_type.type->GetGeneratedTypeName() << " "
<< result_name << " = ca_.UncheckedCast<"
<< field.name_and_type.type->GetGeneratedTNodeTypeName()
<< ">(CodeStubAssembler(state_).LoadFixedArrayElement(" << stack->Top()
<< ", " << (field.offset / kTaggedSize) << "));\n";
<< ">(CodeStubAssembler(state_).UnsafeLoadFixedArrayElement("
<< stack->Top() << ", " << (field.offset / kTaggedSize) << "));\n";
}
stack->Poke(stack->AboveTop() - 1, result_name);
}
......@@ -741,8 +741,9 @@ void CSAGenerator::EmitInstruction(
<< machine_type << ".representation());\n";
}
} else {
out_ << " CodeStubAssembler(state_).StoreFixedArrayElement(" << object
<< ", " << (field.offset / kTaggedSize) << ", " << value << ");\n";
out_ << " CodeStubAssembler(state_).UnsafeStoreFixedArrayElement("
<< object << ", " << (field.offset / kTaggedSize) << ", " << value
<< ");\n";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment