Skip to content

Commit

Permalink
Rename IdentifierTranslation to IdentifierHashes
Browse files Browse the repository at this point in the history
Summary:
The field "identifierTranslations" is used to store the hashes
of identifiers. It was renamed from "hashes" to "translations" in
D14457157 and now we basically need to rename it back, including
related fields, variables and comments.

Reviewed By: tmikov

Differential Revision: D21336820

fbshipit-source-id: fea83d649d08093daca4c9ded41def5f01481078
  • Loading branch information
Huxpro authored and facebook-github-bot committed May 4, 2020
1 parent 6162d3a commit e4d794a
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 59 deletions.
2 changes: 1 addition & 1 deletion doc/Strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The distinction between these is important during bytecode initialisation, parti
In the Hermes bytecode format, the string table is split into the following consecutive sections of the file:

1. String Kinds. A sequence which describes the kinds of the strings in the table (as described in "Hermes Bytecode String Kinds"). Abstractly, the i-th element in the sequence is the kind of the i-th string in the table. Represented as a run-length encoding.
2. Identifier Translations. This sequence has an element corresponding to each identifier in the table (This includes Predefined strings). The i-th element of this sequence corresponds to the i-th identifier in the table. If the string is Predefined, the element contains the index in the Identifier Table where the that string is expected to be. If the string is an Identifier but not Predefined, the element contains a hash of the identifier's string representation.
2. Identifier Hashes. This sequence has an element corresponding to each identifier in the table. The i-th element of this sequence corresponds to the i-th identifier in the table. If the string is an Identifier, the element contains a hash of the identifier's string representation.
3. Small String Table. The primary index into the string table. When a bytecode instruction refers to a string by its index, it uses the offset into this data structure. Represents the string with three pieces of information:
- Whether it is UTF16 or not.
- Its offset into the character storage.
Expand Down
14 changes: 7 additions & 7 deletions include/hermes/BCGen/HBC/Bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ class BytecodeModule {
/// Run-length encoding representing the kinds of strings in the table.
std::vector<StringKind::Entry> stringKinds_;

/// The list of identifier translations, corresponding to the string entries
/// The list of identifier hashes, corresponding to the string entries
/// marked as identifiers, in order.
std::vector<uint32_t> identifierTranslations_;
std::vector<uint32_t> identifierHashes_;

/// The global string table, a list of <offset, length> pair to represent
/// each string in the string storage.
Expand Down Expand Up @@ -251,7 +251,7 @@ class BytecodeModule {
explicit BytecodeModule(
uint32_t functionCount,
std::vector<StringKind::Entry> &&stringKinds,
std::vector<uint32_t> &&identifierTranslations,
std::vector<uint32_t> &&identifierHashes,
std::vector<StringTableEntry> &&stringTable,
std::vector<unsigned char> &&stringStorage,
std::vector<RegExpTableEntry> &&regExpTable,
Expand All @@ -266,7 +266,7 @@ class BytecodeModule {
BytecodeOptions options)
: globalFunctionIndex_(globalFunctionIndex),
stringKinds_(std::move(stringKinds)),
identifierTranslations_(std::move(identifierTranslations)),
identifierHashes_(std::move(identifierHashes)),
stringTable_(std::move(stringTable)),
stringStorage_(std::move(stringStorage)),
regExpStorage_(std::move(regExpStorage)),
Expand Down Expand Up @@ -312,11 +312,11 @@ class BytecodeModule {

/// \return the number of identifiers.
uint32_t getIdentifierCount() const {
return identifierTranslations_.size();
return identifierHashes_.size();
}

llvm::ArrayRef<uint32_t> getIdentifierTranslations() const {
return identifierTranslations_;
llvm::ArrayRef<uint32_t> getIdentifierHashes() const {
return identifierHashes_;
}

uint32_t getStringTableSize() const {
Expand Down
12 changes: 6 additions & 6 deletions include/hermes/BCGen/HBC/BytecodeDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BCProviderBase {
/// Below are all the different global data tables/storage.
uint32_t stringCount_{};
llvm::ArrayRef<StringKind::Entry> stringKinds_{};
llvm::ArrayRef<uint32_t> identifierTranslations_{};
llvm::ArrayRef<uint32_t> identifierHashes_{};
llvm::ArrayRef<unsigned char> stringStorage_{};

llvm::ArrayRef<unsigned char> arrayBuffer_{};
Expand Down Expand Up @@ -166,8 +166,8 @@ class BCProviderBase {
llvm::ArrayRef<StringKind::Entry> getStringKinds() const {
return stringKinds_;
}
llvm::ArrayRef<uint32_t> getIdentifierTranslations() const {
return identifierTranslations_;
llvm::ArrayRef<uint32_t> getIdentifierHashes() const {
return identifierHashes_;
}
llvm::ArrayRef<unsigned char> getStringStorage() const {
return stringStorage_;
Expand Down Expand Up @@ -274,9 +274,9 @@ class BCProviderBase {
/// soon. Only forwards this information to the OS for buffers.
virtual void willNeedStringTable() {}

/// Advise the provider that identifier translations are no longer needed.
/// Advise the provider that identifier hashes are no longer needed.
/// Only forwards this information to the OS for buffers.
virtual void dontNeedIdentifierTranslations() {}
virtual void dontNeedIdentifierHashes() {}

/// Start tracking I/O (only implemented for buffers). Any access before this
/// call (e.g. reading header to construct the provider) will not be recorded.
Expand Down Expand Up @@ -484,7 +484,7 @@ class BCProviderFromBuffer final : public BCProviderBase {
void adviseStringTableSequential() override;
void adviseStringTableRandom() override;
void willNeedStringTable() override;
void dontNeedIdentifierTranslations() override;
void dontNeedIdentifierHashes() override;

void startPageAccessTracker() override;

Expand Down
6 changes: 3 additions & 3 deletions include/hermes/BCGen/HBC/BytecodeFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ template <typename Visitor>
void visitBytecodeSegmentsInOrder(Visitor &visitor) {
visitor.visitFunctionHeaders();
visitor.visitStringKinds();
visitor.visitIdentifierTranslations();
visitor.visitIdentifierHashes();
visitor.visitSmallStringTable();
visitor.visitOverflowStringTable();
visitor.visitStringStorage();
Expand Down Expand Up @@ -420,8 +420,8 @@ struct BytecodeFileFields {
/// Run-length encoding representing the kinds of strings in the table.
Array<StringKind::Entry> stringKinds{};

/// The list of identifier translations.
Array<uint32_t> identifierTranslations{};
/// The list of identifier hashes.
Array<uint32_t> identifierHashes{};

/// The list of overflowed string table entries.
Array<hbc::OverflowStringTableEntry> stringTableOverflowEntries{};
Expand Down
2 changes: 1 addition & 1 deletion include/hermes/BCGen/HBC/BytecodeStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BytecodeSerializer {

void visitFunctionHeaders();
void visitStringKinds();
void visitIdentifierTranslations();
void visitIdentifierHashes();
void visitSmallStringTable();
void visitOverflowStringTable();
void visitStringStorage();
Expand Down
4 changes: 2 additions & 2 deletions include/hermes/BCGen/HBC/UniquingStringLiteralTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ struct StringLiteralTable final : public StringLiteralIDMapping {
inline std::vector<StringTableEntry> acquireStringTable();
inline std::vector<unsigned char> acquireStringStorage();

/// \returns a list of translations corresponding to the strings marked as
/// \returns a list of hashes corresponding to the strings marked as
/// identifiers, in their order in the underlying storage.
std::vector<uint32_t> getIdentifierTranslations() const;
std::vector<uint32_t> getIdentifierHashes() const;

/// \return a sequence of string kinds represented by a run-length encoding.
/// The i'th kind in the abstract sequence (i.e. not the i'th entry in the
Expand Down
23 changes: 11 additions & 12 deletions lib/BCGen/HBC/BytecodeDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,9 @@ bool BytecodeFileFields<Mutable>::populateFromBuffer(
castArrayRef<StringKind::Entry>(buf, h->stringKindCount, end);
}

void visitIdentifierTranslations() {
void visitIdentifierHashes() {
align(buf);
f.identifierTranslations =
castArrayRef<uint32_t>(buf, h->identifierCount, end);
f.identifierHashes = castArrayRef<uint32_t>(buf, h->identifierCount, end);
}

void visitSmallStringTable() {
Expand Down Expand Up @@ -418,14 +417,14 @@ void BCProviderFromBuffer::adviseStringTableSequential() {
size_t adviceLength = end - start;

ASSERT_BOUNDED(start, stringKinds_, end);
ASSERT_BOUNDED(start, identifierTranslations_, end);
ASSERT_BOUNDED(start, identifierHashes_, end);
ASSERT_BOUNDED(start, smallStringTableEntries, end);
ASSERT_BOUNDED(start, overflowStringTableEntries_, end);

ASSERT_TOTAL_ARRAY_LEN(
adviceLength,
stringKinds_,
identifierTranslations_,
identifierHashes_,
smallStringTableEntries,
overflowStringTableEntries_);

Expand All @@ -439,7 +438,7 @@ void BCProviderFromBuffer::adviseStringTableRandom() {

// We only advise the small string table entries, overflow string table
// entries and storage. We do not give advice about the identifier
// translations or string kinds because they are not referred to after
// hashes or string kinds because they are not referred to after
// initialisation.

auto *tableStart = rawptr_cast(stringTableEntries_);
Expand Down Expand Up @@ -470,24 +469,24 @@ void BCProviderFromBuffer::willNeedStringTable() {
size_t prefetchLength = end - start;

ASSERT_BOUNDED(start, stringKinds_, end);
ASSERT_BOUNDED(start, identifierTranslations_, end);
ASSERT_BOUNDED(start, identifierHashes_, end);
ASSERT_BOUNDED(start, smallStringTableEntries, end);
ASSERT_BOUNDED(start, overflowStringTableEntries_, end);

ASSERT_TOTAL_ARRAY_LEN(
prefetchLength,
stringKinds_,
identifierTranslations_,
identifierHashes_,
smallStringTableEntries,
overflowStringTableEntries_);

pageAlignDown(&start, &prefetchLength);
oscompat::vm_prefetch(start, prefetchLength);
}

void BCProviderFromBuffer::dontNeedIdentifierTranslations() {
auto start = reinterpret_cast<uintptr_t>(identifierTranslations_.begin());
auto end = reinterpret_cast<uintptr_t>(identifierTranslations_.end());
void BCProviderFromBuffer::dontNeedIdentifierHashes() {
auto start = reinterpret_cast<uintptr_t>(identifierHashes_.begin());
auto end = reinterpret_cast<uintptr_t>(identifierHashes_.end());
const size_t PS = oscompat::page_size();
start = llvm::alignTo(start, PS);
end = llvm::alignDown(end, PS);
Expand Down Expand Up @@ -525,7 +524,7 @@ BCProviderFromBuffer::BCProviderFromBuffer(
debugInfoOffset_ = fileHeader->debugInfoOffset;
functionHeaders_ = fields.functionHeaders.data();
stringKinds_ = fields.stringKinds;
identifierTranslations_ = fields.identifierTranslations;
identifierHashes_ = fields.identifierHashes;
stringCount_ = fileHeader->stringCount;
stringTableEntries_ = fields.stringTableEntries.data();
overflowStringTableEntries_ = fields.stringTableOverflowEntries;
Expand Down
18 changes: 9 additions & 9 deletions lib/BCGen/HBC/BytecodeDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ void BytecodeDisassembler::disassembleBytecodeFileHeader(raw_ostream &OS) {

void BytecodeDisassembler::disassembleStringStorage(raw_ostream &OS) {
auto strStorage = bcProvider_->getStringStorage();
auto translations = bcProvider_->getIdentifierTranslations();
auto hashes = bcProvider_->getIdentifierHashes();

const auto strCount = bcProvider_->getStringCount();
const auto trnCount = translations.size();
const auto hashCount = hashes.size();

if (strCount == 0)
return;

auto kinds = bcProvider_->getStringKinds();

uint32_t strID = 0;
uint32_t trnID = 0;
uint32_t hashID = 0;

OS << "Global String Table:\n";
const std::locale loc("C");
Expand All @@ -175,7 +175,7 @@ void BytecodeDisassembler::disassembleStringStorage(raw_ostream &OS) {
case StringKind::Identifier:
OS << " #"
<< llvm::format_hex_no_prefix(
translations[trnID++], 8, /* Upper */ true);
hashes[hashID++], 8, /* Upper */ true);
break;

default:
Expand All @@ -198,8 +198,8 @@ void BytecodeDisassembler::disassembleStringStorage(raw_ostream &OS) {

assert(strID == strCount && "Visited all strings.");
(void)strCount;
assert(trnID == trnCount && "Visited all translations.");
(void)trnCount;
assert(hashID == hashCount && "Visited all hashes.");
(void)hashCount;
}

/// NOTE: The output might not show the value of every literal used
Expand Down Expand Up @@ -757,9 +757,9 @@ BytecodeSectionWalker::BytecodeSectionWalker(
bcProvider->getStringKinds().begin(),
bcProvider->getStringKinds().end());
addSection(
"Identifier translations",
bcProvider->getIdentifierTranslations().begin(),
bcProvider->getIdentifierTranslations().end());
"Identifier hashes",
bcProvider->getIdentifierHashes().begin(),
bcProvider->getIdentifierHashes().end());
addSection(
"String table",
bcProvider->getSmallStringTableEntries().begin(),
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ std::unique_ptr<BytecodeModule> BytecodeModuleGenerator::generate() {
"Missing functions.");

auto kinds = stringTable_.getStringKinds();
auto hashes = stringTable_.getIdentifierTranslations();
auto hashes = stringTable_.getIdentifierHashes();

BytecodeOptions bytecodeOptions;
bytecodeOptions.staticBuiltins = options_.staticBuiltinsEnabled;
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/BytecodeProviderFromSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BCProviderFromSrc::BCProviderFromSrc(
globalFunctionIndex_ = module_->getGlobalFunctionIndex();

stringKinds_ = module_->getStringKinds();
identifierTranslations_ = module_->getIdentifierTranslations();
identifierHashes_ = module_->getIdentifierHashes();
stringCount_ = module_->getStringTable().size();
stringStorage_ = module_->getStringStorage();

Expand Down
4 changes: 2 additions & 2 deletions lib/BCGen/HBC/BytecodeStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ void BytecodeSerializer::visitStringKinds() {
writeBinaryArray(bytecodeModule_->getStringKinds());
}

void BytecodeSerializer::visitIdentifierTranslations() {
void BytecodeSerializer::visitIdentifierHashes() {
pad(BYTECODE_ALIGNMENT);
writeBinaryArray(bytecodeModule_->getIdentifierTranslations());
writeBinaryArray(bytecodeModule_->getIdentifierHashes());
}

void BytecodeSerializer::visitSmallStringTable() {
Expand Down
2 changes: 1 addition & 1 deletion lib/BCGen/HBC/UniquingStringLiteralTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ StringLiteralIDMapping::StringLiteralIDMapping(
}
}

std::vector<uint32_t> StringLiteralTable::getIdentifierTranslations() const {
std::vector<uint32_t> StringLiteralTable::getIdentifierHashes() const {
std::vector<uint32_t> result;
assert(strings_.size() == isIdentifier_.size());
for (size_t i = 0; i < strings_.size(); ++i) {
Expand Down
22 changes: 10 additions & 12 deletions lib/VM/RuntimeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,21 @@ void RuntimeModule::importStringIDMapMayAllocate() {
bcProvider_->willNeedStringTable();
}

// Get the array of pre-computed translations from identifiers in the bytecode
// Get the array of pre-computed hashes from identifiers in the bytecode
// to their runtime representation as SymbolIDs.
auto kinds = bcProvider_->getStringKinds();
auto translations = bcProvider_->getIdentifierTranslations();
auto hashes = bcProvider_->getIdentifierHashes();
assert(
translations.size() <= strTableSize &&
hashes.size() <= strTableSize &&
"Should not have more strings than identifiers");

// Preallocate enough space to store all identifiers to prevent
// unnecessary allocations. NOTE: If this module is not the first module,
// then this is an underestimate.
runtime_->getIdentifierTable().reserve(translations.size());
runtime_->getIdentifierTable().reserve(hashes.size());
{
StringID strID = 0;
uint32_t trnID = 0;
uint32_t hashID = 0;

for (auto entry : kinds) {
switch (entry.kind()) {
Expand All @@ -259,18 +259,16 @@ void RuntimeModule::importStringIDMapMayAllocate() {
break;

case StringKind::Identifier:
for (uint32_t i = 0; i < entry.count(); ++i, ++strID, ++trnID) {
for (uint32_t i = 0; i < entry.count(); ++i, ++strID, ++hashID) {
createSymbolFromStringIDMayAllocate(
strID,
bcProvider_->getStringTableEntry(strID),
translations[trnID]);
strID, bcProvider_->getStringTableEntry(strID), hashes[hashID]);
}
break;
}
}

assert(strID == strTableSize && "Should map every string in the bytecode.");
assert(trnID == translations.size() && "Should translate all identifiers.");
assert(hashID == hashes.size() && "Should hash all identifiers.");
}

if (runtime_->getVMExperimentFlags() & experiments::MAdviseStringsRandom) {
Expand All @@ -292,8 +290,8 @@ void RuntimeModule::importStringIDMapMayAllocate() {
mapStringMayAllocate(s, 0, hashString(s));
}

// Done with translations, so advise them out if possible.
bcProvider_->dontNeedIdentifierTranslations();
// Done with hashes, so advise them out if possible.
bcProvider_->dontNeedIdentifierHashes();
}

void RuntimeModule::initializeFunctionMap() {
Expand Down
2 changes: 1 addition & 1 deletion tools/hbc-read-trace/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cat <<EOF > "$TMP/expected"
<unknown>
function-table
string-kinds
identifier-translations
identifier-hashes
string-table
overflow-string-table
string-storage
Expand Down

0 comments on commit e4d794a

Please sign in to comment.