Index: src/code-stubs-hydrogen.cc |
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc |
index 587496fecd1ddf53a32a2a5564aa9cb43f086074..2168d1c3b105cebeb4385133eebae29b99f548c7 100644 |
--- a/src/code-stubs-hydrogen.cc |
+++ b/src/code-stubs-hydrogen.cc |
@@ -1965,71 +1965,59 @@ void CodeStubGraphBuilderBase::BuildInstallFromOptimizedCodeMap( |
is_optimized.Else(); |
{ |
AddIncrementCounter(counters->fast_new_closure_try_optimized()); |
- // optimized_map points to fixed array of 3-element entries |
- // (native context, optimized code, literals). |
- // Map must never be empty, so check the first elements. |
+ // The {optimized_map} points to fixed array of 4-element entries: |
+ // (native context, optimized code, literals, ast-id). |
+ // Iterate through the {optimized_map} backwards. After the loop, if no |
+ // matching optimized code was found, install unoptimized code. |
+ // for(i = map.length() - SharedFunctionInfo::kEntryLength; |
+ // i >= SharedFunctionInfo::kEntriesStart; |
+ // i -= SharedFunctionInfo::kEntryLength) { ... } |
HValue* first_entry_index = |
Add<HConstant>(SharedFunctionInfo::kEntriesStart); |
- IfBuilder already_in(this); |
- BuildCheckAndInstallOptimizedCode(js_function, native_context, &already_in, |
- optimized_map, first_entry_index); |
- already_in.Else(); |
+ HValue* shared_function_entry_length = |
+ Add<HConstant>(SharedFunctionInfo::kEntryLength); |
+ LoopBuilder loop_builder(this, context(), LoopBuilder::kPostDecrement, |
+ shared_function_entry_length); |
+ HValue* array_length = Add<HLoadNamedField>( |
+ optimized_map, nullptr, HObjectAccess::ForFixedArrayLength()); |
+ HValue* start_pos = |
+ AddUncasted<HSub>(array_length, shared_function_entry_length); |
+ HValue* slot_iterator = |
+ loop_builder.BeginBody(start_pos, first_entry_index, Token::GTE); |
{ |
- // Iterate through the rest of map backwards. Do not double check first |
- // entry. After the loop, if no matching optimized code was found, |
- // install unoptimized code. |
- // for(i = map.length() - SharedFunctionInfo::kEntryLength; |
- // i > SharedFunctionInfo::kEntriesStart; |
- // i -= SharedFunctionInfo::kEntryLength) { .. } |
- HValue* shared_function_entry_length = |
- Add<HConstant>(SharedFunctionInfo::kEntryLength); |
- LoopBuilder loop_builder(this, |
- context(), |
- LoopBuilder::kPostDecrement, |
- shared_function_entry_length); |
- HValue* array_length = Add<HLoadNamedField>( |
- optimized_map, nullptr, HObjectAccess::ForFixedArrayLength()); |
- HValue* start_pos = AddUncasted<HSub>(array_length, |
- shared_function_entry_length); |
- HValue* slot_iterator = loop_builder.BeginBody(start_pos, |
- first_entry_index, |
- Token::GT); |
+ IfBuilder done_check(this); |
+ BuildCheckAndInstallOptimizedCode(js_function, native_context, |
+ &done_check, optimized_map, |
+ slot_iterator); |
+ // Fall out of the loop |
+ loop_builder.Break(); |
+ } |
+ loop_builder.EndBody(); |
+ |
+ // If {slot_iterator} is less than the first entry index, then we failed to |
+ // find a context-dependent code and try context-independent code next. |
+ IfBuilder no_optimized_code_check(this); |
+ no_optimized_code_check.If<HCompareNumericAndBranch>( |
+ slot_iterator, first_entry_index, Token::LT); |
+ no_optimized_code_check.Then(); |
+ { |
+ IfBuilder shared_code_check(this); |
+ HValue* shared_code = |
+ Add<HLoadNamedField>(optimized_map, nullptr, |
+ HObjectAccess::ForOptimizedCodeMapSharedCode()); |
+ shared_code_check.IfNot<HCompareObjectEqAndBranch>( |
+ shared_code, graph()->GetConstantUndefined()); |
+ shared_code_check.Then(); |
{ |
- IfBuilder done_check(this); |
- BuildCheckAndInstallOptimizedCode(js_function, native_context, |
- &done_check, |
- optimized_map, |
- slot_iterator); |
- // Fall out of the loop |
- loop_builder.Break(); |
+ // Store the context-independent optimized code. |
+ HValue* literals = Add<HConstant>(factory->empty_fixed_array()); |
+ BuildInstallOptimizedCode(js_function, native_context, shared_code, |
+ literals); |
} |
- loop_builder.EndBody(); |
- |
- // If slot_iterator equals first entry index, then we failed to find a |
- // context-dependent code and try context-independent code next. |
- IfBuilder no_optimized_code_check(this); |
- no_optimized_code_check.If<HCompareNumericAndBranch>( |
- slot_iterator, first_entry_index, Token::EQ); |
- no_optimized_code_check.Then(); |
+ shared_code_check.Else(); |
{ |
- IfBuilder shared_code_check(this); |
- HValue* shared_code = Add<HLoadNamedField>( |
- optimized_map, nullptr, |
- HObjectAccess::ForOptimizedCodeMapSharedCode()); |
- shared_code_check.IfNot<HCompareObjectEqAndBranch>( |
- shared_code, graph()->GetConstantUndefined()); |
- shared_code_check.Then(); |
- { |
- // Store the context-independent optimized code. |
- HValue* literals = Add<HConstant>(factory->empty_fixed_array()); |
- BuildInstallOptimizedCode(js_function, native_context, shared_code, |
- literals); |
- } |
- shared_code_check.Else(); |
- { |
- // Store the unoptimized code. |
- BuildInstallCode(js_function, shared_info); |
- } |
+ // Store the unoptimized code. |
+ BuildInstallCode(js_function, shared_info); |
} |
} |
} |