Clean up JSConstructStub

- fix truthfulness of comments
- use InitializeFieldsWithFiller more consistently
- use unsigned comparisons for pointers

No change in functionality intended.

Bonus: improve JavaScriptFrame::Print() for an enhanced debugging experience:

- print PC of each frame
- print the function's source also for optimized frames

Review URL: https://codereview.chromium.org/1186823003

Cr-Commit-Position: refs/heads/master@{#29082}
This commit is contained in:
jkummerow 2015-06-17 04:58:17 -07:00 committed by Commit bot
parent 25e687965f
commit 882055ff6a
13 changed files with 60 additions and 85 deletions

View File

@ -446,7 +446,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// initial map and properties and elements are set to empty fixed array. // initial map and properties and elements are set to empty fixed array.
// r1: constructor function // r1: constructor function
// r2: initial map // r2: initial map
// r3: object size (not including memento if create_memento) // r3: object size (including memento if create_memento)
// r4: JSObject (not tagged) // r4: JSObject (not tagged)
__ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex); __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
__ mov(r5, r4); __ mov(r5, r4);
@ -520,7 +520,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ add(r4, r4, Operand(kHeapObjectTag)); __ add(r4, r4, Operand(kHeapObjectTag));
// Check if a non-empty properties array is needed. Continue with // Check if a non-empty properties array is needed. Continue with
// allocated object if not fall through to runtime call if it is. // allocated object if not; allocate and initialize a FixedArray if yes.
// r1: constructor function // r1: constructor function
// r4: JSObject // r4: JSObject
// r5: start of next object (not tagged) // r5: start of next object (not tagged)
@ -575,15 +575,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// r5: FixedArray (not tagged) // r5: FixedArray (not tagged)
__ add(r6, r2, Operand(r3, LSL, kPointerSizeLog2)); // End of object. __ add(r6, r2, Operand(r3, LSL, kPointerSizeLog2)); // End of object.
DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize); DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize);
{ Label loop, entry; __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex); __ InitializeFieldsWithFiller(r2, r6, r0);
__ b(&entry);
__ bind(&loop);
__ str(r0, MemOperand(r2, kPointerSize, PostIndex));
__ bind(&entry);
__ cmp(r2, r6);
__ b(lt, &loop);
}
// Store the initialized FixedArray into the properties field of // Store the initialized FixedArray into the properties field of
// the JSObject // the JSObject

View File

@ -3174,7 +3174,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
str(filler, MemOperand(start_offset, kPointerSize, PostIndex)); str(filler, MemOperand(start_offset, kPointerSize, PostIndex));
bind(&entry); bind(&entry);
cmp(start_offset, end_offset); cmp(start_offset, end_offset);
b(lt, &loop); b(lo, &loop);
} }
@ -3402,7 +3402,7 @@ void MacroAssembler::CallCFunctionHelper(Register function,
if (ActivationFrameAlignment() > kPointerSize) { if (ActivationFrameAlignment() > kPointerSize) {
ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
} else { } else {
add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); add(sp, sp, Operand(stack_passed_arguments * kPointerSize));
} }
} }

View File

@ -522,7 +522,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Add(new_obj, new_obj, kHeapObjectTag); __ Add(new_obj, new_obj, kHeapObjectTag);
// Check if a non-empty properties array is needed. Continue with // Check if a non-empty properties array is needed. Continue with
// allocated object if not, or fall through to runtime call if it is. // allocated object if not; allocate and initialize a FixedArray if yes.
Register element_count = x3; Register element_count = x3;
__ Ldrb(element_count, __ Ldrb(element_count,
FieldMemOperand(init_map, Map::kUnusedPropertyFieldsOffset)); FieldMemOperand(init_map, Map::kUnusedPropertyFieldsOffset));

View File

