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

Side by Side Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 2201193004: Use Variable::binding_needs_init() to determine hole initialization (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove one more comment Created 4 years, 4 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
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/interpreter/bytecode-generator.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex); 712 __ CompareRoot(rbx, Heap::kWithContextMapRootIndex);
713 __ Check(not_equal, kDeclarationInWithContext); 713 __ Check(not_equal, kDeclarationInWithContext);
714 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex); 714 __ CompareRoot(rbx, Heap::kCatchContextMapRootIndex);
715 __ Check(not_equal, kDeclarationInCatchContext); 715 __ Check(not_equal, kDeclarationInCatchContext);
716 } 716 }
717 } 717 }
718 718
719 719
720 void FullCodeGenerator::VisitVariableDeclaration( 720 void FullCodeGenerator::VisitVariableDeclaration(
721 VariableDeclaration* declaration) { 721 VariableDeclaration* declaration) {
722 // If it was not possible to allocate the variable at compile time, we
723 // need to "declare" it at runtime to make sure it actually exists in the
724 // local context.
725 VariableProxy* proxy = declaration->proxy(); 722 VariableProxy* proxy = declaration->proxy();
726 VariableMode mode = declaration->mode();
727 Variable* variable = proxy->var(); 723 Variable* variable = proxy->var();
728 bool hole_init = mode == LET || mode == CONST;
729 switch (variable->location()) { 724 switch (variable->location()) {
730 case VariableLocation::GLOBAL: 725 case VariableLocation::GLOBAL:
731 case VariableLocation::UNALLOCATED: { 726 case VariableLocation::UNALLOCATED: {
732 DCHECK(!variable->binding_needs_init()); 727 DCHECK(!variable->binding_needs_init());
733 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); 728 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot();
734 DCHECK(!slot.IsInvalid()); 729 DCHECK(!slot.IsInvalid());
735 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); 730 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
736 globals_->Add(isolate()->factory()->undefined_value(), zone()); 731 globals_->Add(isolate()->factory()->undefined_value(), zone());
737 break; 732 break;
738 } 733 }
739 case VariableLocation::PARAMETER: 734 case VariableLocation::PARAMETER:
740 case VariableLocation::LOCAL: 735 case VariableLocation::LOCAL:
741 if (hole_init) { 736 if (variable->binding_needs_init()) {
742 Comment cmnt(masm_, "[ VariableDeclaration"); 737 Comment cmnt(masm_, "[ VariableDeclaration");
743 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); 738 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
744 __ movp(StackOperand(variable), kScratchRegister); 739 __ movp(StackOperand(variable), kScratchRegister);
745 } 740 }
746 break; 741 break;
747 742
748 case VariableLocation::CONTEXT: 743 case VariableLocation::CONTEXT:
749 if (hole_init) { 744 if (variable->binding_needs_init()) {
750 Comment cmnt(masm_, "[ VariableDeclaration"); 745 Comment cmnt(masm_, "[ VariableDeclaration");
751 EmitDebugCheckDeclarationContext(variable); 746 EmitDebugCheckDeclarationContext(variable);
752 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); 747 __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
753 __ movp(ContextOperand(rsi, variable->index()), kScratchRegister); 748 __ movp(ContextOperand(rsi, variable->index()), kScratchRegister);
754 // No write barrier since the hole value is in old space. 749 // No write barrier since the hole value is in old space.
755 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); 750 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
756 } 751 }
757 break; 752 break;
758 753
759 case VariableLocation::LOOKUP: { 754 case VariableLocation::LOOKUP: {
760 Comment cmnt(masm_, "[ VariableDeclaration"); 755 Comment cmnt(masm_, "[ VariableDeclaration");
761 DCHECK_EQ(VAR, mode); 756 DCHECK_EQ(VAR, variable->mode());
762 DCHECK(!hole_init); 757 DCHECK(!variable->binding_needs_init());
763 __ Push(variable->name()); 758 __ Push(variable->name());
764 __ CallRuntime(Runtime::kDeclareEvalVar); 759 __ CallRuntime(Runtime::kDeclareEvalVar);
765 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); 760 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS);
766 break; 761 break;
767 } 762 }
768 } 763 }
769 } 764 }
770 765
771 766
772 void FullCodeGenerator::VisitFunctionDeclaration( 767 void FullCodeGenerator::VisitFunctionDeclaration(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 // introducing variables. In those cases, we do not want to 1211 // introducing variables. In those cases, we do not want to
1217 // perform a runtime call for all variables in the scope 1212 // perform a runtime call for all variables in the scope
1218 // containing the eval. 1213 // containing the eval.
1219 Variable* var = proxy->var(); 1214 Variable* var = proxy->var();
1220 if (var->mode() == DYNAMIC_GLOBAL) { 1215 if (var->mode() == DYNAMIC_GLOBAL) {
1221 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); 1216 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow);
1222 __ jmp(done); 1217 __ jmp(done);
1223 } else if (var->mode() == DYNAMIC_LOCAL) { 1218 } else if (var->mode() == DYNAMIC_LOCAL) {
1224 Variable* local = var->local_if_not_shadowed(); 1219 Variable* local = var->local_if_not_shadowed();
1225 __ movp(rax, ContextSlotOperandCheckExtensions(local, slow)); 1220 __ movp(rax, ContextSlotOperandCheckExtensions(local, slow));
1226 if (local->mode() == LET || local->mode() == CONST) { 1221 if (local->binding_needs_init()) {
1227 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); 1222 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1228 __ j(not_equal, done); 1223 __ j(not_equal, done);
1229 __ Push(var->name()); 1224 __ Push(var->name());
1230 __ CallRuntime(Runtime::kThrowReferenceError); 1225 __ CallRuntime(Runtime::kThrowReferenceError);
1226 } else {
1227 __ jmp(done);
1231 } 1228 }
1232 __ jmp(done);
1233 } 1229 }
1234 } 1230 }
1235 1231
1236 1232
1237 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, 1233 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy,
1238 TypeofMode typeof_mode) { 1234 TypeofMode typeof_mode) {
1239 #ifdef DEBUG 1235 #ifdef DEBUG
1240 Variable* var = proxy->var(); 1236 Variable* var = proxy->var();
1241 DCHECK(var->IsUnallocatedOrGlobalSlot() || 1237 DCHECK(var->IsUnallocatedOrGlobalSlot() ||
1242 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL)); 1238 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL));
(...skipping 22 matching lines...) Expand all
1265 break; 1261 break;
1266 } 1262 }
1267 1263
1268 case VariableLocation::PARAMETER: 1264 case VariableLocation::PARAMETER:
1269 case VariableLocation::LOCAL: 1265 case VariableLocation::LOCAL:
1270 case VariableLocation::CONTEXT: { 1266 case VariableLocation::CONTEXT: {
1271 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); 1267 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
1272 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context slot" 1268 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context slot"
1273 : "[ Stack slot"); 1269 : "[ Stack slot");
1274 if (NeedsHoleCheckForLoad(proxy)) { 1270 if (NeedsHoleCheckForLoad(proxy)) {
1275 // Let and const need a read barrier. 1271 // Throw a reference error when using an uninitialized let/const
1272 // binding in harmony mode.
1273 DCHECK(IsLexicalVariableMode(var->mode()));
1276 Label done; 1274 Label done;
1277 GetVar(rax, var); 1275 GetVar(rax, var);
1278 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); 1276 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1279 __ j(not_equal, &done, Label::kNear); 1277 __ j(not_equal, &done, Label::kNear);
1280 if (var->mode() == LET || var->mode() == CONST) { 1278 __ Push(var->name());
1281 // Throw a reference error when using an uninitialized let/const 1279 __ CallRuntime(Runtime::kThrowReferenceError);
1282 // binding in harmony mode.
1283 __ Push(var->name());
1284 __ CallRuntime(Runtime::kThrowReferenceError);
1285 }
1286 __ bind(&done); 1280 __ bind(&done);
1287 context()->Plug(rax); 1281 context()->Plug(rax);
1288 break; 1282 break;
1289 } 1283 }
1290 context()->Plug(var); 1284 context()->Plug(var);
1291 break; 1285 break;
1292 } 1286 }
1293 1287
1294 case VariableLocation::LOOKUP: { 1288 case VariableLocation::LOOKUP: {
1295 Comment cmnt(masm_, "[ Lookup slot"); 1289 Comment cmnt(masm_, "[ Lookup slot");
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 2051
2058 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, 2052 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
2059 FeedbackVectorSlot slot) { 2053 FeedbackVectorSlot slot) {
2060 if (var->IsUnallocated()) { 2054 if (var->IsUnallocated()) {
2061 // Global var, const, or let. 2055 // Global var, const, or let.
2062 __ Move(StoreDescriptor::NameRegister(), var->name()); 2056 __ Move(StoreDescriptor::NameRegister(), var->name());
2063 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); 2057 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister());
2064 EmitLoadStoreICSlot(slot); 2058 EmitLoadStoreICSlot(slot);
2065 CallStoreIC(); 2059 CallStoreIC();
2066 2060
2067 } else if (var->mode() == LET && op != Token::INIT) { 2061 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) {
2068 // Non-initializing assignment to let variable needs a write barrier.
2069 DCHECK(!var->IsLookupSlot()); 2062 DCHECK(!var->IsLookupSlot());
2070 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2063 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2071 Label assign;
2072 MemOperand location = VarOperand(var, rcx); 2064 MemOperand location = VarOperand(var, rcx);
2073 __ movp(rdx, location); 2065 // Perform an initialization check for lexically declared variables.
2074 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); 2066 if (var->binding_needs_init()) {
2075 __ j(not_equal, &assign, Label::kNear); 2067 Label assign;
2076 __ Push(var->name()); 2068 __ movp(rdx, location);
2077 __ CallRuntime(Runtime::kThrowReferenceError); 2069 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2078 __ bind(&assign); 2070 __ j(not_equal, &assign, Label::kNear);
2079 EmitStoreToStackLocalOrContextSlot(var, location); 2071 __ Push(var->name());
2080 2072 __ CallRuntime(Runtime::kThrowReferenceError);
2081 } else if (var->mode() == CONST && op != Token::INIT) { 2073 __ bind(&assign);
2082 // Assignment to const variable needs a write barrier. 2074 }
2083 DCHECK(!var->IsLookupSlot()); 2075 if (var->mode() == CONST) {
2084 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2076 __ CallRuntime(Runtime::kThrowConstAssignError);
2085 Label const_error; 2077 } else {
2086 MemOperand location = VarOperand(var, rcx); 2078 EmitStoreToStackLocalOrContextSlot(var, location);
2087 __ movp(rdx, location); 2079 }
2088 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2089 __ j(not_equal, &const_error, Label::kNear);
2090 __ Push(var->name());
2091 __ CallRuntime(Runtime::kThrowReferenceError);
2092 __ bind(&const_error);
2093 __ CallRuntime(Runtime::kThrowConstAssignError);
2094 2080
2095 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { 2081 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) {
2096 // Initializing assignment to const {this} needs a write barrier. 2082 // Initializing assignment to const {this} needs a write barrier.
2097 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); 2083 DCHECK(var->IsStackAllocated() || var->IsContextSlot());
2098 Label uninitialized_this; 2084 Label uninitialized_this;
2099 MemOperand location = VarOperand(var, rcx); 2085 MemOperand location = VarOperand(var, rcx);
2100 __ movp(rdx, location); 2086 __ movp(rdx, location);
2101 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); 2087 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
2102 __ j(equal, &uninitialized_this); 2088 __ j(equal, &uninitialized_this);
2103 __ Push(var->name()); 2089 __ Push(var->name());
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after
3658 DCHECK_EQ( 3644 DCHECK_EQ(
3659 isolate->builtins()->OnStackReplacement()->entry(), 3645 isolate->builtins()->OnStackReplacement()->entry(),
3660 Assembler::target_address_at(call_target_address, unoptimized_code)); 3646 Assembler::target_address_at(call_target_address, unoptimized_code));
3661 return ON_STACK_REPLACEMENT; 3647 return ON_STACK_REPLACEMENT;
3662 } 3648 }
3663 3649
3664 } // namespace internal 3650 } // namespace internal
3665 } // namespace v8 3651 } // namespace v8
3666 3652
3667 #endif // V8_TARGET_ARCH_X64 3653 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/interpreter/bytecode-generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698