From 3141494c3e1d5b1b7014bbb71192fb0c85520eaf Mon Sep 17 00:00:00 2001 From: "karlklose@chromium.org" Date: Wed, 26 Jan 2011 20:48:48 +0000 Subject: [PATCH] Refactor recording of safepoints. Refactor SafepointTableBuilder::DefineSafepoint and ARM LCodeGen::RecordSafepoint to use an enum for different kinds of safepoints. This change removes a lot of duplicated code and makes it easier to include new kinds of safepoints in the future. The remaining variants of LCodeGen::RecordSafepoint remain as a convinient way to record common safepoint kinds. BUG=http://code.google.com/p/v8/issues/detail?id=1043 TEST=none Review URL: http://codereview.chromium.org/6341008 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6505 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-codegen-arm.cc | 53 +++++++++++++------------------- src/arm/lithium-codegen-arm.h | 4 +++ src/ia32/lithium-codegen-ia32.cc | 37 ++++++++++++---------- src/ia32/lithium-codegen-ia32.h | 4 +++ src/safepoint-table.cc | 43 +++++--------------------- src/safepoint-table.h | 25 +++++---------- src/x64/lithium-codegen-x64.cc | 37 ++++++++++++---------- src/x64/lithium-codegen-x64.h | 4 +++ 8 files changed, 89 insertions(+), 118 deletions(-) diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 5e2e380ba..a90287cf1 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -736,37 +736,40 @@ void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { } -void LCodeGen::RecordSafepoint(LPointerMap* pointers, - int deoptimization_index) { +void LCodeGen::RecordSafepoint( + LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index) { const ZoneList* operands = pointers->operands(); Safepoint safepoint = safepoints_.DefineSafepoint(masm(), - deoptimization_index); + kind, arguments, deoptimization_index); for (int i = 0; i < operands->length(); i++) { LOperand* pointer = operands->at(i); if (pointer->IsStackSlot()) { safepoint.DefinePointerSlot(pointer->index()); + } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { + safepoint.DefinePointerRegister(ToRegister(pointer)); } } + if (kind & Safepoint::kWithRegisters) { + // Register cp always contains a pointer to the context. + safepoint.DefinePointerRegister(cp); + } +} + + +void LCodeGen::RecordSafepoint(LPointerMap* pointers, + int deoptimization_index) { + RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); } void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, int deoptimization_index) { - const ZoneList* operands = pointers->operands(); - Safepoint safepoint = - safepoints_.DefineSafepointWithRegisters( - masm(), arguments, deoptimization_index); - for (int i = 0; i < operands->length(); i++) { - LOperand* pointer = operands->at(i); - if (pointer->IsStackSlot()) { - safepoint.DefinePointerSlot(pointer->index()); - } else if (pointer->IsRegister()) { - safepoint.DefinePointerRegister(ToRegister(pointer)); - } - } - // Register cp always contains a pointer to the context. - safepoint.DefinePointerRegister(cp); + RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, + deoptimization_index); } @@ -774,20 +777,8 @@ void LCodeGen::RecordSafepointWithRegistersAndDoubles( LPointerMap* pointers, int arguments, int deoptimization_index) { - const ZoneList* operands = pointers->operands(); - Safepoint safepoint = - safepoints_.DefineSafepointWithRegistersAndDoubles( - masm(), arguments, deoptimization_index); - for (int i = 0; i < operands->length(); i++) { - LOperand* pointer = operands->at(i); - if (pointer->IsStackSlot()) { - safepoint.DefinePointerSlot(pointer->index()); - } else if (pointer->IsRegister()) { - safepoint.DefinePointerRegister(ToRegister(pointer)); - } - } - // Register cp always contains a pointer to the context. - safepoint.DefinePointerRegister(cp); + RecordSafepoint(pointers, Safepoint::kWithRegistersAndDoubles, arguments, + deoptimization_index); } diff --git a/src/arm/lithium-codegen-arm.h b/src/arm/lithium-codegen-arm.h index 3b2ad80c5..27a72f29a 100644 --- a/src/arm/lithium-codegen-arm.h +++ b/src/arm/lithium-codegen-arm.h @@ -223,6 +223,10 @@ class LCodeGen BASE_EMBEDDED { void DoMathSqrt(LUnaryMathOperation* instr); // Support for recording safepoint and position information. + void RecordSafepoint(LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index); void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); void RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 3bfb10f80..29fe10994 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -566,37 +566,40 @@ void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { } -void LCodeGen::RecordSafepoint(LPointerMap* pointers, - int deoptimization_index) { +void LCodeGen::RecordSafepoint( + LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index) { const ZoneList* operands = pointers->operands(); Safepoint safepoint = safepoints_.DefineSafepoint(masm(), - deoptimization_index); + kind, arguments, deoptimization_index); for (int i = 0; i < operands->length(); i++) { LOperand* pointer = operands->at(i); if (pointer->IsStackSlot()) { safepoint.DefinePointerSlot(pointer->index()); + } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { + safepoint.DefinePointerRegister(ToRegister(pointer)); } } + if (kind & Safepoint::kWithRegisters) { + // Register esi always contains a pointer to the context. + safepoint.DefinePointerRegister(esi); + } +} + + +void LCodeGen::RecordSafepoint(LPointerMap* pointers, + int deoptimization_index) { + RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); } void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, int deoptimization_index) { - const ZoneList* operands = pointers->operands(); - Safepoint safepoint = - safepoints_.DefineSafepointWithRegisters( - masm(), arguments, deoptimization_index); - for (int i = 0; i < operands->length(); i++) { - LOperand* pointer = operands->at(i); - if (pointer->IsStackSlot()) { - safepoint.DefinePointerSlot(pointer->index()); - } else if (pointer->IsRegister()) { - safepoint.DefinePointerRegister(ToRegister(pointer)); - } - } - // Register esi always contains a pointer to the context. - safepoint.DefinePointerRegister(esi); + RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, + deoptimization_index); } diff --git a/src/ia32/lithium-codegen-ia32.h b/src/ia32/lithium-codegen-ia32.h index 780525a59..f0379c02e 100644 --- a/src/ia32/lithium-codegen-ia32.h +++ b/src/ia32/lithium-codegen-ia32.h @@ -198,6 +198,10 @@ class LCodeGen BASE_EMBEDDED { void DoMathSin(LUnaryMathOperation* instr); // Support for recording safepoint and position information. + void RecordSafepoint(LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index); void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); void RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, diff --git a/src/safepoint-table.cc b/src/safepoint-table.cc index e79dcff09..153bf4327 100644 --- a/src/safepoint-table.cc +++ b/src/safepoint-table.cc @@ -117,24 +117,9 @@ void Safepoint::DefinePointerRegister(Register reg) { } -Safepoint SafepointTableBuilder::DefineSafepoint(Assembler* assembler, - int deoptimization_index) { - ASSERT(deoptimization_index != -1); - DeoptimizationInfo pc_and_deoptimization_index; - pc_and_deoptimization_index.pc = assembler->pc_offset(); - pc_and_deoptimization_index.deoptimization_index = deoptimization_index; - pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); - pc_and_deoptimization_index.arguments = 0; - pc_and_deoptimization_index.has_doubles = false; - deoptimization_info_.Add(pc_and_deoptimization_index); - indexes_.Add(new ZoneList(8)); - registers_.Add(NULL); - return Safepoint(indexes_.last(), registers_.last()); -} - - -Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( - Assembler* assembler, int arguments, int deoptimization_index) { +Safepoint SafepointTableBuilder::DefineSafepoint( + Assembler* assembler, Safepoint::Kind kind, int arguments, + int deoptimization_index) { ASSERT(deoptimization_index != -1); ASSERT(arguments >= 0); DeoptimizationInfo pc_and_deoptimization_index; @@ -142,30 +127,16 @@ Safepoint SafepointTableBuilder::DefineSafepointWithRegisters( pc_and_deoptimization_index.deoptimization_index = deoptimization_index; pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); pc_and_deoptimization_index.arguments = arguments; - pc_and_deoptimization_index.has_doubles = false; + pc_and_deoptimization_index.has_doubles = (kind & Safepoint::kWithDoubles); deoptimization_info_.Add(pc_and_deoptimization_index); indexes_.Add(new ZoneList(8)); - registers_.Add(new ZoneList(4)); + registers_.Add((kind & Safepoint::kWithRegisters) + ? new ZoneList(4) + : NULL); return Safepoint(indexes_.last(), registers_.last()); } -Safepoint SafepointTableBuilder::DefineSafepointWithRegistersAndDoubles( - Assembler* assembler, int arguments, int deoptimization_index) { - ASSERT(deoptimization_index != -1); - ASSERT(arguments >= 0); - DeoptimizationInfo pc_and_deoptimization_index; - pc_and_deoptimization_index.pc = assembler->pc_offset(); - pc_and_deoptimization_index.deoptimization_index = deoptimization_index; - pc_and_deoptimization_index.pc_after_gap = assembler->pc_offset(); - pc_and_deoptimization_index.arguments = arguments; - pc_and_deoptimization_index.has_doubles = true; - deoptimization_info_.Add(pc_and_deoptimization_index); - indexes_.Add(new ZoneList(8)); - registers_.Add(new ZoneList(4)); - return Safepoint(indexes_.last(), registers_.last()); -} - unsigned SafepointTableBuilder::GetCodeOffset() const { ASSERT(emitted_); return offset_; diff --git a/src/safepoint-table.h b/src/safepoint-table.h index d70305142..fa3590511 100644 --- a/src/safepoint-table.h +++ b/src/safepoint-table.h @@ -180,6 +180,13 @@ class SafepointTable BASE_EMBEDDED { class Safepoint BASE_EMBEDDED { public: + typedef enum { + kSimple = 0, + kWithRegisters = 1 << 0, + kWithDoubles = 1 << 1, + kWithRegistersAndDoubles = kWithRegisters | kWithDoubles + } Kind; + static const int kNoDeoptimizationIndex = (1 << (SafepointEntry::kDeoptIndexBits)) - 1; @@ -210,23 +217,7 @@ class SafepointTableBuilder BASE_EMBEDDED { // Define a new safepoint for the current position in the body. Safepoint DefineSafepoint( Assembler* assembler, - int deoptimization_index = Safepoint::kNoDeoptimizationIndex); - - // Define a new safepoint with registers on the stack for the - // current position in the body and take the number of arguments on - // top of the registers into account. - Safepoint DefineSafepointWithRegisters( - Assembler* assembler, - int arguments, - int deoptimization_index = Safepoint::kNoDeoptimizationIndex); - - // Define a new safepoint with all double registers and the normal - // registers on the stack for the current position in the body and - // take the number of arguments on top of the registers into account. - // TODO(1043) Rewrite the three SafepointTableBuilder::DefineSafepoint - // methods to one method that uses template arguments. - Safepoint DefineSafepointWithRegistersAndDoubles( - Assembler* assembler, + Safepoint::Kind kind, int arguments, int deoptimization_index = Safepoint::kNoDeoptimizationIndex); diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index f04654532..bf0dd5e31 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -495,37 +495,40 @@ void LCodeGen::PopulateDeoptimizationLiteralsWithInlinedFunctions() { } -void LCodeGen::RecordSafepoint(LPointerMap* pointers, - int deoptimization_index) { +void LCodeGen::RecordSafepoint( + LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index) { const ZoneList* operands = pointers->operands(); Safepoint safepoint = safepoints_.DefineSafepoint(masm(), - deoptimization_index); + kind, arguments, deoptimization_index); for (int i = 0; i < operands->length(); i++) { LOperand* pointer = operands->at(i); if (pointer->IsStackSlot()) { safepoint.DefinePointerSlot(pointer->index()); + } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { + safepoint.DefinePointerRegister(ToRegister(pointer)); } } + if (kind & Safepoint::kWithRegisters) { + // Register rsi always contains a pointer to the context. + safepoint.DefinePointerRegister(rsi); + } +} + + +void LCodeGen::RecordSafepoint(LPointerMap* pointers, + int deoptimization_index) { + RecordSafepoint(pointers, Safepoint::kSimple, 0, deoptimization_index); } void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, int deoptimization_index) { - const ZoneList* operands = pointers->operands(); - Safepoint safepoint = - safepoints_.DefineSafepointWithRegisters( - masm(), arguments, deoptimization_index); - for (int i = 0; i < operands->length(); i++) { - LOperand* pointer = operands->at(i); - if (pointer->IsStackSlot()) { - safepoint.DefinePointerSlot(pointer->index()); - } else if (pointer->IsRegister()) { - safepoint.DefinePointerRegister(ToRegister(pointer)); - } - } - // Register rsi always contains a pointer to the context. - safepoint.DefinePointerRegister(rsi); + RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, + deoptimization_index); } diff --git a/src/x64/lithium-codegen-x64.h b/src/x64/lithium-codegen-x64.h index 7da4047e6..cbcc5c8b0 100644 --- a/src/x64/lithium-codegen-x64.h +++ b/src/x64/lithium-codegen-x64.h @@ -192,6 +192,10 @@ class LCodeGen BASE_EMBEDDED { void DoMathSin(LUnaryMathOperation* instr); // Support for recording safepoint and position information. + void RecordSafepoint(LPointerMap* pointers, + Safepoint::Kind kind, + int arguments, + int deoptimization_index); void RecordSafepoint(LPointerMap* pointers, int deoptimization_index); void RecordSafepointWithRegisters(LPointerMap* pointers, int arguments, -- 2.34.1