@ -1120,6 +1120,24 @@ void StackFrame::PrintIndex(StringStream* accumulator,
} }
namespace {
void PrintFunctionSource(StringStream* accumulator, SharedFunctionInfo* shared,
Code* code) {
if (FLAG_max_stack_trace_source_length != 0 && code != NULL) {
std::ostringstream os;
os << "--------- s o u r c e c o d e ---------\n"
<< SourceCodeOf(shared, FLAG_max_stack_trace_source_length)
<< "\n-----------------------------------------\n";
accumulator->Add(os.str().c_str());
}
}
} // namespace
void JavaScriptFrame::Print(StringStream* accumulator, void JavaScriptFrame::Print(StringStream* accumulator,
PrintMode mode, PrintMode mode,
int index) const { int index) const {
@ -1157,7 +1175,7 @@ void JavaScriptFrame::Print(StringStream* accumulator,
accumulator->Add(":~%d", line); accumulator->Add(":~%d", line);
} }
accumulator->Add("] "); accumulator->Add("] [pc=%p] ", pc);
} }
accumulator->Add("(this=%o", receiver); accumulator->Add("(this=%o", receiver);
@ -1182,7 +1200,9 @@ void JavaScriptFrame::Print(StringStream* accumulator,
return; return;
} }
if (is_optimized()) { if (is_optimized()) {
accumulator->Add(" {\n// optimized frame\n}\n"); accumulator->Add(" {\n// optimized frame\n");
PrintFunctionSource(accumulator, shared, code);
accumulator->Add("}\n");
return; return;
} }
accumulator->Add(" {\n"); accumulator->Add(" {\n");
@ -1249,15 +1269,7 @@ void JavaScriptFrame::Print(StringStream* accumulator,
accumulator->Add(" [%02d] : %o\n", i, GetExpression(i)); accumulator->Add(" [%02d] : %o\n", i, GetExpression(i));
} }
// Print details about the function. PrintFunctionSource(accumulator, shared, code);
if (FLAG_max_stack_trace_source_length != 0 && code != NULL) {
std::ostringstream os;
SharedFunctionInfo* shared = function->shared();
os << "--------- s o u r c e c o d e ---------\n"
<< SourceCodeOf(shared, FLAG_max_stack_trace_source_length)
<< "\n-----------------------------------------\n";
accumulator->Add(os.str().c_str());
}
accumulator->Add("}\n\n"); accumulator->Add("}\n\n");
} }

View File

@ -358,17 +358,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// ebx: JSObject // ebx: JSObject
// edi: FixedArray // edi: FixedArray
// ecx: start of next object // ecx: start of next object
{ Label loop, entry; __ mov(edx, factory->undefined_value());
__ mov(edx, factory->undefined_value()); __ lea(eax, Operand(edi, FixedArray::kHeaderSize));
__ lea(eax, Operand(edi, FixedArray::kHeaderSize)); __ InitializeFieldsWithFiller(eax, ecx, edx);
__ jmp(&entry);
__ bind(&loop);
__ mov(Operand(eax, 0), edx);
__ add(eax, Immediate(kPointerSize));
__ bind(&entry);
__ cmp(eax, ecx);
__ j(below, &loop);
}
// Store the initialized FixedArray into the properties field of // Store the initialized FixedArray into the properties field of
// the JSObject // the JSObject

View File

@ -1751,7 +1751,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
add(start_offset, Immediate(kPointerSize)); add(start_offset, Immediate(kPointerSize));
bind(&entry); bind(&entry);
cmp(start_offset, end_offset); cmp(start_offset, end_offset);
j(less, &loop); j(below, &loop);
} }

View File

