Index: src/ic.cc |
diff --git a/src/ic.cc b/src/ic.cc |
index 8e2d589c1e1f4f399f06fb0e942b4c8b9ad6704e..688908ead2fa6a1546577971c16ae4ae36d0feb8 100644 |
--- a/src/ic.cc |
+++ b/src/ic.cc |
@@ -91,9 +91,11 @@ void IC::TraceIC(const char* type, |
} |
JavaScriptFrame::PrintTop(isolate(), stdout, false, true); |
ExtraICState extra_state = new_target->extra_ic_state(); |
- const char* modifier = |
- GetTransitionMarkModifier( |
- KeyedStoreIC::GetKeyedAccessStoreMode(extra_state)); |
+ const char* modifier = ""; |
+ if (new_target->kind() == Code::KEYED_STORE_IC) { |
+ modifier = GetTransitionMarkModifier( |
+ KeyedStoreIC::GetKeyedAccessStoreMode(extra_state)); |
+ } |
PrintF(" (%c->%c%s)", |
TransitionMarkFromState(state()), |
TransitionMarkFromState(new_state), |
@@ -415,6 +417,10 @@ void IC::PostPatching(Address address, Code* target, Code* old_target) { |
target->is_inline_cache_stub()) { |
int delta = ComputeTypeInfoCountDelta(old_target->ic_state(), |
target->ic_state()); |
+ // Call ICs don't have interesting state changes from this point |
+ // of view. |
+ ASSERT(target->kind() != Code::CALL_IC || delta == 0); |
+ |
// Not all Code objects have TypeFeedbackInfo. |
if (host->type_feedback_info()->IsTypeFeedbackInfo() && delta != 0) { |
TypeFeedbackInfo* info = |
@@ -451,6 +457,8 @@ void IC::Clear(Isolate* isolate, Address address, |
return StoreIC::Clear(isolate, address, target, constant_pool); |
case Code::KEYED_STORE_IC: |
return KeyedStoreIC::Clear(isolate, address, target, constant_pool); |
+ case Code::CALL_IC: |
+ return CallIC::Clear(isolate, address, target, constant_pool); |
case Code::COMPARE_IC: |
return CompareIC::Clear(isolate, address, target, constant_pool); |
case Code::COMPARE_NIL_IC: |
@@ -477,6 +485,25 @@ void KeyedLoadIC::Clear(Isolate* isolate, |
} |
+void CallIC::Clear(Isolate* isolate, |
+ Address address, |
+ Code* target, |
+ ConstantPoolArray* constant_pool) { |
+ // CallIC just has a generic stub and a monomorphic stub. Only clear if we |
+ // are monomorphic |
+ if (target->ic_state() != ::v8::internal::MONOMORPHIC) return; |
+ |
+ CallIC::State existing_state(target->extra_ic_state()); |
+ |
+ // Install default stub with the immutable parts of existing state. |
+ HandleScope scope(isolate); |
+ CallICStub stub(State::DefaultCallState(existing_state.arg_count(), |
+ existing_state.call_type())); |
+ Code* code = *stub.GetCode(isolate); |
+ SetTargetAtAddress(address, code, constant_pool); |
+} |
+ |
+ |
void LoadIC::Clear(Isolate* isolate, |
Address address, |
Code* target, |
@@ -1276,6 +1303,32 @@ MaybeObject* StoreIC::Store(Handle<Object> object, |
} |
+void CallIC::State::Print(StringStream* stream) const { |
+ stream->Add("(args(%d), ", |
+ argc_); |
+ stream->Add("%s, ", |
+ call_type_ == CallIC::METHOD ? "METHOD" : "FUNCTION"); |
+ stream->Add("%s, ", |
+ stub_type_ == CallIC::MONOMORPHIC ? |
+ "MONOMORPHIC" : "NOT_MONOMORPHIC"); |
+ stream->Add("%s, ", |
+ argument_check_ == CallIC::ARGUMENTS_MUST_MATCH ? |
+ "args_must_match" : "args_might_match"); |
+ stream->Add("%s)", |
+ strict_mode_ == STRICT ? |
+ "strict" : "sloppy"); |
+} |
+ |
+ |
+Handle<Code> CallIC::initialize_stub(Isolate* isolate, |
+ int argc, |
+ CallType call_type) { |
+ CallICStub stub(State::DefaultCallState(argc, call_type)); |
+ Handle<Code> code = stub.GetCode(isolate); |
+ return code; |
+} |
+ |
+ |
Handle<Code> StoreIC::initialize_stub(Isolate* isolate, |
StrictMode strict_mode) { |
ExtraICState extra_state = ComputeExtraICState(strict_mode); |
@@ -1748,6 +1801,102 @@ MaybeObject* KeyedStoreIC::Store(Handle<Object> object, |
} |
+CallIC::State::State(ExtraICState extra_ic_state) |
+ : argc_(ArgcBits::decode(extra_ic_state)), |
+ call_type_(CallTypeBits::decode(extra_ic_state)), |
+ stub_type_(StubTypeBits::decode(extra_ic_state)), |
+ argument_check_(ArgumentCheckBits::decode(extra_ic_state)), |
+ strict_mode_(StrictModeBits::decode(extra_ic_state)) { |
+} |
+ |
+ |
+ExtraICState CallIC::State::GetExtraICState() const { |
+ ExtraICState extra_ic_state = |
+ ArgcBits::encode(argc_) | |
+ CallTypeBits::encode(call_type_) | |
+ StubTypeBits::encode(stub_type_) | |
+ ArgumentCheckBits::encode(argument_check_) | |
+ StrictModeBits::encode(strict_mode_); |
+ return extra_ic_state; |
+} |
+ |
+ |
+CallIC::State CallIC::State::ToGenericState() { |
+ if (stub_type() == CallIC::MONOMORPHIC) { |
+ return DefaultCallState(arg_count(), call_type()); |
+ } |
+ return *this; |
+} |
+ |
+ |
+CallIC::State CallIC::State::ToMonomorphicState( |
+ Handle<JSFunction> function) { |
+ // Choose the right monomorphic handler |
+ SharedFunctionInfo* shared = function->shared(); |
+ ArgumentCheck new_argument_check = |
+ shared->formal_parameter_count() == arg_count() |
+ ? CallIC::ARGUMENTS_MUST_MATCH |
+ : CallIC::ARGUMENTS_COUNT_UNKNOWN; |
+ StrictMode new_strict_mode = shared->strict_mode(); |
+ if (new_argument_check != argument_check() || |
+ new_strict_mode != strict_mode()) { |
+ return MonomorphicCallState(arg_count(), call_type(), new_argument_check, |
+ new_strict_mode); |
+ } |
+ |
+ return *this; |
+} |
+ |
+ |
+void CallIC::HandleMiss(Handle<Object> receiver, |
+ Handle<Object> function, |
+ Handle<FixedArray> vector, |
+ Handle<Smi> slot) { |
+ State state(target()->extra_ic_state()); |
+ Object* feedback = vector->get(slot->value()); |
+ |
+ if (feedback->IsJSFunction() || !function->IsJSFunction()) { |
+ // We are going generic. |
+ ASSERT(!function->IsJSFunction() || *function != feedback); |
+ |
+ vector->set(slot->value(), |
+ *TypeFeedbackInfo::MegamorphicSentinel(isolate())); |
+ |
+ // We only need to patch if we currently don't have the default stub in |
+ // place. |
+ State new_state = state.ToGenericState(); |
+ if (new_state != state) { |
+ CallICStub stub(new_state); |
+ set_target(*stub.GetCode(isolate())); |
+ TRACE_GENERIC_IC(isolate(), "CallIC", "generic"); |
+ } |
+ } else { |
+ // If we came here feedback must be the uninitialized sentinel, |
+ // and we are going monomorphic. |
+ ASSERT(feedback == *TypeFeedbackInfo::UninitializedSentinel(isolate())); |
+ ASSERT(state.stub_type() != CallIC::MONOMORPHIC); |
+ |
+ vector->set(slot->value(), *function); |
+ |
+ // Choose the right monomorphic handler |
+ Handle<JSFunction> js_function = Handle<JSFunction>::cast(function); |
+ State new_state = state.ToMonomorphicState(js_function); |
+ if (new_state != state) { |
+ CallICStub stub(new_state); |
+ Handle<Code> code = stub.GetCode(isolate()); |
+ // Creating the code above could result in a gc, which clears the type |
+ // vector. If that happens, our plan to go monomorphic has been |
+ // pre-empted. |
+ feedback = vector->get(slot->value()); |
+ if (feedback == *function) { |
+ set_target(*code); |
+ TRACE_IC("CallIC", handle(js_function->shared()->name(), isolate())); |
+ } |
+ } |
+ } |
+} |
+ |
+ |
#undef TRACE_IC |
@@ -1756,6 +1905,19 @@ MaybeObject* KeyedStoreIC::Store(Handle<Object> object, |
// |
// Used from ic-<arch>.cc. |
+RUNTIME_FUNCTION(MaybeObject*, CallIC_Miss) { |
+ HandleScope scope(isolate); |
+ ASSERT(args.length() == 4); |
+ CallIC ic(isolate); |
+ Handle<Object> receiver = args.at<Object>(0); |
+ Handle<Object> function = args.at<Object>(1); |
+ Handle<FixedArray> vector = args.at<FixedArray>(2); |
+ Handle<Smi> slot = args.at<Smi>(3); |
+ ic.HandleMiss(receiver, function, vector, slot); |
+ return *function; |
+} |
+ |
+ |
// Used from ic-<arch>.cc. |
RUNTIME_FUNCTION(MaybeObject*, LoadIC_Miss) { |
HandleScope scope(isolate); |