Revert "[web snap] Support Symbols"
This reverts commit 1267e51873
.
Reason for revert: Turned out to not support them: https://logs.chromium.org/logs/v8/buildbucket/cr-buildbucket/8815278972589078465/+/u/Bisect_1267e518/Retry/web-snapshot-4
Original change's description:
> [web snap] Support Symbols
>
> Bug: v8:11525,v8:12820
> Change-Id: Ie8b1bbe209d8bb6f759623ea01223a05d11090aa
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3616514
> Commit-Queue: Marja Hölttä <marja@chromium.org>
> Reviewed-by: Camillo Bruni <cbruni@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#80299}
Bug: v8:11525,v8:12820
Change-Id: Ia0107dfec12e72dc976348985e5c35dac28c170a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3620278
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Owners-Override: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#80302}
This commit is contained in:
parent
25e3225286
commit
9b78282370
@ -490,7 +490,6 @@ class RuntimeCallTimer final {
|
||||
V(WebSnapshotDeserialize_Maps) \
|
||||
V(WebSnapshotDeserialize_Objects) \
|
||||
V(WebSnapshotDeserialize_Strings) \
|
||||
V(WebSnapshotDeserialize_Symbols) \
|
||||
V(WrappedFunctionLengthGetter) \
|
||||
V(WrappedFunctionNameGetter)
|
||||
|
||||
|
@ -197,7 +197,6 @@ WebSnapshotSerializer::WebSnapshotSerializer(v8::Isolate* isolate)
|
||||
WebSnapshotSerializer::WebSnapshotSerializer(Isolate* isolate)
|
||||
: WebSnapshotSerializerDeserializer(isolate),
|
||||
string_serializer_(isolate_, nullptr),
|
||||
symbol_serializer_(isolate_, nullptr),
|
||||
map_serializer_(isolate_, nullptr),
|
||||
context_serializer_(isolate_, nullptr),
|
||||
function_serializer_(isolate_, nullptr),
|
||||
@ -207,7 +206,6 @@ WebSnapshotSerializer::WebSnapshotSerializer(Isolate* isolate)
|
||||
export_serializer_(isolate_, nullptr),
|
||||
external_objects_ids_(isolate_->heap()),
|
||||
string_ids_(isolate_->heap()),
|
||||
symbol_ids_(isolate_->heap()),
|
||||
map_ids_(isolate_->heap()),
|
||||
context_ids_(isolate_->heap()),
|
||||
function_ids_(isolate_->heap()),
|
||||
@ -216,14 +214,13 @@ WebSnapshotSerializer::WebSnapshotSerializer(Isolate* isolate)
|
||||
object_ids_(isolate_->heap()),
|
||||
all_strings_(isolate_->heap()) {
|
||||
auto empty_array_list = factory()->empty_array_list();
|
||||
strings_ = empty_array_list;
|
||||
symbols_ = empty_array_list;
|
||||
maps_ = empty_array_list;
|
||||
contexts_ = empty_array_list;
|
||||
functions_ = empty_array_list;
|
||||
classes_ = empty_array_list;
|
||||
arrays_ = empty_array_list;
|
||||
objects_ = empty_array_list;
|
||||
strings_ = empty_array_list;
|
||||
maps_ = empty_array_list;
|
||||
}
|
||||
|
||||
WebSnapshotSerializer::~WebSnapshotSerializer() {}
|
||||
@ -319,11 +316,6 @@ void WebSnapshotSerializer::SerializePendingItems() {
|
||||
SerializeString(string, string_serializer_);
|
||||
}
|
||||
|
||||
for (int i = 0; i < symbols_->Length(); ++i) {
|
||||
Handle<Symbol> symbol = handle(Symbol::cast(symbols_->Get(i)), isolate_);
|
||||
SerializeSymbol(symbol);
|
||||
}
|
||||
|
||||
for (int i = 0; i < maps_->Length(); ++i) {
|
||||
Handle<Map> map = handle(Map::cast(maps_->Get(i)), isolate_);
|
||||
SerializeMap(map);
|
||||
@ -363,9 +355,6 @@ void WebSnapshotSerializer::SerializePendingItems() {
|
||||
// - String count
|
||||
// - For each string:
|
||||
// - Serialized string
|
||||
// - Symbol count
|
||||
// - For each symbol:
|
||||
// - Serialized symbol
|
||||
// - Shape count
|
||||
// - For each shape:
|
||||
// - Serialized shape
|
||||
@ -391,11 +380,10 @@ void WebSnapshotSerializer::WriteSnapshot(uint8_t*& buffer,
|
||||
ValueSerializer total_serializer(isolate_, nullptr);
|
||||
size_t needed_size =
|
||||
sizeof(kMagicNumber) + string_serializer_.buffer_size_ +
|
||||
symbol_serializer_.buffer_size_ + map_serializer_.buffer_size_ +
|
||||
context_serializer_.buffer_size_ + function_serializer_.buffer_size_ +
|
||||
class_serializer_.buffer_size_ + array_serializer_.buffer_size_ +
|
||||
object_serializer_.buffer_size_ + export_serializer_.buffer_size_ +
|
||||
8 * sizeof(uint32_t);
|
||||
map_serializer_.buffer_size_ + context_serializer_.buffer_size_ +
|
||||
function_serializer_.buffer_size_ + class_serializer_.buffer_size_ +
|
||||
array_serializer_.buffer_size_ + object_serializer_.buffer_size_ +
|
||||
export_serializer_.buffer_size_ + 8 * sizeof(uint32_t);
|
||||
if (total_serializer.ExpandBuffer(needed_size).IsNothing()) {
|
||||
Throw("Out of memory");
|
||||
return;
|
||||
@ -403,7 +391,6 @@ void WebSnapshotSerializer::WriteSnapshot(uint8_t*& buffer,
|
||||
|
||||
total_serializer.WriteRawBytes(kMagicNumber, 4);
|
||||
WriteObjects(total_serializer, string_count(), string_serializer_, "strings");
|
||||
WriteObjects(total_serializer, symbol_count(), symbol_serializer_, "symbols");
|
||||
WriteObjects(total_serializer, map_count(), map_serializer_, "maps");
|
||||
WriteObjects(total_serializer, context_count(), context_serializer_,
|
||||
"contexts");
|
||||
@ -471,23 +458,6 @@ void WebSnapshotSerializer::SerializeString(Handle<String> string,
|
||||
}
|
||||
}
|
||||
|
||||
// Format (serialized symbol):
|
||||
// - 0 if the symbol is non-global and there's no description, 1 if the symbol
|
||||
// is non-global and there is a description, 2 if the symbol is global (there
|
||||
// must be a description).
|
||||
void WebSnapshotSerializer::SerializeSymbol(Handle<Symbol> symbol) {
|
||||
if (symbol->description().IsUndefined()) {
|
||||
CHECK(!symbol->is_in_public_symbol_table());
|
||||
symbol_serializer_.WriteUint32(SymbolType::NonGlobalNoDesription);
|
||||
} else {
|
||||
symbol_serializer_.WriteUint32(symbol->is_in_public_symbol_table()
|
||||
? SymbolType::Global
|
||||
: SymbolType::NonGlobal);
|
||||
WriteStringId(handle(String::cast(symbol->description()), isolate_),
|
||||
symbol_serializer_);
|
||||
}
|
||||
}
|
||||
|
||||
// Format (serialized shape):
|
||||
// - PropertyAttributesType
|
||||
// - 0 if the __proto__ is Object.prototype, 1 + object id for the __proto__
|
||||
@ -679,9 +649,6 @@ void WebSnapshotSerializer::Discover(Handle<HeapObject> start_object) {
|
||||
case JS_ARRAY_TYPE:
|
||||
DiscoverArray(Handle<JSArray>::cast(object));
|
||||
break;
|
||||
case SYMBOL_TYPE:
|
||||
DiscoverSymbol(Handle<Symbol>::cast(object));
|
||||
break;
|
||||
case ODDBALL_TYPE:
|
||||
case HEAP_NUMBER_TYPE:
|
||||
// Can't contain references to other objects.
|
||||
@ -928,18 +895,6 @@ void WebSnapshotSerializer::DiscoverObject(Handle<JSObject> object) {
|
||||
}
|
||||
}
|
||||
|
||||
void WebSnapshotSerializer::DiscoverSymbol(Handle<Symbol> symbol) {
|
||||
uint32_t id;
|
||||
if (InsertIntoIndexMap(symbol_ids_, *symbol, id)) return;
|
||||
|
||||
DCHECK_EQ(id, symbols_->Length());
|
||||
symbols_ = ArrayList::Add(isolate_, symbols_, symbol);
|
||||
|
||||
if (!symbol->description().IsUndefined()) {
|
||||
DiscoverString(handle(String::cast(symbol->description()), isolate_));
|
||||
}
|
||||
}
|
||||
|
||||
// Format (serialized function):
|
||||
// - 0 if there's no context, 1 + context id otherwise
|
||||
// - String id (source snippet)
|
||||
@ -1162,10 +1117,6 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object,
|
||||
serializer.WriteUint32(ValueType::ARRAY_ID);
|
||||
serializer.WriteUint32(GetArrayId(JSArray::cast(*heap_object)));
|
||||
break;
|
||||
case SYMBOL_TYPE:
|
||||
serializer.WriteUint32(ValueType::SYMBOL_ID);
|
||||
serializer.WriteUint32(GetSymbolId(Symbol::cast(*heap_object)));
|
||||
break;
|
||||
case JS_REG_EXP_TYPE: {
|
||||
Handle<JSRegExp> regexp = Handle<JSRegExp>::cast(heap_object);
|
||||
if (regexp->map() != isolate_->regexp_function()->initial_map()) {
|
||||
@ -1229,14 +1180,6 @@ uint32_t WebSnapshotSerializer::GetStringId(Handle<String> string,
|
||||
return static_cast<uint32_t>(id);
|
||||
}
|
||||
|
||||
uint32_t WebSnapshotSerializer::GetSymbolId(Symbol symbol) {
|
||||
int id;
|
||||
bool return_value = symbol_ids_.Lookup(symbol, &id);
|
||||
DCHECK(return_value);
|
||||
USE(return_value);
|
||||
return static_cast<uint32_t>(id);
|
||||
}
|
||||
|
||||
uint32_t WebSnapshotSerializer::GetMapId(Map map) {
|
||||
int id;
|
||||
bool return_value = map_ids_.Lookup(map, &id);
|
||||
@ -1318,7 +1261,6 @@ WebSnapshotDeserializer::WebSnapshotDeserializer(
|
||||
roots_(isolate) {
|
||||
Handle<FixedArray> empty_array = factory()->empty_fixed_array();
|
||||
strings_handle_ = empty_array;
|
||||
symbols_handle_ = empty_array;
|
||||
maps_handle_ = empty_array;
|
||||
contexts_handle_ = empty_array;
|
||||
functions_handle_ = empty_array;
|
||||
@ -1336,7 +1278,6 @@ WebSnapshotDeserializer::~WebSnapshotDeserializer() {
|
||||
|
||||
void WebSnapshotDeserializer::UpdatePointers() {
|
||||
strings_ = *strings_handle_;
|
||||
symbols_ = *strings_handle_;
|
||||
maps_ = *maps_handle_;
|
||||
contexts_ = *contexts_handle_;
|
||||
functions_ = *functions_handle_;
|
||||
@ -1401,7 +1342,6 @@ base::Vector<const uint8_t> WebSnapshotDeserializer::ExtractScriptBuffer(
|
||||
|
||||
void WebSnapshotDeserializer::Throw(const char* message) {
|
||||
string_count_ = 0;
|
||||
symbol_count_ = 0;
|
||||
map_count_ = 0;
|
||||
context_count_ = 0;
|
||||
class_count_ = 0;
|
||||
@ -1461,7 +1401,6 @@ bool WebSnapshotDeserializer::DeserializeSnapshot(bool skip_exports) {
|
||||
}
|
||||
|
||||
DeserializeStrings();
|
||||
DeserializeSymbols();
|
||||
DeserializeMaps();
|
||||
DeserializeContexts();
|
||||
DeserializeFunctions();
|
||||
@ -1562,54 +1501,6 @@ String WebSnapshotDeserializer::ReadInPlaceString(bool internalize) {
|
||||
return *string;
|
||||
}
|
||||
|
||||
Object WebSnapshotDeserializer::ReadSymbol() {
|
||||
DCHECK(!strings_handle_->is_null());
|
||||
uint32_t symbol_id;
|
||||
if (!deserializer_.ReadUint32(&symbol_id) || symbol_id >= symbol_count_) {
|
||||
Throw("malformed symbol id\n");
|
||||
return roots_.undefined_value();
|
||||
}
|
||||
return symbols_.get(symbol_id);
|
||||
}
|
||||
|
||||
void WebSnapshotDeserializer::DeserializeSymbols() {
|
||||
RCS_SCOPE(isolate_, RuntimeCallCounterId::kWebSnapshotDeserialize_Symbols);
|
||||
if (!deserializer_.ReadUint32(&symbol_count_) ||
|
||||
symbol_count_ > kMaxItemCount) {
|
||||
Throw("Malformed symbol table");
|
||||
return;
|
||||
}
|
||||
STATIC_ASSERT(kMaxItemCount <= FixedArray::kMaxLength);
|
||||
symbols_handle_ = factory()->NewFixedArray(symbol_count_);
|
||||
symbols_ = *symbols_handle_;
|
||||
for (uint32_t i = 0; i < symbol_count_; ++i) {
|
||||
uint32_t symbol_type;
|
||||
if (!deserializer_.ReadUint32(&symbol_type) || symbol_type > 2) {
|
||||
Throw("malformed symbol\n");
|
||||
}
|
||||
|
||||
Handle<Symbol> symbol;
|
||||
if (symbol_type == SymbolType::NonGlobalNoDesription) {
|
||||
symbol = factory()->NewSymbol();
|
||||
} else { // Symbol with description
|
||||
uint32_t string_id;
|
||||
if (!deserializer_.ReadUint32(&string_id) || string_id >= string_count_) {
|
||||
Throw("malformed string id\n");
|
||||
}
|
||||
if (symbol_type == SymbolType::NonGlobal) {
|
||||
symbol = factory()->NewSymbol();
|
||||
symbol->set_description(String::cast(strings_.get(string_id)));
|
||||
} else {
|
||||
DCHECK_EQ(SymbolType::Global, symbol_type);
|
||||
symbol = isolate_->SymbolFor(
|
||||
RootIndex::kPublicSymbolTable,
|
||||
handle(String::cast(strings_.get(string_id)), isolate_), false);
|
||||
}
|
||||
}
|
||||
symbols_.set(i, *symbol);
|
||||
}
|
||||
}
|
||||
|
||||
void WebSnapshotDeserializer::DeserializeMaps() {
|
||||
RCS_SCOPE(isolate_, RuntimeCallCounterId::kWebSnapshotDeserialize_Maps);
|
||||
if (!deserializer_.ReadUint32(&map_count_) || map_count_ > kMaxItemCount) {
|
||||
@ -2301,8 +2192,6 @@ Object WebSnapshotDeserializer::ReadValue(Handle<HeapObject> container,
|
||||
return ReadClass(container, container_index);
|
||||
case ValueType::REGEXP:
|
||||
return ReadRegexp();
|
||||
case ValueType::SYMBOL_ID:
|
||||
return ReadSymbol();
|
||||
case ValueType::EXTERNAL_ID:
|
||||
return ReadExternalReference();
|
||||
case ValueType::IN_PLACE_STRING_ID:
|
||||
|
@ -47,23 +47,16 @@ class WebSnapshotSerializerDeserializer {
|
||||
UNDEFINED_CONSTANT,
|
||||
INTEGER,
|
||||
DOUBLE,
|
||||
REGEXP,
|
||||
STRING_ID,
|
||||
ARRAY_ID,
|
||||
OBJECT_ID,
|
||||
FUNCTION_ID,
|
||||
CLASS_ID,
|
||||
SYMBOL_ID,
|
||||
REGEXP,
|
||||
EXTERNAL_ID,
|
||||
IN_PLACE_STRING_ID
|
||||
};
|
||||
|
||||
enum SymbolType : uint8_t {
|
||||
NonGlobalNoDesription = 0,
|
||||
NonGlobal = 2,
|
||||
Global = 1
|
||||
};
|
||||
|
||||
static constexpr uint8_t kMagicNumber[4] = {'+', '+', '+', ';'};
|
||||
|
||||
enum ContextType : uint8_t { FUNCTION, BLOCK };
|
||||
@ -138,10 +131,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
return static_cast<uint32_t>(string_ids_.size());
|
||||
}
|
||||
|
||||
uint32_t symbol_count() const {
|
||||
return static_cast<uint32_t>(symbol_ids_.size());
|
||||
}
|
||||
|
||||
uint32_t map_count() const { return static_cast<uint32_t>(map_ids_.size()); }
|
||||
|
||||
uint32_t context_count() const {
|
||||
@ -192,7 +181,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
void Discover(Handle<HeapObject> object);
|
||||
void DiscoverString(Handle<String> string,
|
||||
AllowInPlace can_be_in_place = AllowInPlace::No);
|
||||
void DiscoverSymbol(Handle<Symbol> symbol);
|
||||
void DiscoverMap(Handle<Map> map);
|
||||
void DiscoverFunction(Handle<JSFunction> function);
|
||||
void DiscoverClass(Handle<JSFunction> function);
|
||||
@ -207,7 +195,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
Handle<JSFunction> function);
|
||||
|
||||
void SerializeString(Handle<String> string, ValueSerializer& serializer);
|
||||
void SerializeSymbol(Handle<Symbol> symbol);
|
||||
void SerializeMap(Handle<Map> map);
|
||||
void SerializeFunction(Handle<JSFunction> function);
|
||||
void SerializeClass(Handle<JSFunction> function);
|
||||
@ -222,7 +209,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
void WriteStringId(Handle<String> string, ValueSerializer& serializer);
|
||||
|
||||
uint32_t GetStringId(Handle<String> string, bool& in_place);
|
||||
uint32_t GetSymbolId(Symbol symbol);
|
||||
uint32_t GetMapId(Map map);
|
||||
uint32_t GetFunctionId(JSFunction function);
|
||||
uint32_t GetClassId(JSFunction function);
|
||||
@ -232,7 +218,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
uint32_t GetExternalId(HeapObject object);
|
||||
|
||||
ValueSerializer string_serializer_;
|
||||
ValueSerializer symbol_serializer_;
|
||||
ValueSerializer map_serializer_;
|
||||
ValueSerializer context_serializer_;
|
||||
ValueSerializer function_serializer_;
|
||||
@ -242,14 +227,13 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
ValueSerializer export_serializer_;
|
||||
|
||||
// These are needed for being able to serialize items in order.
|
||||
Handle<ArrayList> strings_;
|
||||
Handle<ArrayList> symbols_;
|
||||
Handle<ArrayList> maps_;
|
||||
Handle<ArrayList> contexts_;
|
||||
Handle<ArrayList> functions_;
|
||||
Handle<ArrayList> classes_;
|
||||
Handle<ArrayList> arrays_;
|
||||
Handle<ArrayList> objects_;
|
||||
Handle<ArrayList> strings_;
|
||||
Handle<ArrayList> maps_;
|
||||
|
||||
// IndexMap to keep track of explicitly blocked external objects and
|
||||
// non-serializable/not-supported objects (e.g. API Objects).
|
||||
@ -260,7 +244,6 @@ class V8_EXPORT WebSnapshotSerializer
|
||||
// them in the reverse order. This ensures that the items this item points to
|
||||
// have a lower ID and will be deserialized first.
|
||||
ObjectCacheIndexMap string_ids_;
|
||||
ObjectCacheIndexMap symbol_ids_;
|
||||
ObjectCacheIndexMap map_ids_;
|
||||
ObjectCacheIndexMap context_ids_;
|
||||
ObjectCacheIndexMap function_ids_;
|
||||
@ -300,7 +283,6 @@ class V8_EXPORT WebSnapshotDeserializer
|
||||
|
||||
// For inspecting the state after deserializing a snapshot.
|
||||
uint32_t string_count() const { return string_count_; }
|
||||
uint32_t symbol_count() const { return symbol_count_; }
|
||||
uint32_t map_count() const { return map_count_; }
|
||||
uint32_t context_count() const { return context_count_; }
|
||||
uint32_t function_count() const { return function_count_; }
|
||||
@ -330,7 +312,6 @@ class V8_EXPORT WebSnapshotDeserializer
|
||||
WebSnapshotDeserializer& operator=(const WebSnapshotDeserializer&) = delete;
|
||||
|
||||
void DeserializeStrings();
|
||||
void DeserializeSymbols();
|
||||
void DeserializeMaps();
|
||||
void DeserializeContexts();
|
||||
Handle<ScopeInfo> CreateScopeInfo(uint32_t variable_count, bool has_parent,
|
||||
@ -354,7 +335,6 @@ class V8_EXPORT WebSnapshotDeserializer
|
||||
Object ReadNumber();
|
||||
String ReadString(bool internalize = false);
|
||||
String ReadInPlaceString(bool internalize = false);
|
||||
Object ReadSymbol();
|
||||
Object ReadArray(Handle<HeapObject> container, uint32_t container_index);
|
||||
Object ReadObject(Handle<HeapObject> container, uint32_t container_index);
|
||||
Object ReadFunction(Handle<HeapObject> container, uint32_t container_index);
|
||||
@ -375,9 +355,6 @@ class V8_EXPORT WebSnapshotDeserializer
|
||||
Handle<FixedArray> strings_handle_;
|
||||
FixedArray strings_;
|
||||
|
||||
Handle<FixedArray> symbols_handle_;
|
||||
FixedArray symbols_;
|
||||
|
||||
Handle<FixedArray> maps_handle_;
|
||||
FixedArray maps_;
|
||||
|
||||
@ -412,7 +389,6 @@ class V8_EXPORT WebSnapshotDeserializer
|
||||
Handle<Object> return_value_;
|
||||
|
||||
uint32_t string_count_ = 0;
|
||||
uint32_t symbol_count_ = 0;
|
||||
uint32_t map_count_ = 0;
|
||||
uint32_t context_count_ = 0;
|
||||
uint32_t function_count_ = 0;
|
||||
|
@ -335,26 +335,3 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
|
||||
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
|
||||
assertEquals('bar', foo());
|
||||
})();
|
||||
|
||||
(function TestNonGlobalSymbol() {
|
||||
function createObjects() {
|
||||
const s = Symbol('description');
|
||||
globalThis.foo = {mySymbol: s, innerObject: { symbolHereToo: s}};
|
||||
}
|
||||
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
|
||||
assertEquals(foo.mySymbol, foo.innerObject.symbolHereToo);
|
||||
assertEquals('description', foo.mySymbol.description);
|
||||
assertNotEquals(foo.mySymbol, Symbol('description'));
|
||||
assertNotEquals(foo.mySymbol, Symbol.for('description'));
|
||||
})();
|
||||
|
||||
(function TestNonGlobalSymbol() {
|
||||
function createObjects() {
|
||||
const s = Symbol.for('this is global');
|
||||
globalThis.foo = {mySymbol: s, innerObject: { symbolHereToo: s}};
|
||||
}
|
||||
const {foo} = takeAndUseWebSnapshot(createObjects, ['foo']);
|
||||
assertEquals(foo.mySymbol, foo.innerObject.symbolHereToo);
|
||||
assertEquals('this is global', foo.mySymbol.description);
|
||||
assertEquals(foo.mySymbol, Symbol.for('this is global'));
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user