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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 code->set_type_feedback_info(*info); | 117 code->set_type_feedback_info(*info); |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) { | 121 void FullCodeGenerator::PopulateHandlerTable(Handle<Code> code) { |
122 int handler_table_size = static_cast<int>(handler_table_.size()); | 122 int handler_table_size = static_cast<int>(handler_table_.size()); |
123 Handle<HandlerTable> table = | 123 Handle<HandlerTable> table = |
124 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( | 124 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( |
125 HandlerTable::LengthForRange(handler_table_size), TENURED)); | 125 HandlerTable::LengthForRange(handler_table_size), TENURED)); |
126 for (int i = 0; i < handler_table_size; ++i) { | 126 for (int i = 0; i < handler_table_size; ++i) { |
127 HandlerTable::CatchPrediction prediction = | 127 HandlerTable::CatchPrediction prediction = handler_table_[i].catch_predicted |
128 handler_table_[i].try_catch_depth > 0 ? HandlerTable::CAUGHT | 128 ? HandlerTable::CAUGHT |
129 : HandlerTable::UNCAUGHT; | 129 : HandlerTable::UNCAUGHT; |
130 table->SetRangeStart(i, handler_table_[i].range_start); | 130 table->SetRangeStart(i, handler_table_[i].range_start); |
131 table->SetRangeEnd(i, handler_table_[i].range_end); | 131 table->SetRangeEnd(i, handler_table_[i].range_end); |
132 table->SetRangeHandler(i, handler_table_[i].handler_offset, prediction); | 132 table->SetRangeHandler(i, handler_table_[i].handler_offset, prediction); |
133 table->SetRangeData(i, handler_table_[i].stack_depth); | 133 table->SetRangeData(i, handler_table_[i].stack_depth); |
134 } | 134 } |
135 code->set_handler_table(*table); | 135 code->set_handler_table(*table); |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 int FullCodeGenerator::NewHandlerTableEntry() { | 139 int FullCodeGenerator::NewHandlerTableEntry() { |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 } | 1309 } |
1310 // Restore the context. | 1310 // Restore the context. |
1311 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 1311 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
1312 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 1312 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
1313 scope_ = saved_scope; | 1313 scope_ = saved_scope; |
1314 __ jmp(&exit); | 1314 __ jmp(&exit); |
1315 | 1315 |
1316 // Try block code. Sets up the exception handler chain. | 1316 // Try block code. Sets up the exception handler chain. |
1317 __ bind(&try_entry); | 1317 __ bind(&try_entry); |
1318 | 1318 |
1319 try_catch_depth_++; | |
1320 int handler_index = NewHandlerTableEntry(); | 1319 int handler_index = NewHandlerTableEntry(); |
1321 EnterTryBlock(handler_index, &handler_entry); | 1320 EnterTryBlock(handler_index, &handler_entry, stmt->catch_predicted()); |
1322 { | 1321 { |
1323 Comment cmnt_try(masm(), "[ Try block"); | 1322 Comment cmnt_try(masm(), "[ Try block"); |
1324 Visit(stmt->try_block()); | 1323 Visit(stmt->try_block()); |
1325 } | 1324 } |
1326 ExitTryBlock(handler_index); | 1325 ExitTryBlock(handler_index); |
1327 try_catch_depth_--; | |
1328 __ bind(&exit); | 1326 __ bind(&exit); |
1329 } | 1327 } |
1330 | 1328 |
1331 | 1329 |
1332 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 1330 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
1333 Comment cmnt(masm_, "[ TryFinallyStatement"); | 1331 Comment cmnt(masm_, "[ TryFinallyStatement"); |
1334 SetStatementPosition(stmt, SKIP_BREAK); | 1332 SetStatementPosition(stmt, SKIP_BREAK); |
1335 | 1333 |
1336 // Try finally is compiled by setting up a try-handler on the stack while | 1334 // Try finally is compiled by setting up a try-handler on the stack while |
1337 // executing the try body, and removing it again afterwards. | 1335 // executing the try body, and removing it again afterwards. |
(...skipping 23 matching lines...) Expand all Loading... |
1361 // Exception handler code. This code is only executed when an exception | 1359 // Exception handler code. This code is only executed when an exception |
1362 // is thrown. Record the continuation and jump to the finally block. | 1360 // is thrown. Record the continuation and jump to the finally block. |
1363 { | 1361 { |
1364 Comment cmnt_handler(masm(), "[ Finally handler"); | 1362 Comment cmnt_handler(masm(), "[ Finally handler"); |
1365 deferred.RecordThrow(); | 1363 deferred.RecordThrow(); |
1366 } | 1364 } |
1367 | 1365 |
1368 // Set up try handler. | 1366 // Set up try handler. |
1369 __ bind(&try_entry); | 1367 __ bind(&try_entry); |
1370 int handler_index = NewHandlerTableEntry(); | 1368 int handler_index = NewHandlerTableEntry(); |
1371 EnterTryBlock(handler_index, &handler_entry); | 1369 EnterTryBlock(handler_index, &handler_entry, stmt->catch_predicted()); |
1372 { | 1370 { |
1373 Comment cmnt_try(masm(), "[ Try block"); | 1371 Comment cmnt_try(masm(), "[ Try block"); |
1374 TryFinally try_body(this, &deferred); | 1372 TryFinally try_body(this, &deferred); |
1375 Visit(stmt->try_block()); | 1373 Visit(stmt->try_block()); |
1376 } | 1374 } |
1377 ExitTryBlock(handler_index); | 1375 ExitTryBlock(handler_index); |
1378 // Execute the finally block on the way out. Clobber the unpredictable | 1376 // Execute the finally block on the way out. Clobber the unpredictable |
1379 // value in the result register with one that's safe for GC because the | 1377 // value in the result register with one that's safe for GC because the |
1380 // finally block will unconditionally preserve the result register on the | 1378 // finally block will unconditionally preserve the result register on the |
1381 // stack. | 1379 // stack. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 VisitForStackValue(expr->exception()); | 1542 VisitForStackValue(expr->exception()); |
1545 SetExpressionPosition(expr); | 1543 SetExpressionPosition(expr); |
1546 CallRuntimeWithOperands(Runtime::kThrow); | 1544 CallRuntimeWithOperands(Runtime::kThrow); |
1547 // Never returns here. | 1545 // Never returns here. |
1548 | 1546 |
1549 // Even though this expression doesn't produce a value, we need to simulate | 1547 // Even though this expression doesn't produce a value, we need to simulate |
1550 // plugging of the value context to ensure stack depth tracking is in sync. | 1548 // plugging of the value context to ensure stack depth tracking is in sync. |
1551 if (context()->IsStackValue()) OperandStackDepthIncrement(1); | 1549 if (context()->IsStackValue()) OperandStackDepthIncrement(1); |
1552 } | 1550 } |
1553 | 1551 |
1554 | 1552 void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler, |
1555 void FullCodeGenerator::EnterTryBlock(int handler_index, Label* handler) { | 1553 bool catch_predicted) { |
1556 HandlerTableEntry* entry = &handler_table_[handler_index]; | 1554 HandlerTableEntry* entry = &handler_table_[handler_index]; |
1557 entry->range_start = masm()->pc_offset(); | 1555 entry->range_start = masm()->pc_offset(); |
1558 entry->handler_offset = handler->pos(); | 1556 entry->handler_offset = handler->pos(); |
1559 entry->try_catch_depth = try_catch_depth_; | |
1560 entry->stack_depth = operand_stack_depth_; | 1557 entry->stack_depth = operand_stack_depth_; |
| 1558 entry->catch_predicted = catch_predicted; |
1561 | 1559 |
1562 // We are using the operand stack depth, check for accuracy. | 1560 // We are using the operand stack depth, check for accuracy. |
1563 EmitOperandStackDepthCheck(); | 1561 EmitOperandStackDepthCheck(); |
1564 | 1562 |
1565 // Push context onto operand stack. | 1563 // Push context onto operand stack. |
1566 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); | 1564 STATIC_ASSERT(TryBlockConstant::kElementCount == 1); |
1567 PushOperand(context_register()); | 1565 PushOperand(context_register()); |
1568 } | 1566 } |
1569 | 1567 |
1570 | 1568 |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 return var->scope()->is_nonlinear() || | 1960 return var->scope()->is_nonlinear() || |
1963 var->initializer_position() >= proxy->position(); | 1961 var->initializer_position() >= proxy->position(); |
1964 } | 1962 } |
1965 | 1963 |
1966 | 1964 |
1967 #undef __ | 1965 #undef __ |
1968 | 1966 |
1969 | 1967 |
1970 } // namespace internal | 1968 } // namespace internal |
1971 } // namespace v8 | 1969 } // namespace v8 |
OLD | NEW |