Skip to content

Commit

Permalink
Adapt to refactoring of snapshot APIs in the Dart VM. (flutter#3354)
Browse files Browse the repository at this point in the history
Adapt to refactoring of snapshot APIs in the Dart VM.
  • Loading branch information
rmacnak-google authored Jan 23, 2017
1 parent 858e401 commit adef370
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 113 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vars = {

# Note: When updating the Dart revision, ensure that all entries that are
# dependencies of dart are also updated
'dart_revision': 'b43da048c31a16b9993de1536406ed014ef73ffd',
'dart_revision': 'b46af1e75f9d124ce0e5f8226d570e93ac87d3a9',
'dart_boringssl_gen_revision': '1a810313a0290e1caace9da73fa3ab89995ad2c7',
'dart_boringssl_revision': 'd519bf6be0b447fb80fbc539d4bff4479b5482a2',
'dart_observatory_packages_revision': '26aad88f1c1915d39bbcbff3cad589e2402fdcf1',
Expand Down
8 changes: 4 additions & 4 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct Settings {
bool enable_dart_profiling = false;
bool use_test_fonts = false;
std::string aot_snapshot_path;
std::string aot_isolate_snapshot_file_name;
std::string aot_vm_isolate_snapshot_file_name;
std::string aot_instructions_blob_file_name;
std::string aot_rodata_blob_file_name;
std::string aot_vm_snapshot_data_filename;
std::string aot_vm_snapshot_instr_filename;
std::string aot_isolate_snapshot_data_filename;
std::string aot_isolate_snapshot_instr_filename;
std::string application_library_path;
std::string temp_directory_path;
std::vector<std::string> dart_flags;
Expand Down
8 changes: 6 additions & 2 deletions lib/snapshot/snapshot.c.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
// 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 kVmIsolateSnapshot[]
const uint8_t kDartVmSnapshotData[]
__attribute__((visibility("default"), aligned(8), used)) = { %s };
const uint8_t kDartVmSnapshotInstructions[]
__attribute__((visibility("default"), aligned(8), used)) = {};

// 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 kIsolateSnapshot[]
const uint8_t kDartIsolateSnapshotData[]
__attribute__((visibility("default"), aligned(8), used)) = { %s };
const uint8_t kDartIsolateSnapshotInstructions[]
__attribute__((visibility("default"), aligned(8), used)) = {};
4 changes: 3 additions & 1 deletion runtime/dart_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ void DartController::CreateIsolateFor(const std::string& script_uri,
char* error = nullptr;
Dart_Isolate isolate = Dart_CreateIsolate(
script_uri.c_str(), "main",
reinterpret_cast<uint8_t*>(DART_SYMBOL(kIsolateSnapshot)), nullptr,
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotData)),
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotInstructions)),
nullptr,
static_cast<tonic::DartState*>(state.get()), &error);
FTL_CHECK(isolate) << error;
ui_dart_state_ = state.release();
Expand Down
58 changes: 23 additions & 35 deletions runtime/dart_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ Dart_Isolate ServiceIsolateCreateCallback(const char* script_uri,
tonic::DartState* dart_state = new tonic::DartState();
Dart_Isolate isolate = Dart_CreateIsolate(
script_uri, "main",
reinterpret_cast<const uint8_t*>(DART_SYMBOL(kIsolateSnapshot)), nullptr,
reinterpret_cast<const uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotData)),
reinterpret_cast<const uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotInstructions)),
nullptr,
dart_state, error);
FTL_CHECK(isolate) << error;
dart_state->SetIsolate(isolate);
Expand Down Expand Up @@ -276,7 +278,9 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,

