Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: runtime/vm/benchmark_test.cc

Issue 1663963002: - reorganize DartUtils::PrepareForScriptLoading so that it does not have the wait for service load … (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 9
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 dart2js_path = NULL; 271 dart2js_path = NULL;
272 } 272 }
273 return dart2js_path; 273 return dart2js_path;
274 } 274 }
275 275
276 276
277 static void func(Dart_NativeArguments args) { 277 static void func(Dart_NativeArguments args) {
278 } 278 }
279 279
280 280
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, 281 static Dart_NativeFunction NativeResolver(Dart_Handle name,
344 int arg_count, 282 int arg_count,
345 bool* auto_setup_scope) { 283 bool* auto_setup_scope) {
346 ASSERT(auto_setup_scope != NULL); 284 ASSERT(auto_setup_scope != NULL);
347 *auto_setup_scope = false; 285 *auto_setup_scope = false;
348 return &func; 286 return &func;
349 } 287 }
350 288
351 static void SetupDart2JSPackagePath() { 289 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(); 290 bool worked = bin::DartUtils::SetOriginalWorkingDirectory();
357 EXPECT(worked); 291 EXPECT(worked);
292
293 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(false, false);
294 DART_CHECK_VALID(result);
295
296 // Setup package root.
358 char buffer[2048]; 297 char buffer[2048];
359 char* executable_path = 298 char* executable_path =
360 strdup(File::GetCanonicalPath(Benchmark::Executable())); 299 strdup(File::GetCanonicalPath(Benchmark::Executable()));
361 const char* packages_path = "%s%s..%spackages"; 300 const char* packages_path = "%s%s..%spackages";
362 const char* path_separator = File::PathSeparator(); 301 const char* path_separator = File::PathSeparator();
363 OS::SNPrint(buffer, 2048, packages_path, 302 OS::SNPrint(buffer, 2048, packages_path,
364 executable_path, path_separator, path_separator); 303 executable_path, path_separator, path_separator);
365 Dart_Handle result = PreparePackageRoot(buffer, builtin_lib); 304 result = bin::DartUtils::SetupPackageRoot(buffer, NULL);
366 DART_CHECK_VALID(result); 305 DART_CHECK_VALID(result);
367 } 306 }
368 307
369 BENCHMARK(Dart2JSCompileAll) { 308 BENCHMARK(Dart2JSCompileAll) {
370 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); 309 bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary);
371 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); 310 bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary);
372 SetupDart2JSPackagePath(); 311 SetupDart2JSPackagePath();
373 char* dart_root = ComputeDart2JSPath(Benchmark::Executable()); 312 char* dart_root = ComputeDart2JSPath(Benchmark::Executable());
374 char* script = NULL; 313 char* script = NULL;
375 if (dart_root != NULL) { 314 if (dart_root != NULL) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 thread); 690 thread);
752 reader.ReadObject(); 691 reader.ReadObject();
753 free(buffer); 692 free(buffer);
754 } 693 }
755 timer.Stop(); 694 timer.Stop();
756 int64_t elapsed_time = timer.TotalElapsedTime(); 695 int64_t elapsed_time = timer.TotalElapsedTime();
757 benchmark->set_score(elapsed_time); 696 benchmark->set_score(elapsed_time);
758 } 697 }
759 698
760 } // namespace dart 699 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/benchmark_test.h ('k') | runtime/vm/unit_test.h » ('j') | runtime/vm/unit_test.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698