OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 8052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8063 CHECK_EQ(22, iterator->GetBreakLocation().position()); | 8063 CHECK_EQ(22, iterator->GetBreakLocation().position()); |
8064 iterator->Next(); | 8064 iterator->Next(); |
8065 CHECK(iterator->GetBreakLocation().IsReturn()); | 8065 CHECK(iterator->GetBreakLocation().IsReturn()); |
8066 CHECK_EQ(50, iterator->GetBreakLocation().position()); | 8066 CHECK_EQ(50, iterator->GetBreakLocation().position()); |
8067 iterator->Next(); | 8067 iterator->Next(); |
8068 CHECK(iterator->Done()); | 8068 CHECK(iterator->Done()); |
8069 delete iterator; | 8069 delete iterator; |
8070 | 8070 |
8071 DisableDebugger(isolate); | 8071 DisableDebugger(isolate); |
8072 } | 8072 } |
| 8073 |
| 8074 TEST(DisableTailCallElimination) { |
| 8075 i::FLAG_allow_natives_syntax = true; |
| 8076 i::FLAG_harmony_tailcalls = true; |
| 8077 // TODO(ishell, 4698): Investigate why TurboFan in --always-opt mode makes |
| 8078 // stack[2].getFunctionName() return null. |
| 8079 i::FLAG_turbo_inlining = false; |
| 8080 |
| 8081 DebugLocalContext env; |
| 8082 v8::Isolate* isolate = env->GetIsolate(); |
| 8083 v8::HandleScope scope(isolate); |
| 8084 CHECK(v8::Debug::IsTailCallEliminationEnabled(isolate)); |
| 8085 |
| 8086 CompileRun( |
| 8087 "'use strict'; \n" |
| 8088 "Error.prepareStackTrace = (error,stack) => { \n" |
| 8089 " error.strace = stack; \n" |
| 8090 " return error.message + \"\\n at \" + stack.join(\"\\n at \"); \n" |
| 8091 "} \n" |
| 8092 " \n" |
| 8093 "function getCaller() { \n" |
| 8094 " var e = new Error(); \n" |
| 8095 " e.stack; // prepare stack trace \n" |
| 8096 " var stack = e.strace; \n" |
| 8097 " %GlobalPrint('caller: '); \n" |
| 8098 " %GlobalPrint(stack[2].getFunctionName()); \n" |
| 8099 " %GlobalPrint('\\n'); \n" |
| 8100 " return stack[2].getFunctionName(); \n" |
| 8101 "} \n" |
| 8102 "function f() { \n" |
| 8103 " var caller = getCaller(); \n" |
| 8104 " if (caller === 'g') return 1; \n" |
| 8105 " if (caller === 'h') return 2; \n" |
| 8106 " return 0; \n" |
| 8107 "} \n" |
| 8108 "function g() { \n" |
| 8109 " return f(); \n" |
| 8110 "} \n" |
| 8111 "function h() { \n" |
| 8112 " var result = g(); \n" |
| 8113 " return result; \n" |
| 8114 "} \n" |
| 8115 "%NeverOptimizeFunction(getCaller); \n" |
| 8116 "%NeverOptimizeFunction(f); \n" |
| 8117 "%NeverOptimizeFunction(h); \n" |
| 8118 ""); |
| 8119 ExpectInt32("h();", 2); |
| 8120 ExpectInt32("h(); %OptimizeFunctionOnNextCall(g); h();", 2); |
| 8121 v8::Debug::SetTailCallEliminationEnabled(isolate, false); |
| 8122 CHECK(!v8::Debug::IsTailCallEliminationEnabled(isolate)); |
| 8123 ExpectInt32("h();", 1); |
| 8124 ExpectInt32("h(); %OptimizeFunctionOnNextCall(g); h();", 1); |
| 8125 v8::Debug::SetTailCallEliminationEnabled(isolate, true); |
| 8126 CHECK(v8::Debug::IsTailCallEliminationEnabled(isolate)); |
| 8127 ExpectInt32("h();", 2); |
| 8128 ExpectInt32("h(); %OptimizeFunctionOnNextCall(g); h();", 2); |
| 8129 } |
OLD | NEW |