| 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/pages.h" |
| 11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 // Compiler only implemented on IA32 and x64 now. | 15 // Compiler only implemented on IA32 and x64 now. |
| 16 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 16 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 17 | 17 |
| 18 TEST_CASE(CodeIndexTable) { | 18 TEST_CASE(CodeIndexTable) { |
| 19 #if defined(TARGET_ARCH_IA32) |
| 20 const int kLoopCount = 50000; |
| 21 #else |
| 22 const int kLoopCount = 25000; |
| 23 #endif |
| 19 const int kScriptSize = 512 * KB; | 24 const int kScriptSize = 512 * KB; |
| 20 const int kNumFunctions = 1024; | 25 const int kNumFunctions = 1024; |
| 21 char scriptChars[kScriptSize]; | 26 char scriptChars[kScriptSize]; |
| 22 String& url = String::Handle(String::New("dart-test:CodeIndexTable")); | 27 String& url = String::Handle(String::New("dart-test:CodeIndexTable")); |
| 23 String& source = String::Handle(); | 28 String& source = String::Handle(); |
| 24 Script& script = Script::Handle(); | 29 Script& script = Script::Handle(); |
| 25 Library& lib = Library::Handle(); | 30 Library& lib = Library::Handle(); |
| 26 Class& clsA = Class::Handle(); | 31 Class& clsA = Class::Handle(); |
| 27 Class& clsB = Class::Handle(); | 32 Class& clsB = Class::Handle(); |
| 28 String& function_name = String::Handle(); | 33 String& function_name = String::Handle(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 59 function_name = String::New(buffer); | 64 function_name = String::New(buffer); |
| 60 function = clsA.LookupStaticFunction(function_name); | 65 function = clsA.LookupStaticFunction(function_name); |
| 61 EXPECT(!function.IsNull()); | 66 EXPECT(!function.IsNull()); |
| 62 EXPECT(CompilerTest::TestCompileFunction(function)); | 67 EXPECT(CompilerTest::TestCompileFunction(function)); |
| 63 EXPECT(function.HasCode()); | 68 EXPECT(function.HasCode()); |
| 64 } | 69 } |
| 65 | 70 |
| 66 // Now load up class B with 1024 functions. | 71 // Now load up class B with 1024 functions. |
| 67 written = OS::SNPrint(scriptChars, kScriptSize, "class B {"); | 72 written = OS::SNPrint(scriptChars, kScriptSize, "class B {"); |
| 68 // Create one large function. | 73 // Create one large function. |
| 69 OS::SNPrint(buffer, sizeof(buffer), "static moo0([int i=1]) { "); | 74 OS::SNPrint(buffer, sizeof(buffer), "static moo0([var i=1]) { "); |
| 70 written += OS::SNPrint((scriptChars + written), | 75 written += OS::SNPrint((scriptChars + written), |
| 71 (kScriptSize - written), | 76 (kScriptSize - written), |
| 72 "%s", | 77 "%s", |
| 73 buffer); | 78 buffer); |
| 74 // Generate a large function so that the code for this function when | 79 // Generate a large function so that the code for this function when |
| 75 // compiled will reside in a large page. | 80 // compiled will reside in a large page. |
| 76 for (int i = 0; i < 50000; i++) { | 81 for (int i = 0; i < kLoopCount; i++) { |
| 77 OS::SNPrint(buffer, sizeof(buffer), "i = i+i;"); | 82 OS::SNPrint(buffer, sizeof(buffer), "i = i+i;"); |
| 78 written += OS::SNPrint((scriptChars + written), | 83 written += OS::SNPrint((scriptChars + written), |
| 79 (kScriptSize - written), | 84 (kScriptSize - written), |
| 80 "%s", | 85 "%s", |
| 81 buffer); | 86 buffer); |
| 82 } | 87 } |
| 83 OS::SNPrint(buffer, sizeof(buffer), "return i; }"); | 88 OS::SNPrint(buffer, sizeof(buffer), "return i; }"); |
| 84 written += OS::SNPrint((scriptChars + written), | 89 written += OS::SNPrint((scriptChars + written), |
| 85 (kScriptSize - written), | 90 (kScriptSize - written), |
| 86 "%s", | 91 "%s", |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 EXPECT(code_index_table->LookupCode(pc) == code.raw()); | 152 EXPECT(code_index_table->LookupCode(pc) == code.raw()); |
| 148 EXPECT(code.Size() > (1 * MB)); | 153 EXPECT(code.Size() > (1 * MB)); |
| 149 pc = code.EntryPoint() + (1 * MB); | 154 pc = code.EntryPoint() + (1 * MB); |
| 150 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); | 155 EXPECT(code_index_table->LookupFunction(pc) == function.raw()); |
| 151 EXPECT(code_index_table->LookupCode(pc) == code.raw()); | 156 EXPECT(code_index_table->LookupCode(pc) == code.raw()); |
| 152 } | 157 } |
| 153 | 158 |
| 154 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 | 159 #endif // TARGET_ARCH_IA32 || TARGET_ARCH_X64 |
| 155 | 160 |
| 156 } // namespace dart | 161 } // namespace dart |
| OLD | NEW |