Index: src/hydrogen.cc |
=================================================================== |
--- src/hydrogen.cc (revision 6109) |
+++ src/hydrogen.cc (working copy) |
@@ -4847,7 +4847,42 @@ |
TypeInfo info = oracle()->CompareType(expr, TypeFeedbackOracle::RESULT); |
HInstruction* instr = NULL; |
if (op == Token::INSTANCEOF) { |
- instr = new HInstanceOf(left, right); |
+ // Check to see if the rhs of the instanceof is a global function not |
+ // residing in new space. If it is the assumption used for optimization is |
Mads Ager (chromium)
2011/01/04 17:25:58
Simplify to: If it is we assume that the function
Søren Thygesen Gjesse
2011/01/05 09:28:00
Done.
|
+ // that the function most likely will stay the same. |
+ Handle<JSFunction> target = Handle<JSFunction>::null(); |
+ Variable* var = expr->right()->AsVariableProxy()->AsVariable(); |
+ bool global_function = (var != NULL) && var->is_global() && !var->is_this(); |
+ CompilationInfo* info = graph()->info(); |
+ if (global_function && |
+ info->has_global_object() && |
+ !info->global_object()->IsAccessCheckNeeded()) { |
+ Handle<String> name = var->name(); |
+ Handle<GlobalObject> global(info->global_object()); |
+ Handle<JSGlobalPropertyCell> cell = Handle<JSGlobalPropertyCell>::null(); |
Mads Ager (chromium)
2011/01/04 17:25:58
Do you need the cell declaration out here? Can't y
Søren Thygesen Gjesse
2011/01/05 09:28:00
Don't need the cell at all, can just use lookup.Ge
|
+ LookupResult lookup; |
+ global->Lookup(*name, &lookup); |
+ if (lookup.IsProperty() && lookup.type() == NORMAL) { |
+ cell = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); |
+ if (cell->value()->IsJSFunction()) { |
+ Handle<JSFunction> candidate(JSFunction::cast(cell->value())); |
+ // If the function is in new space we assume it's more likely to |
+ // change and thus prefer the general IC code. |
+ if (!Heap::InNewSpace(*candidate)) { |
+ target = candidate; |
+ } |
+ } |
+ } |
+ } |
+ |
+ // If the traget is not null we have found a known global function that is |
Mads Ager (chromium)
2011/01/04 17:25:58
traget -> target
Søren Thygesen Gjesse
2011/01/05 09:28:00
Done.
|
+ // assumed to stay the same for this instanceof. |
+ if (target.is_null()) { |
+ instr = new HInstanceOf(left, right); |
+ } else { |
+ AddInstruction(new HCheckFunction(right, target)); |
+ instr = new HInstanceOfKnownGlobal(left, target); |
+ } |
} else if (op == Token::IN) { |
BAILOUT("Unsupported comparison: in"); |
} else if (info.IsNonPrimitive()) { |