From d7934d1fbe3b9724f7628e51af3bd56ea57e199b Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Thu, 3 Jul 2014 07:18:30 +0000 Subject: [PATCH] Start using OStreams. Note that until everything is OStream-based, there are a few places where we have to do some impedance matching. A few accessors had to be const-corrected on the way. R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/334763003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22179 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 4 +- src/arm/code-stubs-arm.h | 30 ++--- src/arm64/code-stubs-arm64.h | 34 +++-- src/code-stubs-hydrogen.cc | 6 +- src/code-stubs.cc | 246 ++++++++++++++++++----------------- src/code-stubs.h | 301 +++++++++++++++++++++---------------------- src/codegen.cc | 2 +- src/hydrogen-dce.cc | 12 +- src/hydrogen-gvn.cc | 8 +- src/hydrogen-instructions.cc | 14 +- src/hydrogen-instructions.h | 3 + src/ia32/code-stubs-ia32.h | 20 +-- src/ic.cc | 48 +++---- src/ic.h | 12 +- src/isolate.h | 1 - src/log.cc | 37 +++--- src/objects.cc | 36 +++--- src/property.cc | 41 +++--- src/string-stream.cc | 15 --- src/string-stream.h | 40 ------ src/types.cc | 128 ++++++++---------- src/types.h | 7 +- src/typing.cc | 10 +- src/x64/code-stubs-x64.h | 20 +-- 24 files changed, 501 insertions(+), 574 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index e1f39fa..3870015 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -426,8 +426,8 @@ class ConvertToDoubleStub : public PlatformCodeStub { class ModeBits: public BitField {}; class OpBits: public BitField {}; - Major MajorKey() { return ConvertToDouble; } - int MinorKey() { + Major MajorKey() const { return ConvertToDouble; } + int MinorKey() const { // Encode the parameters in a unique 16 bit value. return result1_.code() + (result2_.code() << 4) + diff --git a/src/arm/code-stubs-arm.h b/src/arm/code-stubs-arm.h index eb7d2c6..5fa19d6 100644 --- a/src/arm/code-stubs-arm.h +++ b/src/arm/code-stubs-arm.h @@ -27,8 +27,8 @@ class StoreBufferOverflowStub: public PlatformCodeStub { private: SaveFPRegsMode save_doubles_; - Major MajorKey() { return StoreBufferOverflow; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return StoreBufferOverflow; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } }; @@ -68,8 +68,8 @@ class SubStringStub: public PlatformCodeStub { explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {} private: - Major MajorKey() { return SubString; } - int MinorKey() { return 0; } + Major MajorKey() const { return SubString; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); }; @@ -99,8 +99,8 @@ class StringCompareStub: public PlatformCodeStub { Register scratch3); private: - virtual Major MajorKey() { return StringCompare; } - virtual int MinorKey() { return 0; } + virtual Major MajorKey() const { return StringCompare; } + virtual int MinorKey() const { return 0; } virtual void Generate(MacroAssembler* masm); static void GenerateAsciiCharsCompareLoop(MacroAssembler* masm, @@ -139,8 +139,8 @@ class WriteInt32ToHeapNumberStub : public PlatformCodeStub { class HeapNumberRegisterBits: public BitField {}; class ScratchRegisterBits: public BitField {}; - Major MajorKey() { return WriteInt32ToHeapNumber; } - int MinorKey() { + Major MajorKey() const { return WriteInt32ToHeapNumber; } + int MinorKey() const { // Encode the parameters in a unique 16 bit value. return IntRegisterBits::encode(the_int_.code()) | HeapNumberRegisterBits::encode(the_heap_number_.code()) @@ -305,9 +305,9 @@ class RecordWriteStub: public PlatformCodeStub { Mode mode); void InformIncrementalMarker(MacroAssembler* masm); - Major MajorKey() { return RecordWrite; } + Major MajorKey() const { return RecordWrite; } - int MinorKey() { + int MinorKey() const { return ObjectBits::encode(object_.code()) | ValueBits::encode(value_.code()) | AddressBits::encode(address_.code()) | @@ -347,8 +347,8 @@ class DirectCEntryStub: public PlatformCodeStub { void GenerateCall(MacroAssembler* masm, Register target); private: - Major MajorKey() { return DirectCEntry; } - int MinorKey() { return 0; } + Major MajorKey() const { return DirectCEntry; } + int MinorKey() const { return 0; } bool NeedsImmovableCode() { return true; } }; @@ -393,11 +393,9 @@ class NameDictionaryLookupStub: public PlatformCodeStub { NameDictionary::kHeaderSize + NameDictionary::kElementsStartIndex * kPointerSize; - Major MajorKey() { return NameDictionaryLookup; } + Major MajorKey() const { return NameDictionaryLookup; } - int MinorKey() { - return LookupModeBits::encode(mode_); - } + int MinorKey() const { return LookupModeBits::encode(mode_); } class LookupModeBits: public BitField {}; diff --git a/src/arm64/code-stubs-arm64.h b/src/arm64/code-stubs-arm64.h index 5ee4c83..9520be9 100644 --- a/src/arm64/code-stubs-arm64.h +++ b/src/arm64/code-stubs-arm64.h @@ -27,8 +27,8 @@ class StoreBufferOverflowStub: public PlatformCodeStub { private: SaveFPRegsMode save_doubles_; - Major MajorKey() { return StoreBufferOverflow; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return StoreBufferOverflow; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } }; @@ -62,8 +62,8 @@ class StoreRegistersStateStub: public PlatformCodeStub { static Register to_be_pushed_lr() { return ip0; } static void GenerateAheadOfTime(Isolate* isolate); private: - Major MajorKey() { return StoreRegistersState; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return StoreRegistersState; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } SaveFPRegsMode save_doubles_; void Generate(MacroAssembler* masm); @@ -77,8 +77,8 @@ class RestoreRegistersStateStub: public PlatformCodeStub { static void GenerateAheadOfTime(Isolate* isolate); private: - Major MajorKey() { return RestoreRegistersState; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return RestoreRegistersState; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } SaveFPRegsMode save_doubles_; void Generate(MacroAssembler* masm); @@ -303,9 +303,9 @@ class RecordWriteStub: public PlatformCodeStub { Mode mode); void InformIncrementalMarker(MacroAssembler* masm); - Major MajorKey() { return RecordWrite; } + Major MajorKey() const { return RecordWrite; } - int MinorKey() { + int MinorKey() const { return MinorKeyFor(object_, value_, address_, remembered_set_action_, save_fp_regs_mode_); } @@ -354,8 +354,8 @@ class DirectCEntryStub: public PlatformCodeStub { void GenerateCall(MacroAssembler* masm, Register target); private: - Major MajorKey() { return DirectCEntry; } - int MinorKey() { return 0; } + Major MajorKey() const { return DirectCEntry; } + int MinorKey() const { return 0; } bool NeedsImmovableCode() { return true; } }; @@ -400,11 +400,9 @@ class NameDictionaryLookupStub: public PlatformCodeStub { NameDictionary::kHeaderSize + NameDictionary::kElementsStartIndex * kPointerSize; - Major MajorKey() { return NameDictionaryLookup; } + Major MajorKey() const { return NameDictionaryLookup; } - int MinorKey() { - return LookupModeBits::encode(mode_); - } + int MinorKey() const { return LookupModeBits::encode(mode_); } class LookupModeBits: public BitField {}; @@ -417,8 +415,8 @@ class SubStringStub: public PlatformCodeStub { explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {} private: - Major MajorKey() { return SubString; } - int MinorKey() { return 0; } + Major MajorKey() const { return SubString; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); }; @@ -447,8 +445,8 @@ class StringCompareStub: public PlatformCodeStub { Register scratch3); private: - virtual Major MajorKey() { return StringCompare; } - virtual int MinorKey() { return 0; } + virtual Major MajorKey() const { return StringCompare; } + virtual int MinorKey() const { return 0; } virtual void Generate(MacroAssembler* masm); static void GenerateAsciiCharsCompareLoop(MacroAssembler* masm, diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc index cce31d9..ab9daf4 100644 --- a/src/code-stubs-hydrogen.cc +++ b/src/code-stubs-hydrogen.cc @@ -270,9 +270,9 @@ static Handle DoGenerateCode(Stub* stub) { LChunk* chunk = OptimizeGraph(builder.CreateGraph()); Handle code = chunk->Codegen(); if (FLAG_profile_hydrogen_code_stub_compilation) { - double ms = timer.Elapsed().InMillisecondsF(); - PrintF("[Lazy compilation of %s took %0.3f ms]\n", - stub->GetName().get(), ms); + OFStream os(stdout); + os << "[Lazy compilation of " << stub << " took " + << timer.Elapsed().InMillisecondsF() << " ms]" << endl; } return code; } diff --git a/src/code-stubs.cc b/src/code-stubs.cc index b960133..963143a 100644 --- a/src/code-stubs.cc +++ b/src/code-stubs.cc @@ -111,21 +111,12 @@ bool CodeStub::FindCodeInCache(Code** code_out) { } -SmartArrayPointer CodeStub::GetName() { - char buffer[100]; - NoAllocationStringAllocator allocator(buffer, - static_cast(sizeof(buffer))); - StringStream stream(&allocator); - PrintName(&stream); - return stream.ToCString(); -} - - void CodeStub::RecordCodeGeneration(Handle code) { IC::RegisterWeakMapDependency(code); - SmartArrayPointer 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 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,14 @@ const char* CodeStub::MajorName(CodeStub::Major major_key, } -void CodeStub::PrintBaseName(StringStream* stream) { - stream->Add("%s", MajorName(MajorKey(), false)); +void CodeStub::PrintBaseName(OStream& os) const { // NOLINT + os << MajorName(MajorKey(), false); } -void CodeStub::PrintName(StringStream* stream) { - PrintBaseName(stream); - PrintState(stream); +void CodeStub::PrintName(OStream& os) const { // NOLINT + PrintBaseName(os); + PrintState(os); } @@ -269,8 +262,8 @@ void BinaryOpICStub::GenerateAheadOfTime(Isolate* isolate) { } -void BinaryOpICStub::PrintState(StringStream* stream) { - state_.Print(stream); +void BinaryOpICStub::PrintState(OStream& os) const { // NOLINT + os << state_; } @@ -289,8 +282,9 @@ void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(Isolate* isolate) { } -void BinaryOpICWithAllocationSiteStub::PrintState(StringStream* stream) { - state_.Print(stream); +void BinaryOpICWithAllocationSiteStub::PrintState( + OStream& os) const { // NOLINT + os << state_; } @@ -304,17 +298,17 @@ void BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime( } -void StringAddStub::PrintBaseName(StringStream* stream) { - stream->Add("StringAddStub"); +void 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"; } } @@ -379,7 +373,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 +466,53 @@ 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(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); + os << ": " << from << "=>" << to << "]" << endl; } -void CompareNilICStub::PrintBaseName(StringStream* stream) { - CodeStub::PrintBaseName(stream); - stream->Add((nil_value_ == kNullValue) ? "(NullValue)": - "(UndefinedValue)"); +void CompareNilICStub::PrintBaseName(OStream& os) const { // NOLINT + CodeStub::PrintBaseName(os); + os << ((nil_value_ == kNullValue) ? "(NullValue)" : "(UndefinedValue)"); } -void CompareNilICStub::PrintState(StringStream* stream) { - state_.Print(stream); +void CompareNilICStub::PrintState(OStream& os) const { // NOLINT + 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 +546,21 @@ Type* CompareNilICStub::GetInputType(Zone* zone, Handle map) { } -void CallIC_ArrayStub::PrintState(StringStream* stream) { - state_.Print(stream); - stream->Add(" (Array)"); +void CallIC_ArrayStub::PrintState(OStream& os) const { // NOLINT + os << state_ << " (Array)"; } -void CallICStub::PrintState(StringStream* stream) { - state_.Print(stream); +void CallICStub::PrintState(OStream& os) const { // NOLINT + 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); +void InstanceofStub::PrintName(OStream& os) const { // NOLINT + os << "InstanceofStub"; + if (HasArgsInRegisters()) os << "_REGS"; + if (HasCallSiteInlineCheck()) os << "_INLINE"; + if (ReturnTrueFalseObject()) os << "_TRUEFALSE"; } @@ -682,47 +671,64 @@ void KeyedStoreElementStub::Generate(MacroAssembler* masm) { } -void ArgumentsAccessStub::PrintName(StringStream* stream) { - stream->Add("ArgumentsAccessStub_"); +void 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: + os << "ReadElement"; + break; + case NEW_SLOPPY_FAST: + os << "NewSloppyFast"; + break; + case NEW_SLOPPY_SLOW: + os << "NewSloppySlow"; + break; + case NEW_STRICT: + os << "NewStrict"; + break; } + return; } -void CallFunctionStub::PrintName(StringStream* stream) { - stream->Add("CallFunctionStub_Args%d", argc_); +void CallFunctionStub::PrintName(OStream& os) const { // NOLINT + os << "CallFunctionStub_Args" << argc_; } -void CallConstructStub::PrintName(StringStream* stream) { - stream->Add("CallConstructStub"); - if (RecordCallTarget()) stream->Add("_Recording"); +void CallConstructStub::PrintName(OStream& os) const { // NOLINT + os << "CallConstructStub"; + if (RecordCallTarget()) os << "_Recording"; } -void ArrayConstructorStub::PrintName(StringStream* stream) { - stream->Add("ArrayConstructorStub"); +void 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: + os << "_Any"; + break; + case NONE: + os << "_None"; + break; + case ONE: + os << "_One"; + break; + case MORE_THAN_ONE: + os << "_More_Than_One"; + break; } + return; } -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 +740,24 @@ bool ToBooleanStub::UpdateStatus(Handle object) { } -void ToBooleanStub::PrintState(StringStream* stream) { - types_.Print(stream); +void ToBooleanStub::PrintState(OStream& os) const { // NOLINT + 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 << ")"; } diff --git a/src/code-stubs.h b/src/code-stubs.h index c68862e..bd97e89 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -171,23 +171,21 @@ class CodeStub BASE_EMBEDDED { bool FindCodeInCache(Code** code_out); // Returns information for computing the number key. - virtual Major MajorKey() = 0; - virtual int MinorKey() = 0; + virtual Major MajorKey() const = 0; + virtual int MinorKey() const = 0; virtual InlineCacheState GetICState() { return UNINITIALIZED; } - virtual ExtraICState GetExtraICState() { - return kNoExtraICState; - } + virtual ExtraICState GetExtraICState() const { return kNoExtraICState; } virtual Code::StubType GetStubType() { return Code::NORMAL; } - virtual void PrintName(StringStream* stream); - - // Returns a name for logging/debugging purposes. - SmartArrayPointer GetName(); + friend OStream& operator<<(OStream& os, const CodeStub& s) { + s.PrintName(os); + return os; + } Isolate* isolate() const { return isolate_; } @@ -199,8 +197,9 @@ class CodeStub BASE_EMBEDDED { // a fixed (non-moveable) code object. virtual bool NeedsImmovableCode() { return false; } - virtual void PrintBaseName(StringStream* stream); - virtual void PrintState(StringStream* stream) { } + virtual void PrintName(OStream& os) const; // NOLINT + virtual void PrintBaseName(OStream& os) const; // NOLINT + virtual void PrintState(OStream& os) const { ; } // NOLINT private: // Perform bookkeeping required after code generation when stub code is @@ -447,7 +446,7 @@ class HydrogenCodeStub : public CodeStub { // Retrieve the code for the stub. Generate the code if needed. virtual Handle GenerateCode() = 0; - virtual int NotMissMinorKey() = 0; + virtual int NotMissMinorKey() const = 0; Handle GenerateLightweightMissCode(); @@ -459,7 +458,7 @@ class HydrogenCodeStub : public CodeStub { class IsMissBits: public BitField {}; void GenerateLightweightMiss(MacroAssembler* masm); - virtual int MinorKey() { + virtual int MinorKey() const { return IsMissBits::encode(is_uninitialized_) | MinorKeyBits::encode(NotMissMinorKey()); } @@ -546,8 +545,8 @@ class ToNumberStub: public HydrogenCodeStub { } private: - Major MajorKey() { return ToNumber; } - int NotMissMinorKey() { return 0; } + Major MajorKey() const { return ToNumber; } + int NotMissMinorKey() const { return 0; } }; @@ -566,8 +565,8 @@ class NumberToStringStub V8_FINAL : public HydrogenCodeStub { static const int kNumber = 0; private: - virtual Major MajorKey() V8_OVERRIDE { return NumberToString; } - virtual int NotMissMinorKey() V8_OVERRIDE { return 0; } + virtual Major MajorKey() const V8_OVERRIDE { return NumberToString; } + virtual int NotMissMinorKey() const V8_OVERRIDE { return 0; } }; @@ -594,8 +593,8 @@ class FastNewClosureStub : public HydrogenCodeStub { class StrictModeBits: public BitField {}; class IsGeneratorBits: public BitField {}; - Major MajorKey() { return FastNewClosure; } - int NotMissMinorKey() { + Major MajorKey() const { return FastNewClosure; } + int NotMissMinorKey() const { return StrictModeBits::encode(strict_mode_ == STRICT) | IsGeneratorBits::encode(is_generator_); } @@ -623,8 +622,8 @@ class FastNewContextStub V8_FINAL : public HydrogenCodeStub { int slots() const { return slots_; } - virtual Major MajorKey() V8_OVERRIDE { return FastNewContext; } - virtual int NotMissMinorKey() V8_OVERRIDE { return slots_; } + virtual Major MajorKey() const V8_OVERRIDE { return FastNewContext; } + virtual int NotMissMinorKey() const V8_OVERRIDE { return slots_; } // Parameters accessed via CodeStubGraphBuilder::GetParameter() static const int kFunction = 0; @@ -657,8 +656,8 @@ class FastCloneShallowArrayStub : public HydrogenCodeStub { class AllocationSiteModeBits: public BitField {}; // Ensure data fits within available bits. - Major MajorKey() { return FastCloneShallowArray; } - int NotMissMinorKey() { + Major MajorKey() const { return FastCloneShallowArray; } + int NotMissMinorKey() const { return AllocationSiteModeBits::encode(allocation_site_mode_); } }; @@ -685,8 +684,8 @@ class FastCloneShallowObjectStub : public HydrogenCodeStub { private: int length_; - Major MajorKey() { return FastCloneShallowObject; } - int NotMissMinorKey() { return length_; } + Major MajorKey() const { return FastCloneShallowObject; } + int NotMissMinorKey() const { return length_; } DISALLOW_COPY_AND_ASSIGN(FastCloneShallowObjectStub); }; @@ -705,8 +704,8 @@ class CreateAllocationSiteStub : public HydrogenCodeStub { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return CreateAllocationSite; } - int NotMissMinorKey() { return 0; } + Major MajorKey() const { return CreateAllocationSite; } + int NotMissMinorKey() const { return 0; } DISALLOW_COPY_AND_ASSIGN(CreateAllocationSiteStub); }; @@ -730,8 +729,8 @@ class InstanceofStub: public PlatformCodeStub { void Generate(MacroAssembler* masm); private: - Major MajorKey() { return Instanceof; } - int MinorKey() { return static_cast(flags_); } + Major MajorKey() const { return Instanceof; } + int MinorKey() const { return static_cast(flags_); } bool HasArgsInRegisters() const { return (flags_ & kArgsInRegisters) != 0; @@ -745,7 +744,7 @@ class InstanceofStub: public PlatformCodeStub { return (flags_ & kReturnTrueFalseObject) != 0; } - virtual void PrintName(StringStream* stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE; // NOLINT Flags flags_; }; @@ -769,10 +768,10 @@ class ArrayConstructorStub: public PlatformCodeStub { private: void GenerateDispatchToArrayStub(MacroAssembler* masm, AllocationSiteOverrideMode mode); - virtual void PrintName(StringStream* stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE; // NOLINT - virtual CodeStub::Major MajorKey() { return ArrayConstructor; } - virtual int MinorKey() { return argument_count_; } + virtual CodeStub::Major MajorKey() const { return ArrayConstructor; } + virtual int MinorKey() const { return argument_count_; } ArgumentCountKey argument_count_; }; @@ -785,8 +784,8 @@ class InternalArrayConstructorStub: public PlatformCodeStub { void Generate(MacroAssembler* masm); private: - virtual CodeStub::Major MajorKey() { return InternalArrayConstructor; } - virtual int MinorKey() { return 0; } + virtual CodeStub::Major MajorKey() const { return InternalArrayConstructor; } + virtual int MinorKey() const { return 0; } void GenerateCase(MacroAssembler* masm, ElementsKind kind); }; @@ -801,8 +800,8 @@ class MathPowStub: public PlatformCodeStub { virtual void Generate(MacroAssembler* masm); private: - virtual CodeStub::Major MajorKey() { return MathPow; } - virtual int MinorKey() { return exponent_type_; } + virtual CodeStub::Major MajorKey() const { return MathPow; } + virtual int MinorKey() const { return exponent_type_; } ExponentType exponent_type_; }; @@ -824,11 +823,9 @@ class ICStub: public PlatformCodeStub { virtual void FinishCode(Handle code) { code->set_stub_info(MinorKey()); } - Code::Kind kind() { return kind_; } + Code::Kind kind() const { return kind_; } - virtual int MinorKey() { - return KindBits::encode(kind_); - } + virtual int MinorKey() const { return KindBits::encode(kind_); } private: Code::Kind kind_; @@ -859,15 +856,15 @@ class CallICStub: public PlatformCodeStub { return state_.GetICState(); } - virtual ExtraICState GetExtraICState() V8_FINAL V8_OVERRIDE { + virtual ExtraICState GetExtraICState() const V8_FINAL V8_OVERRIDE { return state_.GetExtraICState(); } protected: - virtual int MinorKey() { return GetExtraICState(); } - virtual void PrintState(StringStream* stream) V8_OVERRIDE; + virtual int MinorKey() const { return GetExtraICState(); } + virtual void PrintState(OStream& os) const V8_OVERRIDE; // NOLINT - virtual CodeStub::Major MajorKey() { return CallIC; } + virtual CodeStub::Major MajorKey() const { return CallIC; } // Code generation helpers. void GenerateMiss(MacroAssembler* masm, IC::UtilityId id); @@ -884,9 +881,9 @@ class CallIC_ArrayStub: public CallICStub { virtual void Generate(MacroAssembler* masm); protected: - virtual void PrintState(StringStream* stream) V8_OVERRIDE; + virtual void PrintState(OStream& os) const V8_OVERRIDE; // NOLINT - virtual CodeStub::Major MajorKey() { return CallIC_Array; } + virtual CodeStub::Major MajorKey() const { return CallIC_Array; } }; @@ -897,7 +894,7 @@ class FunctionPrototypeStub: public ICStub { virtual void Generate(MacroAssembler* masm); private: - virtual CodeStub::Major MajorKey() { return FunctionPrototype; } + virtual CodeStub::Major MajorKey() const { return FunctionPrototype; } }; @@ -907,14 +904,14 @@ class StoreICStub: public ICStub { : ICStub(isolate, kind), strict_mode_(strict_mode) { } protected: - virtual ExtraICState GetExtraICState() { + virtual ExtraICState GetExtraICState() const { return StoreIC::ComputeExtraICState(strict_mode_); } private: STATIC_ASSERT(KindBits::kSize == 4); class StrictModeBits: public BitField {}; - virtual int MinorKey() { + virtual int MinorKey() const { return KindBits::encode(kind()) | StrictModeBits::encode(strict_mode_); } @@ -937,11 +934,11 @@ class HICStub: public HydrogenCodeStub { class HandlerStub: public HICStub { public: virtual Code::Kind GetCodeKind() const { return Code::HANDLER; } - virtual ExtraICState GetExtraICState() { return kind(); } + virtual ExtraICState GetExtraICState() const { return kind(); } protected: explicit HandlerStub(Isolate* isolate) : HICStub(isolate) { } - virtual int NotMissMinorKey() { return bit_field_; } + virtual int NotMissMinorKey() const { return bit_field_; } int bit_field_; }; @@ -989,7 +986,7 @@ class LoadFieldStub: public HandlerStub { private: STATIC_ASSERT(KindBits::kSize == 4); class EncodedLoadFieldByIndexBits: public BitField {}; - virtual CodeStub::Major MajorKey() { return LoadField; } + virtual CodeStub::Major MajorKey() const { return LoadField; } FieldIndex index_; }; @@ -1013,7 +1010,7 @@ class StringLengthStub: public HandlerStub { } private: - virtual CodeStub::Major MajorKey() { return StringLength; } + virtual CodeStub::Major MajorKey() const { return StringLength; } }; @@ -1026,7 +1023,7 @@ class KeyedStringLengthStub: public StringLengthStub { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - virtual CodeStub::Major MajorKey() { return KeyedStringLength; } + virtual CodeStub::Major MajorKey() const { return KeyedStringLength; } }; @@ -1082,7 +1079,7 @@ class StoreGlobalStub : public HandlerStub { } private: - Major MajorKey() { return StoreGlobal; } + Major MajorKey() const { return StoreGlobal; } class IsConstantBits: public BitField {}; class RepresentationBits: public BitField {}; @@ -1107,8 +1104,8 @@ class CallApiFunctionStub : public PlatformCodeStub { private: virtual void Generate(MacroAssembler* masm) V8_OVERRIDE; - virtual Major MajorKey() V8_OVERRIDE { return CallApiFunction; } - virtual int MinorKey() V8_OVERRIDE { return bit_field_; } + virtual Major MajorKey() const V8_OVERRIDE { return CallApiFunction; } + virtual int MinorKey() const V8_OVERRIDE { return bit_field_; } class IsStoreBits: public BitField {}; class CallDataUndefinedBits: public BitField {}; @@ -1126,8 +1123,8 @@ class CallApiGetterStub : public PlatformCodeStub { private: virtual void Generate(MacroAssembler* masm) V8_OVERRIDE; - virtual Major MajorKey() V8_OVERRIDE { return CallApiGetter; } - virtual int MinorKey() V8_OVERRIDE { return 0; } + virtual Major MajorKey() const V8_OVERRIDE { return CallApiGetter; } + virtual int MinorKey() const V8_OVERRIDE { return 0; } DISALLOW_COPY_AND_ASSIGN(CallApiGetterStub); }; @@ -1144,7 +1141,7 @@ class KeyedLoadFieldStub: public LoadFieldStub { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - virtual CodeStub::Major MajorKey() { return KeyedLoadField; } + virtual CodeStub::Major MajorKey() const { return KeyedLoadField; } }; @@ -1171,7 +1168,7 @@ class BinaryOpICStub : public HydrogenCodeStub { return state_.GetICState(); } - virtual ExtraICState GetExtraICState() V8_FINAL V8_OVERRIDE { + virtual ExtraICState GetExtraICState() const V8_FINAL V8_OVERRIDE { return state_.GetExtraICState(); } @@ -1179,10 +1176,10 @@ class BinaryOpICStub : public HydrogenCodeStub { const BinaryOpIC::State& state() const { return state_; } - virtual void PrintState(StringStream* stream) V8_FINAL V8_OVERRIDE; + virtual void PrintState(OStream& os) const V8_FINAL V8_OVERRIDE; // NOLINT - virtual Major MajorKey() V8_OVERRIDE { return BinaryOpIC; } - virtual int NotMissMinorKey() V8_FINAL V8_OVERRIDE { + virtual Major MajorKey() const V8_OVERRIDE { return BinaryOpIC; } + virtual int NotMissMinorKey() const V8_FINAL V8_OVERRIDE { return GetExtraICState(); } @@ -1224,16 +1221,18 @@ class BinaryOpICWithAllocationSiteStub V8_FINAL : public PlatformCodeStub { return state_.GetICState(); } - virtual ExtraICState GetExtraICState() V8_OVERRIDE { + virtual ExtraICState GetExtraICState() const V8_OVERRIDE { return state_.GetExtraICState(); } virtual void Generate(MacroAssembler* masm) V8_OVERRIDE; - virtual void PrintState(StringStream* stream) V8_OVERRIDE; + virtual void PrintState(OStream& os) const V8_OVERRIDE; // NOLINT - virtual Major MajorKey() V8_OVERRIDE { return BinaryOpICWithAllocationSite; } - virtual int MinorKey() V8_OVERRIDE { return GetExtraICState(); } + virtual Major MajorKey() const V8_OVERRIDE { + return BinaryOpICWithAllocationSite; + } + virtual int MinorKey() const V8_OVERRIDE { return GetExtraICState(); } private: static void GenerateAheadOfTime(Isolate* isolate, @@ -1267,7 +1266,7 @@ class BinaryOpWithAllocationSiteStub V8_FINAL : public BinaryOpICStub { virtual Handle GenerateCode() V8_OVERRIDE; - virtual Major MajorKey() V8_OVERRIDE { + virtual Major MajorKey() const V8_OVERRIDE { return BinaryOpWithAllocationSite; } @@ -1323,10 +1322,10 @@ class StringAddStub V8_FINAL : public HydrogenCodeStub { class PretenureFlagBits: public BitField {}; uint32_t bit_field_; - virtual Major MajorKey() V8_OVERRIDE { return StringAdd; } - virtual int NotMissMinorKey() V8_OVERRIDE { return bit_field_; } + virtual Major MajorKey() const V8_OVERRIDE { return StringAdd; } + virtual int NotMissMinorKey() const V8_OVERRIDE { return bit_field_; } - virtual void PrintBaseName(StringStream* stream) V8_OVERRIDE; + virtual void PrintBaseName(OStream& os) const V8_OVERRIDE; // NOLINT DISALLOW_COPY_AND_ASSIGN(StringAddStub); }; @@ -1369,8 +1368,8 @@ class ICCompareStub: public PlatformCodeStub { code->set_stub_info(MinorKey()); } - virtual CodeStub::Major MajorKey() { return CompareIC; } - virtual int MinorKey(); + virtual CodeStub::Major MajorKey() const { return CompareIC; } + virtual int MinorKey() const; virtual Code::Kind GetCodeKind() const { return Code::COMPARE_IC; } @@ -1443,7 +1442,7 @@ class CompareNilICStub : public HydrogenCodeStub { virtual Handle GenerateCode() V8_OVERRIDE; - virtual ExtraICState GetExtraICState() { + virtual ExtraICState GetExtraICState() const { return NilValueField::encode(nil_value_) | TypesField::encode(state_.ToIntegral()); } @@ -1454,8 +1453,8 @@ class CompareNilICStub : public HydrogenCodeStub { NilValue GetNilValue() const { return nil_value_; } void ClearState() { state_.RemoveAll(); } - virtual void PrintState(StringStream* stream); - virtual void PrintBaseName(StringStream* stream); + virtual void PrintState(OStream& os) const V8_OVERRIDE; // NOLINT + virtual void PrintBaseName(OStream& os) const V8_OVERRIDE; // NOLINT private: friend class CompareNilIC; @@ -1477,9 +1476,8 @@ class CompareNilICStub : public HydrogenCodeStub { public: State() : EnumSet(0) { } explicit State(byte bits) : EnumSet(bits) { } - - void Print(StringStream* stream) const; }; + friend OStream& operator<<(OStream& os, const State& s); CompareNilICStub(Isolate* isolate, NilValue nil, @@ -1489,8 +1487,8 @@ class CompareNilICStub : public HydrogenCodeStub { class NilValueField : public BitField {}; class TypesField : public BitField {}; - virtual CodeStub::Major MajorKey() { return CompareNilIC; } - virtual int NotMissMinorKey() { return GetExtraICState(); } + virtual CodeStub::Major MajorKey() const { return CompareNilIC; } + virtual int NotMissMinorKey() const { return GetExtraICState(); } NilValue nil_value_; State state_; @@ -1499,6 +1497,9 @@ class CompareNilICStub : public HydrogenCodeStub { }; +OStream& operator<<(OStream& os, const CompareNilICStub::State& s); + + class CEntryStub : public PlatformCodeStub { public: CEntryStub(Isolate* isolate, @@ -1521,8 +1522,8 @@ class CEntryStub : public PlatformCodeStub { const int result_size_; SaveFPRegsMode save_doubles_; - Major MajorKey() { return CEntry; } - int MinorKey(); + Major MajorKey() const { return CEntry; } + int MinorKey() const; bool NeedsImmovableCode(); }; @@ -1538,8 +1539,8 @@ class JSEntryStub : public PlatformCodeStub { void GenerateBody(MacroAssembler* masm, bool is_construct); private: - Major MajorKey() { return JSEntry; } - int MinorKey() { return 0; } + Major MajorKey() const { return JSEntry; } + int MinorKey() const { return 0; } virtual void FinishCode(Handle code); @@ -1554,10 +1555,10 @@ class JSConstructEntryStub : public JSEntryStub { void Generate(MacroAssembler* masm) { GenerateBody(masm, true); } private: - int MinorKey() { return 1; } + int MinorKey() const { return 1; } - virtual void PrintName(StringStream* stream) { - stream->Add("JSConstructEntryStub"); + virtual void PrintName(OStream& os) const V8_OVERRIDE { // NOLINT + os << "JSConstructEntryStub"; } }; @@ -1577,8 +1578,8 @@ class ArgumentsAccessStub: public PlatformCodeStub { private: Type type_; - Major MajorKey() { return ArgumentsAccess; } - int MinorKey() { return type_; } + Major MajorKey() const { return ArgumentsAccess; } + int MinorKey() const { return type_; } void Generate(MacroAssembler* masm); void GenerateReadElement(MacroAssembler* masm); @@ -1586,7 +1587,7 @@ class ArgumentsAccessStub: public PlatformCodeStub { void GenerateNewSloppyFast(MacroAssembler* masm); void GenerateNewSloppySlow(MacroAssembler* masm); - virtual void PrintName(StringStream* stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE; // NOLINT }; @@ -1595,8 +1596,8 @@ class RegExpExecStub: public PlatformCodeStub { explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { } private: - Major MajorKey() { return RegExpExec; } - int MinorKey() { return 0; } + Major MajorKey() const { return RegExpExec; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); }; @@ -1612,8 +1613,8 @@ class RegExpConstructResultStub V8_FINAL : public HydrogenCodeStub { virtual void InitializeInterfaceDescriptor( CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; - virtual Major MajorKey() V8_OVERRIDE { return RegExpConstructResult; } - virtual int NotMissMinorKey() V8_OVERRIDE { return 0; } + virtual Major MajorKey() const V8_OVERRIDE { return RegExpConstructResult; } + virtual int NotMissMinorKey() const V8_OVERRIDE { return 0; } static void InstallDescriptors(Isolate* isolate); @@ -1642,14 +1643,14 @@ class CallFunctionStub: public PlatformCodeStub { int argc_; CallFunctionFlags flags_; - virtual void PrintName(StringStream* stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE; // NOLINT // Minor key encoding in 32 bits with Bitfield . class FlagBits: public BitField {}; class ArgcBits: public BitField {}; - Major MajorKey() { return CallFunction; } - int MinorKey() { + Major MajorKey() const { return CallFunction; } + int MinorKey() const { // Encode the parameters in a unique 32 bit value. return FlagBits::encode(flags_) | ArgcBits::encode(argc_); } @@ -1678,12 +1679,12 @@ class CallConstructStub: public PlatformCodeStub { private: CallConstructorFlags flags_; - virtual void PrintName(StringStream* stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE; // NOLINT - Major MajorKey() { return CallConstruct; } - int MinorKey() { return flags_; } + Major MajorKey() const { return CallConstruct; } + int MinorKey() const { return flags_; } - bool RecordCallTarget() { + bool RecordCallTarget() const { return (flags_ & RECORD_CONSTRUCTOR_TARGET) != 0; } }; @@ -1874,8 +1875,8 @@ class KeyedLoadDictionaryElementStub : public HydrogenCodeStub { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return KeyedLoadElement; } - int NotMissMinorKey() { return DICTIONARY_ELEMENTS; } + Major MajorKey() const { return KeyedLoadElement; } + int NotMissMinorKey() const { return DICTIONARY_ELEMENTS; } DISALLOW_COPY_AND_ASSIGN(KeyedLoadDictionaryElementStub); }; @@ -1889,8 +1890,8 @@ class KeyedLoadDictionaryElementPlatformStub : public PlatformCodeStub { void Generate(MacroAssembler* masm); private: - Major MajorKey() { return KeyedLoadElement; } - int MinorKey() { return DICTIONARY_ELEMENTS; } + Major MajorKey() const { return KeyedLoadElement; } + int MinorKey() const { return DICTIONARY_ELEMENTS; } DISALLOW_COPY_AND_ASSIGN(KeyedLoadDictionaryElementPlatformStub); }; @@ -1912,8 +1913,8 @@ class KeyedLoadGenericElementStub : public HydrogenCodeStub { virtual InlineCacheState GetICState() { return GENERIC; } private: - Major MajorKey() { return KeyedLoadGeneric; } - int NotMissMinorKey() { return 0; } + Major MajorKey() const { return KeyedLoadGeneric; } + int NotMissMinorKey() const { return 0; } DISALLOW_COPY_AND_ASSIGN(KeyedLoadGenericElementStub); }; @@ -1977,8 +1978,8 @@ class DoubleToIStub : public PlatformCodeStub { class SSE3Bits: public BitField {}; // NOLINT - Major MajorKey() { return DoubleToI; } - int MinorKey() { return bit_field_; } + Major MajorKey() const { return DoubleToI; } + int MinorKey() const { return bit_field_; } int bit_field_; @@ -2014,8 +2015,8 @@ class KeyedLoadFastElementStub : public HydrogenCodeStub { class IsJSArrayBits: public BitField {}; uint32_t bit_field_; - Major MajorKey() { return KeyedLoadElement; } - int NotMissMinorKey() { return bit_field_; } + Major MajorKey() const { return KeyedLoadElement; } + int NotMissMinorKey() const { return bit_field_; } DISALLOW_COPY_AND_ASSIGN(KeyedLoadFastElementStub); }; @@ -2056,8 +2057,8 @@ class KeyedStoreFastElementStub : public HydrogenCodeStub { class IsJSArrayBits: public BitField {}; uint32_t bit_field_; - Major MajorKey() { return KeyedStoreElement; } - int NotMissMinorKey() { return bit_field_; } + Major MajorKey() const { return KeyedStoreElement; } + int NotMissMinorKey() const { return bit_field_; } DISALLOW_COPY_AND_ASSIGN(KeyedStoreFastElementStub); }; @@ -2097,8 +2098,8 @@ class TransitionElementsKindStub : public HydrogenCodeStub { class IsJSArrayBits: public BitField {}; uint32_t bit_field_; - Major MajorKey() { return TransitionElementsKind; } - int NotMissMinorKey() { return bit_field_; } + Major MajorKey() const { return TransitionElementsKind; } + int NotMissMinorKey() const { return bit_field_; } DISALLOW_COPY_AND_ASSIGN(TransitionElementsKindStub); }; @@ -2135,10 +2136,10 @@ class ArrayConstructorStubBase : public HydrogenCodeStub { static const int kAllocationSite = 1; protected: - void BasePrintName(const char* name, StringStream* stream); + OStream& BasePrintName(OStream& os, const char* name) const; // NOLINT private: - int NotMissMinorKey() { return bit_field_; } + int NotMissMinorKey() const { return bit_field_; } // Ensure data fits within available bits. STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1); @@ -2167,10 +2168,10 @@ class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return ArrayNoArgumentConstructor; } + Major MajorKey() const { return ArrayNoArgumentConstructor; } - virtual void PrintName(StringStream* stream) { - BasePrintName("ArrayNoArgumentConstructorStub", stream); + virtual void PrintName(OStream& os) const V8_OVERRIDE { // NOLINT + BasePrintName(os, "ArrayNoArgumentConstructorStub"); } DISALLOW_COPY_AND_ASSIGN(ArrayNoArgumentConstructorStub); @@ -2192,10 +2193,10 @@ class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return ArraySingleArgumentConstructor; } + Major MajorKey() const { return ArraySingleArgumentConstructor; } - virtual void PrintName(StringStream* stream) { - BasePrintName("ArraySingleArgumentConstructorStub", stream); + virtual void PrintName(OStream& os) const { // NOLINT + BasePrintName(os, "ArraySingleArgumentConstructorStub"); } DISALLOW_COPY_AND_ASSIGN(ArraySingleArgumentConstructorStub); @@ -2217,10 +2218,10 @@ class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return ArrayNArgumentsConstructor; } + Major MajorKey() const { return ArrayNArgumentsConstructor; } - virtual void PrintName(StringStream* stream) { - BasePrintName("ArrayNArgumentsConstructorStub", stream); + virtual void PrintName(OStream& os) const { // NOLINT + BasePrintName(os, "ArrayNArgumentsConstructorStub"); } DISALLOW_COPY_AND_ASSIGN(ArrayNArgumentsConstructorStub); @@ -2243,7 +2244,7 @@ class InternalArrayConstructorStubBase : public HydrogenCodeStub { ElementsKind elements_kind() const { return kind_; } private: - int NotMissMinorKey() { return kind_; } + int NotMissMinorKey() const { return kind_; } ElementsKind kind_; @@ -2264,7 +2265,7 @@ class InternalArrayNoArgumentConstructorStub : public CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return InternalArrayNoArgumentConstructor; } + Major MajorKey() const { return InternalArrayNoArgumentConstructor; } DISALLOW_COPY_AND_ASSIGN(InternalArrayNoArgumentConstructorStub); }; @@ -2283,7 +2284,7 @@ class InternalArraySingleArgumentConstructorStub : public CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return InternalArraySingleArgumentConstructor; } + Major MajorKey() const { return InternalArraySingleArgumentConstructor; } DISALLOW_COPY_AND_ASSIGN(InternalArraySingleArgumentConstructorStub); }; @@ -2301,7 +2302,7 @@ class InternalArrayNArgumentsConstructorStub : public CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; private: - Major MajorKey() { return InternalArrayNArgumentsConstructor; } + Major MajorKey() const { return InternalArrayNArgumentsConstructor; } DISALLOW_COPY_AND_ASSIGN(InternalArrayNArgumentsConstructorStub); }; @@ -2318,8 +2319,8 @@ class KeyedStoreElementStub : public PlatformCodeStub { elements_kind_(elements_kind), store_mode_(store_mode) { } - Major MajorKey() { return KeyedStoreElement; } - int MinorKey() { + Major MajorKey() const { return KeyedStoreElement; } + int MinorKey() const { return ElementsKindBits::encode(elements_kind_) | IsJSArrayBits::encode(is_js_array_) | StoreModeBits::encode(store_mode_); @@ -2364,7 +2365,6 @@ class ToBooleanStub: public HydrogenCodeStub { explicit Types(byte bits) : EnumSet(bits) {} byte ToByte() const { return ToIntegral(); } - void Print(StringStream* stream) const; bool UpdateStatus(Handle object); bool NeedsMap() const; bool CanBeUndetectable() const; @@ -2386,7 +2386,7 @@ class ToBooleanStub: public HydrogenCodeStub { CodeStubInterfaceDescriptor* descriptor) V8_OVERRIDE; virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; } - virtual void PrintState(StringStream* stream); + virtual void PrintState(OStream& os) const V8_OVERRIDE; // NOLINT virtual bool SometimesSetsUpAFrame() { return false; } @@ -2400,9 +2400,7 @@ class ToBooleanStub: public HydrogenCodeStub { return ToBooleanStub(isolate, UNINITIALIZED).GetCode(); } - virtual ExtraICState GetExtraICState() { - return types_.ToIntegral(); - } + virtual ExtraICState GetExtraICState() const { return types_.ToIntegral(); } virtual InlineCacheState GetICState() { if (types_.IsEmpty()) { @@ -2413,8 +2411,8 @@ class ToBooleanStub: public HydrogenCodeStub { } private: - Major MajorKey() { return ToBoolean; } - int NotMissMinorKey() { return GetExtraICState(); } + Major MajorKey() const { return ToBoolean; } + int NotMissMinorKey() const { return GetExtraICState(); } ToBooleanStub(Isolate* isolate, InitializationState init_state) : HydrogenCodeStub(isolate, init_state) {} @@ -2423,6 +2421,9 @@ class ToBooleanStub: public HydrogenCodeStub { }; +OStream& operator<<(OStream& os, const ToBooleanStub::Types& t); + + class ElementsTransitionAndStoreStub : public HydrogenCodeStub { public: ElementsTransitionAndStoreStub(Isolate* isolate, @@ -2452,8 +2453,8 @@ class ElementsTransitionAndStoreStub : public HydrogenCodeStub { class IsJSArrayBits: public BitField {}; class StoreModeBits: public BitField {}; - Major MajorKey() { return ElementsTransitionAndStore; } - int NotMissMinorKey() { + Major MajorKey() const { return ElementsTransitionAndStore; } + int NotMissMinorKey() const { return FromBits::encode(from_kind_) | ToBits::encode(to_kind_) | IsJSArrayBits::encode(is_jsarray_) | @@ -2475,8 +2476,8 @@ class StoreArrayLiteralElementStub : public PlatformCodeStub { : PlatformCodeStub(isolate) { } private: - Major MajorKey() { return StoreArrayLiteralElement; } - int MinorKey() { return 0; } + Major MajorKey() const { return StoreArrayLiteralElement; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); @@ -2495,10 +2496,8 @@ class StubFailureTrampolineStub : public PlatformCodeStub { private: class FunctionModeField: public BitField {}; - Major MajorKey() { return StubFailureTrampoline; } - int MinorKey() { - return FunctionModeField::encode(function_mode_); - } + Major MajorKey() const { return StubFailureTrampoline; } + int MinorKey() const { return FunctionModeField::encode(function_mode_); } void Generate(MacroAssembler* masm); @@ -2523,8 +2522,8 @@ class ProfileEntryHookStub : public PlatformCodeStub { intptr_t stack_pointer, Isolate* isolate); - Major MajorKey() { return ProfileEntryHook; } - int MinorKey() { return 0; } + Major MajorKey() const { return ProfileEntryHook; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); diff --git a/src/codegen.cc b/src/codegen.cc index c039e40..244c227 100644 --- a/src/codegen.cc +++ b/src/codegen.cc @@ -257,7 +257,7 @@ void ArgumentsAccessStub::Generate(MacroAssembler* masm) { } -int CEntryStub::MinorKey() { +int CEntryStub::MinorKey() const { int result = (save_doubles_ == kSaveFPRegs) ? 1 : 0; ASSERT(result_size_ == 1 || result_size_ == 2); #ifdef _WIN64 diff --git a/src/hydrogen-dce.cc b/src/hydrogen-dce.cc index 96f088d..50021aa 100644 --- a/src/hydrogen-dce.cc +++ b/src/hydrogen-dce.cc @@ -32,16 +32,14 @@ void HDeadCodeEliminationPhase::MarkLive( void HDeadCodeEliminationPhase::PrintLive(HValue* ref, HValue* instr) { - HeapStringAllocator allocator; - StringStream stream(&allocator); + OFStream os(stdout); + os << "[MarkLive "; if (ref != NULL) { - ref->PrintTo(&stream); + os << *ref; } else { - stream.Add("root "); + os << "root "; } - stream.Add(" -> "); - instr->PrintTo(&stream); - PrintF("[MarkLive %s]\n", stream.ToCString().get()); + os << " -> " << *instr << "]" << endl; } diff --git a/src/hydrogen-gvn.cc b/src/hydrogen-gvn.cc index 829a0bb..c86bd9b 100644 --- a/src/hydrogen-gvn.cc +++ b/src/hydrogen-gvn.cc @@ -449,11 +449,9 @@ bool SideEffectsTracker::ComputeGlobalVar(Unique cell, int* index) { } if (num_global_vars_ < kNumberOfGlobalVars) { if (FLAG_trace_gvn) { - HeapStringAllocator allocator; - StringStream stream(&allocator); - stream.Add("Tracking global var [%p] (mapped to index %d)\n", - *cell.handle(), num_global_vars_); - stream.OutputToStdOut(); + OFStream os(stdout); + os << "Tracking global var [" << *cell.handle() << "] " + << "(mapped to index " << num_global_vars_ << ")" << endl; } *index = num_global_vars_; global_vars_[num_global_vars_++] = cell; diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 9209b88..173a316 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -525,6 +525,15 @@ void HValue::SetBlock(HBasicBlock* block) { } +OStream& operator<<(OStream& os, const HValue& v) { + // TODO(svenpanne) Temporary impedance matching, to be removed later. + HeapStringAllocator allocator; + StringStream stream(&allocator); + const_cast(&v)->PrintTo(&stream); + return os << stream.ToCString().get(); +} + + void HValue::PrintTypeTo(StringStream* stream) { if (!representation().IsTagged() || type().Equals(HType::Tagged())) return; stream->Add(" type:%s", type().ToString()); @@ -1214,8 +1223,9 @@ bool HBranch::KnownSuccessorBlock(HBasicBlock** block) { void HBranch::PrintDataTo(StringStream* stream) { HUnaryControlInstruction::PrintDataTo(stream); - stream->Add(" "); - expected_input_types().Print(stream); + OStringStream os; + os << " " << expected_input_types(); + stream->Add(os.c_str()); } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index adff7a2..94f9281 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -927,6 +927,9 @@ class HValue : public ZoneObject { }; +OStream& operator<<(OStream& os, const HValue& v); + + #define DECLARE_INSTRUCTION_FACTORY_P0(I) \ static I* New(Zone* zone, HValue* context) { \ return new(zone) I(); \ diff --git a/src/ia32/code-stubs-ia32.h b/src/ia32/code-stubs-ia32.h index 219186c..4c12979 100644 --- a/src/ia32/code-stubs-ia32.h +++ b/src/ia32/code-stubs-ia32.h @@ -30,8 +30,8 @@ class StoreBufferOverflowStub: public PlatformCodeStub { private: SaveFPRegsMode save_doubles_; - Major MajorKey() { return StoreBufferOverflow; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return StoreBufferOverflow; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } }; @@ -70,8 +70,8 @@ class SubStringStub: public PlatformCodeStub { explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {} private: - Major MajorKey() { return SubString; } - int MinorKey() { return 0; } + Major MajorKey() const { return SubString; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); }; @@ -98,8 +98,8 @@ class StringCompareStub: public PlatformCodeStub { Register scratch2); private: - virtual Major MajorKey() { return StringCompare; } - virtual int MinorKey() { return 0; } + virtual Major MajorKey() const { return StringCompare; } + virtual int MinorKey() const { return 0; } virtual void Generate(MacroAssembler* masm); static void GenerateAsciiCharsCompareLoop( @@ -156,9 +156,9 @@ class NameDictionaryLookupStub: public PlatformCodeStub { NameDictionary::kHeaderSize + NameDictionary::kElementsStartIndex * kPointerSize; - Major MajorKey() { return NameDictionaryLookup; } + Major MajorKey() const { return NameDictionaryLookup; } - int MinorKey() { + int MinorKey() const { return DictionaryBits::encode(dictionary_.code()) | ResultBits::encode(result_.code()) | IndexBits::encode(index_.code()) | @@ -405,9 +405,9 @@ class RecordWriteStub: public PlatformCodeStub { Mode mode); void InformIncrementalMarker(MacroAssembler* masm); - Major MajorKey() { return RecordWrite; } + Major MajorKey() const { return RecordWrite; } - int MinorKey() { + int MinorKey() const { return ObjectBits::encode(object_.code()) | ValueBits::encode(value_.code()) | AddressBits::encode(address_.code()) | diff --git a/src/ic.cc b/src/ic.cc index 687960f..39b9416 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1345,11 +1345,10 @@ MaybeHandle StoreIC::Store(Handle object, } -void CallIC::State::Print(StringStream* stream) const { - stream->Add("(args(%d), ", - argc_); - stream->Add("%s, ", - call_type_ == CallIC::METHOD ? "METHOD" : "FUNCTION"); +OStream& operator<<(OStream& os, const CallIC::State& s) { + return os << "(args(" << s.arg_count() << "), " + << (s.call_type() == CallIC::METHOD ? "METHOD" : "FUNCTION") + << ", "; } @@ -2463,18 +2462,20 @@ Type* BinaryOpIC::State::GetResultType(Zone* zone) const { } -void BinaryOpIC::State::Print(StringStream* stream) const { - stream->Add("(%s", Token::Name(op_)); - if (mode_ == OVERWRITE_LEFT) stream->Add("_ReuseLeft"); - else if (mode_ == OVERWRITE_RIGHT) stream->Add("_ReuseRight"); - if (CouldCreateAllocationMementos()) stream->Add("_CreateAllocationMementos"); - stream->Add(":%s*", KindToString(left_kind_)); - if (fixed_right_arg_.has_value) { - stream->Add("%d", fixed_right_arg_.value); +OStream& operator<<(OStream& os, const BinaryOpIC::State& s) { + os << "(" << Token::Name(s.op_); + if (s.mode_ == OVERWRITE_LEFT) + os << "_ReuseLeft"; + else if (s.mode_ == OVERWRITE_RIGHT) + os << "_ReuseRight"; + if (s.CouldCreateAllocationMementos()) os << "_CreateAllocationMementos"; + os << ":" << BinaryOpIC::State::KindToString(s.left_kind_) << "*"; + if (s.fixed_right_arg_.has_value) { + os << s.fixed_right_arg_.value; } else { - stream->Add("%s", KindToString(right_kind_)); + os << BinaryOpIC::State::KindToString(s.right_kind_); } - stream->Add("->%s)", KindToString(result_kind_)); + return os << "->" << BinaryOpIC::State::KindToString(s.result_kind_) << ")"; } @@ -2648,21 +2649,14 @@ MaybeHandle BinaryOpIC::Transition( set_target(*target); if (FLAG_trace_ic) { - char buffer[150]; - NoAllocationStringAllocator allocator( - buffer, static_cast(sizeof(buffer))); - StringStream stream(&allocator); - stream.Add("[BinaryOpIC"); - old_state.Print(&stream); - stream.Add(" => "); - state.Print(&stream); - stream.Add(" @ %p <- ", static_cast(*target)); - stream.OutputToStdOut(); + OFStream os(stdout); + os << "[BinaryOpIC" << old_state << " => " << state << " @ " + << static_cast(*target) << " <- "; JavaScriptFrame::PrintTop(isolate(), stdout, false, true); if (!allocation_site.is_null()) { - PrintF(" using allocation site %p", static_cast(*allocation_site)); + os << " using allocation site " << static_cast(*allocation_site); } - PrintF("]\n"); + os << "]" << endl; } // Patch the inlined smi code as necessary. diff --git a/src/ic.h b/src/ic.h index c2d0c32..19146ac 100644 --- a/src/ic.h +++ b/src/ic.h @@ -354,8 +354,6 @@ class CallIC: public IC { bool CallAsMethod() const { return call_type_ == METHOD; } - void Print(StringStream* stream) const; - private: class ArgcBits: public BitField {}; class CallTypeBits: public BitField {}; @@ -392,6 +390,9 @@ class CallIC: public IC { }; +OStream& operator<<(OStream& os, const CallIC::State& s); + + class LoadIC: public IC { public: // ExtraICState bits @@ -862,8 +863,6 @@ class BinaryOpIC: public IC { } Type* GetResultType(Zone* zone) const; - void Print(StringStream* stream) const; - void Update(Handle left, Handle right, Handle result); @@ -871,6 +870,8 @@ class BinaryOpIC: public IC { Isolate* isolate() const { return isolate_; } private: + friend OStream& operator<<(OStream& os, const BinaryOpIC::State& s); + enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC }; Kind UpdateKind(Handle object, Kind kind) const; @@ -912,6 +913,9 @@ class BinaryOpIC: public IC { }; +OStream& operator<<(OStream& os, const BinaryOpIC::State& s); + + class CompareIC: public IC { public: // The type/state lattice is defined by the following inequations: diff --git a/src/isolate.h b/src/isolate.h index 4fc2fb4..aa9796e 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -58,7 +58,6 @@ class HTracer; class InlineRuntimeFunctionsTable; class InnerPointerToCodeCache; class MaterializedObjectStore; -class NoAllocationStringAllocator; class CodeAgingHelper; class RegExpStack; class SaveContext; diff --git a/src/log.cc b/src/log.cc index 6d88a53..ae5d37a 100644 --- a/src/log.cc +++ b/src/log.cc @@ -1972,16 +1972,15 @@ void Logger::LogAccessorCallbacks() { } -static void AddIsolateIdIfNeeded(Isolate* isolate, StringStream* stream) { - if (FLAG_logfile_per_isolate) stream->Add("isolate-%p-", isolate); +static void AddIsolateIdIfNeeded(OStream& os, // NOLINT + Isolate* isolate) { + if (FLAG_logfile_per_isolate) os << "isolate-" << isolate << "-"; } -static SmartArrayPointer PrepareLogFileName( - Isolate* isolate, const char* file_name) { - HeapStringAllocator allocator; - StringStream stream(&allocator); - AddIsolateIdIfNeeded(isolate, &stream); +static void PrepareLogFileName(OStream& os, // NOLINT + Isolate* isolate, const char* file_name) { + AddIsolateIdIfNeeded(os, isolate); for (const char* p = file_name; *p; p++) { if (*p == '%') { p++; @@ -1992,29 +1991,25 @@ static SmartArrayPointer PrepareLogFileName( p--; break; case 'p': - stream.Add("%d", base::OS::GetCurrentProcessId()); + os << base::OS::GetCurrentProcessId(); break; - case 't': { + case 't': // %t expands to the current time in milliseconds. - double time = base::OS::TimeCurrentMillis(); - stream.Add("%.0f", FmtElm(time)); + os << static_cast(base::OS::TimeCurrentMillis()); break; - } case '%': // %% expands (contracts really) to %. - stream.Put('%'); + os << '%'; break; default: // All other %'s expand to themselves. - stream.Put('%'); - stream.Put(*p); + os << '%' << *p; break; } } else { - stream.Put(*p); + os << *p; } } - return SmartArrayPointer(stream.ToCString()); } @@ -2028,9 +2023,9 @@ bool Logger::SetUp(Isolate* isolate) { FLAG_log_snapshot_positions = true; } - SmartArrayPointer log_file_name = - PrepareLogFileName(isolate, FLAG_logfile); - log_->Initialize(log_file_name.get()); + OStringStream log_file_name; + PrepareLogFileName(log_file_name, isolate, FLAG_logfile); + log_->Initialize(log_file_name.c_str()); if (FLAG_perf_basic_prof) { @@ -2044,7 +2039,7 @@ bool Logger::SetUp(Isolate* isolate) { } if (FLAG_ll_prof) { - ll_logger_ = new LowLevelLogger(log_file_name.get()); + ll_logger_ = new LowLevelLogger(log_file_name.c_str()); addCodeEventListener(ll_logger_); } diff --git a/src/objects.cc b/src/objects.cc index d66d442..c7e44e6 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -1371,37 +1371,35 @@ void Map::PrintGeneralization(FILE* file, Representation new_representation, HeapType* old_field_type, HeapType* new_field_type) { - PrintF(file, "[generalizing "); + OFStream os(file); + os << "[generalizing "; constructor_name()->PrintOn(file); - PrintF(file, "] "); + os << "] "; Name* name = instance_descriptors()->GetKey(modify_index); if (name->IsString()) { String::cast(name)->PrintOn(file); } else { - PrintF(file, "{symbol %p}", static_cast(name)); + os << "{symbol " << static_cast(name) << "}"; } - PrintF(file, ":"); + os << ":"; if (constant_to_field) { - PrintF(file, "c"); + os << "c"; } else { - PrintF(file, "%s", old_representation.Mnemonic()); - PrintF(file, "{"); - old_field_type->TypePrint(file, HeapType::SEMANTIC_DIM); - PrintF(file, "}"); - } - PrintF(file, "->%s", new_representation.Mnemonic()); - PrintF(file, "{"); - new_field_type->TypePrint(file, HeapType::SEMANTIC_DIM); - PrintF(file, "}"); - PrintF(file, " ("); + os << old_representation.Mnemonic() << "{"; + old_field_type->PrintTo(os, HeapType::SEMANTIC_DIM); + os << "}"; + } + os << "->" << new_representation.Mnemonic() << "{"; + new_field_type->PrintTo(os, HeapType::SEMANTIC_DIM); + os << "} ("; if (strlen(reason) > 0) { - PrintF(file, "%s", reason); + os << reason; } else { - PrintF(file, "+%i maps", descriptors - split); + os << "+" << (descriptors - split) << " maps"; } - PrintF(file, ") ["); + os << ") ["; JavaScriptFrame::PrintTop(GetIsolate(), file, false, true); - PrintF(file, "]\n"); + os << "]\n"; } diff --git a/src/property.cc b/src/property.cc index 24b39a9..31f5e9a 100644 --- a/src/property.cc +++ b/src/property.cc @@ -21,47 +21,48 @@ void LookupResult::Iterate(ObjectVisitor* visitor) { #ifdef OBJECT_PRINT void LookupResult::Print(FILE* out) { + OFStream os(out); if (!IsFound()) { - PrintF(out, "Not Found\n"); + os << "Not Found\n"; return; } - PrintF(out, "LookupResult:\n"); - PrintF(out, " -cacheable = %s\n", IsCacheable() ? "true" : "false"); - PrintF(out, " -attributes = %x\n", GetAttributes()); + os << "LookupResult:\n"; + os << " -cacheable = " << (IsCacheable() ? "true" : "false") << "\n"; + os << " -attributes = " << hex << GetAttributes() << dec << "\n"; if (IsTransition()) { - PrintF(out, " -transition target:\n"); + os << " -transition target:\n"; GetTransitionTarget()->Print(out); - PrintF(out, "\n"); + os << "\n"; } switch (type()) { case NORMAL: - PrintF(out, " -type = normal\n"); - PrintF(out, " -entry = %d", GetDictionaryEntry()); + os << " -type = normal\n" + << " -entry = " << GetDictionaryEntry() << "\n"; break; case CONSTANT: - PrintF(out, " -type = constant\n"); - PrintF(out, " -value:\n"); + os << " -type = constant\n" + << " -value:\n"; GetConstant()->Print(out); - PrintF(out, "\n"); + os << "\n"; break; case FIELD: - PrintF(out, " -type = field\n"); - PrintF(out, " -index = %d\n", - GetFieldIndex().property_index()); - PrintF(out, " -field type:\n"); - GetFieldType()->TypePrint(out); + os << " -type = field\n" + << " -index = " << GetFieldIndex().property_index() << "\n" + << " -field type:"; + GetFieldType()->PrintTo(os); + os << "\n"; break; case CALLBACKS: - PrintF(out, " -type = call backs\n"); - PrintF(out, " -callback object:\n"); + os << " -type = call backs\n" + << " -callback object:\n"; GetCallbackObject()->Print(out); break; case HANDLER: - PrintF(out, " -type = lookup proxy\n"); + os << " -type = lookup proxy\n"; break; case INTERCEPTOR: - PrintF(out, " -type = lookup interceptor\n"); + os << " -type = lookup interceptor\n"; break; case NONEXISTENT: UNREACHABLE(); diff --git a/src/string-stream.cc b/src/string-stream.cc index 930ce3d..df48153 100644 --- a/src/string-stream.cc +++ b/src/string-stream.cc @@ -17,13 +17,6 @@ char* HeapStringAllocator::allocate(unsigned bytes) { } -NoAllocationStringAllocator::NoAllocationStringAllocator(char* memory, - unsigned size) { - size_ = size; - space_ = memory; -} - - bool StringStream::Put(char c) { if (full()) return false; ASSERT(length_ < capacity_); @@ -555,12 +548,4 @@ char* HeapStringAllocator::grow(unsigned* bytes) { } -// Only grow once to the maximum allowable size. -char* NoAllocationStringAllocator::grow(unsigned* bytes) { - ASSERT(size_ >= *bytes); - *bytes = size_; - return space_; -} - - } } // namespace v8::internal diff --git a/src/string-stream.h b/src/string-stream.h index d72d5c2..e2475ff 100644 --- a/src/string-stream.h +++ b/src/string-stream.h @@ -35,21 +35,6 @@ class HeapStringAllocator V8_FINAL : public StringAllocator { }; -// Allocator for use when no new c++ heap allocation is allowed. -// Given a preallocated buffer up front and does no allocation while -// building message. -class NoAllocationStringAllocator V8_FINAL : public StringAllocator { - public: - NoAllocationStringAllocator(char* memory, unsigned size); - virtual char* allocate(unsigned bytes) V8_OVERRIDE { return space_; } - virtual char* grow(unsigned* bytes) V8_OVERRIDE; - - private: - unsigned size_; - char* space_; -}; - - class FmtElm V8_FINAL { public: FmtElm(int value) : type_(INT) { // NOLINT @@ -168,31 +153,6 @@ class StringStream V8_FINAL { DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); }; - -// Utility class to print a list of items to a stream, divided by a separator. -class SimpleListPrinter V8_FINAL { - public: - explicit SimpleListPrinter(StringStream* stream, char separator = ',') { - separator_ = separator; - stream_ = stream; - first_ = true; - } - - void Add(const char* str) { - if (first_) { - first_ = false; - } else { - stream_->Put(separator_); - } - stream_->Add(str); - } - - private: - bool first_; - char separator_; - StringStream* stream_; -}; - } } // namespace v8::internal #endif // V8_STRING_STREAM_H_ diff --git a/src/types.cc b/src/types.cc index 22694c0..024d9f6 100644 --- a/src/types.cc +++ b/src/types.cc @@ -860,117 +860,97 @@ const char* TypeImpl::BitsetType::Name(int bitset) { } -template -void TypeImpl::BitsetType::PrintTo(StringStream* stream, int bitset) { +template +void TypeImpl::BitsetType::Print(OStream& os, // NOLINT + int bitset) { DisallowHeapAllocation no_allocation; const char* name = Name(bitset); if (name != NULL) { - stream->Add("%s", name); - } else { - static const int named_bitsets[] = { - #define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), + os << name; + return; + } + + static const int named_bitsets[] = { +#define BITSET_CONSTANT(type, value) REPRESENTATION(k##type), REPRESENTATION_BITSET_TYPE_LIST(BITSET_CONSTANT) - #undef BITSET_CONSTANT +#undef BITSET_CONSTANT - #define BITSET_CONSTANT(type, value) SEMANTIC(k##type), +#define BITSET_CONSTANT(type, value) SEMANTIC(k##type), SEMANTIC_BITSET_TYPE_LIST(BITSET_CONSTANT) - #undef BITSET_CONSTANT - }; - - bool is_first = true; - stream->Add("("); - for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) { - int subset = named_bitsets[i]; - if ((bitset & subset) == subset) { - if (!is_first) stream->Add(" | "); - is_first = false; - stream->Add("%s", Name(subset)); - bitset -= subset; - } +#undef BITSET_CONSTANT + }; + + bool is_first = true; + os << "("; + for (int i(ARRAY_SIZE(named_bitsets) - 1); bitset != 0 && i >= 0; --i) { + int subset = named_bitsets[i]; + if ((bitset & subset) == subset) { + if (!is_first) os << " | "; + is_first = false; + os << Name(subset); + bitset -= subset; } - ASSERT(bitset == 0); - stream->Add(")"); } + ASSERT(bitset == 0); + os << ")"; } -template -void TypeImpl::PrintTo(StringStream* stream, PrintDimension dim) { +template +void TypeImpl::PrintTo(OStream& os, PrintDimension dim) { // NOLINT DisallowHeapAllocation no_allocation; if (dim != REPRESENTATION_DIM) { if (this->IsBitset()) { - BitsetType::PrintTo(stream, SEMANTIC(this->AsBitset())); + BitsetType::Print(os, SEMANTIC(this->AsBitset())); } else if (this->IsClass()) { - stream->Add("Class(%p < ", static_cast(*this->AsClass()->Map())); - BitsetType::New(BitsetType::Lub(this))->PrintTo(stream, dim); - stream->Add(")"); - return; + os << "Class(" << static_cast(*this->AsClass()->Map()) << " < "; + return BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim); + os << ")"; } else if (this->IsConstant()) { - stream->Add("Constant(%p : ", - static_cast(*this->AsConstant()->Value())); - BitsetType::New(BitsetType::Lub(this))->PrintTo(stream, dim); - stream->Add(")"); - return; + os << "Constant(" << static_cast(*this->AsConstant()->Value()) + << " : "; + BitsetType::New(BitsetType::Lub(this))->PrintTo(os, dim); + os << ")"; } else if (this->IsContext()) { - stream->Add("Context("); - this->AsContext()->Outer()->PrintTo(stream, dim); - stream->Add(")"); + os << "Context("; + this->AsContext()->Outer()->PrintTo(os, dim); + os << ")"; } else if (this->IsUnion()) { - stream->Add("("); + os << "("; UnionHandle unioned = handle(this->AsUnion()); for (int i = 0; i < unioned->Length(); ++i) { TypeHandle type_i = unioned->Get(i); - if (i > 0) stream->Add(" | "); - type_i->PrintTo(stream, dim); + if (i > 0) os << " | "; + type_i->PrintTo(os, dim); } - stream->Add(")"); - return; + os << ")"; } else if (this->IsArray()) { - stream->Add("Array("); - AsArray()->Element()->PrintTo(stream, dim); - stream->Add(")"); + os << "Array("; + AsArray()->Element()->PrintTo(os, dim); + os << ")"; } else if (this->IsFunction()) { if (!this->AsFunction()->Receiver()->IsAny()) { - this->AsFunction()->Receiver()->PrintTo(stream, dim); - stream->Add("."); + this->AsFunction()->Receiver()->PrintTo(os, dim); + os << "."; } - stream->Add("("); + os << "("; for (int i = 0; i < this->AsFunction()->Arity(); ++i) { - if (i > 0) stream->Add(", "); - this->AsFunction()->Parameter(i)->PrintTo(stream, dim); + if (i > 0) os << ", "; + this->AsFunction()->Parameter(i)->PrintTo(os, dim); } - stream->Add(")->"); - this->AsFunction()->Result()->PrintTo(stream, dim); + os << ")->"; + this->AsFunction()->Result()->PrintTo(os, dim); } else { UNREACHABLE(); } } - if (dim == BOTH_DIMS) { - stream->Add("/"); - } + if (dim == BOTH_DIMS) os << "/"; if (dim != SEMANTIC_DIM) { - BitsetType::PrintTo(stream, REPRESENTATION(this->BitsetLub())); + BitsetType::Print(os, REPRESENTATION(this->BitsetLub())); } } -template -void TypeImpl::TypePrint(FILE* out, PrintDimension dim) { - HeapStringAllocator allocator; - StringStream stream(&allocator); - PrintTo(&stream, dim); - stream.OutputToFile(out); -} - - -template -void TypeImpl::TypePrint(PrintDimension dim) { - TypePrint(stdout, dim); - PrintF(stdout, "\n"); - Flush(stdout); -} - - // ----------------------------------------------------------------------------- // Instantiations. diff --git a/src/types.h b/src/types.h index aaa76e4..79a29e0 100644 --- a/src/types.h +++ b/src/types.h @@ -6,6 +6,7 @@ #define V8_TYPES_H_ #include "src/handles.h" +#include "src/ostreams.h" namespace v8 { namespace internal { @@ -415,9 +416,7 @@ class TypeImpl : public Config::Base { enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; - void PrintTo(StringStream* stream, PrintDimension = BOTH_DIMS); - void TypePrint(PrintDimension = BOTH_DIMS); - void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); + void PrintTo(OStream& os, PrintDimension dim = BOTH_DIMS); // NOLINT protected: // Friends. @@ -502,7 +501,7 @@ class TypeImpl::BitsetType : public TypeImpl { static int InherentLub(TypeImpl* type); static const char* Name(int bitset); - static void PrintTo(StringStream* stream, int bitset); + static void Print(OStream& os, int bitset); // NOLINT using TypeImpl::PrintTo; }; diff --git a/src/typing.cc b/src/typing.cc index 7762624..7a07f59 100644 --- a/src/typing.cc +++ b/src/typing.cc @@ -50,12 +50,14 @@ void AstTyper::Run(CompilationInfo* info) { #ifdef OBJECT_PRINT static void PrintObserved(Variable* var, Object* value, Type* type) { - PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); + OFStream os(stdout); + os << " observed " << (var->IsParameter() ? "param" : "local") << " "; var->name()->Print(); - PrintF(" : "); + os << " : "; value->ShortPrint(); - PrintF(" -> "); - type->TypePrint(); + os << " -> "; + type->PrintTo(os); + os << endl; } #endif // OBJECT_PRINT diff --git a/src/x64/code-stubs-x64.h b/src/x64/code-stubs-x64.h index 0c35436..7083931 100644 --- a/src/x64/code-stubs-x64.h +++ b/src/x64/code-stubs-x64.h @@ -26,8 +26,8 @@ class StoreBufferOverflowStub: public PlatformCodeStub { private: SaveFPRegsMode save_doubles_; - Major MajorKey() { return StoreBufferOverflow; } - int MinorKey() { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } + Major MajorKey() const { return StoreBufferOverflow; } + int MinorKey() const { return (save_doubles_ == kSaveFPRegs) ? 1 : 0; } }; @@ -66,8 +66,8 @@ class SubStringStub: public PlatformCodeStub { explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {} private: - Major MajorKey() { return SubString; } - int MinorKey() { return 0; } + Major MajorKey() const { return SubString; } + int MinorKey() const { return 0; } void Generate(MacroAssembler* masm); }; @@ -95,8 +95,8 @@ class StringCompareStub: public PlatformCodeStub { Register scratch2); private: - virtual Major MajorKey() { return StringCompare; } - virtual int MinorKey() { return 0; } + virtual Major MajorKey() const { return StringCompare; } + virtual int MinorKey() const { return 0; } virtual void Generate(MacroAssembler* masm); static void GenerateAsciiCharsCompareLoop( @@ -156,9 +156,9 @@ class NameDictionaryLookupStub: public PlatformCodeStub { NameDictionary::kHeaderSize + NameDictionary::kElementsStartIndex * kPointerSize; - Major MajorKey() { return NameDictionaryLookup; } + Major MajorKey() const { return NameDictionaryLookup; } - int MinorKey() { + int MinorKey() const { return DictionaryBits::encode(dictionary_.code()) | ResultBits::encode(result_.code()) | IndexBits::encode(index_.code()) | @@ -387,9 +387,9 @@ class RecordWriteStub: public PlatformCodeStub { Mode mode); void InformIncrementalMarker(MacroAssembler* masm); - Major MajorKey() { return RecordWrite; } + Major MajorKey() const { return RecordWrite; } - int MinorKey() { + int MinorKey() const { return ObjectBits::encode(object_.code()) | ValueBits::encode(value_.code()) | AddressBits::encode(address_.code()) | -- 2.7.4