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 "vm/benchmark_test.h" | 5 #include "vm/benchmark_test.h" |
6 | 6 |
7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 #include "bin/isolate_data.h" | 9 #include "bin/isolate_data.h" |
10 | 10 |
11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
13 | 13 |
14 #include "vm/clustered_snapshot.h" | 14 #include "vm/clustered_snapshot.h" |
15 #include "vm/compiler_stats.h" | 15 #include "vm/compiler_stats.h" |
16 #include "vm/dart_api_impl.h" | 16 #include "vm/dart_api_impl.h" |
17 #include "vm/stack_frame.h" | 17 #include "vm/stack_frame.h" |
18 #include "vm/unit_test.h" | 18 #include "vm/unit_test.h" |
19 | 19 |
20 using dart::bin::File; | 20 using dart::bin::File; |
21 | 21 |
22 namespace dart { | 22 namespace dart { |
23 | 23 |
24 Benchmark* Benchmark::first_ = NULL; | 24 Benchmark* Benchmark::first_ = NULL; |
25 Benchmark* Benchmark::tail_ = NULL; | 25 Benchmark* Benchmark::tail_ = NULL; |
26 const char* Benchmark::executable_ = NULL; | 26 const char* Benchmark::executable_ = NULL; |
27 | 27 |
28 | |
29 // | 28 // |
30 // Measure compile of all dart2js(compiler) functions. | 29 // Measure compile of all dart2js(compiler) functions. |
31 // | 30 // |
32 static char* ComputeDart2JSPath(const char* arg) { | 31 static char* ComputeDart2JSPath(const char* arg) { |
33 char buffer[2048]; | 32 char buffer[2048]; |
34 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); | 33 char* dart2js_path = strdup(File::GetCanonicalPath(arg)); |
35 const char* compiler_path = "%s%spkg%scompiler%slib%scompiler.dart"; | 34 const char* compiler_path = "%s%spkg%scompiler%slib%scompiler.dart"; |
36 const char* path_separator = File::PathSeparator(); | 35 const char* path_separator = File::PathSeparator(); |
37 ASSERT(path_separator != NULL && strlen(path_separator) == 1); | 36 ASSERT(path_separator != NULL && strlen(path_separator) == 1); |
38 char* ptr = strrchr(dart2js_path, *path_separator); | 37 char* ptr = strrchr(dart2js_path, *path_separator); |
39 while (ptr != NULL) { | 38 while (ptr != NULL) { |
40 *ptr = '\0'; | 39 *ptr = '\0'; |
41 OS::SNPrint(buffer, 2048, compiler_path, dart2js_path, path_separator, | 40 OS::SNPrint(buffer, 2048, compiler_path, dart2js_path, path_separator, |
42 path_separator, path_separator, path_separator, path_separator); | 41 path_separator, path_separator, path_separator, path_separator); |
43 if (File::Exists(buffer)) { | 42 if (File::Exists(buffer)) { |
44 break; | 43 break; |
45 } | 44 } |
46 ptr = strrchr(dart2js_path, *path_separator); | 45 ptr = strrchr(dart2js_path, *path_separator); |
47 } | 46 } |
48 if (ptr == NULL) { | 47 if (ptr == NULL) { |
49 free(dart2js_path); | 48 free(dart2js_path); |
50 dart2js_path = NULL; | 49 dart2js_path = NULL; |
51 } | 50 } |
52 return dart2js_path; | 51 return dart2js_path; |
53 } | 52 } |
54 | 53 |
55 | |
56 static void func(Dart_NativeArguments args) {} | 54 static void func(Dart_NativeArguments args) {} |
57 | 55 |
58 | |
59 static Dart_NativeFunction NativeResolver(Dart_Handle name, | 56 static Dart_NativeFunction NativeResolver(Dart_Handle name, |
60 int arg_count, | 57 int arg_count, |
61 bool* auto_setup_scope) { | 58 bool* auto_setup_scope) { |
62 ASSERT(auto_setup_scope != NULL); | 59 ASSERT(auto_setup_scope != NULL); |
63 *auto_setup_scope = false; | 60 *auto_setup_scope = false; |
64 return &func; | 61 return &func; |
65 } | 62 } |
66 | 63 |
67 | |
68 static void SetupDart2JSPackagePath() { | 64 static void SetupDart2JSPackagePath() { |
69 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); | 65 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); |
70 EXPECT(worked); | 66 EXPECT(worked); |
71 | 67 |
72 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false); | 68 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false); |
73 DART_CHECK_VALID(result); | 69 DART_CHECK_VALID(result); |
74 | 70 |
75 // Setup package root. | 71 // Setup package root. |
76 char buffer[2048]; | 72 char buffer[2048]; |
77 char* executable_path = | 73 char* executable_path = |
78 strdup(File::GetCanonicalPath(Benchmark::Executable())); | 74 strdup(File::GetCanonicalPath(Benchmark::Executable())); |
79 const char* packages_path = "%s%s..%spackages"; | 75 const char* packages_path = "%s%s..%spackages"; |
80 const char* path_separator = File::PathSeparator(); | 76 const char* path_separator = File::PathSeparator(); |
81 OS::SNPrint(buffer, 2048, packages_path, executable_path, path_separator, | 77 OS::SNPrint(buffer, 2048, packages_path, executable_path, path_separator, |
82 path_separator); | 78 path_separator); |
83 result = bin::DartUtils::SetupPackageRoot(buffer, NULL); | 79 result = bin::DartUtils::SetupPackageRoot(buffer, NULL); |
84 DART_CHECK_VALID(result); | 80 DART_CHECK_VALID(result); |
85 } | 81 } |
86 | 82 |
87 | |
88 void Benchmark::RunAll(const char* executable) { | 83 void Benchmark::RunAll(const char* executable) { |
89 SetExecutable(executable); | 84 SetExecutable(executable); |
90 Benchmark* benchmark = first_; | 85 Benchmark* benchmark = first_; |
91 while (benchmark != NULL) { | 86 while (benchmark != NULL) { |
92 benchmark->RunBenchmark(); | 87 benchmark->RunBenchmark(); |
93 benchmark = benchmark->next_; | 88 benchmark = benchmark->next_; |
94 } | 89 } |
95 } | 90 } |
96 | 91 |
97 | |
98 Dart_Isolate Benchmark::CreateIsolate(const uint8_t* snapshot_data, | 92 Dart_Isolate Benchmark::CreateIsolate(const uint8_t* snapshot_data, |
99 const uint8_t* snapshot_instructions) { | 93 const uint8_t* snapshot_instructions) { |
100 char* err = NULL; | 94 char* err = NULL; |
101 isolate_ = Dart_CreateIsolate(NULL, NULL, snapshot_data, | 95 isolate_ = Dart_CreateIsolate(NULL, NULL, snapshot_data, |
102 snapshot_instructions, NULL, NULL, &err); | 96 snapshot_instructions, NULL, NULL, &err); |
103 EXPECT(isolate_ != NULL); | 97 EXPECT(isolate_ != NULL); |
104 free(err); | 98 free(err); |
105 return isolate_; | 99 return isolate_; |
106 } | 100 } |
107 | 101 |
108 | |
109 // | 102 // |
110 // Measure compile of all functions in dart core lib classes. | 103 // Measure compile of all functions in dart core lib classes. |
111 // | 104 // |
112 BENCHMARK(CorelibCompileAll) { | 105 BENCHMARK(CorelibCompileAll) { |
113 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 106 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
114 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 107 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
115 TransitionNativeToVM transition(thread); | 108 TransitionNativeToVM transition(thread); |
116 Timer timer(true, "Compile all of Core lib benchmark"); | 109 Timer timer(true, "Compile all of Core lib benchmark"); |
117 timer.Start(); | 110 timer.Start(); |
118 const Error& error = Error::Handle(Library::CompileAll()); | 111 const Error& error = Error::Handle(Library::CompileAll()); |
119 if (!error.IsNull()) { | 112 if (!error.IsNull()) { |
120 OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", | 113 OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", |
121 error.ToErrorCString()); | 114 error.ToErrorCString()); |
122 } | 115 } |
123 timer.Stop(); | 116 timer.Stop(); |
124 int64_t elapsed_time = timer.TotalElapsedTime(); | 117 int64_t elapsed_time = timer.TotalElapsedTime(); |
125 benchmark->set_score(elapsed_time); | 118 benchmark->set_score(elapsed_time); |
126 } | 119 } |
127 | 120 |
128 | |
129 #ifndef PRODUCT | 121 #ifndef PRODUCT |
130 | 122 |
131 | |
132 BENCHMARK(CorelibCompilerStats) { | 123 BENCHMARK(CorelibCompilerStats) { |
133 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 124 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
134 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 125 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
135 TransitionNativeToVM transition(thread); | 126 TransitionNativeToVM transition(thread); |
136 CompilerStats* stats = thread->isolate()->aggregate_compiler_stats(); | 127 CompilerStats* stats = thread->isolate()->aggregate_compiler_stats(); |
137 ASSERT(stats != NULL); | 128 ASSERT(stats != NULL); |
138 stats->EnableBenchmark(); | 129 stats->EnableBenchmark(); |
139 Timer timer(true, "Compiler stats compiling all of Core lib"); | 130 Timer timer(true, "Compiler stats compiling all of Core lib"); |
140 timer.Start(); | 131 timer.Start(); |
141 const Error& error = Error::Handle(Library::CompileAll()); | 132 const Error& error = Error::Handle(Library::CompileAll()); |
142 if (!error.IsNull()) { | 133 if (!error.IsNull()) { |
143 OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", | 134 OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", |
144 error.ToErrorCString()); | 135 error.ToErrorCString()); |
145 } | 136 } |
146 timer.Stop(); | 137 timer.Stop(); |
147 int64_t elapsed_time = timer.TotalElapsedTime(); | 138 int64_t elapsed_time = timer.TotalElapsedTime(); |
148 benchmark->set_score(elapsed_time); | 139 benchmark->set_score(elapsed_time); |
149 } | 140 } |
150 | 141 |
151 | |
152 BENCHMARK(Dart2JSCompilerStats) { | 142 BENCHMARK(Dart2JSCompilerStats) { |
153 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 143 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
154 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 144 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
155 SetupDart2JSPackagePath(); | 145 SetupDart2JSPackagePath(); |
156 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 146 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
157 char* script = NULL; | 147 char* script = NULL; |
158 if (dart_root != NULL) { | 148 if (dart_root != NULL) { |
159 HANDLESCOPE(thread); | 149 HANDLESCOPE(thread); |
160 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", | 150 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", |
161 dart_root); | 151 dart_root); |
(...skipping 21 matching lines...) Expand all Loading... |
183 FLAG_background_compilation = old_flag; | 173 FLAG_background_compilation = old_flag; |
184 #endif | 174 #endif |
185 EXPECT_VALID(result); | 175 EXPECT_VALID(result); |
186 timer.Stop(); | 176 timer.Stop(); |
187 int64_t elapsed_time = timer.TotalElapsedTime(); | 177 int64_t elapsed_time = timer.TotalElapsedTime(); |
188 benchmark->set_score(elapsed_time); | 178 benchmark->set_score(elapsed_time); |
189 free(dart_root); | 179 free(dart_root); |
190 free(script); | 180 free(script); |
191 } | 181 } |
192 | 182 |
193 | |
194 #endif // !PRODUCT | 183 #endif // !PRODUCT |
195 | 184 |
196 | |
197 // | 185 // |
198 // Measure creation of core isolate from a snapshot. | 186 // Measure creation of core isolate from a snapshot. |
199 // | 187 // |
200 BENCHMARK(CorelibIsolateStartup) { | 188 BENCHMARK(CorelibIsolateStartup) { |
201 const int kNumIterations = 1000; | 189 const int kNumIterations = 1000; |
202 Timer timer(true, "CorelibIsolateStartup"); | 190 Timer timer(true, "CorelibIsolateStartup"); |
203 Isolate* isolate = thread->isolate(); | 191 Isolate* isolate = thread->isolate(); |
204 Dart_ExitIsolate(); | 192 Dart_ExitIsolate(); |
205 for (int i = 0; i < kNumIterations; i++) { | 193 for (int i = 0; i < kNumIterations; i++) { |
206 timer.Start(); | 194 timer.Start(); |
207 TestCase::CreateTestIsolate(); | 195 TestCase::CreateTestIsolate(); |
208 timer.Stop(); | 196 timer.Stop(); |
209 Dart_ShutdownIsolate(); | 197 Dart_ShutdownIsolate(); |
210 } | 198 } |
211 benchmark->set_score(timer.TotalElapsedTime() / kNumIterations); | 199 benchmark->set_score(timer.TotalElapsedTime() / kNumIterations); |
212 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(isolate)); | 200 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(isolate)); |
213 } | 201 } |
214 | 202 |
215 | |
216 // | 203 // |
217 // Measure invocation of Dart API functions. | 204 // Measure invocation of Dart API functions. |
218 // | 205 // |
219 static void InitNativeFields(Dart_NativeArguments args) { | 206 static void InitNativeFields(Dart_NativeArguments args) { |
220 Dart_EnterScope(); | 207 Dart_EnterScope(); |
221 int count = Dart_GetNativeArgumentCount(args); | 208 int count = Dart_GetNativeArgumentCount(args); |
222 EXPECT_EQ(1, count); | 209 EXPECT_EQ(1, count); |
223 | 210 |
224 Dart_Handle recv = Dart_GetNativeArgument(args, 0); | 211 Dart_Handle recv = Dart_GetNativeArgument(args, 0); |
225 EXPECT_VALID(recv); | 212 EXPECT_VALID(recv); |
226 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7); | 213 Dart_Handle result = Dart_SetNativeInstanceField(recv, 0, 7); |
227 EXPECT_VALID(result); | 214 EXPECT_VALID(result); |
228 | 215 |
229 Dart_ExitScope(); | 216 Dart_ExitScope(); |
230 } | 217 } |
231 | 218 |
232 | |
233 // The specific api functions called here are a bit arbitrary. We are | 219 // The specific api functions called here are a bit arbitrary. We are |
234 // trying to get a sense of the overhead for using the dart api. | 220 // trying to get a sense of the overhead for using the dart api. |
235 static void UseDartApi(Dart_NativeArguments args) { | 221 static void UseDartApi(Dart_NativeArguments args) { |
236 int count = Dart_GetNativeArgumentCount(args); | 222 int count = Dart_GetNativeArgumentCount(args); |
237 EXPECT_EQ(3, count); | 223 EXPECT_EQ(3, count); |
238 | 224 |
239 // Get native field from receiver. | 225 // Get native field from receiver. |
240 intptr_t receiver_value; | 226 intptr_t receiver_value; |
241 Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value); | 227 Dart_Handle result = Dart_GetNativeReceiver(args, &receiver_value); |
242 EXPECT_VALID(result); | 228 EXPECT_VALID(result); |
(...skipping 10 matching lines...) Expand all Loading... |
253 int64_t value1; | 239 int64_t value1; |
254 result = Dart_IntegerToInt64(param1, &value1); | 240 result = Dart_IntegerToInt64(param1, &value1); |
255 EXPECT_VALID(result); | 241 EXPECT_VALID(result); |
256 EXPECT_LE(0, value1); | 242 EXPECT_LE(0, value1); |
257 EXPECT_LE(value1, 1000000); | 243 EXPECT_LE(value1, 1000000); |
258 | 244 |
259 // Return param + receiver.field. | 245 // Return param + receiver.field. |
260 Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value)); | 246 Dart_SetReturnValue(args, Dart_NewInteger(value1 * receiver_value)); |
261 } | 247 } |
262 | 248 |
263 | |
264 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, | 249 static Dart_NativeFunction bm_uda_lookup(Dart_Handle name, |
265 int argument_count, | 250 int argument_count, |
266 bool* auto_setup_scope) { | 251 bool* auto_setup_scope) { |
267 ASSERT(auto_setup_scope != NULL); | 252 ASSERT(auto_setup_scope != NULL); |
268 *auto_setup_scope = true; | 253 *auto_setup_scope = true; |
269 const char* cstr = NULL; | 254 const char* cstr = NULL; |
270 Dart_Handle result = Dart_StringToCString(name, &cstr); | 255 Dart_Handle result = Dart_StringToCString(name, &cstr); |
271 EXPECT_VALID(result); | 256 EXPECT_VALID(result); |
272 if (strcmp(cstr, "init") == 0) { | 257 if (strcmp(cstr, "init") == 0) { |
273 return InitNativeFields; | 258 return InitNativeFields; |
274 } else { | 259 } else { |
275 return UseDartApi; | 260 return UseDartApi; |
276 } | 261 } |
277 } | 262 } |
278 | 263 |
279 | |
280 BENCHMARK(UseDartApi) { | 264 BENCHMARK(UseDartApi) { |
281 const int kNumIterations = 1000000; | 265 const int kNumIterations = 1000000; |
282 const char* kScriptChars = | 266 const char* kScriptChars = |
283 "class Class extends NativeFieldsWrapper{\n" | 267 "class Class extends NativeFieldsWrapper{\n" |
284 " int init() native 'init';\n" | 268 " int init() native 'init';\n" |
285 " int method(int param1, int param2) native 'method';\n" | 269 " int method(int param1, int param2) native 'method';\n" |
286 "}\n" | 270 "}\n" |
287 "\n" | 271 "\n" |
288 "void benchmark(int count) {\n" | 272 "void benchmark(int count) {\n" |
289 " Class c = new Class();\n" | 273 " Class c = new Class();\n" |
(...skipping 21 matching lines...) Expand all Loading... |
311 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 295 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
312 | 296 |
313 Timer timer(true, "UseDartApi benchmark"); | 297 Timer timer(true, "UseDartApi benchmark"); |
314 timer.Start(); | 298 timer.Start(); |
315 Dart_Invoke(lib, NewString("benchmark"), 1, args); | 299 Dart_Invoke(lib, NewString("benchmark"), 1, args); |
316 timer.Stop(); | 300 timer.Stop(); |
317 int64_t elapsed_time = timer.TotalElapsedTime(); | 301 int64_t elapsed_time = timer.TotalElapsedTime(); |
318 benchmark->set_score(elapsed_time); | 302 benchmark->set_score(elapsed_time); |
319 } | 303 } |
320 | 304 |
321 | |
322 // | 305 // |
323 // Measure time accessing internal and external strings. | 306 // Measure time accessing internal and external strings. |
324 // | 307 // |
325 BENCHMARK(DartStringAccess) { | 308 BENCHMARK(DartStringAccess) { |
326 const int kNumIterations = 10000000; | 309 const int kNumIterations = 10000000; |
327 Timer timer(true, "DartStringAccess benchmark"); | 310 Timer timer(true, "DartStringAccess benchmark"); |
328 timer.Start(); | 311 timer.Start(); |
329 Dart_EnterScope(); | 312 Dart_EnterScope(); |
330 | 313 |
331 // Create strings. | 314 // Create strings. |
(...skipping 18 matching lines...) Expand all Loading... |
350 EXPECT_EQ(4, str_len); | 333 EXPECT_EQ(4, str_len); |
351 EXPECT_EQ(&external_peer_data, external_peer); | 334 EXPECT_EQ(&external_peer_data, external_peer); |
352 } | 335 } |
353 | 336 |
354 Dart_ExitScope(); | 337 Dart_ExitScope(); |
355 timer.Stop(); | 338 timer.Stop(); |
356 int64_t elapsed_time = timer.TotalElapsedTime(); | 339 int64_t elapsed_time = timer.TotalElapsedTime(); |
357 benchmark->set_score(elapsed_time); | 340 benchmark->set_score(elapsed_time); |
358 } | 341 } |
359 | 342 |
360 | |
361 BENCHMARK(Dart2JSCompileAll) { | 343 BENCHMARK(Dart2JSCompileAll) { |
362 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 344 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
363 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 345 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
364 SetupDart2JSPackagePath(); | 346 SetupDart2JSPackagePath(); |
365 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 347 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
366 char* script = NULL; | 348 char* script = NULL; |
367 if (dart_root != NULL) { | 349 if (dart_root != NULL) { |
368 HANDLESCOPE(thread); | 350 HANDLESCOPE(thread); |
369 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", | 351 script = OS::SCreate(NULL, "import '%s/pkg/compiler/lib/compiler.dart';", |
370 dart_root); | 352 dart_root); |
(...skipping 17 matching lines...) Expand all Loading... |
388 FLAG_background_compilation = old_flag; | 370 FLAG_background_compilation = old_flag; |
389 #endif | 371 #endif |
390 EXPECT_VALID(result); | 372 EXPECT_VALID(result); |
391 timer.Stop(); | 373 timer.Stop(); |
392 int64_t elapsed_time = timer.TotalElapsedTime(); | 374 int64_t elapsed_time = timer.TotalElapsedTime(); |
393 benchmark->set_score(elapsed_time); | 375 benchmark->set_score(elapsed_time); |
394 free(dart_root); | 376 free(dart_root); |
395 free(script); | 377 free(script); |
396 } | 378 } |
397 | 379 |
398 | |
399 // | 380 // |
400 // Measure frame lookup during stack traversal. | 381 // Measure frame lookup during stack traversal. |
401 // | 382 // |
402 static void StackFrame_accessFrame(Dart_NativeArguments args) { | 383 static void StackFrame_accessFrame(Dart_NativeArguments args) { |
403 const int kNumIterations = 100; | 384 const int kNumIterations = 100; |
404 Code& code = Code::Handle(); | 385 Code& code = Code::Handle(); |
405 Timer timer(true, "LookupDartCode benchmark"); | 386 Timer timer(true, "LookupDartCode benchmark"); |
406 timer.Start(); | 387 timer.Start(); |
407 for (int i = 0; i < kNumIterations; i++) { | 388 for (int i = 0; i < kNumIterations; i++) { |
408 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, | 389 StackFrameIterator frames(StackFrameIterator::kDontValidateFrames, |
409 Thread::Current(), | 390 Thread::Current(), |
410 StackFrameIterator::kNoCrossThreadIteration); | 391 StackFrameIterator::kNoCrossThreadIteration); |
411 StackFrame* frame = frames.NextFrame(); | 392 StackFrame* frame = frames.NextFrame(); |
412 while (frame != NULL) { | 393 while (frame != NULL) { |
413 if (frame->IsStubFrame()) { | 394 if (frame->IsStubFrame()) { |
414 code = frame->LookupDartCode(); | 395 code = frame->LookupDartCode(); |
415 EXPECT(code.function() == Function::null()); | 396 EXPECT(code.function() == Function::null()); |
416 } else if (frame->IsDartFrame()) { | 397 } else if (frame->IsDartFrame()) { |
417 code = frame->LookupDartCode(); | 398 code = frame->LookupDartCode(); |
418 EXPECT(code.function() != Function::null()); | 399 EXPECT(code.function() != Function::null()); |
419 } | 400 } |
420 frame = frames.NextFrame(); | 401 frame = frames.NextFrame(); |
421 } | 402 } |
422 } | 403 } |
423 timer.Stop(); | 404 timer.Stop(); |
424 int64_t elapsed_time = timer.TotalElapsedTime(); | 405 int64_t elapsed_time = timer.TotalElapsedTime(); |
425 Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time)); | 406 Dart_SetReturnValue(args, Dart_NewInteger(elapsed_time)); |
426 } | 407 } |
427 | 408 |
428 | |
429 static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name, | 409 static Dart_NativeFunction StackFrameNativeResolver(Dart_Handle name, |
430 int arg_count, | 410 int arg_count, |
431 bool* auto_setup_scope) { | 411 bool* auto_setup_scope) { |
432 ASSERT(auto_setup_scope != NULL); | 412 ASSERT(auto_setup_scope != NULL); |
433 *auto_setup_scope = false; | 413 *auto_setup_scope = false; |
434 return &StackFrame_accessFrame; | 414 return &StackFrame_accessFrame; |
435 } | 415 } |
436 | 416 |
437 | |
438 // Unit test case to verify stack frame iteration. | 417 // Unit test case to verify stack frame iteration. |
439 BENCHMARK(FrameLookup) { | 418 BENCHMARK(FrameLookup) { |
440 const char* kScriptChars = | 419 const char* kScriptChars = |
441 "class StackFrame {" | 420 "class StackFrame {" |
442 " static int accessFrame() native \"StackFrame_accessFrame\";" | 421 " static int accessFrame() native \"StackFrame_accessFrame\";" |
443 "} " | 422 "} " |
444 "class First {" | 423 "class First {" |
445 " First() { }" | 424 " First() { }" |
446 " int method1(int param) {" | 425 " int method1(int param) {" |
447 " if (param == 1) {" | 426 " if (param == 1) {" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); | 459 reinterpret_cast<Dart_NativeEntryResolver>(StackFrameNativeResolver)); |
481 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); | 460 Dart_Handle cls = Dart_GetClass(lib, NewString("StackFrameTest")); |
482 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 461 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
483 EXPECT_VALID(result); | 462 EXPECT_VALID(result); |
484 int64_t elapsed_time = 0; | 463 int64_t elapsed_time = 0; |
485 result = Dart_IntegerToInt64(result, &elapsed_time); | 464 result = Dart_IntegerToInt64(result, &elapsed_time); |
486 EXPECT_VALID(result); | 465 EXPECT_VALID(result); |
487 benchmark->set_score(elapsed_time); | 466 benchmark->set_score(elapsed_time); |
488 } | 467 } |
489 | 468 |
490 | |
491 static uint8_t* malloc_allocator(uint8_t* ptr, | 469 static uint8_t* malloc_allocator(uint8_t* ptr, |
492 intptr_t old_size, | 470 intptr_t old_size, |
493 intptr_t new_size) { | 471 intptr_t new_size) { |
494 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); | 472 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); |
495 } | 473 } |
496 | 474 |
497 | |
498 static void malloc_deallocator(uint8_t* ptr) { | 475 static void malloc_deallocator(uint8_t* ptr) { |
499 free(ptr); | 476 free(ptr); |
500 } | 477 } |
501 | 478 |
502 | |
503 BENCHMARK_SIZE(CoreSnapshotSize) { | 479 BENCHMARK_SIZE(CoreSnapshotSize) { |
504 const char* kScriptChars = | 480 const char* kScriptChars = |
505 "import 'dart:async';\n" | 481 "import 'dart:async';\n" |
506 "import 'dart:core';\n" | 482 "import 'dart:core';\n" |
507 "import 'dart:collection';\n" | 483 "import 'dart:collection';\n" |
508 "import 'dart:_internal';\n" | 484 "import 'dart:_internal';\n" |
509 "import 'dart:math';\n" | 485 "import 'dart:math';\n" |
510 "import 'dart:isolate';\n" | 486 "import 'dart:isolate';\n" |
511 "import 'dart:mirrors';\n" | 487 "import 'dart:mirrors';\n" |
512 "import 'dart:typed_data';\n" | 488 "import 'dart:typed_data';\n" |
(...skipping 14 matching lines...) Expand all Loading... |
527 writer.WriteFullSnapshot(); | 503 writer.WriteFullSnapshot(); |
528 const Snapshot* snapshot = | 504 const Snapshot* snapshot = |
529 Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); | 505 Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); |
530 ASSERT(snapshot->kind() == Snapshot::kFull); | 506 ASSERT(snapshot->kind() == Snapshot::kFull); |
531 benchmark->set_score(snapshot->length()); | 507 benchmark->set_score(snapshot->length()); |
532 | 508 |
533 free(vm_snapshot_data_buffer); | 509 free(vm_snapshot_data_buffer); |
534 free(isolate_snapshot_data_buffer); | 510 free(isolate_snapshot_data_buffer); |
535 } | 511 } |
536 | 512 |
537 | |
538 BENCHMARK_SIZE(StandaloneSnapshotSize) { | 513 BENCHMARK_SIZE(StandaloneSnapshotSize) { |
539 const char* kScriptChars = | 514 const char* kScriptChars = |
540 "import 'dart:async';\n" | 515 "import 'dart:async';\n" |
541 "import 'dart:core';\n" | 516 "import 'dart:core';\n" |
542 "import 'dart:collection';\n" | 517 "import 'dart:collection';\n" |
543 "import 'dart:_internal';\n" | 518 "import 'dart:_internal';\n" |
544 "import 'dart:convert';\n" | 519 "import 'dart:convert';\n" |
545 "import 'dart:math';\n" | 520 "import 'dart:math';\n" |
546 "import 'dart:isolate';\n" | 521 "import 'dart:isolate';\n" |
547 "import 'dart:mirrors';\n" | 522 "import 'dart:mirrors';\n" |
(...skipping 17 matching lines...) Expand all Loading... |
565 writer.WriteFullSnapshot(); | 540 writer.WriteFullSnapshot(); |
566 const Snapshot* snapshot = | 541 const Snapshot* snapshot = |
567 Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); | 542 Snapshot::SetupFromBuffer(isolate_snapshot_data_buffer); |
568 ASSERT(snapshot->kind() == Snapshot::kFull); | 543 ASSERT(snapshot->kind() == Snapshot::kFull); |
569 benchmark->set_score(snapshot->length()); | 544 benchmark->set_score(snapshot->length()); |
570 | 545 |
571 free(vm_snapshot_data_buffer); | 546 free(vm_snapshot_data_buffer); |
572 free(isolate_snapshot_data_buffer); | 547 free(isolate_snapshot_data_buffer); |
573 } | 548 } |
574 | 549 |
575 | |
576 BENCHMARK(CreateMirrorSystem) { | 550 BENCHMARK(CreateMirrorSystem) { |
577 const char* kScriptChars = | 551 const char* kScriptChars = |
578 "import 'dart:mirrors';\n" | 552 "import 'dart:mirrors';\n" |
579 "\n" | 553 "\n" |
580 "void benchmark() {\n" | 554 "void benchmark() {\n" |
581 " currentMirrorSystem();\n" | 555 " currentMirrorSystem();\n" |
582 "}\n"; | 556 "}\n"; |
583 | 557 |
584 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 558 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
585 | 559 |
586 Timer timer(true, "currentMirrorSystem() benchmark"); | 560 Timer timer(true, "currentMirrorSystem() benchmark"); |
587 timer.Start(); | 561 timer.Start(); |
588 Dart_Invoke(lib, NewString("benchmark"), 0, NULL); | 562 Dart_Invoke(lib, NewString("benchmark"), 0, NULL); |
589 timer.Stop(); | 563 timer.Stop(); |
590 int64_t elapsed_time = timer.TotalElapsedTime(); | 564 int64_t elapsed_time = timer.TotalElapsedTime(); |
591 benchmark->set_score(elapsed_time); | 565 benchmark->set_score(elapsed_time); |
592 } | 566 } |
593 | 567 |
594 | |
595 BENCHMARK(EnterExitIsolate) { | 568 BENCHMARK(EnterExitIsolate) { |
596 const char* kScriptChars = | 569 const char* kScriptChars = |
597 "import 'dart:core';\n" | 570 "import 'dart:core';\n" |
598 "\n"; | 571 "\n"; |
599 const intptr_t kLoopCount = 1000000; | 572 const intptr_t kLoopCount = 1000000; |
600 TestCase::LoadTestScript(kScriptChars, NULL); | 573 TestCase::LoadTestScript(kScriptChars, NULL); |
601 Api::CheckAndFinalizePendingClasses(thread); | 574 Api::CheckAndFinalizePendingClasses(thread); |
602 Dart_Isolate isolate = Dart_CurrentIsolate(); | 575 Dart_Isolate isolate = Dart_CurrentIsolate(); |
603 Timer timer(true, "Enter and Exit isolate"); | 576 Timer timer(true, "Enter and Exit isolate"); |
604 timer.Start(); | 577 timer.Start(); |
605 for (intptr_t i = 0; i < kLoopCount; i++) { | 578 for (intptr_t i = 0; i < kLoopCount; i++) { |
606 Dart_ExitIsolate(); | 579 Dart_ExitIsolate(); |
607 Dart_EnterIsolate(isolate); | 580 Dart_EnterIsolate(isolate); |
608 } | 581 } |
609 timer.Stop(); | 582 timer.Stop(); |
610 int64_t elapsed_time = timer.TotalElapsedTime(); | 583 int64_t elapsed_time = timer.TotalElapsedTime(); |
611 benchmark->set_score(elapsed_time); | 584 benchmark->set_score(elapsed_time); |
612 } | 585 } |
613 | 586 |
614 | |
615 static uint8_t message_buffer[64]; | 587 static uint8_t message_buffer[64]; |
616 static uint8_t* message_allocator(uint8_t* ptr, | 588 static uint8_t* message_allocator(uint8_t* ptr, |
617 intptr_t old_size, | 589 intptr_t old_size, |
618 intptr_t new_size) { | 590 intptr_t new_size) { |
619 return message_buffer; | 591 return message_buffer; |
620 } | 592 } |
621 static void message_deallocator(uint8_t* ptr) {} | 593 static void message_deallocator(uint8_t* ptr) {} |
622 | 594 |
623 | |
624 BENCHMARK(SerializeNull) { | 595 BENCHMARK(SerializeNull) { |
625 const Object& null_object = Object::Handle(); | 596 const Object& null_object = Object::Handle(); |
626 const intptr_t kLoopCount = 1000000; | 597 const intptr_t kLoopCount = 1000000; |
627 uint8_t* buffer; | 598 uint8_t* buffer; |
628 Timer timer(true, "Serialize Null"); | 599 Timer timer(true, "Serialize Null"); |
629 timer.Start(); | 600 timer.Start(); |
630 for (intptr_t i = 0; i < kLoopCount; i++) { | 601 for (intptr_t i = 0; i < kLoopCount; i++) { |
631 StackZone zone(thread); | 602 StackZone zone(thread); |
632 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, | 603 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, |
633 true); | 604 true); |
634 writer.WriteMessage(null_object); | 605 writer.WriteMessage(null_object); |
635 intptr_t buffer_len = writer.BytesWritten(); | 606 intptr_t buffer_len = writer.BytesWritten(); |
636 | 607 |
637 // Read object back from the snapshot. | 608 // Read object back from the snapshot. |
638 MessageSnapshotReader reader(buffer, buffer_len, thread); | 609 MessageSnapshotReader reader(buffer, buffer_len, thread); |
639 reader.ReadObject(); | 610 reader.ReadObject(); |
640 } | 611 } |
641 timer.Stop(); | 612 timer.Stop(); |
642 int64_t elapsed_time = timer.TotalElapsedTime(); | 613 int64_t elapsed_time = timer.TotalElapsedTime(); |
643 benchmark->set_score(elapsed_time); | 614 benchmark->set_score(elapsed_time); |
644 } | 615 } |
645 | 616 |
646 | |
647 BENCHMARK(SerializeSmi) { | 617 BENCHMARK(SerializeSmi) { |
648 const Integer& smi_object = Integer::Handle(Smi::New(42)); | 618 const Integer& smi_object = Integer::Handle(Smi::New(42)); |
649 const intptr_t kLoopCount = 1000000; | 619 const intptr_t kLoopCount = 1000000; |
650 uint8_t* buffer; | 620 uint8_t* buffer; |
651 Timer timer(true, "Serialize Smi"); | 621 Timer timer(true, "Serialize Smi"); |
652 timer.Start(); | 622 timer.Start(); |
653 for (intptr_t i = 0; i < kLoopCount; i++) { | 623 for (intptr_t i = 0; i < kLoopCount; i++) { |
654 StackZone zone(thread); | 624 StackZone zone(thread); |
655 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, | 625 MessageWriter writer(&buffer, &message_allocator, &message_deallocator, |
656 true); | 626 true); |
657 writer.WriteMessage(smi_object); | 627 writer.WriteMessage(smi_object); |
658 intptr_t buffer_len = writer.BytesWritten(); | 628 intptr_t buffer_len = writer.BytesWritten(); |
659 | 629 |
660 // Read object back from the snapshot. | 630 // Read object back from the snapshot. |
661 MessageSnapshotReader reader(buffer, buffer_len, thread); | 631 MessageSnapshotReader reader(buffer, buffer_len, thread); |
662 reader.ReadObject(); | 632 reader.ReadObject(); |
663 } | 633 } |
664 timer.Stop(); | 634 timer.Stop(); |
665 int64_t elapsed_time = timer.TotalElapsedTime(); | 635 int64_t elapsed_time = timer.TotalElapsedTime(); |
666 benchmark->set_score(elapsed_time); | 636 benchmark->set_score(elapsed_time); |
667 } | 637 } |
668 | 638 |
669 | |
670 BENCHMARK(SimpleMessage) { | 639 BENCHMARK(SimpleMessage) { |
671 TransitionNativeToVM transition(thread); | 640 TransitionNativeToVM transition(thread); |
672 const Array& array_object = Array::Handle(Array::New(2)); | 641 const Array& array_object = Array::Handle(Array::New(2)); |
673 array_object.SetAt(0, Integer::Handle(Smi::New(42))); | 642 array_object.SetAt(0, Integer::Handle(Smi::New(42))); |
674 array_object.SetAt(1, Object::Handle()); | 643 array_object.SetAt(1, Object::Handle()); |
675 const intptr_t kLoopCount = 1000000; | 644 const intptr_t kLoopCount = 1000000; |
676 uint8_t* buffer; | 645 uint8_t* buffer; |
677 Timer timer(true, "Simple Message"); | 646 Timer timer(true, "Simple Message"); |
678 timer.Start(); | 647 timer.Start(); |
679 for (intptr_t i = 0; i < kLoopCount; i++) { | 648 for (intptr_t i = 0; i < kLoopCount; i++) { |
680 StackZone zone(thread); | 649 StackZone zone(thread); |
681 MessageWriter writer(&buffer, &malloc_allocator, &malloc_deallocator, true); | 650 MessageWriter writer(&buffer, &malloc_allocator, &malloc_deallocator, true); |
682 writer.WriteMessage(array_object); | 651 writer.WriteMessage(array_object); |
683 intptr_t buffer_len = writer.BytesWritten(); | 652 intptr_t buffer_len = writer.BytesWritten(); |
684 | 653 |
685 // Read object back from the snapshot. | 654 // Read object back from the snapshot. |
686 MessageSnapshotReader reader(buffer, buffer_len, thread); | 655 MessageSnapshotReader reader(buffer, buffer_len, thread); |
687 reader.ReadObject(); | 656 reader.ReadObject(); |
688 free(buffer); | 657 free(buffer); |
689 } | 658 } |
690 timer.Stop(); | 659 timer.Stop(); |
691 int64_t elapsed_time = timer.TotalElapsedTime(); | 660 int64_t elapsed_time = timer.TotalElapsedTime(); |
692 benchmark->set_score(elapsed_time); | 661 benchmark->set_score(elapsed_time); |
693 } | 662 } |
694 | 663 |
695 | |
696 BENCHMARK(LargeMap) { | 664 BENCHMARK(LargeMap) { |
697 const char* kScript = | 665 const char* kScript = |
698 "makeMap() {\n" | 666 "makeMap() {\n" |
699 " Map m = {};\n" | 667 " Map m = {};\n" |
700 " for (int i = 0; i < 100000; ++i) m[i*13+i*(i>>7)] = i;\n" | 668 " for (int i = 0; i < 100000; ++i) m[i*13+i*(i>>7)] = i;\n" |
701 " return m;\n" | 669 " return m;\n" |
702 "}"; | 670 "}"; |
703 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 671 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
704 EXPECT_VALID(h_lib); | 672 EXPECT_VALID(h_lib); |
705 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); | 673 Dart_Handle h_result = Dart_Invoke(h_lib, NewString("makeMap"), 0, NULL); |
(...skipping 13 matching lines...) Expand all Loading... |
719 // Read object back from the snapshot. | 687 // Read object back from the snapshot. |
720 MessageSnapshotReader reader(buffer, buffer_len, thread); | 688 MessageSnapshotReader reader(buffer, buffer_len, thread); |
721 reader.ReadObject(); | 689 reader.ReadObject(); |
722 free(buffer); | 690 free(buffer); |
723 } | 691 } |
724 timer.Stop(); | 692 timer.Stop(); |
725 int64_t elapsed_time = timer.TotalElapsedTime(); | 693 int64_t elapsed_time = timer.TotalElapsedTime(); |
726 benchmark->set_score(elapsed_time); | 694 benchmark->set_score(elapsed_time); |
727 } | 695 } |
728 | 696 |
729 | |
730 BENCHMARK_MEMORY(InitialRSS) { | 697 BENCHMARK_MEMORY(InitialRSS) { |
731 benchmark->set_score(OS::MaxRSS()); | 698 benchmark->set_score(OS::MaxRSS()); |
732 } | 699 } |
733 | 700 |
734 } // namespace dart | 701 } // namespace dart |
OLD | NEW |