Unverified Commit a3221667 authored by Dan Field's avatar Dan Field Committed by GitHub

Kill dead code (#38652)

parent 13844aa6
......@@ -18,7 +18,6 @@ import '../reporting/reporting.dart';
import 'context.dart';
import 'file_system.dart';
import 'fingerprint.dart';
import 'process.dart';
GenSnapshot get genSnapshot => context.get<GenSnapshot>();
......@@ -349,142 +348,3 @@ class AOTSnapshotter {
return value;
}
}
class JITSnapshotter {
/// Builds a JIT VM snapshot of the specified kernel. This snapshot includes
/// data as well as either machine code or DBC, depending on build configuration.
Future<int> build({
@required TargetPlatform platform,
@required BuildMode buildMode,
@required String mainPath,
@required String packagesPath,
@required String outputPath,
@required String compilationTraceFilePath,
List<String> extraGenSnapshotOptions = const <String>[],
}) async {
if (!_isValidJitPlatform(platform)) {
printError('${getNameForTargetPlatform(platform)} does not support JIT snapshotting.');
return 1;
}
final Directory outputDir = fs.directory(outputPath);
outputDir.createSync(recursive: true);
final String engineVmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: buildMode);
final String engineIsolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: buildMode);
final String isolateSnapshotData = fs.path.join(outputDir.path, 'isolate_snapshot_data');
final String isolateSnapshotInstructions = fs.path.join(outputDir.path, 'isolate_snapshot_instr');
final List<String> inputPaths = <String>[
mainPath, compilationTraceFilePath, engineVmSnapshotData, engineIsolateSnapshotData,
];
final String depfilePath = fs.path.join(outputDir.path, 'snapshot.d');
final List<String> genSnapshotArgs = <String>[
'--deterministic',
];
if (buildMode == BuildMode.debug) {
genSnapshotArgs.add('--enable_asserts');
}
if (extraGenSnapshotOptions != null && extraGenSnapshotOptions.isNotEmpty) {
printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions');
genSnapshotArgs.addAll(extraGenSnapshotOptions);
}
final Set<String> outputPaths = <String>{
isolateSnapshotData,
isolateSnapshotInstructions,
};
// There are a couple special cases below where we create a snapshot
// with only the data section, which only contains interpreted code.
bool supportsAppJit = true;
if (platform == TargetPlatform.android_x64 &&
getCurrentHostPlatform() == HostPlatform.windows_x64) {
supportsAppJit = false;
printStatus('Android x64 dynamic build on Windows x64 will use purely interpreted '
'code for now (see https://github.com/flutter/flutter/issues/17489).');
}
if (platform == TargetPlatform.android_x86) {
supportsAppJit = false;
printStatus('Android x86 dynamic build will use purely interpreted code for now. '
'To optimize performance, consider using --target-platform=android-x64.');
}
genSnapshotArgs.addAll(<String>[
'--snapshot_kind=${supportsAppJit ? 'app-jit' : 'app'}',
'--load_compilation_trace=$compilationTraceFilePath',
'--load_vm_snapshot_data=$engineVmSnapshotData',
'--load_isolate_snapshot_data=$engineIsolateSnapshotData',
'--isolate_snapshot_data=$isolateSnapshotData',
]);
genSnapshotArgs.add('--isolate_snapshot_instructions=$isolateSnapshotInstructions');
if (platform == TargetPlatform.android_arm) {
// Use softfp for Android armv7 devices.
// TODO(cbracken): eliminate this when we fix https://github.com/flutter/flutter/issues/17489
genSnapshotArgs.add('--no-sim-use-hardfp');
// Not supported by the Pixel in 32-bit mode.
genSnapshotArgs.add('--no-use-integer-division');
}
genSnapshotArgs.add(mainPath);
// Verify that all required inputs exist.
final Iterable<String> missingInputs = inputPaths.where((String p) => !fs.isFileSync(p));
if (missingInputs.isNotEmpty) {
printError('Missing input files: $missingInputs from $inputPaths');
return 1;
}
// If inputs and outputs have not changed since last run, skip the build.
final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: '$depfilePath.fingerprint',
paths: <String>[mainPath, ...inputPaths, ...outputPaths],
properties: <String, String>{
'buildMode': buildMode.toString(),
'targetPlatform': platform.toString(),
'entryPoint': mainPath,
'extraGenSnapshotOptions': extraGenSnapshotOptions.join(' '),
},
depfilePaths: <String>[],
);
// TODO(jonahwilliams): re-enable once this can be proved correct.
// if (await fingerprinter.doesFingerprintMatch()) {
// printTrace('Skipping JIT snapshot build. Fingerprint match.');
// return 0;
// }
final SnapshotType snapshotType = SnapshotType(platform, buildMode);
final int genSnapshotExitCode = await genSnapshot.run(
snapshotType: snapshotType,
additionalArgs: genSnapshotArgs,
);
if (genSnapshotExitCode != 0) {
printError('Dart snapshot generator failed with exit code $genSnapshotExitCode');
return genSnapshotExitCode;
}
// Write path to gen_snapshot, since snapshots have to be re-generated when we roll
// the Dart SDK.
final String genSnapshotPath = GenSnapshot.getSnapshotterPath(snapshotType);
await outputDir.childFile('gen_snapshot.d').writeAsString('gen_snapshot.d: $genSnapshotPath\n');
// Compute and record build fingerprint.
await fingerprinter.writeFingerprint();
return 0;
}
bool _isValidJitPlatform(TargetPlatform platform) {
return const <TargetPlatform>[
TargetPlatform.android_arm,
TargetPlatform.android_arm64,
TargetPlatform.android_x86,
TargetPlatform.android_x64,
].contains(platform);
}
}
......@@ -468,305 +468,4 @@ void main() {
expect(bufferLogger.statusText, matches(RegExp(r'snapshot\(CompileTime\): \d+ ms.')));
}, overrides: contextOverrides);
});
group('Snapshotter - JIT', () {
const String kTrace = 'trace.txt';
const String kEngineVmSnapshotData = 'engine_vm_snapshot_data';
const String kEngineIsolateSnapshotData = 'engine_isolate_snapshot_data';
_FakeGenSnapshot genSnapshot;
MemoryFileSystem fs;
JITSnapshotter snapshotter;
MockAndroidSdk mockAndroidSdk;
MockArtifacts mockArtifacts;
setUp(() async {
fs = MemoryFileSystem();
fs.file(kTrace).createSync();
fs.file(kEngineVmSnapshotData).createSync();
fs.file(kEngineIsolateSnapshotData).createSync();
genSnapshot = _FakeGenSnapshot();
snapshotter = JITSnapshotter();
mockAndroidSdk = MockAndroidSdk();
mockArtifacts = MockArtifacts();
for (BuildMode mode in BuildMode.values) {
when(mockArtifacts.getArtifactPath(Artifact.vmSnapshotData,
platform: anyNamed('platform'), mode: mode))
.thenReturn(kEngineVmSnapshotData);
when(mockArtifacts.getArtifactPath(Artifact.isolateSnapshotData,
platform: anyNamed('platform'), mode: mode))
.thenReturn(kEngineIsolateSnapshotData);
}
});
final Map<Type, Generator> contextOverrides = <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
Artifacts: () => mockArtifacts,
FileSystem: () => fs,
GenSnapshot: () => genSnapshot,
};
testUsingContext('iOS debug JIT snapshot is invalid', () async {
final String outputPath = fs.path.join('build', 'foo');
expect(await snapshotter.build(
platform: TargetPlatform.ios,
buildMode: BuildMode.debug,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
), isNot(equals(0)));
}, overrides: contextOverrides);
testUsingContext('builds Android arm debug JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm,
buildMode: BuildMode.debug,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm);
expect(genSnapshot.snapshotType.mode, BuildMode.debug);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--enable_asserts',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'--no-sim-use-hardfp',
'--no-use-integer-division',
'main.dill',
]);
}, overrides: contextOverrides);
testUsingContext('builds Android arm64 debug JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm64,
buildMode: BuildMode.debug,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm64);
expect(genSnapshot.snapshotType.mode, BuildMode.debug);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--enable_asserts',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'main.dill',
]);
}, overrides: contextOverrides);
testUsingContext('iOS release JIT snapshot is invalid', () async {
final String outputPath = fs.path.join('build', 'foo');
expect(await snapshotter.build(
platform: TargetPlatform.ios,
buildMode: BuildMode.profile,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
), isNot(equals(0)));
}, overrides: contextOverrides);
testUsingContext('builds Android arm profile JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm,
buildMode: BuildMode.profile,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm);
expect(genSnapshot.snapshotType.mode, BuildMode.profile);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'--no-sim-use-hardfp',
'--no-use-integer-division',
'main.dill',
]);
}, overrides: contextOverrides);
testUsingContext('builds Android arm64 profile JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm64,
buildMode: BuildMode.profile,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm64);
expect(genSnapshot.snapshotType.mode, BuildMode.profile);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'main.dill',
]);
}, overrides: contextOverrides);
testUsingContext('iOS release JIT snapshot is invalid', () async {
final String outputPath = fs.path.join('build', 'foo');
expect(await snapshotter.build(
platform: TargetPlatform.ios,
buildMode: BuildMode.release,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
), isNot(equals(0)));
}, overrides: contextOverrides);
testUsingContext('builds Android arm release JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm,
buildMode: BuildMode.release,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm);
expect(genSnapshot.snapshotType.mode, BuildMode.release);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'--no-sim-use-hardfp',
'--no-use-integer-division',
'main.dill',
]);
}, overrides: contextOverrides);
testUsingContext('builds Android arm64 release JIT snapshot', () async {
fs.file('main.dill').writeAsStringSync('binary magic');
final String outputPath = fs.path.join('build', 'foo');
fs.directory(outputPath).createSync(recursive: true);
genSnapshot.outputs = <String, String>{
fs.path.join(outputPath, 'isolate_snapshot_data'): '',
fs.path.join(outputPath, 'isolate_snapshot_instr'): '',
};
final int genSnapshotExitCode = await snapshotter.build(
platform: TargetPlatform.android_arm64,
buildMode: BuildMode.release,
mainPath: 'main.dill',
packagesPath: '.packages',
outputPath: outputPath,
compilationTraceFilePath: kTrace,
);
expect(genSnapshotExitCode, 0);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm64);
expect(genSnapshot.snapshotType.mode, BuildMode.release);
expect(genSnapshot.additionalArgs, <String>[
'--deterministic',
'--snapshot_kind=app-jit',
'--load_compilation_trace=$kTrace',
'--load_vm_snapshot_data=$kEngineVmSnapshotData',
'--load_isolate_snapshot_data=$kEngineIsolateSnapshotData',
'--isolate_snapshot_data=build/foo/isolate_snapshot_data',
'--isolate_snapshot_instructions=build/foo/isolate_snapshot_instr',
'main.dill',
]);
}, overrides: contextOverrides);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment