From 3f8eddf34a5ffa494b870cd033c60f6701ab60f0 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 7 Jun 2017 09:57:24 -0700 Subject: [PATCH] Plumbing for a core snapshot with code (currently empty). (#3749) --- build/flutter_app.gni | 12 +++ build/script_snapshot.py | 8 +- lib/snapshot/BUILD.gn | 122 ++++++++++++++++++------ lib/snapshot/snapshot.c.tmpl | 29 ------ lib/snapshot/snapshot.h | 8 +- travis/licenses_golden/licenses_flutter | 1 - 6 files changed, 115 insertions(+), 65 deletions(-) delete mode 100644 lib/snapshot/snapshot.c.tmpl diff --git a/build/flutter_app.gni b/build/flutter_app.gni index b9e3f8bff..c3e42c0f9 100644 --- a/build/flutter_app.gni +++ b/build/flutter_app.gni @@ -75,8 +75,12 @@ template("flutter_app") { get_label_info(flutter_core_snapshot_label, "target_gen_dir") flutter_core_snapshot_vm_data = "$flutter_core_snapshot_gen_dir/vm_isolate_snapshot.bin" + flutter_core_snapshot_vm_instructions = + "$flutter_core_snapshot_gen_dir/vm_snapshot_instructions.bin" flutter_core_snapshot_isolate_data = "$flutter_core_snapshot_gen_dir/isolate_snapshot.bin" + flutter_core_snapshot_isolate_instructions = + "$flutter_core_snapshot_gen_dir/isolate_snapshot_instructions.bin" dot_packages = "$target_gen_dir/$dart_package_name.packages" bundle_path = "$target_gen_dir/$bundle_name" @@ -93,6 +97,10 @@ template("flutter_app") { inputs = [ main_dart, + flutter_core_snapshot_vm_data, + flutter_core_snapshot_vm_instructions, + flutter_core_snapshot_isolate_data, + flutter_core_snapshot_isolate_instructions, ] outputs = [ @@ -110,8 +118,12 @@ template("flutter_app") { rebase_path(gen_snapshot), "--vm-snapshot-data", rebase_path(flutter_core_snapshot_vm_data), + "--vm-snapshot-instructions", + rebase_path(flutter_core_snapshot_vm_instructions), "--isolate-snapshot-data", rebase_path(flutter_core_snapshot_isolate_data), + "--isolate-snapshot-instructions", + rebase_path(flutter_core_snapshot_isolate_instructions), "--main-dart", rebase_path(main_dart), "--packages", diff --git a/build/script_snapshot.py b/build/script_snapshot.py index 57df10f21..8eb24e940 100755 --- a/build/script_snapshot.py +++ b/build/script_snapshot.py @@ -16,8 +16,12 @@ def main(): help='The Flutter snapshotter') parser.add_argument('--vm-snapshot-data', type=str, required=True, help='Path to vm_isolate_snapshot.bin') + parser.add_argument('--vm-snapshot-instructions', type=str, required=True, + help='Path to vm_isolate_snapshot.bin') parser.add_argument('--isolate-snapshot-data', type=str, required=True, help='Path to isolate_snapshot.bin') + parser.add_argument('--isolate-snapshot-instructions', type=str, required=True, + help='Path to isolate_snapshot.bin') parser.add_argument('--main-dart', type=str, required=True, help='The main.dart file to use') parser.add_argument('--packages', type=str, required=True, @@ -35,11 +39,13 @@ def main(): args.snapshotter_path, '--snapshot_kind=script', '--vm_snapshot_data=%s' % args.vm_snapshot_data, + '--vm_snapshot_instructions=%s' % args.vm_snapshot_instructions, '--isolate_snapshot_data=%s' % args.isolate_snapshot_data, + '--isolate_snapshot_instructions=%s' % args.isolate_snapshot_instructions, '--packages=%s' % args.packages, '--script_snapshot=%s' % args.snapshot, '--dependencies=%s' % args.depfile, - args.main_dart, + args.main_dart ] result = subprocess.call(cmd, cwd=args.root_build_dir) diff --git a/lib/snapshot/BUILD.gn b/lib/snapshot/BUILD.gn index 6ba13bbbc..889076628 100644 --- a/lib/snapshot/BUILD.gn +++ b/lib/snapshot/BUILD.gn @@ -38,11 +38,16 @@ action("generate_snapshot_bin") { snapshot_dart, ] + dart_ui_files - vm_isolate_snapshot = "$target_gen_dir/vm_isolate_snapshot.bin" - isolate_snapshot = "$target_gen_dir/isolate_snapshot.bin" + vm_snapshot_data = "$target_gen_dir/vm_isolate_snapshot.bin" + vm_snapshot_instructions = "$target_gen_dir/vm_snapshot_instructions.bin" + isolate_snapshot_data = "$target_gen_dir/isolate_snapshot.bin" + isolate_snapshot_instructions = + "$target_gen_dir/isolate_snapshot_instructions.bin" outputs = [ - vm_isolate_snapshot, - isolate_snapshot, + vm_snapshot_data, + vm_snapshot_instructions, + isolate_snapshot_data, + isolate_snapshot_instructions, ] rebased_dart_ui_path = rebase_path(dart_ui_path) @@ -62,9 +67,13 @@ action("generate_snapshot_bin") { "--snapshot_kind", "core", "--vm_output_bin", - rebase_path(vm_isolate_snapshot, root_build_dir), + rebase_path(vm_snapshot_data, root_build_dir), + "--vm_instructions_output_bin", + rebase_path(vm_snapshot_instructions, root_build_dir), "--isolate_output_bin", - rebase_path(isolate_snapshot, root_build_dir), + rebase_path(isolate_snapshot_data, root_build_dir), + "--isolate_instructions_output_bin", + rebase_path(isolate_snapshot_instructions, root_build_dir), "--url_mapping=dart:ui,$rebased_dart_ui_path", ] @@ -79,40 +88,93 @@ action("generate_snapshot_bin") { } } -action("generate_snapshot_file") { +# Generates an assembly file defining a given symbol with the bytes from a +# binary file. Places the symbol in a text section if 'executable' is true, +# otherwise places the symbol in a read-only data section. +template("bin_to_assembly") { + assert(defined(invoker.deps), "Must define deps") + assert(defined(invoker.input), "Must define input binary file") + assert(defined(invoker.output), "Must define output assembly file") + assert(defined(invoker.symbol), "Must define symbol name") + assert(defined(invoker.executable), "Must define boolean executable") + + action(target_name) { + deps = invoker.deps + script = "//dart/runtime/tools/bin_to_assembly.py" + args = [ + "--input", + rebase_path(invoker.input), + "--output", + rebase_path(invoker.output), + "--symbol_name", + invoker.symbol, + "--target_os", + current_os, + ] + if (invoker.executable) { + args += [ "--executable" ] + } + inputs = [ + script, + invoker.input, + ] + outputs = [ + invoker.output, + ] + } +} + +bin_to_assembly("vm_snapshot_data_assembly") { deps = [ ":generate_snapshot_bin", ] - inputs = [ - "//dart/runtime/tools/create_snapshot_file.py", - "snapshot.c.tmpl", - "$target_gen_dir/vm_isolate_snapshot.bin", - "$target_gen_dir/isolate_snapshot.bin", - ] - output = "$target_gen_dir/snapshot.c" - outputs = [ - output, + input = "$target_gen_dir/vm_isolate_snapshot.bin" + output = "$target_gen_dir/vm_snapshot_data.S" + symbol = "kDartVmSnapshotData" + executable = false +} + +bin_to_assembly("vm_snapshot_instructions_assembly") { + deps = [ + ":generate_snapshot_bin", ] + input = "$target_gen_dir/vm_snapshot_instructions.bin" + output = "$target_gen_dir/vm_snapshot_instructions.S" + symbol = "kDartVmSnapshotInstructions" + executable = true +} - script = "//dart/runtime/tools/create_snapshot_file.py" - args = [ - "--vm_input_bin", - rebase_path("$target_gen_dir/vm_isolate_snapshot.bin"), - "--input_bin", - rebase_path("$target_gen_dir/isolate_snapshot.bin"), - "--input_cc", - rebase_path("snapshot.c.tmpl"), - "--output", - rebase_path(output), +bin_to_assembly("isolate_snapshot_data_assembly") { + deps = [ + ":generate_snapshot_bin", ] + input = "$target_gen_dir/isolate_snapshot.bin" + output = "$target_gen_dir/isolate_snapshot_data.S" + symbol = "kDartIsolateCoreSnapshotData" + executable = false } -source_set("snapshot") { - sources = [ - "$target_gen_dir/snapshot.c", +bin_to_assembly("isolate_snapshot_instructions_assembly") { + deps = [ + ":generate_snapshot_bin", ] + input = "$target_gen_dir/isolate_snapshot_instructions.bin" + output = "$target_gen_dir/isolate_snapshot_instructions.S" + symbol = "kDartIsolateCoreSnapshotInstructions" + executable = true +} +source_set("snapshot") { deps = [ - ":generate_snapshot_file", + ":isolate_snapshot_data_assembly", + ":isolate_snapshot_instructions_assembly", + ":vm_snapshot_data_assembly", + ":vm_snapshot_instructions_assembly", + ] + sources = [ + "$target_gen_dir/isolate_snapshot_data.S", + "$target_gen_dir/isolate_snapshot_instructions.S", + "$target_gen_dir/vm_snapshot_data.S", + "$target_gen_dir/vm_snapshot_instructions.S", ] } diff --git a/lib/snapshot/snapshot.c.tmpl b/lib/snapshot/snapshot.c.tmpl deleted file mode 100644 index 7b0fdba62..000000000 --- a/lib/snapshot/snapshot.c.tmpl +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include -#include -#include - -// The string on the next line will be filled in with the contents of the -// generated snapshot binary file for the vm isolate. -// This string forms the content of the dart vm isolate snapshot which -// is loaded into the vm isolate. -const uint8_t kDartVmSnapshotData_[] - __attribute__((aligned(8))) = { %s }; -const uint8_t* kDartVmSnapshotData - __attribute__((visibility("default"), used)) = kDartVmSnapshotData_; -const uint8_t* kDartVmSnapshotInstructions - __attribute__((visibility("default"), used)) = NULL; - -// The string on the next line will be filled in with the contents of the -// generated snapshot binary file for a regular dart isolate. -// This string forms the content of a regular dart isolate snapshot which -// is loaded into an isolate when it is created. -const uint8_t kDartIsolateCoreSnapshotData_[] - __attribute__((aligned(8))) = { %s }; -const uint8_t* kDartIsolateCoreSnapshotData - __attribute__((visibility("default"), used)) = kDartIsolateCoreSnapshotData_; -const uint8_t* kDartIsolateCoreSnapshotInstructions - __attribute__((visibility("default"), used)) = NULL; diff --git a/lib/snapshot/snapshot.h b/lib/snapshot/snapshot.h index f6ef1300e..3574207c9 100644 --- a/lib/snapshot/snapshot.h +++ b/lib/snapshot/snapshot.h @@ -7,8 +7,8 @@ #include extern "C" { -extern const uint8_t* kDartVmSnapshotData; -extern const uint8_t* kDartVmSnapshotInstructions; -extern const uint8_t* kDartIsolateCoreSnapshotData; -extern const uint8_t* kDartIsolateCoreSnapshotInstructions; +extern const uint8_t kDartVmSnapshotData[]; +extern const uint8_t kDartVmSnapshotInstructions[]; +extern const uint8_t kDartIsolateCoreSnapshotData[]; +extern const uint8_t kDartIsolateCoreSnapshotInstructions[]; } diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index fd9b1aec7..4fd155e7f 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -1528,7 +1528,6 @@ FILE: ../../../flutter/flow/layers/picture_layer.cc FILE: ../../../flutter/flow/layers/picture_layer.h FILE: ../../../flutter/flow/layers/transform_layer.cc FILE: ../../../flutter/flow/layers/transform_layer.h -FILE: ../../../flutter/lib/snapshot/snapshot.c.tmpl FILE: ../../../flutter/lib/snapshot/snapshot.dart FILE: ../../../flutter/lib/snapshot/snapshot.h FILE: ../../../flutter/lib/snapshot/snapshot_fuchsia.dart -- GitLab