OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 4861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4872 VISIT_FOR_VALUE(expr->left()); | 4872 VISIT_FOR_VALUE(expr->left()); |
4873 VISIT_FOR_VALUE(expr->right()); | 4873 VISIT_FOR_VALUE(expr->right()); |
4874 | 4874 |
4875 HValue* right = Pop(); | 4875 HValue* right = Pop(); |
4876 HValue* left = Pop(); | 4876 HValue* left = Pop(); |
4877 Token::Value op = expr->op(); | 4877 Token::Value op = expr->op(); |
4878 | 4878 |
4879 TypeInfo info = oracle()->CompareType(expr, TypeFeedbackOracle::RESULT); | 4879 TypeInfo info = oracle()->CompareType(expr, TypeFeedbackOracle::RESULT); |
4880 HInstruction* instr = NULL; | 4880 HInstruction* instr = NULL; |
4881 if (op == Token::INSTANCEOF) { | 4881 if (op == Token::INSTANCEOF) { |
4882 instr = new HInstanceOf(left, right); | 4882 // Check to see if the rhs of the instanceof is a global function not |
| 4883 // residing in new space. If it is we assume that the function will stay the |
| 4884 // same. |
| 4885 Handle<JSFunction> target = Handle<JSFunction>::null(); |
| 4886 Variable* var = expr->right()->AsVariableProxy()->AsVariable(); |
| 4887 bool global_function = (var != NULL) && var->is_global() && !var->is_this(); |
| 4888 CompilationInfo* info = graph()->info(); |
| 4889 if (global_function && |
| 4890 info->has_global_object() && |
| 4891 !info->global_object()->IsAccessCheckNeeded()) { |
| 4892 Handle<String> name = var->name(); |
| 4893 Handle<GlobalObject> global(info->global_object()); |
| 4894 LookupResult lookup; |
| 4895 global->Lookup(*name, &lookup); |
| 4896 if (lookup.IsProperty() && |
| 4897 lookup.type() == NORMAL && |
| 4898 lookup.GetValue()->IsJSFunction()) { |
| 4899 Handle<JSFunction> candidate(JSFunction::cast(lookup.GetValue())); |
| 4900 // If the function is in new space we assume it's more likely to |
| 4901 // change and thus prefer the general IC code. |
| 4902 if (!Heap::InNewSpace(*candidate)) { |
| 4903 target = candidate; |
| 4904 } |
| 4905 } |
| 4906 } |
| 4907 |
| 4908 // If the target is not null we have found a known global function that is |
| 4909 // assumed to stay the same for this instanceof. |
| 4910 if (target.is_null()) { |
| 4911 instr = new HInstanceOf(left, right); |
| 4912 } else { |
| 4913 AddInstruction(new HCheckFunction(right, target)); |
| 4914 instr = new HInstanceOfKnownGlobal(left, target); |
| 4915 } |
4883 } else if (op == Token::IN) { | 4916 } else if (op == Token::IN) { |
4884 BAILOUT("Unsupported comparison: in"); | 4917 BAILOUT("Unsupported comparison: in"); |
4885 } else if (info.IsNonPrimitive()) { | 4918 } else if (info.IsNonPrimitive()) { |
4886 switch (op) { | 4919 switch (op) { |
4887 case Token::EQ: | 4920 case Token::EQ: |
4888 case Token::EQ_STRICT: { | 4921 case Token::EQ_STRICT: { |
4889 AddInstruction(new HCheckNonSmi(left)); | 4922 AddInstruction(new HCheckNonSmi(left)); |
4890 AddInstruction(HCheckInstanceType::NewIsJSObjectOrJSFunction(left)); | 4923 AddInstruction(HCheckInstanceType::NewIsJSObjectOrJSFunction(left)); |
4891 AddInstruction(new HCheckNonSmi(right)); | 4924 AddInstruction(new HCheckNonSmi(right)); |
4892 AddInstruction(HCheckInstanceType::NewIsJSObjectOrJSFunction(right)); | 4925 AddInstruction(HCheckInstanceType::NewIsJSObjectOrJSFunction(right)); |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5743 } | 5776 } |
5744 | 5777 |
5745 #ifdef DEBUG | 5778 #ifdef DEBUG |
5746 if (graph_ != NULL) graph_->Verify(); | 5779 if (graph_ != NULL) graph_->Verify(); |
5747 if (chunk_ != NULL) chunk_->Verify(); | 5780 if (chunk_ != NULL) chunk_->Verify(); |
5748 if (allocator_ != NULL) allocator_->Verify(); | 5781 if (allocator_ != NULL) allocator_->Verify(); |
5749 #endif | 5782 #endif |
5750 } | 5783 } |
5751 | 5784 |
5752 } } // namespace v8::internal | 5785 } } // namespace v8::internal |
OLD | NEW |