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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 235 } |
236 if (h2->IsSmi()) return false; | 236 if (h2->IsSmi()) return false; |
237 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1); | 237 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1); |
238 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2); | 238 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2); |
239 ASSERT(isfinite(n1->value())); | 239 ASSERT(isfinite(n1->value())); |
240 ASSERT(isfinite(n2->value())); | 240 ASSERT(isfinite(n2->value())); |
241 return n1->value() == n2->value(); | 241 return n1->value() == n2->value(); |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 void ObjectLiteral::CalculateEmitStore() { | 245 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
246 ZoneHashMap table(Literal::Match); | 246 ZoneAllocationPolicy allocator(zone); |
247 | |
248 ZoneHashMap table(Literal::Match, 8, allocator); | |
danno
2012/06/05 13:42:35
Please use a constant for this. Didn't you add one
sanjoy
2012/06/05 14:21:39
Fixed.
| |
247 for (int i = properties()->length() - 1; i >= 0; i--) { | 249 for (int i = properties()->length() - 1; i >= 0; i--) { |
248 ObjectLiteral::Property* property = properties()->at(i); | 250 ObjectLiteral::Property* property = properties()->at(i); |
249 Literal* literal = property->key(); | 251 Literal* literal = property->key(); |
250 if (literal->handle()->IsNull()) continue; | 252 if (literal->handle()->IsNull()) continue; |
251 uint32_t hash = literal->Hash(); | 253 uint32_t hash = literal->Hash(); |
252 // If the key of a computed property is in the table, do not emit | 254 // If the key of a computed property is in the table, do not emit |
253 // a store for the property later. | 255 // a store for the property later. |
254 if (property->kind() == ObjectLiteral::Property::COMPUTED && | 256 if (property->kind() == ObjectLiteral::Property::COMPUTED && |
255 table.Lookup(literal, hash, false) != NULL) { | 257 table.Lookup(literal, hash, false, allocator) != NULL) { |
256 property->set_emit_store(false); | 258 property->set_emit_store(false); |
257 } else { | 259 } else { |
258 // Add key to the table. | 260 // Add key to the table. |
259 table.Lookup(literal, hash, true); | 261 table.Lookup(literal, hash, true, allocator); |
260 } | 262 } |
261 } | 263 } |
262 } | 264 } |
263 | 265 |
264 | 266 |
265 void TargetCollector::AddTarget(Label* target) { | 267 void TargetCollector::AddTarget(Label* target, Zone* zone) { |
266 // Add the label to the collector, but discard duplicates. | 268 // Add the label to the collector, but discard duplicates. |
267 int length = targets_.length(); | 269 int length = targets_.length(); |
268 for (int i = 0; i < length; i++) { | 270 for (int i = 0; i < length; i++) { |
269 if (targets_[i] == target) return; | 271 if (targets_[i] == target) return; |
270 } | 272 } |
271 targets_.Add(target); | 273 targets_.Add(target, zone); |
272 } | 274 } |
273 | 275 |
274 | 276 |
275 bool UnaryOperation::ResultOverwriteAllowed() { | 277 bool UnaryOperation::ResultOverwriteAllowed() { |
276 switch (op_) { | 278 switch (op_) { |
277 case Token::BIT_NOT: | 279 case Token::BIT_NOT: |
278 case Token::SUB: | 280 case Token::SUB: |
279 return true; | 281 return true; |
280 default: | 282 default: |
281 return false; | 283 return false; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 } | 392 } |
391 | 393 |
392 bool FunctionDeclaration::IsInlineable() const { | 394 bool FunctionDeclaration::IsInlineable() const { |
393 return false; | 395 return false; |
394 } | 396 } |
395 | 397 |
396 | 398 |
397 // ---------------------------------------------------------------------------- | 399 // ---------------------------------------------------------------------------- |
398 // Recording of type feedback | 400 // Recording of type feedback |
399 | 401 |
400 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 402 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
403 Zone* zone) { | |
401 // Record type feedback from the oracle in the AST. | 404 // Record type feedback from the oracle in the AST. |
402 is_uninitialized_ = oracle->LoadIsUninitialized(this); | 405 is_uninitialized_ = oracle->LoadIsUninitialized(this); |
403 if (is_uninitialized_) return; | 406 if (is_uninitialized_) return; |
404 | 407 |
405 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); | 408 is_monomorphic_ = oracle->LoadIsMonomorphicNormal(this); |
406 receiver_types_.Clear(); | 409 receiver_types_.Clear(); |
407 if (key()->IsPropertyName()) { | 410 if (key()->IsPropertyName()) { |
408 if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) { | 411 if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_ArrayLength)) { |
409 is_array_length_ = true; | 412 is_array_length_ = true; |
410 } else if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_StringLength)) { | 413 } else if (oracle->LoadIsBuiltin(this, Builtins::kLoadIC_StringLength)) { |
411 is_string_length_ = true; | 414 is_string_length_ = true; |
412 } else if (oracle->LoadIsBuiltin(this, | 415 } else if (oracle->LoadIsBuiltin(this, |
413 Builtins::kLoadIC_FunctionPrototype)) { | 416 Builtins::kLoadIC_FunctionPrototype)) { |
414 is_function_prototype_ = true; | 417 is_function_prototype_ = true; |
415 } else { | 418 } else { |
416 Literal* lit_key = key()->AsLiteral(); | 419 Literal* lit_key = key()->AsLiteral(); |
417 ASSERT(lit_key != NULL && lit_key->handle()->IsString()); | 420 ASSERT(lit_key != NULL && lit_key->handle()->IsString()); |
418 Handle<String> name = Handle<String>::cast(lit_key->handle()); | 421 Handle<String> name = Handle<String>::cast(lit_key->handle()); |
419 oracle->LoadReceiverTypes(this, name, &receiver_types_); | 422 oracle->LoadReceiverTypes(this, name, &receiver_types_); |
420 } | 423 } |
421 } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { | 424 } else if (oracle->LoadIsBuiltin(this, Builtins::kKeyedLoadIC_String)) { |
422 is_string_access_ = true; | 425 is_string_access_ = true; |
423 } else if (is_monomorphic_) { | 426 } else if (is_monomorphic_) { |
424 receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this)); | 427 receiver_types_.Add(oracle->LoadMonomorphicReceiverType(this), |
428 zone); | |
425 } else if (oracle->LoadIsMegamorphicWithTypeInfo(this)) { | 429 } else if (oracle->LoadIsMegamorphicWithTypeInfo(this)) { |
426 receiver_types_.Reserve(kMaxKeyedPolymorphism); | 430 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
427 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); | 431 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
428 } | 432 } |
429 } | 433 } |
430 | 434 |
431 | 435 |
432 void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 436 void Assignment::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
437 Zone* zone) { | |
433 Property* prop = target()->AsProperty(); | 438 Property* prop = target()->AsProperty(); |
434 ASSERT(prop != NULL); | 439 ASSERT(prop != NULL); |
435 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); | 440 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); |
436 receiver_types_.Clear(); | 441 receiver_types_.Clear(); |
437 if (prop->key()->IsPropertyName()) { | 442 if (prop->key()->IsPropertyName()) { |
438 Literal* lit_key = prop->key()->AsLiteral(); | 443 Literal* lit_key = prop->key()->AsLiteral(); |
439 ASSERT(lit_key != NULL && lit_key->handle()->IsString()); | 444 ASSERT(lit_key != NULL && lit_key->handle()->IsString()); |
440 Handle<String> name = Handle<String>::cast(lit_key->handle()); | 445 Handle<String> name = Handle<String>::cast(lit_key->handle()); |
441 oracle->StoreReceiverTypes(this, name, &receiver_types_); | 446 oracle->StoreReceiverTypes(this, name, &receiver_types_); |
442 } else if (is_monomorphic_) { | 447 } else if (is_monomorphic_) { |
443 // Record receiver type for monomorphic keyed stores. | 448 // Record receiver type for monomorphic keyed stores. |
444 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this)); | 449 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this), zone); |
445 } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { | 450 } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { |
446 receiver_types_.Reserve(kMaxKeyedPolymorphism); | 451 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
447 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); | 452 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
448 } | 453 } |
449 } | 454 } |
450 | 455 |
451 | 456 |
452 void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 457 void CountOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle, |
458 Zone* zone) { | |
453 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); | 459 is_monomorphic_ = oracle->StoreIsMonomorphicNormal(this); |
454 receiver_types_.Clear(); | 460 receiver_types_.Clear(); |
455 if (is_monomorphic_) { | 461 if (is_monomorphic_) { |
456 // Record receiver type for monomorphic keyed stores. | 462 // Record receiver type for monomorphic keyed stores. |
457 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this)); | 463 receiver_types_.Add(oracle->StoreMonomorphicReceiverType(this), zone); |
458 } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { | 464 } else if (oracle->StoreIsMegamorphicWithTypeInfo(this)) { |
459 receiver_types_.Reserve(kMaxKeyedPolymorphism); | 465 receiver_types_.Reserve(kMaxKeyedPolymorphism, zone); |
460 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); | 466 oracle->CollectKeyedReceiverTypes(this->id(), &receiver_types_); |
461 } | 467 } |
462 } | 468 } |
463 | 469 |
464 | 470 |
465 void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 471 void CaseClause::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
466 TypeInfo info = oracle->SwitchType(this); | 472 TypeInfo info = oracle->SwitchType(this); |
467 if (info.IsSmi()) { | 473 if (info.IsSmi()) { |
468 compare_type_ = SMI_ONLY; | 474 compare_type_ = SMI_ONLY; |
469 } else if (info.IsSymbol()) { | 475 } else if (info.IsSymbol()) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 } | 783 } |
778 | 784 |
779 | 785 |
780 // Convert regular expression trees to a simple sexp representation. | 786 // Convert regular expression trees to a simple sexp representation. |
781 // This representation should be different from the input grammar | 787 // This representation should be different from the input grammar |
782 // in as many cases as possible, to make it more difficult for incorrect | 788 // in as many cases as possible, to make it more difficult for incorrect |
783 // parses to look as correct ones which is likely if the input and | 789 // parses to look as correct ones which is likely if the input and |
784 // output formats are alike. | 790 // output formats are alike. |
785 class RegExpUnparser: public RegExpVisitor { | 791 class RegExpUnparser: public RegExpVisitor { |
786 public: | 792 public: |
787 RegExpUnparser(); | 793 explicit RegExpUnparser(Zone* zone); |
788 void VisitCharacterRange(CharacterRange that); | 794 void VisitCharacterRange(CharacterRange that); |
789 SmartArrayPointer<const char> ToString() { return stream_.ToCString(); } | 795 SmartArrayPointer<const char> ToString() { return stream_.ToCString(); } |
790 #define MAKE_CASE(Name) virtual void* Visit##Name(RegExp##Name*, void* data); | 796 #define MAKE_CASE(Name) virtual void* Visit##Name(RegExp##Name*, void* data); |
791 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) | 797 FOR_EACH_REG_EXP_TREE_TYPE(MAKE_CASE) |
792 #undef MAKE_CASE | 798 #undef MAKE_CASE |
793 private: | 799 private: |
794 StringStream* stream() { return &stream_; } | 800 StringStream* stream() { return &stream_; } |
795 HeapStringAllocator alloc_; | 801 HeapStringAllocator alloc_; |
796 StringStream stream_; | 802 StringStream stream_; |
803 Zone* zone_; | |
797 }; | 804 }; |
798 | 805 |
799 | 806 |
800 RegExpUnparser::RegExpUnparser() : stream_(&alloc_) { | 807 RegExpUnparser::RegExpUnparser(Zone* zone) : stream_(&alloc_), zone_(zone) { |
801 } | 808 } |
802 | 809 |
803 | 810 |
804 void* RegExpUnparser::VisitDisjunction(RegExpDisjunction* that, void* data) { | 811 void* RegExpUnparser::VisitDisjunction(RegExpDisjunction* that, void* data) { |
805 stream()->Add("(|"); | 812 stream()->Add("(|"); |
806 for (int i = 0; i < that->alternatives()->length(); i++) { | 813 for (int i = 0; i < that->alternatives()->length(); i++) { |
807 stream()->Add(" "); | 814 stream()->Add(" "); |
808 that->alternatives()->at(i)->Accept(this, data); | 815 that->alternatives()->at(i)->Accept(this, data); |
809 } | 816 } |
810 stream()->Add(")"); | 817 stream()->Add(")"); |
(...skipping 19 matching lines...) Expand all Loading... | |
830 } | 837 } |
831 } | 838 } |
832 | 839 |
833 | 840 |
834 | 841 |
835 void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that, | 842 void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that, |
836 void* data) { | 843 void* data) { |
837 if (that->is_negated()) | 844 if (that->is_negated()) |
838 stream()->Add("^"); | 845 stream()->Add("^"); |
839 stream()->Add("["); | 846 stream()->Add("["); |
840 for (int i = 0; i < that->ranges()->length(); i++) { | 847 for (int i = 0; i < that->ranges(zone_)->length(); i++) { |
841 if (i > 0) stream()->Add(" "); | 848 if (i > 0) stream()->Add(" "); |
842 VisitCharacterRange(that->ranges()->at(i)); | 849 VisitCharacterRange(that->ranges(zone_)->at(i)); |
843 } | 850 } |
844 stream()->Add("]"); | 851 stream()->Add("]"); |
845 return NULL; | 852 return NULL; |
846 } | 853 } |
847 | 854 |
848 | 855 |
849 void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) { | 856 void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) { |
850 switch (that->type()) { | 857 switch (that->type()) { |
851 case RegExpAssertion::START_OF_INPUT: | 858 case RegExpAssertion::START_OF_INPUT: |
852 stream()->Add("@^i"); | 859 stream()->Add("@^i"); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 return NULL; | 941 return NULL; |
935 } | 942 } |
936 | 943 |
937 | 944 |
938 void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) { | 945 void* RegExpUnparser::VisitEmpty(RegExpEmpty* that, void* data) { |
939 stream()->Put('%'); | 946 stream()->Put('%'); |
940 return NULL; | 947 return NULL; |
941 } | 948 } |
942 | 949 |
943 | 950 |
944 SmartArrayPointer<const char> RegExpTree::ToString() { | 951 SmartArrayPointer<const char> RegExpTree::ToString(Zone* zone) { |
945 RegExpUnparser unparser; | 952 RegExpUnparser unparser(zone); |
946 Accept(&unparser, NULL); | 953 Accept(&unparser, NULL); |
947 return unparser.ToString(); | 954 return unparser.ToString(); |
948 } | 955 } |
949 | 956 |
950 | 957 |
951 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) | 958 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) |
952 : alternatives_(alternatives) { | 959 : alternatives_(alternatives) { |
953 ASSERT(alternatives->length() > 1); | 960 ASSERT(alternatives->length() > 1); |
954 RegExpTree* first_alternative = alternatives->at(0); | 961 RegExpTree* first_alternative = alternatives->at(0); |
955 min_match_ = first_alternative->min_match(); | 962 min_match_ = first_alternative->min_match(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1104 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); | 1111 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); |
1105 str = arr; | 1112 str = arr; |
1106 } else { | 1113 } else { |
1107 str = DoubleToCString(handle_->Number(), buffer); | 1114 str = DoubleToCString(handle_->Number(), buffer); |
1108 } | 1115 } |
1109 return FACTORY->NewStringFromAscii(CStrVector(str)); | 1116 return FACTORY->NewStringFromAscii(CStrVector(str)); |
1110 } | 1117 } |
1111 | 1118 |
1112 | 1119 |
1113 } } // namespace v8::internal | 1120 } } // namespace v8::internal |
OLD | NEW |