Dart_Isolate isolate = Dart_CreateIsolate(
script_uri, main,
reinterpret_cast<uint8_t*>(DART_SYMBOL(kIsolateSnapshot)), nullptr,
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotData)),
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartIsolateSnapshotInstructions)),
nullptr,
dart_state, error);
FTL_CHECK(isolate) << error;
dart_state->SetIsolate(isolate);
Expand Down Expand Up @@ -373,10 +377,10 @@ DartJniIsolateData* GetDartJniDataForCurrentIsolate() {

#if DART_ALLOW_DYNAMIC_RESOLUTION

constexpr char kVmIsolateSnapshotName[] = "kVmIsolateSnapshot";
constexpr char kIsolateSnapshotName[] = "kIsolateSnapshot";
constexpr char kInstructionsSnapshotName[] = "kInstructionsSnapshot";
constexpr char kDataSnapshotName[] = "kDataSnapshot";
constexpr char kDartVmSnapshotDataName[] = "kDartVmSnapshotData";
constexpr char kDartVmSnapshotInstructionsName[] = "kDartVmSnapshotInstructions";
constexpr char kDartIsolateSnapshotDataName[] = "kDartIsolateSnapshotData";
constexpr char kDartIsolateSnapshotInstructionsName[] = "kDartIsolateSnapshotInstructions";

#if OS(IOS)

Expand Down Expand Up @@ -437,14 +441,14 @@ struct SymbolAsset {
};

static SymbolAsset g_symbol_assets[] = {
{kVmIsolateSnapshotName, "snapshot_aot_vmisolate", false,
offsetof(Settings, aot_vm_isolate_snapshot_file_name)},
{kIsolateSnapshotName, "snapshot_aot_isolate", false,
offsetof(Settings, aot_isolate_snapshot_file_name)},
{kInstructionsSnapshotName, "snapshot_aot_instr", true,
offsetof(Settings, aot_instructions_blob_file_name)},
{kDataSnapshotName, "snapshot_aot_rodata", false,
offsetof(Settings, aot_rodata_blob_file_name)},
{kDartVmSnapshotDataName, "vm_snapshot_data", false,
offsetof(Settings, aot_vm_snapshot_data_filename)},
{kDartVmSnapshotInstructionsName, "vm_snapshot_instr", true,
offsetof(Settings, aot_vm_snapshot_instr_filename)},
{kDartIsolateSnapshotDataName, "isolate_snapshot_data", false,
offsetof(Settings, aot_isolate_snapshot_data_filename)},
{kDartIsolateSnapshotInstructionsName, "isolate_snapshot_instr", true,
offsetof(Settings, aot_isolate_snapshot_instr_filename)},
};

// Resolve a precompiled snapshot symbol by mapping the corresponding asset
Expand Down Expand Up @@ -498,29 +502,13 @@ void* _DartSymbolLookup(const char* symbol_name) {

#endif

static const uint8_t* PrecompiledInstructionsSymbolIfPresent() {
return reinterpret_cast<uint8_t*>(DART_SYMBOL(kInstructionsSnapshot));
}

static const uint8_t* PrecompiledDataSnapshotSymbolIfPresent() {
return reinterpret_cast<uint8_t*>(DART_SYMBOL(kDataSnapshot));
}

bool IsRunningPrecompiledCode() {
TRACE_EVENT0("flutter", __func__);
return PrecompiledInstructionsSymbolIfPresent() != nullptr;
return Dart_IsPrecompiledRuntime();
}

#else // DART_ALLOW_DYNAMIC_RESOLUTION

static const uint8_t* PrecompiledInstructionsSymbolIfPresent() {
return nullptr;
}

static const uint8_t* PrecompiledDataSnapshotSymbolIfPresent() {
return nullptr;
}

bool IsRunningPrecompiledCode() {
return false;
}
Expand Down Expand Up @@ -691,10 +679,10 @@ void InitDartVM() {
TRACE_EVENT0("flutter", "Dart_Initialize");
Dart_InitializeParams params = {};
params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
params.vm_isolate_snapshot =
reinterpret_cast<uint8_t*>(DART_SYMBOL(kVmIsolateSnapshot));
params.instructions_snapshot = PrecompiledInstructionsSymbolIfPresent();
params.data_snapshot = PrecompiledDataSnapshotSymbolIfPresent();
params.vm_snapshot_data =
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartVmSnapshotData));
params.vm_snapshot_instructions =
reinterpret_cast<uint8_t*>(DART_SYMBOL(kDartVmSnapshotInstructions));
params.create = IsolateCreateCallback;
params.shutdown = IsolateShutdownCallback;
params.thread_exit = ThreadExitCallback;
Expand Down
14 changes: 8 additions & 6 deletions runtime/dart_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace blink {

#if DART_ALLOW_DYNAMIC_RESOLUTION

extern const char kVmIsolateSnapshotName[];
extern const char kIsolateSnapshotName[];
extern const char kInstructionsSnapshotName[];
extern const char kDataSnapshotName[];
extern const char kDartVmSnapshotDataName[];
extern const char kDartVmSnapshotInstructionsName[];
extern const char kDartIsolateSnapshotDataName[];
extern const char kDartIsolateSnapshotInstructionsName[];

void* _DartSymbolLookup(const char* symbol_name);

Expand All @@ -30,8 +30,10 @@ void* _DartSymbolLookup(const char* symbol_name);
#else // DART_ALLOW_DYNAMIC_RESOLUTION

extern "C" {
extern void* kVmIsolateSnapshot;
extern void* kIsolateSnapshot;
extern void* kDartVmSnapshotData;
extern void* kDartVmSnapshotInstructions;
extern void* kDartIsolateSnapshotData;
extern void* kDartIsolateSnapshotInstructions;
}

#define DART_SYMBOL(symbol) (&symbol)
Expand Down
20 changes: 8 additions & 12 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,14 @@ void Shell::InitStandalone(std::string icu_data_path,

settings.aot_snapshot_path =
command_line.GetSwitchValueASCII(FlagForSwitch(Switch::AotSnapshotPath));

settings.aot_isolate_snapshot_file_name = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotIsolateSnapshot));

settings.aot_vm_isolate_snapshot_file_name = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotVmIsolateSnapshot));

