OLD | NEW |
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 #include "src/full-codegen/full-codegen.h" | 5 #include "src/full-codegen/full-codegen.h" |
6 | 6 |
7 #include "src/ast/ast-numbering.h" | 7 #include "src/ast/ast-numbering.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/prettyprinter.h" | 9 #include "src/ast/prettyprinter.h" |
10 #include "src/ast/scopeinfo.h" | 10 #include "src/ast/scopeinfo.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 code->set_type_feedback_info(*info); | 118 code->set_type_feedback_info(*info); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) { | 122 void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) { |
123 int handler_table_size = static_cast<int>(handler_table_.size()); | 123 int handler_table_size = static_cast<int>(handler_table_.size()); |
124 Handle<HandlerTable> table = | 124 Handle<HandlerTable> table = |
125 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( | 125 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( |
126 HandlerTable::LengthForRange(handler_table_size), TENURED)); | 126 HandlerTable::LengthForRange(handler_table_size), TENURED)); |
127 for (int i = 0; i < handler_table_size; ++i) { | 127 for (int i = 0; i < handler_table_size; ++i) { |
128 HandlerTable::CatchPrediction prediction = handler_table_[i].catch_predicted | |
129 ? HandlerTable::CAUGHT | |
130 : HandlerTable::UNCAUGHT; | |
131 table->SetRangeStart(i, handler_table_[i].range_start); | 128 table->SetRangeStart(i, handler_table_[i].range_start); |
132 table->SetRangeEnd(i, handler_table_[i].range_end); | 129 table->SetRangeEnd(i, handler_table_[i].range_end); |
133 table->SetRangeHandler(i, handler_table_[i].handler_offset, prediction); | 130 table->SetRangeHandler(i, handler_table_[i].handler_offset, |
| 131 handler_table_[i].catch_prediction); |
134 table->SetRangeData(i, handler_table_[i].stack_depth); | 132 table->SetRangeData(i, handler_table_[i].stack_depth); |
135 } | 133 } |
136 code->set_handler_table(*table); | 134 code->set_handler_table(*table); |
137 } | 135 } |
138 | 136 |
139 | 137 |
140 int FullCodeGenerator::NewHandlerTableEntry() { | 138 int FullCodeGenerator::NewHandlerTableEntry() { |
141 int index = static_cast<int>(handler_table_.size()); | 139 int index = static_cast<int>(handler_table_.size()); |
142 HandlerTableEntry entry = {0, 0, 0, 0, 0}; | 140 HandlerTableEntry entry = {0, 0, 0, 0, HandlerTable::UNCAUGHT}; |
143 handler_table_.push_back(entry); | 141 handler_table_.push_back(entry); |
144 return index; | 142 return index; |
145 } | 143 } |
146 | 144 |
147 | 145 |
148 bool FullCodeGenerator::MustCreateObjectLiteralWithRuntime( | 146 bool FullCodeGenerator::MustCreateObjectLiteralWithRuntime( |
149 ObjectLiteral* expr) const { | 147 ObjectLiteral* expr) const { |
150 return masm()->serializer_enabled() || | 148 return masm()->serializer_enabled() || |
151 !FastCloneShallowObjectStub::IsSupported(expr); | 149 !FastCloneShallowObjectStub::IsSupported(expr); |
152 } | 150 } |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 // Restore the context. | 1286 // Restore the context. |
1289 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 1287 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
1290 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 1288 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
1291 scope_ = saved_scope; | 1289 scope_ = saved_scope; |
1292 __ jmp(&exit); | 1290 __ jmp(&exit); |
1293 | 1291 |
1294 // Try block code. Sets up the exception handler chain. | 1292 // Try block code. Sets up the exception handler chain. |
1295 __ bind(&try_entry); | 1293 __ bind(&try_entry); |
1296 | 1294 |
1297 int handler_index = NewHandlerTableEntry(); | 1295 int handler_index = NewHandlerTableEntry(); |
1298 EnterTryBlock(handler_index, &handler_entry, stmt->catch_predicted()); | 1296 EnterTryBlock(handler_index, &handler_entry, stmt->catch_prediction()); |
1299 { | 1297 { |
1300 Comment cmnt_try(masm(), "[ Try block"); | 1298 Comment cmnt_try(masm(), "[ Try block"); |
1301 Visit(stmt->try_block()); | 1299 Visit(stmt->try_block()); |
1302 } | 1300 } |
1303 ExitTryBlock(handler_index); | 1301 ExitTryBlock(handler_index); |
1304 __ bind(&exit); | 1302 __ bind(&exit); |
1305 } | 1303 } |
1306 | 1304 |
1307 | 1305 |
1308 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 1306 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
(...skipping 28 matching lines...) Expand all Loading... |
1337 // Exception handler code. This code is only executed when an exception | 1335 // Exception handler code. This code is only executed when an exception |
1338 // is thrown. Record the continuation and jump to the finally block. | 1336 // is thrown. Record the continuation and jump to the finally block. |
1339 { | 1337 { |
1340 Comment cmnt_handler(masm(), "[ Finally handler"); | 1338 Comment cmnt_handler(masm(), "[ Finally handler"); |
1341 deferred.RecordThrow(); | 1339 deferred.RecordThrow(); |
1342 } | 1340 } |
1343 | 1341 |
1344 // Set up try handler. | 1342 // Set up try handler. |
1345 __ bind(&try_entry); | 1343 __ bind(&try_entry); |
1346 int handler_index = NewHandlerTableEntry(); | 1344 int handler_index = NewHandlerTableEntry(); |
1347 EnterTryBlock(handler_index, &handler_entry, stmt->catch_predicted()); | 1345 EnterTryBlock(handler_index, &handler_entry, stmt->catch_prediction()); |
1348 { | 1346 { |
1349 Comment cmnt_try(masm(), "[ Try block"); | 1347 Comment cmnt_try(masm(), "[ Try block"); |
1350 TryFinally try_body(this, &deferred); | 1348 TryFinally try_body(this, &deferred); |
1351 Visit(stmt->try_block()); | 1349 Visit(stmt->try_block()); |
1352 } | 1350 } |
1353 ExitTryBlock(handler_index); | 1351 ExitTryBlock(handler_index); |
1354 // Execute the finally block on the way out. Clobber the unpredictable | 1352 // Execute the finally block on the way out. Clobber the unpredictable |
1355 // value in the result register with one that's safe for GC because the | 1353 // value in the result register with one that's safe for GC because the |
1356 // finally block will unconditionally preserve the result register on the | 1354 // finally block will unconditionally preserve the result register on the |
1357 // stack. | 1355 // stack. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 VisitForStackValue(expr->exception()); | 1518 VisitForStackValue(expr->exception()); |
1521 SetExpressionPosition(expr); | 1519 SetExpressionPosition(expr); |
1522 CallRuntimeWithOperands(Runtime::kThrow); | 1520 CallRuntimeWithOperands(Runtime::kThrow); |
1523 // Never returns here. | 1521 // Never returns here. |
1524 | 1522 |
1525 // Even though this expression doesn't produce a value, we need to simulate | 1523 // Even though this expression doesn't produce a value, we need to simulate |
1526 // plugging of the value context to ensure stack depth tracking is in sync. | 1524 // plugging of the value context to ensure stack depth tracking is in sync. |
1527 if (context()->IsStackValue()) OperandStackDepthIncrement(1); | 1525 if (context()->IsStackValue()) OperandStackDepthIncrement(1); |
1528 } | 1526 } |
1529 | 1527 |
1530 void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler, | 1528 void FullCodeGenerator::EnterTryBlock( |
1531 bool catch_predicted) { | 1529 int handler_index, Label* handler, |
| 1530 HandlerTable::CatchPrediction catch_prediction) { |
1532 HandlerTableEntry* entry = &handler_table_[handler_index]; | 1531 HandlerTableEntry* entry = &handler_table_[handler_index]; |
1533 entry->range_start = masm()->pc_offset(); | 1532 entry->range_start = masm()->pc_offset(); |
1534 entry->handler_offset = handler->pos(); | 1533 entry->handler_offset = handler->pos(); |
1535 entry->stack_depth = operand_stack_depth_; | 1534 entry->stack_depth = operand_stack_depth_; |
1536 entry->catch_predicted = catch_predicted; | 1535 entry->catch_prediction = catch_prediction; |
1537 | 1536 |
1538 // We are using the operand stack depth, check for accuracy. | 1537 // We are using the operand stack depth, check for accuracy. |
1539 EmitOperandStackDepthCheck(); | 1538 EmitOperandStackDepthCheck(); |
1540 | 1539 |
1541 // Push context onto operand stack. | 1540 // Push context onto operand stack. |
1542 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); | 1541 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); |
1543 PushOperand(context_register()); | 1542 PushOperand(context_register()); |
1544 } | 1543 } |
1545 | 1544 |
1546 | 1545 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 return var->scope()->is_nonlinear() || | 1937 return var->scope()->is_nonlinear() || |
1939 var->initializer_position() >= proxy->position(); | 1938 var->initializer_position() >= proxy->position(); |
1940 } | 1939 } |
1941 | 1940 |
1942 | 1941 |
1943 #undef __ | 1942 #undef __ |
1944 | 1943 |
1945 | 1944 |
1946 } // namespace internal | 1945 } // namespace internal |
1947 } // namespace v8 | 1946 } // namespace v8 |
OLD | NEW |