Index: src/code-stubs.cc |
diff --git a/src/code-stubs.cc b/src/code-stubs.cc |
index 0ac07de0ddfd93a262a6a6fc544c113de3962181..2a15b628cd121d293abf38ef91527d7b6c5419ff 100644 |
--- a/src/code-stubs.cc |
+++ b/src/code-stubs.cc |
@@ -111,21 +111,12 @@ bool CodeStub::FindCodeInCache(Code** code_out) { |
} |
-SmartArrayPointer<const char> CodeStub::GetName() { |
- char buffer[100]; |
- NoAllocationStringAllocator allocator(buffer, |
- static_cast<unsigned>(sizeof(buffer))); |
- StringStream stream(&allocator); |
- PrintName(&stream); |
- return stream.ToCString(); |
-} |
- |
- |
void CodeStub::RecordCodeGeneration(Handle<Code> code) { |
IC::RegisterWeakMapDependency(code); |
- SmartArrayPointer<const char> name = GetName(); |
- PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, name.get())); |
- GDBJIT(AddCode(GDBJITInterface::STUB, name.get(), *code)); |
+ OStringStream os; |
+ os << *this; |
+ PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, os.c_str())); |
+ GDBJIT(AddCode(GDBJITInterface::STUB, os.c_str(), *code)); |
Counters* counters = isolate()->counters(); |
counters->total_stubs_code_size()->Increment(code->instruction_size()); |
} |
@@ -198,7 +189,9 @@ Handle<Code> CodeStub::GetCode() { |
#ifdef ENABLE_DISASSEMBLER |
if (FLAG_print_code_stubs) { |
CodeTracer::Scope trace_scope(isolate()->GetCodeTracer()); |
- new_object->Disassemble(GetName().get(), trace_scope.file()); |
+ OStringStream os; |
+ os << *this; |
+ new_object->Disassemble(os.c_str(), trace_scope.file()); |
PrintF(trace_scope.file(), "\n"); |
} |
#endif |
@@ -241,14 +234,15 @@ const char* CodeStub::MajorName(CodeStub::Major major_key, |
} |
-void CodeStub::PrintBaseName(StringStream* stream) { |
- stream->Add("%s", MajorName(MajorKey(), false)); |
+OStream& CodeStub::PrintBaseName(OStream& os) const { // NOLINT |
+ return os << MajorName(MajorKey(), false); |
} |
-void CodeStub::PrintName(StringStream* stream) { |
- PrintBaseName(stream); |
- PrintState(stream); |
+OStream& CodeStub::PrintName(OStream& os) const { // NOLINT |
+ PrintBaseName(os); |
+ PrintState(os); |
+ return os; |
} |
@@ -269,8 +263,8 @@ void BinaryOpICStub::GenerateAheadOfTime(Isolate* isolate) { |
} |
-void BinaryOpICStub::PrintState(StringStream* stream) { |
- state_.Print(stream); |
+OStream& BinaryOpICStub::PrintState(OStream& os) const { // NOLINT |
+ return os << state_; |
} |
@@ -289,8 +283,9 @@ void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { |
} |
-void BinaryOpICWithAllocationSiteStub::PrintState(StringStream* stream) { |
- state_.Print(stream); |
+OStream& BinaryOpICWithAllocationSiteStub::PrintState( |
+ OStream& os) const { // NOLINT |
+ return os << state_; |
} |
@@ -304,18 +299,19 @@ void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime( |
} |
-void StringAddStub::PrintBaseName(StringStream* stream) { |
- stream->Add("StringAddStub"); |
+OStream& StringAddStub::PrintBaseName(OStream& os) const { // NOLINT |
+ os << "StringAddStub"; |
if ((flags() & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
- stream->Add("_CheckBoth"); |
+ os << "_CheckBoth"; |
} else if ((flags() & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
- stream->Add("_CheckLeft"); |
+ os << "_CheckLeft"; |
} else if ((flags() & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
- stream->Add("_CheckRight"); |
+ os << "_CheckRight"; |
} |
if (pretenure_flag() == TENURED) { |
- stream->Add("_Tenured"); |
+ os << "_Tenured"; |
} |
+ return os; |
} |
@@ -379,7 +375,7 @@ bool ICCompareStub::FindCodeInSpecialCache(Code** code_out) { |
} |
-int ICCompareStub::MinorKey() { |
+int ICCompareStub::MinorKey() const { |
return OpField::encode(op_ - Token::EQ) | |
LeftStateField::encode(left_) | |
RightStateField::encode(right_) | |
@@ -472,42 +468,52 @@ void HydrogenCodeStub::TraceTransition(StateType from, StateType to) { |
// bug somewhere in our state transition machinery. |
ASSERT(from != to); |
if (!FLAG_trace_ic) return; |
- char buffer[100]; |
- NoAllocationStringAllocator allocator(buffer, |
- static_cast<unsigned>(sizeof(buffer))); |
- StringStream stream(&allocator); |
- stream.Add("["); |
- PrintBaseName(&stream); |
- stream.Add(": "); |
- from.Print(&stream); |
- stream.Add("=>"); |
- to.Print(&stream); |
- stream.Add("]\n"); |
- stream.OutputToStdOut(); |
+ OFStream os(stdout); |
+ os << "["; |
+ PrintBaseName(os) << ": " << from << "=>" << to << "]" << endl; |
} |
-void CompareNilICStub::PrintBaseName(StringStream* stream) { |
- CodeStub::PrintBaseName(stream); |
- stream->Add((nil_value_ == kNullValue) ? "(NullValue)": |
- "(UndefinedValue)"); |
+OStream& CompareNilICStub::PrintBaseName(OStream& os) const { // NOLINT |
+ return CodeStub::PrintBaseName(os) << |
+ ((nil_value_ == kNullValue) ? "(NullValue)": "(UndefinedValue)"); |
} |
-void CompareNilICStub::PrintState(StringStream* stream) { |
- state_.Print(stream); |
+OStream& CompareNilICStub::PrintState(OStream& os) const { // NOLINT |
+ return os << state_; |
} |
-void CompareNilICStub::State::Print(StringStream* stream) const { |
- stream->Add("("); |
- SimpleListPrinter printer(stream); |
- if (IsEmpty()) printer.Add("None"); |
- if (Contains(UNDEFINED)) printer.Add("Undefined"); |
- if (Contains(NULL_TYPE)) printer.Add("Null"); |
- if (Contains(MONOMORPHIC_MAP)) printer.Add("MonomorphicMap"); |
- if (Contains(GENERIC)) printer.Add("Generic"); |
- stream->Add(")"); |
+// TODO(svenpanne) Make this a real infix_ostream_iterator. |
+class SimpleListPrinter { |
+ public: |
+ explicit SimpleListPrinter(OStream& os) : os_(os), first_(true) { } |
+ |
+ void Add(const char* s) { |
+ if (first_) { |
+ first_ = false; |
+ } else { |
+ os_ << ","; |
+ } |
+ os_ << s; |
+ } |
+ |
+ private: |
+ OStream& os_; |
+ bool first_; |
+}; |
+ |
+ |
+OStream& operator<<(OStream& os, const CompareNilICStub::State& s) { |
+ os << "("; |
+ SimpleListPrinter p(os); |
+ if (s.IsEmpty()) p.Add("None"); |
+ if (s.Contains(CompareNilICStub::UNDEFINED)) p.Add("Undefined"); |
+ if (s.Contains(CompareNilICStub::NULL_TYPE)) p.Add("Null"); |
+ if (s.Contains(CompareNilICStub::MONOMORPHIC_MAP)) p.Add("MonomorphicMap"); |
+ if (s.Contains(CompareNilICStub::GENERIC)) p.Add("Generic"); |
+ return os << ")"; |
} |
@@ -541,37 +547,22 @@ Type* CompareNilICStub::GetInputType(Zone* zone, Handle<Map> map) { |
} |
-void CallIC_ArrayStub::PrintState(StringStream* stream) { |
- state_.Print(stream); |
- stream->Add(" (Array)"); |
+OStream& CallIC_ArrayStub::PrintState(OStream& os) const { // NOLINT |
+ return os << state_ << " (Array)"; |
} |
-void CallICStub::PrintState(StringStream* stream) { |
- state_.Print(stream); |
+OStream& CallICStub::PrintState(OStream& os) const { // NOLINT |
+ return os << state_; |
} |
-void InstanceofStub::PrintName(StringStream* stream) { |
- const char* args = ""; |
- if (HasArgsInRegisters()) { |
- args = "_REGS"; |
- } |
- |
- const char* inline_check = ""; |
- if (HasCallSiteInlineCheck()) { |
- inline_check = "_INLINE"; |
- } |
- |
- const char* return_true_false_object = ""; |
- if (ReturnTrueFalseObject()) { |
- return_true_false_object = "_TRUEFALSE"; |
- } |
- |
- stream->Add("InstanceofStub%s%s%s", |
- args, |
- inline_check, |
- return_true_false_object); |
+OStream& InstanceofStub::PrintName(OStream& os) const { // NOLINT |
+ os << "InstanceofStub"; |
+ if (HasArgsInRegisters()) os << "_REGS"; |
+ if (HasCallSiteInlineCheck()) os << "_INLINE"; |
+ if (ReturnTrueFalseObject()) os << "_TRUEFALSE"; |
+ return os; |
} |
@@ -682,47 +673,51 @@ void KeyedStoreElementStub::Generate(MacroAssembler* masm) { |
} |
-void ArgumentsAccessStub::PrintName(StringStream* stream) { |
- stream->Add("ArgumentsAccessStub_"); |
+OStream& ArgumentsAccessStub::PrintName(OStream& os) const { // NOLINT |
+ os << "ArgumentsAccessStub_"; |
switch (type_) { |
- case READ_ELEMENT: stream->Add("ReadElement"); break; |
- case NEW_SLOPPY_FAST: stream->Add("NewSloppyFast"); break; |
- case NEW_SLOPPY_SLOW: stream->Add("NewSloppySlow"); break; |
- case NEW_STRICT: stream->Add("NewStrict"); break; |
+ case READ_ELEMENT: return os << "ReadElement"; |
+ case NEW_SLOPPY_FAST: return os << "NewSloppyFast"; |
+ case NEW_SLOPPY_SLOW: return os << "NewSloppySlow"; |
+ case NEW_STRICT: return os << "NewStrict"; |
} |
+ UNREACHABLE(); |
+ return os; |
} |
-void CallFunctionStub::PrintName(StringStream* stream) { |
- stream->Add("CallFunctionStub_Args%d", argc_); |
+OStream& CallFunctionStub::PrintName(OStream& os) const { // NOLINT |
+ return os << "CallFunctionStub_Args" << argc_; |
} |
-void CallConstructStub::PrintName(StringStream* stream) { |
- stream->Add("CallConstructStub"); |
- if (RecordCallTarget()) stream->Add("_Recording"); |
+OStream& CallConstructStub::PrintName(OStream& os) const { // NOLINT |
+ os << "CallConstructStub"; |
+ if (RecordCallTarget()) os << "_Recording"; |
+ return os; |
} |
-void ArrayConstructorStub::PrintName(StringStream* stream) { |
- stream->Add("ArrayConstructorStub"); |
+OStream& ArrayConstructorStub::PrintName(OStream& os) const { // NOLINT |
+ os << "ArrayConstructorStub"; |
switch (argument_count_) { |
- case ANY: stream->Add("_Any"); break; |
- case NONE: stream->Add("_None"); break; |
- case ONE: stream->Add("_One"); break; |
- case MORE_THAN_ONE: stream->Add("_More_Than_One"); break; |
+ case ANY: return os << "_Any"; |
+ case NONE: return os << "_None"; |
+ case ONE: return os << "_One"; |
+ case MORE_THAN_ONE: return os << "_More_Than_One"; |
} |
+ UNREACHABLE(); |
+ return os; |
} |
-void ArrayConstructorStubBase::BasePrintName(const char* name, |
- StringStream* stream) { |
- stream->Add(name); |
- stream->Add("_"); |
- stream->Add(ElementsKindToString(elements_kind())); |
+OStream& ArrayConstructorStubBase::BasePrintName(OStream& os, // NOLINT |
+ const char* name) const { |
+ os << name << "_" << ElementsKindToString(elements_kind()); |
if (override_mode() == DISABLE_ALLOCATION_SITES) { |
- stream->Add("_DISABLE_ALLOCATION_SITES"); |
+ os << "_DISABLE_ALLOCATION_SITES"; |
} |
+ return os; |
} |
@@ -734,24 +729,24 @@ bool ToBooleanStub::UpdateStatus(Handle<Object> object) { |
} |
-void ToBooleanStub::PrintState(StringStream* stream) { |
- types_.Print(stream); |
+OStream& ToBooleanStub::PrintState(OStream& os) const { // NOLINT |
+ return os << types_; |
} |
-void ToBooleanStub::Types::Print(StringStream* stream) const { |
- stream->Add("("); |
- SimpleListPrinter printer(stream); |
- if (IsEmpty()) printer.Add("None"); |
- if (Contains(UNDEFINED)) printer.Add("Undefined"); |
- if (Contains(BOOLEAN)) printer.Add("Bool"); |
- if (Contains(NULL_TYPE)) printer.Add("Null"); |
- if (Contains(SMI)) printer.Add("Smi"); |
- if (Contains(SPEC_OBJECT)) printer.Add("SpecObject"); |
- if (Contains(STRING)) printer.Add("String"); |
- if (Contains(SYMBOL)) printer.Add("Symbol"); |
- if (Contains(HEAP_NUMBER)) printer.Add("HeapNumber"); |
- stream->Add(")"); |
+OStream& operator<<(OStream& os, const ToBooleanStub::Types& s) { |
+ os << "("; |
+ SimpleListPrinter p(os); |
+ if (s.IsEmpty()) p.Add("None"); |
+ if (s.Contains(ToBooleanStub::UNDEFINED)) p.Add("Undefined"); |
+ if (s.Contains(ToBooleanStub::BOOLEAN)) p.Add("Bool"); |
+ if (s.Contains(ToBooleanStub::NULL_TYPE)) p.Add("Null"); |
+ if (s.Contains(ToBooleanStub::SMI)) p.Add("Smi"); |
+ if (s.Contains(ToBooleanStub::SPEC_OBJECT)) p.Add("SpecObject"); |
+ if (s.Contains(ToBooleanStub::STRING)) p.Add("String"); |
+ if (s.Contains(ToBooleanStub::SYMBOL)) p.Add("Symbol"); |
+ if (s.Contains(ToBooleanStub::HEAP_NUMBER)) p.Add("HeapNumber"); |
+ return os << ")"; |
} |