Skip to content

Commit

Permalink
Switch to using precompiled snapshots on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde committed Oct 23, 2015
1 parent db8dc93 commit d6ff8e9
Show file tree
Hide file tree
Showing 24 changed files with 278 additions and 108 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vars = {

# Note: When updating the Dart revision, ensure that all entries that are
# dependencies of dart are also updated
'dart_revision': '6aab1cecb25f8e04087320f2082336073628afb4',
'dart_revision': '2da9b9ce0a786c9dc7742a1045ed5b326c73076d',
'dart_observatory_packages_revision': '5c199c5954146747f75ed127871207718dc87786',
'dart_root_certificates_revision': 'c3a41df63afacec62fcb8135196177e35fe72f71',

Expand Down
2 changes: 1 addition & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ declare_args() {
# depending on the application type, may be unnecessary. If the type of
# architecture is known beforehand, setting that as the active arch will
# greatly reduce build times and reduce binary sizes.
ios_active_arch = "armv7"
ios_active_arch = "arm64"
}

# default_include_dirs ---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion sky/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ group("sky") {
"//sky/engine/wtf:unittests($host_toolchain)",
"//examples",
"//sky/tools/imagediff($host_toolchain)",
"//sky/tools/sky_snapshot($host_toolchain)",
":sky_dev",
]

Expand Down
5 changes: 5 additions & 0 deletions sky/build/flx.gni
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ template("flx") {
"--output-file", rebase_path(bundle, root_build_dir),
]

if(is_ios) {
# This makes the tools bypass the script snapshot compiler
args += [ "--precompiled" ]
}

