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

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

Issue 7535004: Merge bleeding edge up to 8774 into the GC branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/full-codegen.h ('k') | src/globals.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 430 }
431 431
432 432
433 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { 433 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
434 __ Move(result_register(), reg); 434 __ Move(result_register(), reg);
435 } 435 }
436 436
437 437
438 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { 438 void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
439 __ push(reg); 439 __ push(reg);
440 codegen()->increment_stack_height();
440 } 441 }
441 442
442 443
443 void FullCodeGenerator::TestContext::Plug(Register reg) const { 444 void FullCodeGenerator::TestContext::Plug(Register reg) const {
444 // For simplicity we always test the accumulator register. 445 // For simplicity we always test the accumulator register.
445 __ Move(result_register(), reg); 446 __ Move(result_register(), reg);
446 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); 447 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
447 codegen()->DoTest(this); 448 codegen()->DoTest(this);
448 } 449 }
449 450
450 451
451 void FullCodeGenerator::EffectContext::PlugTOS() const { 452 void FullCodeGenerator::EffectContext::PlugTOS() const {
452 __ Drop(1); 453 __ Drop(1);
454 codegen()->decrement_stack_height();
453 } 455 }
454 456
455 457
456 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { 458 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
457 __ pop(result_register()); 459 __ pop(result_register());
460 codegen()->decrement_stack_height();
458 } 461 }
459 462
460 463
461 void FullCodeGenerator::StackValueContext::PlugTOS() const { 464 void FullCodeGenerator::StackValueContext::PlugTOS() const {
462 } 465 }
463 466
464 467
465 void FullCodeGenerator::TestContext::PlugTOS() const { 468 void FullCodeGenerator::TestContext::PlugTOS() const {
466 // For simplicity we always test the accumulator register. 469 // For simplicity we always test the accumulator register.
467 __ pop(result_register()); 470 __ pop(result_register());
471 codegen()->decrement_stack_height();
468 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); 472 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
469 codegen()->DoTest(this); 473 codegen()->DoTest(this);
470 } 474 }
471 475
472 476
473 void FullCodeGenerator::EffectContext::PrepareTest( 477 void FullCodeGenerator::EffectContext::PrepareTest(
474 Label* materialize_true, 478 Label* materialize_true,
475 Label* materialize_false, 479 Label* materialize_false,
476 Label** if_true, 480 Label** if_true,
477 Label** if_false, 481 Label** if_false,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction); 683 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction);
680 ASSERT(lookup_index >= 0); 684 ASSERT(lookup_index >= 0);
681 ASSERT(static_cast<size_t>(lookup_index) < 685 ASSERT(static_cast<size_t>(lookup_index) <
682 ARRAY_SIZE(kInlineFunctionGenerators)); 686 ARRAY_SIZE(kInlineFunctionGenerators));
683 return kInlineFunctionGenerators[lookup_index]; 687 return kInlineFunctionGenerators[lookup_index];
684 } 688 }
685 689
686 690
687 void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) { 691 void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) {
688 ZoneList<Expression*>* args = node->arguments(); 692 ZoneList<Expression*>* args = node->arguments();
689 Handle<String> name = node->name();
690 const Runtime::Function* function = node->function(); 693 const Runtime::Function* function = node->function();
691 ASSERT(function != NULL); 694 ASSERT(function != NULL);
692 ASSERT(function->intrinsic_type == Runtime::INLINE); 695 ASSERT(function->intrinsic_type == Runtime::INLINE);
693 InlineFunctionGenerator generator = 696 InlineFunctionGenerator generator =
694 FindInlineFunctionGenerator(function->function_id); 697 FindInlineFunctionGenerator(function->function_id);
695 ((*this).*(generator))(args); 698 ((*this).*(generator))(args);
696 } 699 }
697 700
698 701
699 void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { 702 void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 957
955 958
956 void FullCodeGenerator::VisitEnterWithContextStatement( 959 void FullCodeGenerator::VisitEnterWithContextStatement(
957 EnterWithContextStatement* stmt) { 960 EnterWithContextStatement* stmt) {
958 Comment cmnt(masm_, "[ EnterWithContextStatement"); 961 Comment cmnt(masm_, "[ EnterWithContextStatement");
959 SetStatementPosition(stmt); 962 SetStatementPosition(stmt);
960 963
961 VisitForStackValue(stmt->expression()); 964 VisitForStackValue(stmt->expression());
962 PushFunctionArgumentForContextAllocation(); 965 PushFunctionArgumentForContextAllocation();
963 __ CallRuntime(Runtime::kPushWithContext, 2); 966 __ CallRuntime(Runtime::kPushWithContext, 2);
967 decrement_stack_height();
964 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); 968 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
965 } 969 }
966 970
967 971
968 void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) { 972 void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) {
969 Comment cmnt(masm_, "[ ExitContextStatement"); 973 Comment cmnt(masm_, "[ ExitContextStatement");
970 SetStatementPosition(stmt); 974 SetStatementPosition(stmt);
971 975
972 // Pop context. 976 // Pop context.
973 LoadContextField(context_register(), Context::PREVIOUS_INDEX); 977 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 ASSERT(scope_->declarations()->is_empty()); 1126 ASSERT(scope_->declarations()->is_empty());
1123 Visit(stmt->catch_block()); 1127 Visit(stmt->catch_block());
1124 scope_ = saved_scope; 1128 scope_ = saved_scope;
1125 __ jmp(&done); 1129 __ jmp(&done);
1126 1130
1127 // Try block code. Sets up the exception handler chain. 1131 // Try block code. Sets up the exception handler chain.
1128 __ bind(&try_handler_setup); 1132 __ bind(&try_handler_setup);
1129 { 1133 {
1130 TryCatch try_block(this, &catch_entry); 1134 TryCatch try_block(this, &catch_entry);
1131 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); 1135 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER);
1136 increment_stack_height(StackHandlerConstants::kSize / kPointerSize);
1132 Visit(stmt->try_block()); 1137 Visit(stmt->try_block());
1133 __ PopTryHandler(); 1138 __ PopTryHandler();
1139 decrement_stack_height(StackHandlerConstants::kSize / kPointerSize);
1134 } 1140 }
1135 __ bind(&done); 1141 __ bind(&done);
1136 } 1142 }
1137 1143
1138 1144
1139 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { 1145 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1140 Comment cmnt(masm_, "[ TryFinallyStatement"); 1146 Comment cmnt(masm_, "[ TryFinallyStatement");
1141 SetStatementPosition(stmt); 1147 SetStatementPosition(stmt);
1142 // Try finally is compiled by setting up a try-handler on the stack while 1148 // Try finally is compiled by setting up a try-handler on the stack while
1143 // executing the try body, and removing it again afterwards. 1149 // executing the try body, and removing it again afterwards.
(...skipping 11 matching lines...) Expand all
1155 // handler code. The handler code then calls the finally-block before 1161 // handler code. The handler code then calls the finally-block before
1156 // rethrowing the exception. 1162 // rethrowing the exception.
1157 // 1163 //
1158 // The finally block must assume a return address on top of the stack 1164 // The finally block must assume a return address on top of the stack
1159 // (or in the link register on ARM chips) and a value (return value or 1165 // (or in the link register on ARM chips) and a value (return value or
1160 // exception) in the result register (rax/eax/r0), both of which must 1166 // exception) in the result register (rax/eax/r0), both of which must
1161 // be preserved. The return address isn't GC-safe, so it should be 1167 // be preserved. The return address isn't GC-safe, so it should be
1162 // cooked before GC. 1168 // cooked before GC.
1163 Label finally_entry; 1169 Label finally_entry;
1164 Label try_handler_setup; 1170 Label try_handler_setup;
1171 const int original_stack_height = stack_height();
1172 const int finally_block_stack_height = original_stack_height + 2;
1173 const int try_block_stack_height = original_stack_height + 4;
1174 STATIC_ASSERT(StackHandlerConstants::kSize / kPointerSize == 4);
1165 1175
1166 // Setup the try-handler chain. Use a call to 1176 // Setup the try-handler chain. Use a call to
1167 // Jump to try-handler setup and try-block code. Use call to put try-handler 1177 // Jump to try-handler setup and try-block code. Use call to put try-handler
1168 // address on stack. 1178 // address on stack.
1169 __ Call(&try_handler_setup); 1179 __ Call(&try_handler_setup);
1170 // Try handler code. Return address of call is pushed on handler stack. 1180 // Try handler code. Return address of call is pushed on handler stack.
1171 { 1181 {
1172 // This code is only executed during stack-handler traversal when an 1182 // This code is only executed during stack-handler traversal when an
1173 // exception is thrown. The execption is in the result register, which 1183 // exception is thrown. The execption is in the result register, which
1174 // is retained by the finally block. 1184 // is retained by the finally block.
1175 // Call the finally block and then rethrow the exception. 1185 // Call the finally block and then rethrow the exception.
1176 __ Call(&finally_entry); 1186 __ Call(&finally_entry);
1177 __ push(result_register()); 1187 __ push(result_register());
1178 __ CallRuntime(Runtime::kReThrow, 1); 1188 __ CallRuntime(Runtime::kReThrow, 1);
1179 } 1189 }
1180 1190
1181 __ bind(&finally_entry); 1191 __ bind(&finally_entry);
1182 { 1192 {
1183 // Finally block implementation. 1193 // Finally block implementation.
1184 Finally finally_block(this); 1194 Finally finally_block(this);
1185 EnterFinallyBlock(); 1195 EnterFinallyBlock();
1196 set_stack_height(finally_block_stack_height);
1186 Visit(stmt->finally_block()); 1197 Visit(stmt->finally_block());
1187 ExitFinallyBlock(); // Return to the calling code. 1198 ExitFinallyBlock(); // Return to the calling code.
1188 } 1199 }
1189 1200
1190 __ bind(&try_handler_setup); 1201 __ bind(&try_handler_setup);
1191 { 1202 {
1192 // Setup try handler (stack pointer registers). 1203 // Setup try handler (stack pointer registers).
1193 TryFinally try_block(this, &finally_entry); 1204 TryFinally try_block(this, &finally_entry);
1194 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); 1205 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER);
1206 set_stack_height(try_block_stack_height);
1195 Visit(stmt->try_block()); 1207 Visit(stmt->try_block());
1196 __ PopTryHandler(); 1208 __ PopTryHandler();
1209 set_stack_height(original_stack_height);
1197 } 1210 }
1198 // Execute the finally block on the way out. Clobber the unpredictable 1211 // Execute the finally block on the way out. Clobber the unpredictable
1199 // value in the accumulator with one that's safe for GC. The finally 1212 // value in the accumulator with one that's safe for GC. The finally
1200 // block will unconditionally preserve the accumulator on the stack. 1213 // block will unconditionally preserve the accumulator on the stack.
1201 ClearAccumulator(); 1214 ClearAccumulator();
1202 __ Call(&finally_entry); 1215 __ Call(&finally_entry);
1203 } 1216 }
1204 1217
1205 1218
1206 void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { 1219 void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1207 #ifdef ENABLE_DEBUGGER_SUPPORT 1220 #ifdef ENABLE_DEBUGGER_SUPPORT
1208 Comment cmnt(masm_, "[ DebuggerStatement"); 1221 Comment cmnt(masm_, "[ DebuggerStatement");
1209 SetStatementPosition(stmt); 1222 SetStatementPosition(stmt);
1210 1223
1211 __ DebugBreak(); 1224 __ DebugBreak();
1212 // Ignore the return value. 1225 // Ignore the return value.
1213 #endif 1226 #endif
1214 } 1227 }
1215 1228
1216 1229
1217 void FullCodeGenerator::VisitConditional(Conditional* expr) { 1230 void FullCodeGenerator::VisitConditional(Conditional* expr) {
1218 Comment cmnt(masm_, "[ Conditional"); 1231 Comment cmnt(masm_, "[ Conditional");
1219 Label true_case, false_case, done; 1232 Label true_case, false_case, done;
1220 VisitForControl(expr->condition(), &true_case, &false_case, &true_case); 1233 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
1221 1234
1222 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); 1235 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS);
1223 __ bind(&true_case); 1236 __ bind(&true_case);
1224 SetExpressionPosition(expr->then_expression(), 1237 SetExpressionPosition(expr->then_expression(),
1225 expr->then_expression_position()); 1238 expr->then_expression_position());
1239 int start_stack_height = stack_height();
1226 if (context()->IsTest()) { 1240 if (context()->IsTest()) {
1227 const TestContext* for_test = TestContext::cast(context()); 1241 const TestContext* for_test = TestContext::cast(context());
1228 VisitForControl(expr->then_expression(), 1242 VisitForControl(expr->then_expression(),
1229 for_test->true_label(), 1243 for_test->true_label(),
1230 for_test->false_label(), 1244 for_test->false_label(),
1231 NULL); 1245 NULL);
1232 } else { 1246 } else {
1233 VisitInCurrentContext(expr->then_expression()); 1247 VisitInCurrentContext(expr->then_expression());
1234 __ jmp(&done); 1248 __ jmp(&done);
1235 } 1249 }
1236 1250
1237 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); 1251 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS);
1238 __ bind(&false_case); 1252 __ bind(&false_case);
1253 set_stack_height(start_stack_height);
1239 if (context()->IsTest()) ForwardBailoutToChild(expr); 1254 if (context()->IsTest()) ForwardBailoutToChild(expr);
1240 SetExpressionPosition(expr->else_expression(), 1255 SetExpressionPosition(expr->else_expression(),
1241 expr->else_expression_position()); 1256 expr->else_expression_position());
1242 VisitInCurrentContext(expr->else_expression()); 1257 VisitInCurrentContext(expr->else_expression());
1243 // If control flow falls through Visit, merge it with true case here. 1258 // If control flow falls through Visit, merge it with true case here.
1244 if (!context()->IsTest()) { 1259 if (!context()->IsTest()) {
1245 __ bind(&done); 1260 __ bind(&done);
1246 } 1261 }
1247 } 1262 }
1248 1263
(...skipping 20 matching lines...) Expand all
1269 1284
1270 void FullCodeGenerator::VisitSharedFunctionInfoLiteral( 1285 void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
1271 SharedFunctionInfoLiteral* expr) { 1286 SharedFunctionInfoLiteral* expr) {
1272 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); 1287 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
1273 EmitNewClosure(expr->shared_function_info(), false); 1288 EmitNewClosure(expr->shared_function_info(), false);
1274 } 1289 }
1275 1290
1276 1291
1277 void FullCodeGenerator::VisitThrow(Throw* expr) { 1292 void FullCodeGenerator::VisitThrow(Throw* expr) {
1278 Comment cmnt(masm_, "[ Throw"); 1293 Comment cmnt(masm_, "[ Throw");
1294 // Throw has no effect on the stack height or the current expression context.
1295 // Usually the expression context is null, because throw is a statement.
1279 VisitForStackValue(expr->exception()); 1296 VisitForStackValue(expr->exception());
1280 __ CallRuntime(Runtime::kThrow, 1); 1297 __ CallRuntime(Runtime::kThrow, 1);
1298 decrement_stack_height();
1281 // Never returns here. 1299 // Never returns here.
1282 } 1300 }
1283 1301
1284 1302
1285 int FullCodeGenerator::TryFinally::Exit(int stack_depth) { 1303 int FullCodeGenerator::TryFinally::Exit(int stack_depth) {
1286 // The macros used here must preserve the result register. 1304 // The macros used here must preserve the result register.
1287 __ Drop(stack_depth); 1305 __ Drop(stack_depth);
1288 __ PopTryHandler(); 1306 __ PopTryHandler();
1289 __ Call(finally_entry_); 1307 __ Call(finally_entry_);
1290 return 0; 1308 return 0;
(...skipping 25 matching lines...) Expand all
1316 } 1334 }
1317 1335
1318 return false; 1336 return false;
1319 } 1337 }
1320 1338
1321 1339
1322 #undef __ 1340 #undef __
1323 1341
1324 1342
1325 } } // namespace v8::internal 1343 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698