| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/class_finalizer.h" | 6 #include "vm/class_finalizer.h" |
| 7 #include "vm/code_index_table.h" | 7 #include "vm/code_index_table.h" |
| 8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/pages.h" |
| 10 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 // Compiler only implemented on IA32 and x64 now. | 15 // Compiler only implemented on IA32 and x64 now. |
| 15 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 16 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 16 | 17 |
| 17 TEST_CASE(CodeIndexTable) { | 18 TEST_CASE(CodeIndexTable) { |
| 18 const int kScriptSize = 512 * KB; | 19 const int kScriptSize = 512 * KB; |
| 19 const int kNumFunctions = 1024; | 20 const int kNumFunctions = 1024; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 function_name = String::New(buffer); | 59 function_name = String::New(buffer); |
| 59 function = clsA.LookupStaticFunction(function_name); | 60 function = clsA.LookupStaticFunction(function_name); |
| 60 EXPECT(!function.IsNull()); | 61 EXPECT(!function.IsNull()); |
| 61 EXPECT(CompilerTest::TestCompileFunction(function)); | 62 EXPECT(CompilerTest::TestCompileFunction(function)); |
| 62 EXPECT(function.HasCode()); | 63 EXPECT(function.HasCode()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Now load up class B with 1024 functions. | 66 // Now load up class B with 1024 functions. |
| 66 written = OS::SNPrint(scriptChars, kScriptSize, "class B {"); | 67 written = OS::SNPrint(scriptChars, kScriptSize, "class B {"); |
| 67 // Create one large function. | 68 // Create one large function. |
| 68 OS::SNPrint(buffer, sizeof(buffer), "static moo0([int i=1]) { return "); | 69 OS::SNPrint(buffer, sizeof(buffer), "static moo0([int i=1]) { "); |
| 69 written += OS::SNPrint((scriptChars + written), | 70 written += OS::SNPrint((scriptChars + written), |
| 70 (kScriptSize - written), | 71 (kScriptSize - written), |
| 71 "%s", | 72 "%s", |
| 72 buffer); | 73 buffer); |
| 73 // Currently this causes about 750KB of code to be allocated. The | 74 // Generate a large function so that the code for this function when |
| 74 // nesting level of binary operations is reduced from 50000 so this | 75 // compiled will reside in a large page. |
| 75 // test will pass on Windows. Larger nesting leads to stack overflow | 76 for (int i = 0; i < 50000; i++) { |
| 76 // in debug mode in the code generation visitor even when the stack | 77 OS::SNPrint(buffer, sizeof(buffer), "i = i+i;"); |
| 77 // reserved size is set to 2MB. | |
| 78 for (int i = 0; i < 35000; i++) { | |
| 79 OS::SNPrint(buffer, sizeof(buffer), "i+"); | |
| 80 written += OS::SNPrint((scriptChars + written), | 78 written += OS::SNPrint((scriptChars + written), |
| 81 (kScriptSize - written), | 79 (kScriptSize - written), |
| 82 "%s", | 80 "%s", |
| 83 buffer); | 81 buffer); |
| 84 } | 82 } |
| 85 OS::SNPrint(buffer, sizeof(buffer), "i; }"); | 83 OS::SNPrint(buffer, sizeof(buffer), "return i; }"); |
| 86 written += OS::SNPrint((scriptChars + written), | 84 written += OS::SNPrint((scriptChars + written), |
| 87 (kScriptSize - written), | 85 (kScriptSize - written), |
| 88 "%s", | 86 "%s", |
| 89 buffer); | 87 buffer); |
| 90 for (int i = 1; i < kNumFunctions; i++) { | 88 for (int i = 1; i < kNumFunctions; i++) { |
| 91 OS::SNPrint(buffer, | 89 OS::SNPrint(buffer, |
| 92 256, | 90 256, |
| 93 "static moo%d([int i=1,int j=2,int k=3]){return i+j+k;}", i); | 91 "static moo%d([int i=1,int j=2,int k=3]){return i+j+k;}", i); |
| 94 written += OS::SNPrint((scriptChars + written), | 92 written += OS::SNPrint((scriptChars + written), |
| 95 (kScriptSize - written), | 93 (kScriptSize - written), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 EXPECT(code_index_table->LookupCode(pc) == code.raw()); | 135 EXPECT(code_index_table->LookupCode(pc) == code.raw()); |
| 138 | 136 |
| 139 // Lookup the large function | 137 // Lookup the large function |
| 140 OS::SNPrint(buffer, 256, "moo%d", 0); | 138 OS::SNPrint(buffer, 256, "moo%d", 0); |
| 141 function_name = String::New(buffer); | 139 function_name = String::New(buffer); |
| 142 function = clsB.LookupStaticFunction(function_name); | 140 function = clsB.LookupStaticFunction(function_name); |
| 143 EXPECT(!function.IsNull()); | 141 EXPECT(!function.IsNull()); |
| 144 code = function.code(); | 142 code = function.code(); |
| 145 EXPECT(code.Size() > 16); | 143 EXPECT(code.Size() > 16); |
| 146 pc = code.EntryPoint() + 16; | 144 pc = code.EntryPoint() + 16; |
| 145 EXPECT(code.Size() > PageSpace::kPageSize); |
| 147 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); | 146 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); |
| 148 EXPECT(code_index_table->LookupCode(pc) == code.raw()); | 147 EXPECT(code_index_table->LookupCode(pc) == code.raw()); |
| 149 EXPECT(code.Size() > 750 * KB); | 148 EXPECT(code.Size() > (1 * MB)); |
| 150 pc = code.EntryPoint() + 750 * KB; | 149 pc = code.EntryPoint() + (1 * MB); |
| 151 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); | 150 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); |
| 152 EXPECT(code_index_table->LookupCode(pc) == code.raw()); | 151 EXPECT(code_index_table->LookupCode(pc) == code.raw()); |
| 153 } | 152 } |
| 154 | 153 |
| 155 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 | 154 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 |
| 156 | 155 |
| 157 } // namespace dart | 156 } // namespace dart |
| OLD | NEW |