if (defined(invoker.manifest)) {
inputs += [ invoker.manifest ]
args += [
Expand Down
8 changes: 8 additions & 0 deletions sky/build/sky_app.gni
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ template("sky_app") {
} else if (is_ios && defined(invoker.info_plist)) {
import("//build/config/ios/rules.gni")
import("//build/config/ios/ios_sdk.gni")
import("//sky/engine/bindings/bindings.gni")

ios_app(target_name) {
app_name = target_name + "_app"
Expand Down Expand Up @@ -124,10 +125,17 @@ template("sky_app") {
deps = [ ":app" ]
}

precompiled_gen_target = target_name + "_precompiled"
dart_precompile(precompiled_gen_target) {
dart_package_root = rebase_path("packages", root_build_dir)
dart_script = invoker.main_dart
}

deps = [
"//sky/shell:ios_scaffolding",
":$resources_gen_target_name",
":$flx_target_name",
":$precompiled_gen_target",
]

if (defined(invoker.deps)) {
Expand Down
7 changes: 5 additions & 2 deletions sky/dist/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ copy("sky_shell") {
deps = [
"//sky/shell",
]
} else if (is_ios || is_mac) {
} else if (is_mac) {
sources = [
"$root_build_dir/SkyShell.app",
]

deps = [
"//sky/shell:shell_struct",
]
} else {
} else if(!is_ios) {
sources = [
"$root_build_dir/sky_shell",
"$root_build_dir/icudtl.dat",
Expand All @@ -45,6 +45,9 @@ copy("sky_shell") {
"//sky/shell",
"//third_party/icu:icudata",
]
} else {
sources = []
deps = []
}

sky_snapshot_dir =
Expand Down
13 changes: 11 additions & 2 deletions sky/engine/bindings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ source_set("bindings") {
"//sky/engine/tonic",
"//sky/engine/wtf",
":generated_bindings",
":snapshot_cc",
":updater_snapshot_cc",
]

# On iOS, precompiled snapshots contain the instruction buffer. Generation
# of the same requires all application specific script code to be specified
# up front. In such cases, there can be no updater or generic snapshotter
if (!is_ios) {
deps += [
":snapshot_cc",
":updater_snapshot_cc",
]
}

include_dirs = [
"..",
"$root_build_dir",
Expand Down
115 changes: 115 additions & 0 deletions sky/engine/bindings/bindings.gni
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,118 @@ idl_compiler_files = [
"scripts/v8_types.py",
"scripts/v8_utilities.py",
]

template("dart_precompile") {
assert(defined(invoker.dart_package_root),
"The dart package root must be defined")
assert(defined(invoker.dart_script),
"The dart script must be specified")

vm_isolate_snapshot_name = target_name + "_vm_isolate.bin"
vm_isolate_snapshot = "$target_gen_dir/$vm_isolate_snapshot_name"
isolate_snapshot_name = target_name + "_isolate.bin"
isolate_snapshot = "$target_gen_dir/$isolate_snapshot_name"

assembly_path =
"$target_gen_dir/" + target_name + "_instructions.S"
instructions_gen_target_name = target_name + "_instructions"
action(instructions_gen_target_name) {
deps = [
"//dart/runtime/bin:gen_snapshot($host_toolchain)",
]
embedder_entry_points_manifest =
"//sky/engine/bindings/dart_vm_entry_points.txt"
inputs = [
"//dart/runtime/tools/create_snapshot_bin.py",
"//mojo/public/dart/mojo/sdk_ext/internal.dart",
"//mojo/public/dart/mojo/sdk_ext/src/handle_watcher.dart",
"//mojo/public/dart/mojo/sdk_ext/src/natives.dart",
"//mojo/public/dart/mojo/sdk_ext/src/timer_queue.dart",
"//sky/engine/bindings/internals.dart",
embedder_entry_points_manifest,
]
outputs = [
vm_isolate_snapshot,
isolate_snapshot,
assembly_path
]

dart_mojo_internal_path =
rebase_path("//mojo/public/dart/mojo/sdk_ext/internal.dart")
dart_ui_internals_path =
rebase_path("//sky/engine/bindings/internals.dart")
dart_ui_path =
rebase_path("$root_build_dir/clang_x64/gen/sky/bindings/dart_ui.dart")

gen_snapshot_dir =
get_label_info("//dart/runtime/bin:gen_snapshot($host_toolchain)",
"root_out_dir")
script = "//dart/runtime/tools/create_snapshot_bin.py"

args = [
"--executable",
rebase_path("$gen_snapshot_dir/gen_snapshot"),
"--package_root",
rebase_path(invoker.dart_package_root, root_build_dir),
"--script",
rebase_path(invoker.dart_script, root_build_dir),
"--vm_output_bin",
rebase_path(vm_isolate_snapshot, root_build_dir),
"--output_bin",
rebase_path(isolate_snapshot, root_build_dir),
"--instructions_bin",
rebase_path(assembly_path, root_build_dir),
"--embedder_entry_points_manifest",
rebase_path(embedder_entry_points_manifest, root_build_dir),
"--target_os",
target_os,
"--url_mapping=dart:mojo.internal,$dart_mojo_internal_path",
"--url_mapping=dart:ui,$dart_ui_path",
"--url_mapping=dart:ui_internals,$dart_ui_internals_path",
]
}

snapshot_cc = "$target_gen_dir/" + target_name + "_precompiled_snapshot.cc"
snapshot_cc_gen_target_name = target_name + "_snapshot_cc"
action(snapshot_cc_gen_target_name) {
deps = [
":$instructions_gen_target_name",
]

template_file = "//sky/engine/bindings/snapshot.cc.tmpl"

inputs = [
template_file,
vm_isolate_snapshot,
isolate_snapshot,
]

outputs = [
snapshot_cc,
]

script = "//dart/runtime/tools/create_snapshot_file.py"
args = [
"--vm_input_bin",
rebase_path(vm_isolate_snapshot, root_build_dir),
"--input_bin",
rebase_path(isolate_snapshot, root_build_dir),
"--input_cc",
rebase_path(template_file, root_build_dir),
"--output",
rebase_path(snapshot_cc),
]
}

source_set(target_name) {
sources = [
assembly_path,
snapshot_cc,
]

deps = [
":$instructions_gen_target_name",
":$snapshot_cc_gen_target_name",
]
}
}
2 changes: 2 additions & 0 deletions sky/engine/bindings/dart_natives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ static void InitDartInternal(Dart_Handle builtin_library,
} else {
CHECK(isolate_type == DartNatives::DartIOIsolate);
Dart_Handle io_lib = DartBuiltin::LookupLibrary("dart:io");
DART_CHECK_VALID(io_lib);
Dart_Handle setup_hooks = Dart_NewStringFromCString("_setupHooks");
DART_CHECK_VALID(Dart_Invoke(io_lib, setup_hooks, 0, NULL));
Dart_Handle isolate_lib = DartBuiltin::LookupLibrary("dart:isolate");
DART_CHECK_VALID(isolate_lib);
DART_CHECK_VALID(Dart_Invoke(isolate_lib, setup_hooks, 0, NULL));
}
}
Expand Down
59 changes: 59 additions & 0 deletions sky/engine/bindings/dart_vm_entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
dart:io,::,_setupHooks
dart:mojo.internal,MojoHandleWatcher,_start
dart:ui,::,_getCreateTimerClosure
dart:ui,::,_getGetBaseURLClosure
dart:ui,::,_getMainClosure
dart:ui,::,_getPrintClosure
dart:ui,::,_getScheduleMicrotaskClosure
dart:ui,Canvas,Canvas.
dart:ui,CharacterData,CharacterData.
dart:ui,ClientRect,ClientRect.
dart:ui,ClientRectList,ClientRectList.
dart:ui,CSSStyleDeclaration,CSSStyleDeclaration.
dart:ui,Document,Document.
dart:ui,DocumentFragment,DocumentFragment.
dart:ui,DOMError,DOMError.
dart:ui,DOMException,DOMException.
dart:ui,Drawable,Drawable.
dart:ui,DrawLooper,DrawLooper.
dart:ui,DrawLooperLayerInfo,DrawLooperLayerInfo.
dart:ui,Element,Element.
dart:ui,Event,Event.
dart:ui,Event,Event.
dart:ui,GestureVelocity,GestureVelocity.
dart:ui,HTMLElement,HTMLElement.
dart:ui,Image,Image.
dart:ui,ImageData,ImageData.
dart:ui,ImageShader,ImageShader.
dart:ui,KeyboardEvent,KeyboardEvent.
dart:ui,KeyboardEvent,KeyboardEvent.
dart:ui,LayerDrawLooperBuilder,LayerDrawLooperBuilder.
dart:ui,LayoutRoot,LayoutRoot.
dart:ui,Node,Node.
dart:ui,Paragraph,Paragraph.
dart:ui,ParagraphBuilder,ParagraphBuilder.
dart:ui,ParagraphStyle,ParagraphStyle.
dart:ui,ParentNode,ParentNode.
dart:ui,Path,Path.
dart:ui,Picture,Picture.
dart:ui,PictureRecorder,PictureRecorder.
dart:ui,PointerEvent,PointerEvent.
dart:ui,PointerEvent,PointerEvent.
dart:ui,Range,Range.
dart:ui,RRect,RRect.
dart:ui,Scene,Scene.
dart:ui,SceneBuilder,SceneBuilder.
dart:ui,Shader,Shader.
dart:ui,Text,Text.
dart:ui,TextMetrics,TextMetrics.
dart:ui,TextStyle,TextStyle.
dart:ui,Tracing,Tracing.
dart:ui,VelocityTracker,VelocityTracker.
dart:ui,View,View.
dart:ui,WheelEvent,WheelEvent.
dart:ui,WheelEvent,WheelEvent.
dart:ui_internals,::,takeRootBundleHandle
dart:ui_internals,::,takeServiceRegistry
dart:ui_internals,::,takeServicesProvidedByEmbedder
dart:ui_internals,::,takeServicesProvidedToEmbedder
dart:ui_internals,::,takeShellProxyHandle
1 change: 0 additions & 1 deletion sky/engine/bindings/snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:io';
import 'dart:isolate';
import 'dart:math';
import 'dart:mojo.internal';
import 'dart:mirrors';
import 'dart:ui';
import 'dart:ui_internals';
import 'dart:typed_data';
7 changes: 7 additions & 0 deletions sky/engine/core/dart/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ _getPrintClosure() => _print;
_getScheduleMicrotaskClosure() => _scheduleMicrotask;
_getGetBaseURLClosure() =>_getBaseURL;
_getCreateTimerClosure() => _createTimer;

// Though the "main" symbol is not included in any of the libraries imported
// above, the builtin library will be included manually during VM setup. This
// symbol is only necessary for precompilation. It is marked as a stanalone
// entry point into the VM. This prevents the precompiler from tree shaking
// away "main"
_getMainClosure() => main;
7 changes: 5 additions & 2 deletions sky/engine/core/script/dart_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ void DartController::DidLoadSnapshot() {
DartApiScope dart_api_scope;

Dart_Handle library = Dart_RootLibrary();
if (LogIfError(library))
return;
DART_CHECK_VALID(library);
DartInvokeAppField(library, ToDart("main"), 0, nullptr);
}

void DartController::RunFromPrecompiledSnapshot() {
DidLoadSnapshot();
}

void DartController::RunFromSnapshot(
mojo::ScopedDataPipeConsumerHandle snapshot) {
snapshot_loader_ = adoptPtr(new DartSnapshotLoader(dart_state()));
Expand Down
1 change: 1 addition & 0 deletions sky/engine/core/script/dart_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DartController {

void RunFromLibrary(const String& name,
DartLibraryProvider* library_provider);
void RunFromPrecompiledSnapshot();
void RunFromSnapshot(mojo::ScopedDataPipeConsumerHandle snapshot);
void RunFromSnapshotBuffer(const uint8_t* buffer, size_t size);

Expand Down
Loading

0 comments on commit d6ff8e9

Please sign in to comment.