@ -452,7 +452,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// initial map and properties and elements are set to empty fixed array. // initial map and properties and elements are set to empty fixed array.
// a1: constructor function // a1: constructor function
// a2: initial map // a2: initial map
// a3: object size (not including memento if create_memento) // a3: object size (including memento if create_memento)
// t4: JSObject (not tagged) // t4: JSObject (not tagged)
__ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex); __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex);
__ mov(t5, t4); __ mov(t5, t4);
@ -532,7 +532,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Addu(t4, t4, Operand(kHeapObjectTag)); __ Addu(t4, t4, Operand(kHeapObjectTag));
// Check if a non-empty properties array is needed. Continue with // Check if a non-empty properties array is needed. Continue with
// allocated object if not fall through to runtime call if it is. // allocated object if not; allocate and initialize a FixedArray if yes.
// a1: constructor function // a1: constructor function
// t4: JSObject // t4: JSObject
// t5: start of next object (not tagged) // t5: start of next object (not tagged)
@ -568,7 +568,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// a1: constructor // a1: constructor
// a3: number of elements in properties array (untagged) // a3: number of elements in properties array (untagged)
// t4: JSObject // t4: JSObject
// t5: start of next object // t5: start of FixedArray (untagged)
__ LoadRoot(t6, Heap::kFixedArrayMapRootIndex); __ LoadRoot(t6, Heap::kFixedArrayMapRootIndex);
__ mov(a2, t5); __ mov(a2, t5);
__ sw(t6, MemOperand(a2, JSObject::kMapOffset)); __ sw(t6, MemOperand(a2, JSObject::kMapOffset));
@ -588,20 +588,13 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ sll(t3, a3, kPointerSizeLog2); __ sll(t3, a3, kPointerSizeLog2);
__ addu(t6, a2, t3); // End of object. __ addu(t6, a2, t3); // End of object.
DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize); DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize);
{ Label loop, entry; if (!is_api_function || create_memento) {
if (!is_api_function || create_memento) { __ LoadRoot(t7, Heap::kUndefinedValueRootIndex);
__ LoadRoot(t7, Heap::kUndefinedValueRootIndex); } else if (FLAG_debug_code) {
} else if (FLAG_debug_code) { __ LoadRoot(t2, Heap::kUndefinedValueRootIndex);
__ LoadRoot(t2, Heap::kUndefinedValueRootIndex); __ Assert(eq, kUndefinedValueNotLoaded, t7, Operand(t2));
__ Assert(eq, kUndefinedValueNotLoaded, t7, Operand(t2));
}
__ jmp(&entry);
__ bind(&loop);
__ sw(t7, MemOperand(a2));
__ addiu(a2, a2, kPointerSize);
__ bind(&entry);
__ Branch(&loop, less, a2, Operand(t6));
} }
__ InitializeFieldsWithFiller(a2, t6, t7);
// Store the initialized FixedArray into the properties field of // Store the initialized FixedArray into the properties field of
// the JSObject. // the JSObject.

View File

@ -3804,7 +3804,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
sw(filler, MemOperand(start_offset)); sw(filler, MemOperand(start_offset));
Addu(start_offset, start_offset, kPointerSize); Addu(start_offset, start_offset, kPointerSize);
bind(&entry); bind(&entry);
Branch(&loop, lt, start_offset, Operand(end_offset)); Branch(&loop, ult, start_offset, Operand(end_offset));
} }
@ -5567,7 +5567,7 @@ void MacroAssembler::CallCFunctionHelper(Register function,
if (base::OS::ActivationFrameAlignment() > kPointerSize) { if (base::OS::ActivationFrameAlignment() > kPointerSize) {
lw(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); lw(sp, MemOperand(sp, stack_passed_arguments * kPointerSize));
} else { } else {
Addu(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); Addu(sp, sp, Operand(stack_passed_arguments * kPointerSize));
} }
} }

View File

