| 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 #ifndef VM_BENCHMARK_TEST_H_ | 5 #ifndef VM_BENCHMARK_TEST_H_ |
| 6 #define VM_BENCHMARK_TEST_H_ | 6 #define VM_BENCHMARK_TEST_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| 11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
| 12 #include "vm/heap.h" | 12 #include "vm/heap.h" |
| 13 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
| 14 #include "vm/object.h" | 14 #include "vm/object.h" |
| 15 #include "vm/unit_test.h" |
| 15 #include "vm/zone.h" | 16 #include "vm/zone.h" |
| 16 | 17 |
| 17 namespace dart { | 18 namespace dart { |
| 18 | 19 |
| 19 DECLARE_FLAG(int, code_heap_size); | 20 DECLARE_FLAG(int, code_heap_size); |
| 20 | 21 |
| 21 // The BENCHMARK macro is used for benchmarking a specific functionality | 22 // The BENCHMARK macro is used for benchmarking a specific functionality |
| 22 // of the VM | 23 // of the VM |
| 23 #define BENCHMARK(name) \ | 24 #define BENCHMARK(name) \ |
| 24 void Dart_Benchmark##name(Benchmark* benchmark); \ | 25 void Dart_Benchmark##name(Benchmark* benchmark); \ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 DISALLOW_COPY_AND_ASSIGN(Benchmark); | 88 DISALLOW_COPY_AND_ASSIGN(Benchmark); |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 | 91 |
| 91 class BenchmarkIsolateScope { | 92 class BenchmarkIsolateScope { |
| 92 public: | 93 public: |
| 93 explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) { | 94 explicit BenchmarkIsolateScope(Benchmark* benchmark) : benchmark_(benchmark) { |
| 94 benchmark_->CreateIsolate(NULL); | 95 benchmark_->CreateIsolate(NULL); |
| 95 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks. | 96 Dart_EnterScope(); // Create a Dart API scope for unit benchmarks. |
| 97 |
| 98 // Setup builtin library mock for 'print' in coreimpl. |
| 99 const char* builtin_source = |
| 100 "#library('dart:builtin');\n" |
| 101 "void print(Object o) { }"; |
| 102 Dart_Handle coreimpl = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); |
| 103 EXPECT_VALID(coreimpl); |
| 104 Dart_Handle builtin = Dart_LoadLibrary(Dart_NewString("dart:builtin"), |
| 105 Dart_NewString(builtin_source)); |
| 106 EXPECT_VALID(builtin); |
| 107 Dart_Handle imported = |
| 108 Dart_LibraryImportLibrary(coreimpl, builtin, Dart_NewString("builtin")); |
| 109 EXPECT_VALID(imported); |
| 96 } | 110 } |
| 97 ~BenchmarkIsolateScope() { | 111 ~BenchmarkIsolateScope() { |
| 98 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. | 112 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
| 99 ASSERT(benchmark_->isolate() == Isolate::Current()); | 113 ASSERT(benchmark_->isolate() == Isolate::Current()); |
| 100 Dart_ShutdownIsolate(); | 114 Dart_ShutdownIsolate(); |
| 101 benchmark_ = NULL; | 115 benchmark_ = NULL; |
| 102 } | 116 } |
| 103 Benchmark* benchmark() const { return benchmark_; } | 117 Benchmark* benchmark() const { return benchmark_; } |
| 104 | 118 |
| 105 private: | 119 private: |
| 106 Benchmark* benchmark_; | 120 Benchmark* benchmark_; |
| 107 | 121 |
| 108 DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope); | 122 DISALLOW_COPY_AND_ASSIGN(BenchmarkIsolateScope); |
| 109 }; | 123 }; |
| 110 | 124 |
| 111 } // namespace dart | 125 } // namespace dart |
| 112 | 126 |
| 113 #endif // VM_BENCHMARK_TEST_H_ | 127 #endif // VM_BENCHMARK_TEST_H_ |
| OLD | NEW |