9f49b47823
This is a major revamp of bytecode metadata format. Now bytecode has its own serialization mechanisms. This CL adds 'bytecode component' metadata, which contains bytecode object table and string table. All references from bytecode (constant pools) to libraries, classes, members, types and strings now have a new format. References to frequently used objects are represented as indices in object table, while rarely used objects are written inline. This allows VM to cache frequently used objects while reading bytecode. Representation of strings is aligned with VM - string characters are stored in separate pools of one-byte and two-byte strings. This allows VM to avoid UTF-8 decoding and extra copying. Closure declarations are now explicit. Type parameters no longer require enslosing scopes when reading/writing them. Benchmarks: GenKernelKernelReadAllBytecode (Intel Core i5) +29.84% GenKernelKernelReadAllBytecode (Intel Xeon) +28.74% Change-Id: I4b80009733a8f8c038264af74f97c4e094b9e311 Reviewed-on: https://dart-review.googlesource.com/c/85469 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Régis Crelier <regis@google.com> Reviewed-by: Zach Anderson <zra@google.com>
57 lines
2.0 KiB
Dart
57 lines
2.0 KiB
Dart
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:front_end/src/api_unstable/vm.dart'
|
|
show CompilerOptions, DiagnosticMessage;
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:vm/bytecode/gen_bytecode.dart' show generateBytecode;
|
|
import 'package:vm/kernel_front_end.dart' show runWithFrontEndCompilerContext;
|
|
|
|
import '../common_test_utils.dart';
|
|
|
|
final String pkgVmDir = Platform.script.resolve('../..').toFilePath();
|
|
|
|
runTestCase(Uri source) async {
|
|
// Certain tests require super-mixin semantics which is used in Flutter.
|
|
bool enableSuperMixins = source.pathSegments.last == 'super_calls.dart';
|
|
|
|
Component component = await compileTestCaseToKernelProgram(source,
|
|
enableSuperMixins: enableSuperMixins);
|
|
|
|
final options = new CompilerOptions()
|
|
..onDiagnostic = (DiagnosticMessage message) {
|
|
fail("Compilation error: ${message.plainTextFormatted.join('\n')}");
|
|
};
|
|
|
|
await runWithFrontEndCompilerContext(source, options, component, () {
|
|
// Need to omit source positions from bytecode as they are different on
|
|
// Linux and Windows (due to differences in newline characters).
|
|
generateBytecode(component, omitAssertSourcePositions: true);
|
|
});
|
|
|
|
String actual = kernelLibraryToString(component.mainMethod.enclosingLibrary);
|
|
|
|
// Remove absolute library URIs.
|
|
actual = actual.replaceAll(new Uri.file(pkgVmDir).toString(), '#pkg/vm');
|
|
|
|
compareResultWithExpectationsFile(source, actual);
|
|
}
|
|
|
|
main() {
|
|
group('gen-bytecode', () {
|
|
final testCasesDir = new Directory(pkgVmDir + '/testcases/bytecode');
|
|
|
|
for (var entry
|
|
in testCasesDir.listSync(recursive: true, followLinks: false)) {
|
|
if (entry.path.endsWith(".dart")) {
|
|
test(entry.path, () => runTestCase(entry.uri));
|
|
}
|
|
}
|
|
});
|
|
}
|