OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 | 290 |
291 Failure* IC::ReferenceError(const char* type, Handle<String> name) { | 291 Failure* IC::ReferenceError(const char* type, Handle<String> name) { |
292 HandleScope scope(isolate()); | 292 HandleScope scope(isolate()); |
293 Handle<Object> error = isolate()->factory()->NewReferenceError( | 293 Handle<Object> error = isolate()->factory()->NewReferenceError( |
294 type, HandleVector(&name, 1)); | 294 type, HandleVector(&name, 1)); |
295 return isolate()->Throw(*error); | 295 return isolate()->Throw(*error); |
296 } | 296 } |
297 | 297 |
298 | 298 |
| 299 static int ComputeTypeInfoCountDelta(IC::State old_state, IC::State new_state) { |
| 300 bool was_uninitialized = |
| 301 old_state == UNINITIALIZED || old_state == PREMONOMORPHIC; |
| 302 bool is_uninitialized = |
| 303 new_state == UNINITIALIZED || new_state == PREMONOMORPHIC; |
| 304 return (was_uninitialized && !is_uninitialized) ? 1 : |
| 305 (!was_uninitialized && is_uninitialized) ? -1 : 0; |
| 306 } |
| 307 |
| 308 |
299 void IC::PostPatching(Address address, Code* target, Code* old_target) { | 309 void IC::PostPatching(Address address, Code* target, Code* old_target) { |
300 if (FLAG_type_info_threshold > 0) { | 310 if (FLAG_type_info_threshold == 0 && !FLAG_watch_ic_patching) { |
301 if (old_target->is_inline_cache_stub() && | 311 return; |
302 target->is_inline_cache_stub()) { | 312 } |
303 State old_state = old_target->ic_state(); | 313 Code* host = target->GetHeap()->isolate()-> |
304 State new_state = target->ic_state(); | 314 inner_pointer_to_code_cache()->GetCacheEntry(address)->code; |
305 bool was_uninitialized = | 315 if (host->kind() != Code::FUNCTION) return; |
306 old_state == UNINITIALIZED || old_state == PREMONOMORPHIC; | 316 |
307 bool is_uninitialized = | 317 if (FLAG_type_info_threshold > 0 && |
308 new_state == UNINITIALIZED || new_state == PREMONOMORPHIC; | 318 old_target->is_inline_cache_stub() && |
309 int delta = 0; | 319 target->is_inline_cache_stub()) { |
310 if (was_uninitialized && !is_uninitialized) { | 320 int delta = ComputeTypeInfoCountDelta(old_target->ic_state(), |
311 delta = 1; | 321 target->ic_state()); |
312 } else if (!was_uninitialized && is_uninitialized) { | 322 // Not all Code objects have TypeFeedbackInfo. |
313 delta = -1; | 323 if (delta != 0 && host->type_feedback_info()->IsTypeFeedbackInfo()) { |
314 } | 324 TypeFeedbackInfo* info = |
315 if (delta != 0) { | 325 TypeFeedbackInfo::cast(host->type_feedback_info()); |
316 Code* host = target->GetHeap()->isolate()-> | 326 info->set_ic_with_type_info_count( |
317 inner_pointer_to_code_cache()->GetCacheEntry(address)->code; | 327 info->ic_with_type_info_count() + delta); |
318 // Not all Code objects have TypeFeedbackInfo. | |
319 if (host->type_feedback_info()->IsTypeFeedbackInfo()) { | |
320 TypeFeedbackInfo* info = | |
321 TypeFeedbackInfo::cast(host->type_feedback_info()); | |
322 info->set_ic_with_typeinfo_count( | |
323 info->ic_with_typeinfo_count() + delta); | |
324 } | |
325 } | |
326 } | 328 } |
327 } | 329 } |
328 if (FLAG_watch_ic_patching) { | 330 if (FLAG_watch_ic_patching) { |
| 331 host->set_profiler_ticks(0); |
329 Isolate::Current()->runtime_profiler()->NotifyICChanged(); | 332 Isolate::Current()->runtime_profiler()->NotifyICChanged(); |
330 // We do not want to optimize until the ICs have settled down, | |
331 // so when they are patched, we postpone optimization for the | |
332 // current function and the functions above it on the stack that | |
333 // might want to inline this one. | |
334 StackFrameIterator it; | |
335 if (it.done()) return; | |
336 it.Advance(); | |
337 static const int kStackFramesToMark = Compiler::kMaxInliningLevels - 1; | |
338 for (int i = 0; i < kStackFramesToMark; ++i) { | |
339 if (it.done()) return; | |
340 StackFrame* raw_frame = it.frame(); | |
341 if (raw_frame->is_java_script()) { | |
342 JSFunction* function = | |
343 JSFunction::cast(JavaScriptFrame::cast(raw_frame)->function()); | |
344 if (function->IsOptimized()) continue; | |
345 SharedFunctionInfo* shared = function->shared(); | |
346 shared->set_profiler_ticks(0); | |
347 } | |
348 it.Advance(); | |
349 } | |
350 } | 333 } |
| 334 // TODO(2029): When an optimized function is patched, it would |
| 335 // be nice to propagate the corresponding type information to its |
| 336 // unoptimized version for the benefit of later inlining. |
351 } | 337 } |
352 | 338 |
353 | 339 |
354 void IC::Clear(Address address) { | 340 void IC::Clear(Address address) { |
355 Code* target = GetTargetAtAddress(address); | 341 Code* target = GetTargetAtAddress(address); |
356 | 342 |
357 // Don't clear debug break inline cache as it will remove the break point. | 343 // Don't clear debug break inline cache as it will remove the break point. |
358 if (target->ic_state() == DEBUG_BREAK) return; | 344 if (target->ic_state() == DEBUG_BREAK) return; |
359 | 345 |
360 switch (target->kind()) { | 346 switch (target->kind()) { |
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2577 #undef ADDR | 2563 #undef ADDR |
2578 }; | 2564 }; |
2579 | 2565 |
2580 | 2566 |
2581 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2567 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2582 return IC_utilities[id]; | 2568 return IC_utilities[id]; |
2583 } | 2569 } |
2584 | 2570 |
2585 | 2571 |
2586 } } // namespace v8::internal | 2572 } } // namespace v8::internal |
OLD | NEW |