Commit 2f952652 authored by danno's avatar danno Committed by Commit bot

[Reland]: Improve CodeStubAssembler assert functionality

Introduce CSA_ASSERT macro that outputs a message, file name and line number to
console before calling DebugBreak.

Committed: https://crrev.com/23836e9c14f3df9b675fe02e2c23bb11e728b83d
Review-Url: https://codereview.chromium.org/2419433008
Cr-Original-Commit-Position: refs/heads/master@{#40307}
Cr-Commit-Position: refs/heads/master@{#40322}
parent 80caaac3
...@@ -26,11 +26,29 @@ CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone, ...@@ -26,11 +26,29 @@ CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
const char* name) const char* name)
: compiler::CodeAssembler(isolate, zone, parameter_count, flags, name) {} : compiler::CodeAssembler(isolate, zone, parameter_count, flags, name) {}
void CodeStubAssembler::Assert(Node* condition) { void CodeStubAssembler::Assert(Node* condition, const char* message,
const char* file, int line) {
#if defined(DEBUG) #if defined(DEBUG)
Label ok(this); Label ok(this);
Comment("[ Assert"); if (message != nullptr && FLAG_code_comments) {
Comment("[ Assert: %s", message);
} else {
Comment("[ Assert ");
}
GotoIf(condition, &ok); GotoIf(condition, &ok);
if (message != nullptr) {
char chars[1024];
Vector<char> buffer(chars);
if (file != nullptr) {
SNPrintF(buffer, "CSA_ASSERT failed: %s [%s:%d]\n", message, file, line);
} else {
SNPrintF(buffer, "CSA_ASSERT failed: %s\n", message);
}
CallRuntime(
Runtime::kGlobalPrint, SmiConstant(Smi::kZero),
HeapConstant(factory()->NewStringFromAsciiChecked(&(buffer[0]))));
}
DebugBreak(); DebugBreak();
Goto(&ok); Goto(&ok);
Bind(&ok); Bind(&ok);
...@@ -895,7 +913,8 @@ Node* CodeStubAssembler::LoadInstanceType(Node* object) { ...@@ -895,7 +913,8 @@ Node* CodeStubAssembler::LoadInstanceType(Node* object) {
void CodeStubAssembler::AssertInstanceType(Node* object, void CodeStubAssembler::AssertInstanceType(Node* object,
InstanceType instance_type) { InstanceType instance_type) {
Assert(Word32Equal(LoadInstanceType(object), Int32Constant(instance_type))); CSA_ASSERT(
Word32Equal(LoadInstanceType(object), Int32Constant(instance_type)));
} }
Node* CodeStubAssembler::LoadProperties(Node* object) { Node* CodeStubAssembler::LoadProperties(Node* object) {
...@@ -955,7 +974,7 @@ Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) { ...@@ -955,7 +974,7 @@ Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) {
Node* CodeStubAssembler::LoadMapInobjectProperties(Node* map) { Node* CodeStubAssembler::LoadMapInobjectProperties(Node* map) {
// See Map::GetInObjectProperties() for details. // See Map::GetInObjectProperties() for details.
STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE); STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
Assert(Int32GreaterThanOrEqual(LoadMapInstanceType(map), CSA_ASSERT(Int32GreaterThanOrEqual(LoadMapInstanceType(map),
Int32Constant(FIRST_JS_OBJECT_TYPE))); Int32Constant(FIRST_JS_OBJECT_TYPE)));
return ChangeUint32ToWord(LoadObjectField( return ChangeUint32ToWord(LoadObjectField(
map, Map::kInObjectPropertiesOrConstructorFunctionIndexOffset, map, Map::kInObjectPropertiesOrConstructorFunctionIndexOffset,
...@@ -965,7 +984,7 @@ Node* CodeStubAssembler::LoadMapInobjectProperties(Node* map) { ...@@ -965,7 +984,7 @@ Node* CodeStubAssembler::LoadMapInobjectProperties(Node* map) {
Node* CodeStubAssembler::LoadMapConstructorFunctionIndex(Node* map) { Node* CodeStubAssembler::LoadMapConstructorFunctionIndex(Node* map) {
// See Map::GetConstructorFunctionIndex() for details. // See Map::GetConstructorFunctionIndex() for details.
STATIC_ASSERT(FIRST_PRIMITIVE_TYPE == FIRST_TYPE); STATIC_ASSERT(FIRST_PRIMITIVE_TYPE == FIRST_TYPE);
Assert(Int32LessThanOrEqual(LoadMapInstanceType(map), CSA_ASSERT(Int32LessThanOrEqual(LoadMapInstanceType(map),
Int32Constant(LAST_PRIMITIVE_TYPE))); Int32Constant(LAST_PRIMITIVE_TYPE)));
return ChangeUint32ToWord(LoadObjectField( return ChangeUint32ToWord(LoadObjectField(
map, Map::kInObjectPropertiesOrConstructorFunctionIndexOffset, map, Map::kInObjectPropertiesOrConstructorFunctionIndexOffset,
...@@ -1380,7 +1399,7 @@ Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length, ...@@ -1380,7 +1399,7 @@ Node* CodeStubAssembler::AllocateRegExpResult(Node* context, Node* length,
Node* index, Node* input) { Node* index, Node* input) {
Node* const max_length = Node* const max_length =
SmiConstant(Smi::FromInt(JSArray::kInitialMaxFastElementArray)); SmiConstant(Smi::FromInt(JSArray::kInitialMaxFastElementArray));
Assert(SmiLessThanOrEqual(length, max_length)); CSA_ASSERT(SmiLessThanOrEqual(length, max_length));
// Allocate the JSRegExpResult. // Allocate the JSRegExpResult.
// TODO(jgruber): Fold JSArray and FixedArray allocations, then remove // TODO(jgruber): Fold JSArray and FixedArray allocations, then remove
...@@ -3150,8 +3169,8 @@ Node* CodeStubAssembler::ToName(Node* context, Node* value) { ...@@ -3150,8 +3169,8 @@ Node* CodeStubAssembler::ToName(Node* context, Node* value) {
Node* CodeStubAssembler::NonNumberToNumber(Node* context, Node* input) { Node* CodeStubAssembler::NonNumberToNumber(Node* context, Node* input) {
// Assert input is a HeapObject (not smi or heap number) // Assert input is a HeapObject (not smi or heap number)
Assert(Word32BinaryNot(TaggedIsSmi(input))); CSA_ASSERT(Word32BinaryNot(TaggedIsSmi(input)));
Assert(Word32NotEqual(LoadMap(input), HeapNumberMapConstant())); CSA_ASSERT(Word32NotEqual(LoadMap(input), HeapNumberMapConstant()));
// We might need to loop once here due to ToPrimitive conversions. // We might need to loop once here due to ToPrimitive conversions.
Variable var_input(this, MachineRepresentation::kTagged); Variable var_input(this, MachineRepresentation::kTagged);
...@@ -3613,7 +3632,7 @@ void CodeStubAssembler::TryLookupProperty( ...@@ -3613,7 +3632,7 @@ void CodeStubAssembler::TryLookupProperty(
Node* bit_field = LoadMapBitField(map); Node* bit_field = LoadMapBitField(map);
Node* mask = Int32Constant(1 << Map::kHasNamedInterceptor | Node* mask = Int32Constant(1 << Map::kHasNamedInterceptor |
1 << Map::kIsAccessCheckNeeded); 1 << Map::kIsAccessCheckNeeded);
Assert(Word32Equal(Word32And(bit_field, mask), Int32Constant(0))); CSA_ASSERT(Word32Equal(Word32And(bit_field, mask), Int32Constant(0)));
Node* bit_field3 = LoadMapBitField3(map); Node* bit_field3 = LoadMapBitField3(map);
Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3); Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3);
...@@ -4028,7 +4047,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map, ...@@ -4028,7 +4047,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
{ {
AssertInstanceType(object, JS_VALUE_TYPE); AssertInstanceType(object, JS_VALUE_TYPE);
Node* string = LoadJSValueValue(object); Node* string = LoadJSValueValue(object);
Assert(IsStringInstanceType(LoadInstanceType(string))); CSA_ASSERT(IsStringInstanceType(LoadInstanceType(string)));
Node* length = LoadStringLength(string); Node* length = LoadStringLength(string);
GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found); GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found);
Goto(&if_isobjectorsmi); Goto(&if_isobjectorsmi);
...@@ -4037,7 +4056,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map, ...@@ -4037,7 +4056,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
{ {
AssertInstanceType(object, JS_VALUE_TYPE); AssertInstanceType(object, JS_VALUE_TYPE);
Node* string = LoadJSValueValue(object); Node* string = LoadJSValueValue(object);
Assert(IsStringInstanceType(LoadInstanceType(string))); CSA_ASSERT(IsStringInstanceType(LoadInstanceType(string)));
Node* length = LoadStringLength(string); Node* length = LoadStringLength(string);
GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found); GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found);
Goto(&if_isdictionary); Goto(&if_isdictionary);
...@@ -4468,7 +4487,7 @@ compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name, ...@@ -4468,7 +4487,7 @@ compiler::Node* CodeStubAssembler::StubCachePrimaryOffset(compiler::Node* name,
STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift); STATIC_ASSERT(StubCache::kCacheIndexShift == Name::kHashShift);
// Compute the hash of the name (use entire hash field). // Compute the hash of the name (use entire hash field).
Node* hash_field = LoadNameHashField(name); Node* hash_field = LoadNameHashField(name);
Assert(Word32Equal( CSA_ASSERT(Word32Equal(
Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)), Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)),
Int32Constant(0))); Int32Constant(0)));
...@@ -4949,10 +4968,10 @@ void CodeStubAssembler::HandleLoadICHandlerCase( ...@@ -4949,10 +4968,10 @@ void CodeStubAssembler::HandleLoadICHandlerCase(
LoadWeakCellValue(LoadObjectField(handler, Tuple3::kValue2Offset)); LoadWeakCellValue(LoadObjectField(handler, Tuple3::kValue2Offset));
// The |holder| is guaranteed to be alive at this point since we passed // The |holder| is guaranteed to be alive at this point since we passed
// both the receiver map check and the validity cell check. // both the receiver map check and the validity cell check.
Assert(WordNotEqual(holder, IntPtrConstant(0))); CSA_ASSERT(WordNotEqual(holder, IntPtrConstant(0)));
Node* smi_handler = LoadObjectField(handler, Tuple3::kValue3Offset); Node* smi_handler = LoadObjectField(handler, Tuple3::kValue3Offset);
Assert(TaggedIsSmi(smi_handler)); CSA_ASSERT(TaggedIsSmi(smi_handler));
var_holder.Bind(holder); var_holder.Bind(holder);
var_smi_handler.Bind(smi_handler); var_smi_handler.Bind(smi_handler);
...@@ -5336,8 +5355,9 @@ void CodeStubAssembler::ExtendPropertiesBackingStore(compiler::Node* object) { ...@@ -5336,8 +5355,9 @@ void CodeStubAssembler::ExtendPropertiesBackingStore(compiler::Node* object) {
FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind)); FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind));
// The size of a new properties backing store is guaranteed to be small // The size of a new properties backing store is guaranteed to be small
// enough that the new backing store will be allocated in new space. // enough that the new backing store will be allocated in new space.
Assert(UintPtrLessThan(new_capacity, IntPtrConstant(kMaxNumberOfDescriptors + CSA_ASSERT(UintPtrLessThan(
JSObject::kFieldsAdded))); new_capacity,
IntPtrConstant(kMaxNumberOfDescriptors + JSObject::kFieldsAdded)));
Node* new_properties = AllocateFixedArray(kind, new_capacity, mode); Node* new_properties = AllocateFixedArray(kind, new_capacity, mode);
...@@ -5484,7 +5504,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key, ...@@ -5484,7 +5504,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
Bind(&if_mapped); Bind(&if_mapped);
{ {
Assert(TaggedIsSmi(mapped_index)); CSA_ASSERT(TaggedIsSmi(mapped_index));
mapped_index = SmiUntag(mapped_index); mapped_index = SmiUntag(mapped_index);
Node* the_context = LoadFixedArrayElement(elements, IntPtrConstant(0), 0, Node* the_context = LoadFixedArrayElement(elements, IntPtrConstant(0), 0,
INTPTR_PARAMETERS); INTPTR_PARAMETERS);
...@@ -5496,7 +5516,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key, ...@@ -5496,7 +5516,7 @@ Node* CodeStubAssembler::EmitKeyedSloppyArguments(Node* receiver, Node* key,
if (is_load) { if (is_load) {
Node* result = LoadFixedArrayElement(the_context, mapped_index, 0, Node* result = LoadFixedArrayElement(the_context, mapped_index, 0,
INTPTR_PARAMETERS); INTPTR_PARAMETERS);
Assert(WordNotEqual(result, TheHoleConstant())); CSA_ASSERT(WordNotEqual(result, TheHoleConstant()));
var_result.Bind(result); var_result.Bind(result);
} else { } else {
StoreFixedArrayElement(the_context, mapped_index, value, StoreFixedArrayElement(the_context, mapped_index, value,
...@@ -7360,7 +7380,7 @@ compiler::Node* CodeStubAssembler::Typeof(compiler::Node* value, ...@@ -7360,7 +7380,7 @@ compiler::Node* CodeStubAssembler::Typeof(compiler::Node* value,
SIMD128_TYPES(SIMD128_BRANCH) SIMD128_TYPES(SIMD128_BRANCH)
#undef SIMD128_BRANCH #undef SIMD128_BRANCH
Assert(Word32Equal(instance_type, Int32Constant(SYMBOL_TYPE))); CSA_ASSERT(Word32Equal(instance_type, Int32Constant(SYMBOL_TYPE)));
result_var.Bind(HeapConstant(isolate()->factory()->symbol_string())); result_var.Bind(HeapConstant(isolate()->factory()->symbol_string()));
Goto(&return_result); Goto(&return_result);
......
...@@ -146,7 +146,8 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -146,7 +146,8 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* InnerAllocate(compiler::Node* previous, compiler::Node* InnerAllocate(compiler::Node* previous,
compiler::Node* offset); compiler::Node* offset);
void Assert(compiler::Node* condition); void Assert(compiler::Node* condition, const char* string = nullptr,
const char* file = nullptr, int line = 0);
// Check a value for smi-ness // Check a value for smi-ness
compiler::Node* TaggedIsSmi(compiler::Node* a); compiler::Node* TaggedIsSmi(compiler::Node* a);
...@@ -989,6 +990,8 @@ class CodeStubAssembler : public compiler::CodeAssembler { ...@@ -989,6 +990,8 @@ class CodeStubAssembler : public compiler::CodeAssembler {
static const int kElementLoopUnrollThreshold = 8; static const int kElementLoopUnrollThreshold = 8;
}; };
#define CSA_ASSERT(x) Assert((x), #x, __FILE__, __LINE__)
DEFINE_OPERATORS_FOR_FLAGS(CodeStubAssembler::AllocationFlags); DEFINE_OPERATORS_FOR_FLAGS(CodeStubAssembler::AllocationFlags);
} // namespace internal } // namespace internal
......
...@@ -444,7 +444,7 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) { ...@@ -444,7 +444,7 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) {
OFStream os(stdout); OFStream os(stdout);
#ifdef DEBUG #ifdef DEBUG
if (args[0]->IsString()) { if (args[0]->IsString() && isolate->context() != nullptr) {
// If we have a string, assume it's a code "marker" // If we have a string, assume it's a code "marker"
// and print some interesting cpu debugging info. // and print some interesting cpu debugging info.
JavaScriptFrameIterator it(isolate); JavaScriptFrameIterator it(isolate);
......
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