[kernel] Remove NNBD compilation mode dummy from kernel binary
Also clean up some of the magic constants around this. TEST=CI Change-Id: Ie02df874cb30761d5ea08ae52c1507cf25318280 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416940 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
committed by
Commit Queue
parent
d361b8fdd5
commit
6ad56c68dc
@@ -4,6 +4,8 @@
|
||||
|
||||
import "dart:math" as math;
|
||||
|
||||
import "package:kernel/binary/tag.dart" show numberOfFixedFields;
|
||||
|
||||
class BinaryMdDillReader {
|
||||
final String _binaryMdContent;
|
||||
|
||||
@@ -121,8 +123,7 @@ class BinaryMdDillReader {
|
||||
numLibs = _peekUint32();
|
||||
|
||||
// Skip to the start of the index.
|
||||
_binaryOffset = _dillContent.length -
|
||||
((numLibs + 1) + 12 /* number of fixed fields */) * 4;
|
||||
_binaryOffset = _dillContent.length - numberOfFixedFields(numLibs) * 4;
|
||||
|
||||
// Read index.
|
||||
binaryOffsetForSourceTable = _peekUint32();
|
||||
@@ -143,7 +144,6 @@ class BinaryMdDillReader {
|
||||
_binaryOffset += 4;
|
||||
mainMethodReference = _peekUint32();
|
||||
_binaryOffset += 4;
|
||||
/*int compilationMode = */ _peekUint32();
|
||||
|
||||
_binaryOffset = binaryOffsetForStringTable;
|
||||
var saved = readingInstructions["ComponentFile"]!;
|
||||
@@ -157,8 +157,7 @@ class BinaryMdDillReader {
|
||||
Map componentFile = _readBinary("ComponentFile", "");
|
||||
if (_binaryOffset != _dillContent.length) {
|
||||
throw "Didn't read the entire binary: "
|
||||
"Only read $_binaryOffset of ${_dillContent.length} bytes. "
|
||||
"($componentFile)";
|
||||
"Only read $_binaryOffset of ${_dillContent.length} bytes.";
|
||||
}
|
||||
if (verboseLevel > 0) {
|
||||
print("Successfully read the dill file.");
|
||||
@@ -537,8 +536,8 @@ class BinaryMdDillReader {
|
||||
} else if (what == "ComponentIndex" &&
|
||||
instruction == "Byte[] 8bitAlignment;") {
|
||||
// Special-case 8-byte alignment.
|
||||
int sizeWithoutPadding = _binaryOffset +
|
||||
((numLibs + 1) + 10 /* number of fixed fields */) * 4;
|
||||
int sizeWithoutPadding =
|
||||
_binaryOffset + numberOfFixedFields(numLibs) * 4;
|
||||
int padding = 8 - sizeWithoutPadding % 8;
|
||||
if (padding == 8) padding = 0;
|
||||
_binaryOffset += padding;
|
||||
|
||||
@@ -147,7 +147,7 @@ type CanonicalName {
|
||||
|
||||
type ComponentFile {
|
||||
UInt32 magic = 0x90ABCDEF;
|
||||
UInt32 formatVersion = 123;
|
||||
UInt32 formatVersion = 124;
|
||||
Byte[10] shortSdkHash;
|
||||
List<String> problemsAsJson; // Described in problems.md.
|
||||
Library[] libraries;
|
||||
@@ -188,7 +188,6 @@ type ComponentIndex {
|
||||
UInt32 binaryOffsetForStringTable;
|
||||
UInt32 binaryOffsetForStartOfComponentIndex;
|
||||
UInt32 mainMethodReference; // This is a ProcedureReference with a fixed-size integer.
|
||||
UInt32 _dummy; // TODO(jensj): Previously the component mode. Remove this.
|
||||
UInt32[libraryCount + 1] libraryOffsets;
|
||||
UInt32 libraryCount;
|
||||
UInt32 componentFileSizeInBytes;
|
||||
|
||||
@@ -67,8 +67,6 @@ class CompilationModeError {
|
||||
}
|
||||
|
||||
class _ComponentIndex {
|
||||
static const int numberOfFixedFields = 12;
|
||||
|
||||
final int binaryOffsetForSourceTable;
|
||||
final int binaryOffsetForCanonicalNames;
|
||||
final int binaryOffsetForMetadataPayloads;
|
||||
@@ -790,8 +788,7 @@ class BinaryBuilder {
|
||||
}
|
||||
|
||||
// Skip to the start of the index.
|
||||
_byteOffset -=
|
||||
((libraryCount + 1) + _ComponentIndex.numberOfFixedFields) * 4;
|
||||
_byteOffset -= numberOfFixedFields(libraryCount) * 4;
|
||||
|
||||
// Now read the component index.
|
||||
int binaryOffsetForSourceTable = _componentStartOffset + readUint32();
|
||||
@@ -805,8 +802,6 @@ class BinaryBuilder {
|
||||
int binaryOffsetForStartOfComponentIndex =
|
||||
_componentStartOffset + readUint32();
|
||||
int mainMethodReference = readUint32();
|
||||
// TODO(jensj): Previously the component mode. Remove this.
|
||||
readUint32();
|
||||
for (int i = 0; i < libraryCount + 1; ++i) {
|
||||
libraryOffsets[i] = _componentStartOffset + readUint32();
|
||||
}
|
||||
|
||||
@@ -805,11 +805,9 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
// is added before component index.
|
||||
const int kernelFileAlignment = 8;
|
||||
|
||||
// Keep this in sync with number of writeUInt32 below.
|
||||
int numComponentIndexEntries = 10 + libraryOffsets.length + 3;
|
||||
int componentIndexOffset = getBufferOffset();
|
||||
|
||||
int unalignedSize = componentIndexOffset + numComponentIndexEntries * 4;
|
||||
int unalignedSize =
|
||||
componentIndexOffset + numberOfFixedFields(libraryOffsets.length) * 4;
|
||||
int padding =
|
||||
((unalignedSize + kernelFileAlignment - 1) & -kernelFileAlignment) -
|
||||
unalignedSize;
|
||||
@@ -817,7 +815,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
writeByte(0);
|
||||
}
|
||||
|
||||
// Fixed-size ints at the end used as an index.
|
||||
// Fixed-size ints at the end used as an index. Including main there's
|
||||
// [fixedFieldsBeforeLibraries] fields.
|
||||
assert(_binaryOffsetForSourceTable >= 0);
|
||||
writeUInt32(_binaryOffsetForSourceTable);
|
||||
assert(_binaryOffsetForConstantTable >= 0);
|
||||
@@ -843,16 +842,17 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
|
||||
_ensureCanonicalName(getNonNullableMemberReferenceGetter(mainMethod));
|
||||
writeUInt32(main.index + 1);
|
||||
}
|
||||
// TODO(jensj): Previously the component mode. Remove this.
|
||||
writeUInt32(0);
|
||||
|
||||
// Offset for the libraries.
|
||||
assert(libraryOffsets.length == libraries.length);
|
||||
for (int offset in libraryOffsets) {
|
||||
writeUInt32(offset);
|
||||
}
|
||||
writeUInt32(_binaryOffsetForSourceTable); // end of last library.
|
||||
writeUInt32(libraries.length);
|
||||
// and the end of the last library.
|
||||
writeUInt32(_binaryOffsetForSourceTable);
|
||||
|
||||
// And an additional [fixedFieldsAfterLibraries] fields.
|
||||
writeUInt32(libraries.length);
|
||||
writeUInt32(getBufferOffset() + 4); // total size.
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ class Tag {
|
||||
/// Internal version of kernel binary format.
|
||||
/// Bump it when making incompatible changes in kernel binaries.
|
||||
/// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md.
|
||||
static const int BinaryFormatVersion = 123;
|
||||
static const int BinaryFormatVersion = 124;
|
||||
}
|
||||
|
||||
abstract class ConstantTag {
|
||||
@@ -274,3 +274,14 @@ bool isValidSdkHash(String sdkHash) {
|
||||
expectedSdkHash == sdkHashNull ||
|
||||
sdkHash == expectedSdkHash);
|
||||
}
|
||||
|
||||
/// These should match with what is written in
|
||||
/// BinaryPrinter.writeComponentIndex.
|
||||
const int fixedFieldsBeforeLibraries = 9;
|
||||
const int fixedFieldsAfterLibraries = 2;
|
||||
int numberOfFixedFields(int numberOfLibraries) {
|
||||
return fixedFieldsBeforeLibraries +
|
||||
numberOfLibraries +
|
||||
1 +
|
||||
fixedFieldsAfterLibraries;
|
||||
}
|
||||
|
||||
@@ -3095,34 +3095,22 @@ TokenPosition KernelReaderHelper::ReadPosition() {
|
||||
|
||||
intptr_t KernelReaderHelper::SourceTableSize() {
|
||||
AlternativeReadingScope alt(&reader_);
|
||||
intptr_t library_count = reader_.ReadFromIndexNoReset(
|
||||
reader_.size(), LibraryCountFieldCountFromEnd, 1, 0);
|
||||
intptr_t library_count = reader_.ReadSingleFieldFromIndexNoReset(
|
||||
reader_.size(), KernelFixedFieldsAfterLibraries);
|
||||
|
||||
const intptr_t count_from_first_library_offset =
|
||||
SourceTableFieldCountFromFirstLibraryOffset;
|
||||
|
||||
intptr_t source_table_offset = reader_.ReadFromIndexNoReset(
|
||||
reader_.size(),
|
||||
LibraryCountFieldCountFromEnd + 1 + library_count + 1 +
|
||||
count_from_first_library_offset,
|
||||
1, 0);
|
||||
intptr_t source_table_offset = reader_.ReadSingleFieldFromIndexNoReset(
|
||||
reader_.size(), KernelNumberOfFixedFields(library_count));
|
||||
SetOffset(source_table_offset); // read source table offset.
|
||||
return reader_.ReadUInt32(); // read source table size.
|
||||
}
|
||||
|
||||
intptr_t KernelReaderHelper::GetOffsetForSourceInfo(intptr_t index) {
|
||||
AlternativeReadingScope alt(&reader_);
|
||||
intptr_t library_count = reader_.ReadFromIndexNoReset(
|
||||
reader_.size(), LibraryCountFieldCountFromEnd, 1, 0);
|
||||
intptr_t library_count = reader_.ReadSingleFieldFromIndexNoReset(
|
||||
reader_.size(), KernelFixedFieldsAfterLibraries);
|
||||
|
||||
const intptr_t count_from_first_library_offset =
|
||||
SourceTableFieldCountFromFirstLibraryOffset;
|
||||
|
||||
intptr_t source_table_offset = reader_.ReadFromIndexNoReset(
|
||||
reader_.size(),
|
||||
LibraryCountFieldCountFromEnd + 1 + library_count + 1 +
|
||||
count_from_first_library_offset,
|
||||
1, 0);
|
||||
intptr_t source_table_offset = reader_.ReadSingleFieldFromIndexNoReset(
|
||||
reader_.size(), KernelNumberOfFixedFields(library_count));
|
||||
intptr_t next_field_offset = reader_.ReadUInt32();
|
||||
SetOffset(source_table_offset);
|
||||
intptr_t size = reader_.ReadUInt32(); // read source table size.
|
||||
|
||||
@@ -154,15 +154,10 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
||||
program->single_program_ = subprogram_count == 1;
|
||||
|
||||
// Read backwards at the end.
|
||||
program->library_count_ = reader->ReadFromIndexNoReset(
|
||||
reader->size_, LibraryCountFieldCountFromEnd, 1, 0);
|
||||
intptr_t count_from_first_library_offset =
|
||||
SourceTableFieldCountFromFirstLibraryOffset;
|
||||
program->source_table_offset_ = reader->ReadFromIndexNoReset(
|
||||
reader->size_,
|
||||
LibraryCountFieldCountFromEnd + 1 + program->library_count_ + 1 +
|
||||
count_from_first_library_offset,
|
||||
1, 0);
|
||||
program->library_count_ = reader->ReadSingleFieldFromIndexNoReset(
|
||||
reader->size_, KernelFixedFieldsAfterLibraries);
|
||||
program->source_table_offset_ = reader->ReadSingleFieldFromIndexNoReset(
|
||||
reader->size_, KernelNumberOfFixedFields(program->library_count_));
|
||||
program->constant_table_offset_ = reader->ReadUInt32();
|
||||
reader->ReadUInt32(); // offset for constant table index.
|
||||
program->name_table_offset_ = reader->ReadUInt32();
|
||||
@@ -174,8 +169,6 @@ std::unique_ptr<Program> Program::ReadFrom(Reader* reader, const char** error) {
|
||||
program->component_index_offset_ = reader->ReadUInt32();
|
||||
|
||||
program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
|
||||
// TODO(jensj): Remove this.
|
||||
reader->ReadUInt32(); // Read and ignore NNBD compilation mode.
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace kernel {
|
||||
// package:kernel/binary.md.
|
||||
|
||||
static const uint32_t kMagicProgramFile = 0x90ABCDEFu;
|
||||
static const uint32_t kSupportedKernelFormatVersion = 123;
|
||||
static const uint32_t kSupportedKernelFormatVersion = 124;
|
||||
|
||||
// Keep in sync with package:kernel/lib/binary/tag.dart
|
||||
#define KERNEL_TAG_LIST(V) \
|
||||
@@ -271,9 +271,15 @@ enum class FunctionAccessKind {
|
||||
};
|
||||
|
||||
static constexpr int SpecializedIntLiteralBias = 3;
|
||||
static constexpr int LibraryCountFieldCountFromEnd = 1;
|
||||
static constexpr int KernelFormatVersionOffset = 4;
|
||||
static constexpr int SourceTableFieldCountFromFirstLibraryOffset = 9;
|
||||
|
||||
// These should be kept in sync with the constants in kernels tag.dart.
|
||||
static constexpr int KernelFixedFieldsBeforeLibraries = 9;
|
||||
static constexpr int KernelFixedFieldsAfterLibraries = 2;
|
||||
static inline int KernelNumberOfFixedFields(int numberOfLibraries) {
|
||||
return KernelFixedFieldsBeforeLibraries + numberOfLibraries + 1 +
|
||||
KernelFixedFieldsAfterLibraries;
|
||||
}
|
||||
|
||||
static constexpr int HeaderSize = 8; // 'magic', 'formatVersion'.
|
||||
|
||||
@@ -310,6 +316,12 @@ class Reader : public ValueObject {
|
||||
return ReadUInt32();
|
||||
}
|
||||
|
||||
uint32_t ReadSingleFieldFromIndexNoReset(intptr_t end_offset,
|
||||
intptr_t fields_before) {
|
||||
offset_ = end_offset - fields_before * 4;
|
||||
return ReadUInt32();
|
||||
}
|
||||
|
||||
uint32_t ReadUInt32() {
|
||||
uint32_t value = ReadUInt32At(offset_);
|
||||
offset_ += 4;
|
||||
|
||||
@@ -273,7 +273,7 @@ class KernelLoader : public ValueObject {
|
||||
intptr_t library_offset(intptr_t index) {
|
||||
kernel::Reader reader(program_->binary());
|
||||
return reader.ReadFromIndexNoReset(reader.size(),
|
||||
LibraryCountFieldCountFromEnd + 1,
|
||||
KernelFixedFieldsAfterLibraries,
|
||||
program_->library_count() + 1, index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user