Chromium Code Reviews| Index: src/code-stubs.cc |
| diff --git a/src/code-stubs.cc b/src/code-stubs.cc |
| index 5bec7e05f913be19ef8526f76e86580b99041115..628e76467b8d888a9f2ddcc9d52d482bae97e127 100644 |
| --- a/src/code-stubs.cc |
| +++ b/src/code-stubs.cc |
| @@ -183,9 +183,77 @@ const char* CodeStub::MajorName(CodeStub::Major major_key, |
| } |
| } |
| +void CodeStub::PrintBaseName(StringStream* stream) { |
| + stream->Add("%s", MajorName(MajorKey(), false)); |
| +} |
| + |
| void CodeStub::PrintName(StringStream* stream) { |
| - stream->Add("%s", MajorName(MajorKey(), false)); |
| + PrintBaseName(stream); |
| + PrintState(stream); |
| +} |
| + |
| + |
| +Builtins::JavaScript UnaryOpStub::ToJSBuiltin() { |
| + switch (operation_) { |
| + default: |
| + UNREACHABLE(); |
| + case Token::SUB: |
| + return Builtins::UNARY_MINUS; |
| + case Token::BIT_NOT: |
| + return Builtins::BIT_NOT; |
| + } |
| +} |
| + |
| + |
| +Handle<JSFunction> UnaryOpStub::ToJSFunction(Isolate* isolate) { |
| + Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object()); |
| + Object* builtin = builtins->javascript_builtin(ToJSBuiltin()); |
| + return Handle<JSFunction>(JSFunction::cast(builtin), isolate); |
| +} |
| + |
|
danno
2013/06/21 16:38:04
nit: two empty lines, please
|
| +MaybeObject* UnaryOpStub::Result(Handle<Object> object, Isolate* isolate) { |
| + Handle<JSFunction> builtin_function = ToJSFunction(isolate); |
| + bool caught_exception; |
| + Handle<Object> result = Execution::Call(builtin_function, object, |
| + 0, NULL, &caught_exception); |
| + if (caught_exception) { |
| + return Failure::Exception(); |
| + } |
| + return *result; |
| +} |
| + |
| + |
| +void UnaryOpStub::Record(Handle<Object> object) { |
|
danno
2013/06/21 16:38:04
UpdateState?
|
| + State old_state(state_); |
| + if (object->IsSmi()) { |
| + state_.Add(SMI); |
| + if (operation_ == Token::SUB && *object == 0) { |
| + // The result (-0) has to be represented as double. |
| + state_.Add(HEAP_NUMBER); |
| + } |
| + } else if (object->IsHeapNumber()) { |
| + state_.Add(HEAP_NUMBER); |
| + } else { |
| + state_.Add(GENERIC); |
| + } |
| + TraceTransition(old_state, state_); |
| +} |
| + |
|
danno
2013/06/21 16:38:04
nit: two spaces between functions
|
| +Handle<Type> UnaryOpStub::GetType(Isolate* isolate) { |
| + if (state_.Contains(GENERIC)) { |
| + return handle(Type::Any(), isolate); |
| + } |
| + Handle<Type> type = handle(Type::None(), isolate); |
| + if (state_.Contains(SMI)) { |
| + type = handle( |
| + Type::Union(type, handle(Type::Integer31(), isolate)), isolate); |
| + } |
| + if (state_.Contains(HEAP_NUMBER)) { |
| + type = handle( |
| + Type::Union(type, handle(Type::Double(), isolate)), isolate); |
| + } |
| + return type; |
| } |
| @@ -274,6 +342,29 @@ void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) { |
| #undef __ |
| +void UnaryOpStub::PrintBaseName(StringStream* stream) { |
| + CodeStub::PrintBaseName(stream); |
| + if (operation_ == Token::SUB) stream->Add("Minus"); |
| + if (operation_ == Token::BIT_NOT) stream->Add("Not"); |
| +} |
| + |
| + |
| +void UnaryOpStub::PrintState(StringStream* stream) { |
| + state_.Print(stream); |
| +} |
| + |
| + |
| +void UnaryOpStub::State::Print(StringStream* stream) const { |
| + stream->Add("("); |
| + SimpleListPrinter printer(stream); |
| + if (IsEmpty()) printer.Add("None"); |
| + if (Contains(GENERIC)) printer.Add("Generic"); |
| + if (Contains(HEAP_NUMBER)) printer.Add("HeapNumber"); |
| + if (Contains(SMI)) printer.Add("Smi"); |
| + stream->Add(")"); |
| +} |
| + |
| + |
| void BinaryOpStub::PrintName(StringStream* stream) { |
| const char* op_name = Token::Name(op_); |
| const char* overwrite_name; |
| @@ -432,6 +523,7 @@ void ICCompareStub::Generate(MacroAssembler* masm) { |
| void CompareNilICStub::Record(Handle<Object> object) { |
| ASSERT(state_ != State::Generic()); |
| + State old_state(state_); |
| if (object->IsNull()) { |
| state_.Add(NULL_TYPE); |
| } else if (object->IsUndefined()) { |
| @@ -445,18 +537,22 @@ void CompareNilICStub::Record(Handle<Object> object) { |
| } else { |
| state_.Add(MONOMORPHIC_MAP); |
| } |
| + TraceTransition(old_state, state_); |
| } |
| -void CompareNilICStub::State::TraceTransition(State to) const { |
| +template<class StateType> |
| +void HydrogenCodeStub::TraceTransition(StateType from, StateType to) { |
| #ifdef DEBUG |
| if (!FLAG_trace_ic) return; |
| char buffer[100]; |
| NoAllocationStringAllocator allocator(buffer, |
| static_cast<unsigned>(sizeof(buffer))); |
| StringStream stream(&allocator); |
| - stream.Add("[CompareNilIC : "); |
| - Print(&stream); |
| + stream.Add("["); |
| + PrintBaseName(&stream); |
| + stream.Add(": "); |
| + from.Print(&stream); |
| stream.Add("=>"); |
| to.Print(&stream); |
| stream.Add("]\n"); |
| @@ -464,12 +560,14 @@ void CompareNilICStub::State::TraceTransition(State to) const { |
| #endif |
| } |
| +void CompareNilICStub::PrintBaseName(StringStream* stream) { |
| + CodeStub::PrintBaseName(stream); |
| + stream->Add((nil_value_ == kNullValue) ? "(NullValue)": |
| + "(UndefinedValue)"); |
| +} |
| -void CompareNilICStub::PrintName(StringStream* stream) { |
| - stream->Add("CompareNilICStub_"); |
| +void CompareNilICStub::PrintState(StringStream* stream) { |
| state_.Print(stream); |
| - stream->Add((nil_value_ == kNullValue) ? "(NullValue|": |
| - "(UndefinedValue|"); |
| } |
| @@ -617,13 +715,12 @@ void CallConstructStub::PrintName(StringStream* stream) { |
| bool ToBooleanStub::Record(Handle<Object> object) { |
| Types old_types(types_); |
| bool to_boolean_value = types_.Record(object); |
| - old_types.TraceTransition(types_); |
| + TraceTransition(old_types, types_); |
| return to_boolean_value; |
| } |
| -void ToBooleanStub::PrintName(StringStream* stream) { |
| - stream->Add("ToBooleanStub_"); |
| +void ToBooleanStub::PrintState(StringStream* stream) { |
| types_.Print(stream); |
| } |
| @@ -644,23 +741,6 @@ void ToBooleanStub::Types::Print(StringStream* stream) const { |
| } |
| -void ToBooleanStub::Types::TraceTransition(Types to) const { |
| - #ifdef DEBUG |
| - if (!FLAG_trace_ic) return; |
| - char buffer[100]; |
| - NoAllocationStringAllocator allocator(buffer, |
| - static_cast<unsigned>(sizeof(buffer))); |
| - StringStream stream(&allocator); |
| - stream.Add("[ToBooleanIC : "); |
| - Print(&stream); |
| - stream.Add("=>"); |
| - to.Print(&stream); |
| - stream.Add("]\n"); |
| - stream.OutputToStdOut(); |
| - #endif |
| -} |
| - |
| - |
| bool ToBooleanStub::Types::Record(Handle<Object> object) { |
| if (object->IsUndefined()) { |
| Add(UNDEFINED); |