@ -453,7 +453,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// initial map and properties and elements are set to empty fixed array. // initial map and properties and elements are set to empty fixed array.
// a1: constructor function // a1: constructor function
// a2: initial map // a2: initial map
// a3: object size (not including memento if create_memento) // a3: object size (including memento if create_memento)
// t0: JSObject (not tagged) // t0: JSObject (not tagged)
__ LoadRoot(t2, Heap::kEmptyFixedArrayRootIndex); __ LoadRoot(t2, Heap::kEmptyFixedArrayRootIndex);
__ mov(t1, t0); __ mov(t1, t0);
@ -535,7 +535,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Daddu(t0, t0, Operand(kHeapObjectTag)); __ Daddu(t0, t0, Operand(kHeapObjectTag));
// Check if a non-empty properties array is needed. Continue with // Check if a non-empty properties array is needed. Continue with
// allocated object if not fall through to runtime call if it is. // allocated object if not; allocate and initialize a FixedArray if yes.
// a1: constructor function // a1: constructor function
// t0: JSObject // t0: JSObject
// t1: start of next object (not tagged) // t1: start of next object (not tagged)
@ -574,7 +574,7 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// a1: constructor // a1: constructor
// a3: number of elements in properties array (untagged) // a3: number of elements in properties array (untagged)
// t0: JSObject // t0: JSObject
// t1: start of next object // t1: start of FixedArray (untagged)
__ LoadRoot(t2, Heap::kFixedArrayMapRootIndex); __ LoadRoot(t2, Heap::kFixedArrayMapRootIndex);
__ mov(a2, t1); __ mov(a2, t1);
__ sd(t2, MemOperand(a2, JSObject::kMapOffset)); __ sd(t2, MemOperand(a2, JSObject::kMapOffset));
@ -595,20 +595,13 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ dsll(a7, a3, kPointerSizeLog2); __ dsll(a7, a3, kPointerSizeLog2);
__ daddu(t2, a2, a7); // End of object. __ daddu(t2, a2, a7); // End of object.
DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize); DCHECK_EQ(2 * kPointerSize, FixedArray::kHeaderSize);
{ Label loop, entry; if (!is_api_function || create_memento) {
if (!is_api_function || create_memento) { __ LoadRoot(t3, Heap::kUndefinedValueRootIndex);
__ LoadRoot(t3, Heap::kUndefinedValueRootIndex); } else if (FLAG_debug_code) {
} else if (FLAG_debug_code) { __ LoadRoot(a6, Heap::kUndefinedValueRootIndex);
__ LoadRoot(a6, Heap::kUndefinedValueRootIndex); __ Assert(eq, kUndefinedValueNotLoaded, t3, Operand(a6));
__ Assert(eq, kUndefinedValueNotLoaded, t3, Operand(a6));
}
__ jmp(&entry);
__ bind(&loop);
__ sd(t3, MemOperand(a2));
__ daddiu(a2, a2, kPointerSize);
__ bind(&entry);
__ Branch(&loop, less, a2, Operand(t2));
} }
__ InitializeFieldsWithFiller(a2, t2, t3);
// Store the initialized FixedArray into the properties field of // Store the initialized FixedArray into the properties field of
// the JSObject. // the JSObject.

View File

@ -3857,7 +3857,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
sd(filler, MemOperand(start_offset)); sd(filler, MemOperand(start_offset));
Daddu(start_offset, start_offset, kPointerSize); Daddu(start_offset, start_offset, kPointerSize);
bind(&entry); bind(&entry);
Branch(&loop, lt, start_offset, Operand(end_offset)); Branch(&loop, ult, start_offset, Operand(end_offset));
} }

View File

@ -353,17 +353,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
// rdi: FixedArray // rdi: FixedArray
// rax: start of next object // rax: start of next object
// rdx: number of elements // rdx: number of elements
{ Label loop, entry; __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex);
__ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); __ leap(rcx, Operand(rdi, FixedArray::kHeaderSize));
__ leap(rcx, Operand(rdi, FixedArray::kHeaderSize)); __ InitializeFieldsWithFiller(rcx, rax, rdx);
__ jmp(&entry);
__ bind(&loop);
__ movp(Operand(rcx, 0), rdx);
__ addp(rcx, Immediate(kPointerSize));
__ bind(&entry);
__ cmpp(rcx, rax);
__ j(below, &loop);
}
// Store the initialized FixedArray into the properties field of // Store the initialized FixedArray into the properties field of
// the JSObject // the JSObject

View File

@ -4570,7 +4570,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
addp(start_offset, Immediate(kPointerSize)); addp(start_offset, Immediate(kPointerSize));
bind(&entry); bind(&entry);
cmpp(start_offset, end_offset); cmpp(start_offset, end_offset);
j(less, &loop); j(below, &loop);
} }

View File

@ -1717,7 +1717,7 @@ void MacroAssembler::InitializeFieldsWithFiller(Register start_offset,
add(start_offset, Immediate(kPointerSize)); add(start_offset, Immediate(kPointerSize));
bind(&entry); bind(&entry);
cmp(start_offset, end_offset); cmp(start_offset, end_offset);
j(less, &loop); j(below, &loop);
} }