Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: src/ast.cc

Issue 6597029: [Isolates] Merge r 6300:6500 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ast.h ('k') | src/builtins.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "ast.h" 30 #include "ast.h"
31 #include "jump-target-inl.h" 31 #include "jump-target-inl.h"
32 #include "parser.h" 32 #include "parser.h"
33 #include "scopes.h" 33 #include "scopes.h"
34 #include "string-stream.h" 34 #include "string-stream.h"
35 #include "stub-cache.h"
36 35
37 namespace v8 { 36 namespace v8 {
38 namespace internal { 37 namespace internal {
39 38
40 AstSentinels::AstSentinels() 39 AstSentinels::AstSentinels()
41 : this_proxy_(true), 40 : this_proxy_(true),
42 identifier_proxy_(false), 41 identifier_proxy_(false),
43 valid_left_hand_side_sentinel_(), 42 valid_left_hand_side_sentinel_(),
44 this_property_(&this_proxy_, NULL, 0), 43 this_property_(&this_proxy_, NULL, 0),
45 call_sentinel_(NULL, NULL, 0) { 44 call_sentinel_(NULL, NULL, 0) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 158 }
160 return Token::ILLEGAL; 159 return Token::ILLEGAL;
161 } 160 }
162 161
163 162
164 bool FunctionLiteral::AllowsLazyCompilation() { 163 bool FunctionLiteral::AllowsLazyCompilation() {
165 return scope()->AllowsLazyCompilation(); 164 return scope()->AllowsLazyCompilation();
166 } 165 }
167 166
168 167
169 bool FunctionLiteral::AllowOptimize() {
170 // We can't deal with heap-allocated locals.
171 return scope()->num_heap_slots() == 0;
172 }
173
174
175 ObjectLiteral::Property::Property(Literal* key, Expression* value) { 168 ObjectLiteral::Property::Property(Literal* key, Expression* value) {
176 emit_store_ = true; 169 emit_store_ = true;
177 key_ = key; 170 key_ = key;
178 value_ = value; 171 value_ = value;
179 Object* k = *key->handle(); 172 Object* k = *key->handle();
180 if (k->IsSymbol() && HEAP->Proto_symbol()->Equals(String::cast(k))) { 173 if (k->IsSymbol() && HEAP->Proto_symbol()->Equals(String::cast(k))) {
181 kind_ = PROTOTYPE; 174 kind_ = PROTOTYPE;
182 } else if (value_->AsMaterializedLiteral() != NULL) { 175 } else if (value_->AsMaterializedLiteral() != NULL) {
183 kind_ = MATERIALIZED_LITERAL; 176 kind_ = MATERIALIZED_LITERAL;
184 } else if (value_->AsLiteral() != NULL) { 177 } else if (value_->AsLiteral() != NULL) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 Handle<Object> handle = literal->handle(); 232 Handle<Object> handle = literal->handle();
240 233
241 if (handle->IsNull()) { 234 if (handle->IsNull()) {
242 continue; 235 continue;
243 } 236 }
244 237
245 uint32_t hash; 238 uint32_t hash;
246 HashMap* table; 239 HashMap* table;
247 void* key; 240 void* key;
248 uint32_t index; 241 uint32_t index;
242 Smi* smi_key_location;
249 if (handle->IsSymbol()) { 243 if (handle->IsSymbol()) {
250 Handle<String> name(String::cast(*handle)); 244 Handle<String> name(String::cast(*handle));
251 ASSERT(!name->AsArrayIndex(&index)); 245 if (name->AsArrayIndex(&index)) {
252 key = name.location(); 246 smi_key_location = Smi::FromInt(index);
253 hash = name->Hash(); 247 key = &smi_key_location;
254 table = &properties; 248 hash = index;
249 table = &elements;
250 } else {
251 key = name.location();
252 hash = name->Hash();
253 table = &properties;
254 }
255 } else if (handle->ToArrayIndex(&index)) { 255 } else if (handle->ToArrayIndex(&index)) {
256 key = handle.location(); 256 key = handle.location();
257 hash = index; 257 hash = index;
258 table = &elements; 258 table = &elements;
259 } else { 259 } else {
260 ASSERT(handle->IsNumber()); 260 ASSERT(handle->IsNumber());
261 double num = handle->Number(); 261 double num = handle->Number();
262 char arr[100]; 262 char arr[100];
263 Vector<char> buffer(arr, ARRAY_SIZE(arr)); 263 Vector<char> buffer(arr, ARRAY_SIZE(arr));
264 const char* str = DoubleToCString(num, buffer); 264 const char* str = DoubleToCString(num, buffer);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 514
515 // ---------------------------------------------------------------------------- 515 // ----------------------------------------------------------------------------
516 // Recording of type feedback 516 // Recording of type feedback
517 517
518 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { 518 void Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
519 // Record type feedback from the oracle in the AST. 519 // Record type feedback from the oracle in the AST.
520 is_monomorphic_ = oracle->LoadIsMonomorphic(this); 520 is_monomorphic_ = oracle->LoadIsMonomorphic(this);
521 if (key()->IsPropertyName()) { 521 if (key()->IsPropertyName()) {
522 if (oracle->LoadIsBuiltin(this, Builtins::LoadIC_ArrayLength)) { 522 if (oracle->LoadIsBuiltin(this, Builtins::LoadIC_ArrayLength)) {
523 is_array_length_ = true; 523 is_array_length_ = true;
524 } else if (oracle->LoadIsBuiltin(this, Builtins::LoadIC_StringLength)) {
525 is_string_length_ = true;
524 } else if (oracle->LoadIsBuiltin(this, 526 } else if (oracle->LoadIsBuiltin(this,
525 Builtins::LoadIC_FunctionPrototype)) { 527 Builtins::LoadIC_FunctionPrototype)) {
526 is_function_prototype_ = true; 528 is_function_prototype_ = true;
527 } else { 529 } else {
528 Literal* lit_key = key()->AsLiteral(); 530 Literal* lit_key = key()->AsLiteral();
529 ASSERT(lit_key != NULL && lit_key->handle()->IsString()); 531 ASSERT(lit_key != NULL && lit_key->handle()->IsString());
530 Handle<String> name = Handle<String>::cast(lit_key->handle()); 532 Handle<String> name = Handle<String>::cast(lit_key->handle());
531 ZoneMapList* types = oracle->LoadReceiverTypes(this, name); 533 ZoneMapList* types = oracle->LoadReceiverTypes(this, name);
532 receiver_types_ = types; 534 receiver_types_ = types;
533 } 535 }
(...skipping 25 matching lines...) Expand all
559 if (info.IsSmi()) { 561 if (info.IsSmi()) {
560 compare_type_ = SMI_ONLY; 562 compare_type_ = SMI_ONLY;
561 } else if (info.IsNonPrimitive()) { 563 } else if (info.IsNonPrimitive()) {
562 compare_type_ = OBJECT_ONLY; 564 compare_type_ = OBJECT_ONLY;
563 } else { 565 } else {
564 ASSERT(compare_type_ == NONE); 566 ASSERT(compare_type_ == NONE);
565 } 567 }
566 } 568 }
567 569
568 570
569 static bool CallWithoutIC(Handle<JSFunction> target, int arity) { 571 static bool CanCallWithoutIC(Handle<JSFunction> target, int arity) {
570 SharedFunctionInfo* info = target->shared(); 572 SharedFunctionInfo* info = target->shared();
571 if (target->NeedsArgumentsAdaption()) { 573 // If the number of formal parameters of the target function does
572 // If the number of formal parameters of the target function 574 // not match the number of arguments we're passing, we don't want to
573 // does not match the number of arguments we're passing, we 575 // deal with it. Otherwise, we can call it directly.
574 // don't want to deal with it. 576 return !target->NeedsArgumentsAdaption() ||
575 return info->formal_parameter_count() == arity; 577 info->formal_parameter_count() == arity;
576 } else {
577 // If the target doesn't need arguments adaption, we can call
578 // it directly, but we avoid to do so if it has a custom call
579 // generator, because that is likely to generate better code.
580 return !info->HasBuiltinFunctionId() ||
581 !CallStubCompiler::HasCustomCallGenerator(info->builtin_function_id());
582 }
583 } 578 }
584 579
585 580
586 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) { 581 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) {
587 holder_ = Handle<JSObject>::null(); 582 if (check_type_ == RECEIVER_MAP_CHECK) {
583 // For primitive checks the holder is set up to point to the
584 // corresponding prototype object, i.e. one step of the algorithm
585 // below has been already performed.
586 // For non-primitive checks we clear it to allow computing targets
587 // for polymorphic calls.
588 holder_ = Handle<JSObject>::null();
589 }
588 while (true) { 590 while (true) {
589 LookupResult lookup; 591 LookupResult lookup;
590 type->LookupInDescriptors(NULL, *name, &lookup); 592 type->LookupInDescriptors(NULL, *name, &lookup);
591 // If the function wasn't found directly in the map, we start 593 // If the function wasn't found directly in the map, we start
592 // looking upwards through the prototype chain. 594 // looking upwards through the prototype chain.
593 if (!lookup.IsFound() && type->prototype()->IsJSObject()) { 595 if (!lookup.IsFound() && type->prototype()->IsJSObject()) {
594 holder_ = Handle<JSObject>(JSObject::cast(type->prototype())); 596 holder_ = Handle<JSObject>(JSObject::cast(type->prototype()));
595 type = Handle<Map>(holder()->map()); 597 type = Handle<Map>(holder()->map());
596 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) { 598 } else if (lookup.IsProperty() && lookup.type() == CONSTANT_FUNCTION) {
597 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type)); 599 target_ = Handle<JSFunction>(lookup.GetConstantFunctionFromMap(*type));
598 return CallWithoutIC(target_, arguments()->length()); 600 return CanCallWithoutIC(target_, arguments()->length());
599 } else { 601 } else {
600 return false; 602 return false;
601 } 603 }
602 } 604 }
603 } 605 }
604 606
605 607
606 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global, 608 bool Call::ComputeGlobalTarget(Handle<GlobalObject> global,
607 Handle<String> name) { 609 Handle<String> name) {
608 target_ = Handle<JSFunction>::null(); 610 target_ = Handle<JSFunction>::null();
609 cell_ = Handle<JSGlobalPropertyCell>::null(); 611 cell_ = Handle<JSGlobalPropertyCell>::null();
610 LookupResult lookup; 612 LookupResult lookup;
611 global->Lookup(*name, &lookup); 613 global->Lookup(*name, &lookup);
612 if (lookup.IsProperty() && lookup.type() == NORMAL) { 614 if (lookup.IsProperty() && lookup.type() == NORMAL) {
613 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup)); 615 cell_ = Handle<JSGlobalPropertyCell>(global->GetPropertyCell(&lookup));
614 if (cell_->value()->IsJSFunction()) { 616 if (cell_->value()->IsJSFunction()) {
615 Handle<JSFunction> candidate(JSFunction::cast(cell_->value())); 617 Handle<JSFunction> candidate(JSFunction::cast(cell_->value()));
616 // If the function is in new space we assume it's more likely to 618 // If the function is in new space we assume it's more likely to
617 // change and thus prefer the general IC code. 619 // change and thus prefer the general IC code.
618 if (!Isolate::Current()->heap()->InNewSpace(*candidate) 620 if (!HEAP->InNewSpace(*candidate) &&
619 && CallWithoutIC(candidate, arguments()->length())) { 621 CanCallWithoutIC(candidate, arguments()->length())) {
620 target_ = candidate; 622 target_ = candidate;
621 return true; 623 return true;
622 } 624 }
623 } 625 }
624 } 626 }
625 return false; 627 return false;
626 } 628 }
627 629
628 630
629 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) { 631 void Call::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
(...skipping 17 matching lines...) Expand all
647 #endif 649 #endif
648 is_monomorphic_ = oracle->CallIsMonomorphic(this); 650 is_monomorphic_ = oracle->CallIsMonomorphic(this);
649 check_type_ = oracle->GetCallCheckType(this); 651 check_type_ = oracle->GetCallCheckType(this);
650 if (is_monomorphic_) { 652 if (is_monomorphic_) {
651 Handle<Map> map; 653 Handle<Map> map;
652 if (receiver_types_ != NULL && receiver_types_->length() > 0) { 654 if (receiver_types_ != NULL && receiver_types_->length() > 0) {
653 ASSERT(check_type_ == RECEIVER_MAP_CHECK); 655 ASSERT(check_type_ == RECEIVER_MAP_CHECK);
654 map = receiver_types_->at(0); 656 map = receiver_types_->at(0);
655 } else { 657 } else {
656 ASSERT(check_type_ != RECEIVER_MAP_CHECK); 658 ASSERT(check_type_ != RECEIVER_MAP_CHECK);
657 map = Handle<Map>( 659 holder_ = Handle<JSObject>(
658 oracle->GetPrototypeForPrimitiveCheck(check_type_)->map()); 660 oracle->GetPrototypeForPrimitiveCheck(check_type_));
661 map = Handle<Map>(holder_->map());
659 } 662 }
660 is_monomorphic_ = ComputeTarget(map, name); 663 is_monomorphic_ = ComputeTarget(map, name);
661 } 664 }
662 } 665 }
663 666
664 667
665 void BinaryOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) { 668 void BinaryOperation::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
666 TypeInfo left = oracle->BinaryType(this, TypeFeedbackOracle::LEFT); 669 TypeInfo left = oracle->BinaryType(this, TypeFeedbackOracle::LEFT);
667 TypeInfo right = oracle->BinaryType(this, TypeFeedbackOracle::RIGHT); 670 TypeInfo right = oracle->BinaryType(this, TypeFeedbackOracle::RIGHT);
668 is_smi_only_ = left.IsSmi() && right.IsSmi(); 671 is_smi_only_ = left.IsSmi() && right.IsSmi();
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 1057
1055 CaseClause::CaseClause(Expression* label, 1058 CaseClause::CaseClause(Expression* label,
1056 ZoneList<Statement*>* statements, 1059 ZoneList<Statement*>* statements,
1057 int pos) 1060 int pos)
1058 : label_(label), 1061 : label_(label),
1059 statements_(statements), 1062 statements_(statements),
1060 position_(pos), 1063 position_(pos),
1061 compare_type_(NONE) {} 1064 compare_type_(NONE) {}
1062 1065
1063 } } // namespace v8::internal 1066 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698