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 | 10 |
10 #include "platform/assert.h" | 11 #include "platform/assert.h" |
11 #include "platform/globals.h" | 12 #include "platform/globals.h" |
12 | 13 |
13 #include "vm/compiler_stats.h" | 14 #include "vm/compiler_stats.h" |
14 #include "vm/dart_api_impl.h" | 15 #include "vm/dart_api_impl.h" |
15 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
16 #include "vm/unit_test.h" | 17 #include "vm/unit_test.h" |
17 | 18 |
18 using dart::bin::File; | 19 using dart::bin::File; |
19 | 20 |
20 namespace dart { | 21 namespace dart { |
21 | 22 |
22 Benchmark* Benchmark::first_ = NULL; | 23 Benchmark* Benchmark::first_ = NULL; |
23 Benchmark* Benchmark::tail_ = NULL; | 24 Benchmark* Benchmark::tail_ = NULL; |
24 const char* Benchmark::executable_ = NULL; | 25 const char* Benchmark::executable_ = NULL; |
25 | 26 |
26 void Benchmark::RunAll(const char* executable) { | 27 void Benchmark::RunAll(const char* executable) { |
27 SetExecutable(executable); | 28 SetExecutable(executable); |
28 Benchmark* benchmark = first_; | 29 Benchmark* benchmark = first_; |
29 while (benchmark != NULL) { | 30 while (benchmark != NULL) { |
30 benchmark->RunBenchmark(); | 31 benchmark->RunBenchmark(); |
31 benchmark = benchmark->next_; | 32 benchmark = benchmark->next_; |
32 } | 33 } |
33 } | 34 } |
34 | 35 |
35 | 36 |
| 37 Dart_Isolate Benchmark::CreateIsolate(const uint8_t* buffer) { |
| 38 bin::IsolateData* isolate_data = new bin::IsolateData(NULL, NULL, NULL); |
| 39 char* err = NULL; |
| 40 isolate_ = Dart_CreateIsolate(NULL, NULL, buffer, NULL, isolate_data, &err); |
| 41 EXPECT(isolate_ != NULL); |
| 42 free(err); |
| 43 return isolate_; |
| 44 } |
| 45 |
| 46 |
36 // | 47 // |
37 // Measure compile of all functions in dart core lib classes. | 48 // Measure compile of all functions in dart core lib classes. |
38 // | 49 // |
39 BENCHMARK(CorelibCompileAll) { | 50 BENCHMARK(CorelibCompileAll) { |
40 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 51 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
41 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 52 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
42 TransitionNativeToVM transition(thread); | 53 TransitionNativeToVM transition(thread); |
43 Timer timer(true, "Compile all of Core lib benchmark"); | 54 Timer timer(true, "Compile all of Core lib benchmark"); |
44 timer.Start(); | 55 timer.Start(); |
45 const Error& error = Error::Handle(Library::CompileAll()); | 56 const Error& error = Error::Handle(Library::CompileAll()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 dart2js_path = NULL; | 282 dart2js_path = NULL; |
272 } | 283 } |
273 return dart2js_path; | 284 return dart2js_path; |
274 } | 285 } |
275 | 286 |
276 | 287 |
277 static void func(Dart_NativeArguments args) { | 288 static void func(Dart_NativeArguments args) { |
278 } | 289 } |
279 | 290 |
280 | 291 |
281 // Emulates DartUtils::PrepareForScriptLoading. | |
282 static Dart_Handle PreparePackageRoot(const char* package_root, | |
283 Dart_Handle builtin_lib) { | |
284 // First ensure all required libraries are available. | |
285 Dart_Handle url = NewString(bin::DartUtils::kCoreLibURL); | |
286 DART_CHECK_VALID(url); | |
287 Dart_Handle core_lib = Dart_LookupLibrary(url); | |
288 DART_CHECK_VALID(core_lib); | |
289 url = NewString(bin::DartUtils::kAsyncLibURL); | |
290 DART_CHECK_VALID(url); | |
291 Dart_Handle async_lib = Dart_LookupLibrary(url); | |
292 DART_CHECK_VALID(async_lib); | |
293 url = NewString(bin::DartUtils::kIsolateLibURL); | |
294 DART_CHECK_VALID(url); | |
295 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | |
296 DART_CHECK_VALID(isolate_lib); | |
297 url = NewString(bin::DartUtils::kInternalLibURL); | |
298 DART_CHECK_VALID(url); | |
299 Dart_Handle internal_lib = Dart_LookupLibrary(url); | |
300 DART_CHECK_VALID(internal_lib); | |
301 Dart_Handle io_lib = | |
302 bin::Builtin::LoadAndCheckLibrary(bin::Builtin::kIOLibrary); | |
303 DART_CHECK_VALID(io_lib); | |
304 | |
305 // We need to ensure that all the scripts loaded so far are finalized | |
306 // as we are about to invoke some Dart code below to setup closures. | |
307 Dart_Handle result = Dart_FinalizeLoading(false); | |
308 DART_CHECK_VALID(result); | |
309 | |
310 // Necessary parts from PrepareBuiltinLibrary. | |
311 // Setup the internal library's 'internalPrint' function. | |
312 result = Dart_Invoke(builtin_lib, NewString("_getPrintClosure"), 0, NULL); | |
313 DART_CHECK_VALID(result); | |
314 result = Dart_SetField(internal_lib, NewString("_printClosure"), result); | |
315 DART_CHECK_VALID(result); | |
316 #if defined(TARGET_OS_WINDOWS) | |
317 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | |
318 DART_CHECK_VALID(result); | |
319 #endif // defined(TARGET_OS_WINDOWS) | |
320 // Set current working directory. | |
321 result = bin::DartUtils::SetWorkingDirectory(builtin_lib); | |
322 DART_CHECK_VALID(result); | |
323 // Set the package root for builtin.dart. | |
324 result = NewString(package_root); | |
325 DART_CHECK_VALID(result); | |
326 const int kNumArgs = 1; | |
327 Dart_Handle dart_args[kNumArgs]; | |
328 dart_args[0] = result; | |
329 result = Dart_Invoke(builtin_lib, | |
330 NewString("_setPackageRoot"), | |
331 kNumArgs, | |
332 dart_args); | |
333 DART_CHECK_VALID(result); | |
334 | |
335 bin::DartUtils::PrepareAsyncLibrary(async_lib, isolate_lib); | |
336 bin::DartUtils::PrepareCoreLibrary(core_lib, builtin_lib, false); | |
337 bin::DartUtils::PrepareIsolateLibrary(isolate_lib); | |
338 bin::DartUtils::PrepareIOLibrary(io_lib); | |
339 return Dart_True(); | |
340 } | |
341 | |
342 | |
343 static Dart_NativeFunction NativeResolver(Dart_Handle name, | 292 static Dart_NativeFunction NativeResolver(Dart_Handle name, |
344 int arg_count, | 293 int arg_count, |
345 bool* auto_setup_scope) { | 294 bool* auto_setup_scope) { |
346 ASSERT(auto_setup_scope != NULL); | 295 ASSERT(auto_setup_scope != NULL); |
347 *auto_setup_scope = false; | 296 *auto_setup_scope = false; |
348 return &func; | 297 return &func; |
349 } | 298 } |
350 | 299 |
351 static void SetupDart2JSPackagePath() { | 300 static void SetupDart2JSPackagePath() { |
352 Dart_Handle builtin_lib = | |
353 bin::Builtin::LoadAndCheckLibrary(bin::Builtin::kBuiltinLibrary); | |
354 DART_CHECK_VALID(builtin_lib); | |
355 | |
356 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); | 301 bool worked = bin::DartUtils::SetOriginalWorkingDirectory(); |
357 EXPECT(worked); | 302 EXPECT(worked); |
| 303 |
| 304 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false); |
| 305 DART_CHECK_VALID(result); |
| 306 |
| 307 // Setup package root. |
358 char buffer[2048]; | 308 char buffer[2048]; |
359 char* executable_path = | 309 char* executable_path = |
360 strdup(File::GetCanonicalPath(Benchmark::Executable())); | 310 strdup(File::GetCanonicalPath(Benchmark::Executable())); |
361 const char* packages_path = "%s%s..%spackages"; | 311 const char* packages_path = "%s%s..%spackages"; |
362 const char* path_separator = File::PathSeparator(); | 312 const char* path_separator = File::PathSeparator(); |
363 OS::SNPrint(buffer, 2048, packages_path, | 313 OS::SNPrint(buffer, 2048, packages_path, |
364 executable_path, path_separator, path_separator); | 314 executable_path, path_separator, path_separator); |
365 Dart_Handle result = PreparePackageRoot(buffer, builtin_lib); | 315 result = bin::DartUtils::SetupPackageRoot(buffer, NULL); |
366 DART_CHECK_VALID(result); | 316 DART_CHECK_VALID(result); |
367 } | 317 } |
368 | 318 |
369 BENCHMARK(Dart2JSCompileAll) { | 319 BENCHMARK(Dart2JSCompileAll) { |
370 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); | 320 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); |
371 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); | 321 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); |
372 SetupDart2JSPackagePath(); | 322 SetupDart2JSPackagePath(); |
373 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); | 323 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); |
374 char* script = NULL; | 324 char* script = NULL; |
375 if (dart_root != NULL) { | 325 if (dart_root != NULL) { |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 thread); | 701 thread); |
752 reader.ReadObject(); | 702 reader.ReadObject(); |
753 free(buffer); | 703 free(buffer); |
754 } | 704 } |
755 timer.Stop(); | 705 timer.Stop(); |
756 int64_t elapsed_time = timer.TotalElapsedTime(); | 706 int64_t elapsed_time = timer.TotalElapsedTime(); |
757 benchmark->set_score(elapsed_time); | 707 benchmark->set_score(elapsed_time); |
758 } | 708 } |
759 | 709 |
760 } // namespace dart | 710 } // namespace dart |
OLD | NEW |