Improve code (less code, slightly faster) for polymorphic calls, by loading the argument descriptor only once instead of once for each call.
Review URL: https://codereview.chromium.org//12646012 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20254 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -93,7 +93,7 @@ class InstanceCall : public DartCallPattern {
|
||||
|
||||
|
||||
// The expected pattern of a dart static call:
|
||||
// mov EDX, arguments_descriptor_array
|
||||
// mov EDX, arguments_descriptor_array (optional in polymorphic calls)
|
||||
// call target_address
|
||||
// <- return address
|
||||
class StaticCall : public ValueObject {
|
||||
@@ -108,8 +108,7 @@ class StaticCall : public ValueObject {
|
||||
uint8_t* code_bytes =
|
||||
reinterpret_cast<uint8_t*>(
|
||||
return_address - (kNumInstructions * kInstructionSize));
|
||||
return (code_bytes[0] == 0xBA) &&
|
||||
(code_bytes[1 * kInstructionSize] == 0xE8);
|
||||
return (code_bytes[0] == 0xE8);
|
||||
}
|
||||
|
||||
uword target() const {
|
||||
@@ -124,7 +123,7 @@ class StaticCall : public ValueObject {
|
||||
CPU::FlushICache(call_address(), kInstructionSize);
|
||||
}
|
||||
|
||||
static const int kNumInstructions = 2;
|
||||
static const int kNumInstructions = 1;
|
||||
static const int kInstructionSize = 5; // All instructions have same length.
|
||||
|
||||
private:
|
||||
@@ -133,7 +132,7 @@ class StaticCall : public ValueObject {
|
||||
}
|
||||
|
||||
uword call_address() const {
|
||||
return start_ + 1 * kInstructionSize;
|
||||
return start_;
|
||||
}
|
||||
|
||||
uword start_;
|
||||
|
||||
@@ -86,7 +86,7 @@ class InstanceCall : public DartCallPattern {
|
||||
|
||||
|
||||
// The expected pattern of a dart static call:
|
||||
// mov R10, arguments_descriptor_array (10 bytes)
|
||||
// mov R10, arguments_descriptor_array (10 bytes) (optional in polym. calls)
|
||||
// mov R11, target_address (10 bytes)
|
||||
// call R11 (3 bytes)
|
||||
// <- return address
|
||||
@@ -95,28 +95,27 @@ class StaticCall : public ValueObject {
|
||||
explicit StaticCall(uword return_address)
|
||||
: start_(return_address - kCallPatternSize) {
|
||||
ASSERT(IsValid(return_address));
|
||||
ASSERT((kCallPatternSize - 10) == Assembler::kCallExternalLabelSize);
|
||||
ASSERT(kCallPatternSize == Assembler::kCallExternalLabelSize);
|
||||
}
|
||||
|
||||
static const int kCallPatternSize = 23;
|
||||
static const int kCallPatternSize = 13;
|
||||
|
||||
static bool IsValid(uword return_address) {
|
||||
uint8_t* code_bytes =
|
||||
reinterpret_cast<uint8_t*>(return_address - kCallPatternSize);
|
||||
return (code_bytes[00] == 0x49) && (code_bytes[01] == 0xBA) &&
|
||||
(code_bytes[10] == 0x49) && (code_bytes[11] == 0xBB) &&
|
||||
(code_bytes[20] == 0x41) && (code_bytes[21] == 0xFF) &&
|
||||
(code_bytes[22] == 0xD3);
|
||||
return (code_bytes[00] == 0x49) && (code_bytes[01] == 0xBB) &&
|
||||
(code_bytes[10] == 0x41) && (code_bytes[11] == 0xFF) &&
|
||||
(code_bytes[12] == 0xD3);
|
||||
}
|
||||
|
||||
uword target() const {
|
||||
return *reinterpret_cast<uword*>(start_ + 10 + 2);
|
||||
return *reinterpret_cast<uword*>(start_ + 2);
|
||||
}
|
||||
|
||||
void set_target(uword target) const {
|
||||
uword* target_addr = reinterpret_cast<uword*>(start_ + 10 + 2);
|
||||
uword* target_addr = reinterpret_cast<uword*>(start_ + 2);
|
||||
*target_addr = target;
|
||||
CPU::FlushICache(start_ + 10, 2 + 8);
|
||||
CPU::FlushICache(start_, 2 + 8);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1386,8 +1386,8 @@ void FlowGraphCompiler::RestoreLiveRegisters(LocationSummary* locs) {
|
||||
|
||||
void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
Register class_id_reg,
|
||||
intptr_t arg_count,
|
||||
const Array& arg_names,
|
||||
intptr_t argument_count,
|
||||
const Array& argument_names,
|
||||
Label* deopt,
|
||||
intptr_t deopt_id,
|
||||
intptr_t token_index,
|
||||
@@ -1397,6 +1397,12 @@ void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
const intptr_t len = ic_data.NumberOfChecks();
|
||||
GrowableArray<CidTarget> sorted(len);
|
||||
SortICDataByCount(ic_data, &sorted);
|
||||
ASSERT(class_id_reg != EDX);
|
||||
ASSERT(len > 0); // Why bother otherwise.
|
||||
const Array& arguments_descriptor =
|
||||
Array::ZoneHandle(ArgumentsDescriptor::New(argument_count,
|
||||
argument_names));
|
||||
__ LoadObject(EDX, arguments_descriptor);
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
const bool is_last_check = (i == (len - 1));
|
||||
Label next_test;
|
||||
@@ -1406,12 +1412,16 @@ void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
} else {
|
||||
assembler()->j(NOT_EQUAL, &next_test);
|
||||
}
|
||||
GenerateStaticCall(deopt_id,
|
||||
token_index,
|
||||
*sorted[i].target,
|
||||
arg_count,
|
||||
arg_names,
|
||||
locs);
|
||||
// Do not use the code from the function, but let the code be patched so
|
||||
// that we can record the outgoing edges to other code.
|
||||
GenerateDartCall(deopt_id,
|
||||
token_index,
|
||||
&StubCode::CallStaticFunctionLabel(),
|
||||
PcDescriptors::kFuncCall,
|
||||
locs);
|
||||
const Function& function = *sorted[i].target;
|
||||
AddStaticCallTarget(function);
|
||||
__ Drop(argument_count);
|
||||
if (!is_last_check) {
|
||||
assembler()->jmp(&match_found);
|
||||
}
|
||||
|
||||
@@ -1386,8 +1386,8 @@ void FlowGraphCompiler::RestoreLiveRegisters(LocationSummary* locs) {
|
||||
|
||||
void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
Register class_id_reg,
|
||||
intptr_t arg_count,
|
||||
const Array& arg_names,
|
||||
intptr_t argument_count,
|
||||
const Array& argument_names,
|
||||
Label* deopt,
|
||||
intptr_t deopt_id,
|
||||
intptr_t token_index,
|
||||
@@ -1397,6 +1397,12 @@ void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
const intptr_t len = ic_data.NumberOfChecks();
|
||||
GrowableArray<CidTarget> sorted(len);
|
||||
SortICDataByCount(ic_data, &sorted);
|
||||
ASSERT(class_id_reg != R10);
|
||||
ASSERT(len > 0); // Why bother otherwise.
|
||||
const Array& arguments_descriptor =
|
||||
Array::ZoneHandle(ArgumentsDescriptor::New(argument_count,
|
||||
argument_names));
|
||||
__ LoadObject(R10, arguments_descriptor);
|
||||
for (intptr_t i = 0; i < len; i++) {
|
||||
const bool is_last_check = (i == (len - 1));
|
||||
Label next_test;
|
||||
@@ -1406,12 +1412,16 @@ void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data,
|
||||
} else {
|
||||
assembler()->j(NOT_EQUAL, &next_test);
|
||||
}
|
||||
GenerateStaticCall(deopt_id,
|
||||
token_index,
|
||||
*sorted[i].target,
|
||||
arg_count,
|
||||
arg_names,
|
||||
locs);
|
||||
// Do not use the code from the function, but let the code be patched so
|
||||
// that we can record the outgoing edges to other code.
|
||||
GenerateDartCall(deopt_id,
|
||||
token_index,
|
||||
&StubCode::CallStaticFunctionLabel(),
|
||||
PcDescriptors::kFuncCall,
|
||||
locs);
|
||||
const Function& function = *sorted[i].target;
|
||||
AddStaticCallTarget(function);
|
||||
__ Drop(argument_count);
|
||||
if (!is_last_check) {
|
||||
assembler()->jmp(&match_found);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user