settings.aot_instructions_blob_file_name = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotInstructionsBlob));

settings.aot_rodata_blob_file_name =
command_line.GetSwitchValueASCII(FlagForSwitch(Switch::AotRodataBlob));
settings.aot_vm_snapshot_data_filename = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotVmSnapshotData));
settings.aot_vm_snapshot_instr_filename = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotVmSnapshotInstructions));
settings.aot_isolate_snapshot_data_filename = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotIsolateSnapshotData));
settings.aot_isolate_snapshot_instr_filename = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::AotIsolateSnapshotInstructions));

settings.temp_directory_path =
command_line.GetSwitchValueASCII(FlagForSwitch(Switch::CacheDirPath));
Expand Down
14 changes: 4 additions & 10 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ namespace shell {
// clang-format on

DEF_SWITCHES_START
DEF_SWITCH(AotInstructionsBlob,
"instructions-blob",
"Path to the instructions snapshot blob.")
DEF_SWITCH(AotIsolateSnapshot,
"isolate-snapshot",
"Path to the isolate snapshot blob.")
DEF_SWITCH(AotRodataBlob, "rodata-blob", "Path to the rodata blob.")
DEF_SWITCH(AotSnapshotPath, "aot-snapshot-path", "Path to the AOT snapshot.")
DEF_SWITCH(AotVmIsolateSnapshot,
"vm-isolate-snapshot",
"Path to the VM isolate snapshot.")
DEF_SWITCH(AotVmSnapshotData, "vm-snapshot-data", "")
DEF_SWITCH(AotVmSnapshotInstructions, "vm-snapshot-instr", "")
DEF_SWITCH(AotIsolateSnapshotData, "isolate-snapshot-data", "")
DEF_SWITCH(AotIsolateSnapshotInstructions, "isolate-snapshot-instr", "")
DEF_SWITCH(CacheDirPath, "cache-dir-path", "Path to the cache directory.")
DEF_SWITCH(DartFlags,
"dart-flags",
Expand Down
74 changes: 36 additions & 38 deletions shell/platform/android/io/flutter/view/FlutterMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ public class FlutterMain {

// Must match values in sky::shell::switches
private static final String AOT_SNAPSHOT_PATH_KEY = "aot-snapshot-path";
private static final String AOT_ISOLATE_KEY = "isolate-snapshot";
private static final String AOT_VM_ISOLATE_KEY = "vm-isolate-snapshot";
private static final String AOT_INSTRUCTIONS_KEY = "instructions-blob";
private static final String AOT_RODATA_KEY = "rodata-blob";
private static final String AOT_VM_SNAPSHOT_DATA_KEY = "vm-snapshot-data";
private static final String AOT_VM_SNAPSHOT_INSTR_KEY = "vm-snapshot-instr";
private static final String AOT_ISOLATE_SNAPSHOT_DATA_KEY = "isolate-snapshot-data";
private static final String AOT_ISOLATE_SNAPSHOT_INSTR_KEY = "isolate-snapshot-instr";
private static final String FLX_KEY = "flx";

// XML Attribute keys supported in AndroidManifest.xml
public static final String PUBLIC_AOT_ISOLATE_KEY =
FlutterMain.class.getName() + '.' + AOT_ISOLATE_KEY;
public static final String PUBLIC_AOT_VM_ISOLATE_KEY =
FlutterMain.class.getName() + '.' + AOT_VM_ISOLATE_KEY;
public static final String PUBLIC_AOT_INSTRUCTIONS_KEY =
FlutterMain.class.getName() + '.' + AOT_INSTRUCTIONS_KEY;
public static final String PUBLIC_AOT_RODATA_KEY =
FlutterMain.class.getName() + '.' + AOT_RODATA_KEY;
public static final String PUBLIC_AOT_VM_SNAPSHOT_DATA_KEY =
FlutterMain.class.getName() + '.' + AOT_VM_SNAPSHOT_DATA_KEY;
public static final String PUBLIC_AOT_VM_SNAPSHOT_INSTR_KEY =
FlutterMain.class.getName() + '.' + AOT_VM_SNAPSHOT_INSTR_KEY;
public static final String PUBLIC_AOT_ISOLATE_SNAPSHOT_DATA_KEY =
FlutterMain.class.getName() + '.' + AOT_ISOLATE_SNAPSHOT_DATA_KEY;
public static final String PUBLIC_AOT_ISOLATE_SNAPSHOT_INSTR_KEY =
FlutterMain.class.getName() + '.' + AOT_ISOLATE_SNAPSHOT_INSTR_KEY;
public static final String PUBLIC_FLX_KEY =
FlutterMain.class.getName() + '.' + FLX_KEY;

// Resource names used for components of the precompiled snapshot.
private static final String DEFAULT_AOT_ISOLATE = "snapshot_aot_isolate";
private static final String DEFAULT_AOT_VM_ISOLATE = "snapshot_aot_vmisolate";
private static final String DEFAULT_AOT_INSTRUCTIONS = "snapshot_aot_instr";
private static final String DEFAULT_AOT_RODATA = "snapshot_aot_rodata";
private static final String DEFAULT_AOT_VM_SNAPSHOT_DATA = "vm_snapshot_data";
private static final String DEFAULT_AOT_VM_SNAPSHOT_INSTR = "vm_snapshot_instr";
private static final String DEFAULT_AOT_ISOLATE_SNAPSHOT_DATA = "isolate_snapshot_data";
private static final String DEFAULT_AOT_ISOLATE_SNAPSHOT_INSTR = "isolate_snapshot_instr";
private static final String DEFAULT_FLX = "app.flx";

private static final String MANIFEST = "flutter.yaml";
Expand All @@ -74,10 +74,10 @@ public class FlutterMain {
.build();

// Mutable because default values can be overridden via config properties
private static String sAotIsolate = DEFAULT_AOT_ISOLATE;
private static String sAotVmIsolate = DEFAULT_AOT_VM_ISOLATE;
private static String sAotInstructions = DEFAULT_AOT_INSTRUCTIONS;
private static String sAotRodata = DEFAULT_AOT_RODATA;
private static String sAotVmSnapshotData = DEFAULT_AOT_VM_SNAPSHOT_DATA;
private static String sAotVmSnapshotInstr = DEFAULT_AOT_VM_SNAPSHOT_INSTR;
private static String sAotIsolateSnapshotData = DEFAULT_AOT_ISOLATE_SNAPSHOT_DATA;
private static String sAotIsolateSnapshotInstr = DEFAULT_AOT_ISOLATE_SNAPSHOT_INSTR;
private static String sFlx = DEFAULT_FLX;

private static boolean sInitialized = false;
Expand Down Expand Up @@ -173,10 +173,10 @@ public static void ensureInitializationComplete(Context applicationContext, Stri
if (sIsPrecompiled) {
shellArgs.add("--" + AOT_SNAPSHOT_PATH_KEY + "=" +
PathUtils.getDataDirectory(applicationContext));
shellArgs.add("--" + AOT_ISOLATE_KEY + "=" + sAotIsolate);
shellArgs.add("--" + AOT_VM_ISOLATE_KEY + "=" + sAotVmIsolate);
shellArgs.add("--" + AOT_INSTRUCTIONS_KEY + "=" + sAotInstructions);
shellArgs.add("--" + AOT_RODATA_KEY + "=" + sAotRodata);
shellArgs.add("--" + AOT_VM_SNAPSHOT_DATA_KEY + "=" + sAotVmSnapshotData);
shellArgs.add("--" + AOT_VM_SNAPSHOT_INSTR_KEY + "=" + sAotVmSnapshotInstr);
shellArgs.add("--" + AOT_ISOLATE_SNAPSHOT_DATA_KEY + "=" + sAotIsolateSnapshotData);
shellArgs.add("--" + AOT_ISOLATE_SNAPSHOT_INSTR_KEY + "=" + sAotIsolateSnapshotInstr);
} else {
shellArgs.add("--cache-dir-path=" +
PathUtils.getCacheDirectory(applicationContext));
Expand Down Expand Up @@ -207,12 +207,10 @@ private static void initConfig(Context applicationContext) {
Bundle metadata = applicationContext.getPackageManager().getApplicationInfo(
applicationContext.getPackageName(), PackageManager.GET_META_DATA).metaData;
if (metadata != null) {
sAotIsolate = metadata.getString(PUBLIC_AOT_ISOLATE_KEY, DEFAULT_AOT_ISOLATE);
sAotVmIsolate = metadata.getString(PUBLIC_AOT_VM_ISOLATE_KEY,
DEFAULT_AOT_VM_ISOLATE);
sAotInstructions = metadata.getString(PUBLIC_AOT_INSTRUCTIONS_KEY,
DEFAULT_AOT_INSTRUCTIONS);
sAotRodata = metadata.getString(PUBLIC_AOT_RODATA_KEY, DEFAULT_AOT_RODATA);
sAotVmSnapshotData = metadata.getString(PUBLIC_AOT_VM_SNAPSHOT_DATA_KEY, DEFAULT_AOT_VM_SNAPSHOT_DATA);
sAotVmSnapshotInstr = metadata.getString(PUBLIC_AOT_VM_SNAPSHOT_INSTR_KEY, DEFAULT_AOT_VM_SNAPSHOT_INSTR);
sAotIsolateSnapshotData = metadata.getString(PUBLIC_AOT_ISOLATE_SNAPSHOT_DATA_KEY, DEFAULT_AOT_ISOLATE_SNAPSHOT_DATA);
sAotIsolateSnapshotInstr = metadata.getString(PUBLIC_AOT_ISOLATE_SNAPSHOT_INSTR_KEY, DEFAULT_AOT_ISOLATE_SNAPSHOT_INSTR);
sFlx = metadata.getString(PUBLIC_FLX_KEY, DEFAULT_FLX);
}
} catch (PackageManager.NameNotFoundException e) {
Expand All @@ -230,10 +228,10 @@ private static void initResources(Context applicationContext) {
new ResourceCleaner(context).start();
sResourceExtractor = new ResourceExtractor(context)
.addResources(SKY_RESOURCES)
.addResource(sAotIsolate)
.addResource(sAotVmIsolate)
.addResource(sAotInstructions)
.addResource(sAotRodata)
.addResource(sAotVmSnapshotData)
.addResource(sAotVmSnapshotInstr)
.addResource(sAotIsolateSnapshotData)
.addResource(sAotIsolateSnapshotInstr)
.addResource(sFlx)
.start();
}
Expand Down Expand Up @@ -267,10 +265,10 @@ private static Set<String> listRootAssets(Context applicationContext) {
private static void initAot(Context applicationContext) {
Set<String> assets = listRootAssets(applicationContext);
sIsPrecompiled = assets.containsAll(Arrays.asList(
sAotIsolate,
sAotVmIsolate,
sAotInstructions,
sAotRodata
sAotVmSnapshotData,
sAotVmSnapshotInstr,
sAotIsolateSnapshotData,
sAotIsolateSnapshotInstr
));
}

Expand Down
12 changes: 8 additions & 4 deletions snapshotter/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
#include "lib/tonic/file_loader/file_loader.h"

extern "C" {
extern const uint8_t kVmIsolateSnapshot[];
extern const uint8_t kIsolateSnapshot[];
extern const uint8_t kDartVmSnapshotData[];
extern const uint8_t kDartVmSnapshotInstructions[];
extern const uint8_t kDartIsolateSnapshotData[];
extern const uint8_t kDartIsolateSnapshotInstructions[];
}

namespace {
Expand Down Expand Up @@ -92,7 +94,8 @@ void InitDartVM() {
FTL_CHECK(Dart_SetVMFlags(arraysize(kDartArgs), kDartArgs));
Dart_InitializeParams params = {};
params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION;
params.vm_isolate_snapshot = kVmIsolateSnapshot;
params.vm_snapshot_data = kDartVmSnapshotData;
params.vm_snapshot_instructions = kDartVmSnapshotInstructions;
char* error = Dart_Initialize(&params);
if (error)
FTL_LOG(FATAL) << error;
Expand All @@ -101,7 +104,8 @@ void InitDartVM() {
Dart_Isolate CreateDartIsolate() {
char* error = nullptr;
Dart_Isolate isolate =
Dart_CreateIsolate("dart:snapshot", "main", kIsolateSnapshot,
Dart_CreateIsolate("dart:snapshot", "main", kDartIsolateSnapshotData,
kDartIsolateSnapshotInstructions,
nullptr, nullptr, &error);
FTL_CHECK(isolate) << error;
Dart_ExitIsolate();
Expand Down

0 comments on commit adef370

Please sign in to comment.